Updated time freeze, and fixed many happy birthday bugs regarding gifts and dialogue.

This commit is contained in:
JoshuaNavarro 2019-07-07 17:09:28 -07:00
parent 9072c57013
commit 5c8a7d8abb
8 changed files with 217 additions and 44 deletions

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Omegasis.HappyBirthday.Framework
{
public class VillagerInfo
{
public bool hasGivenBirthdayWish;
public bool hasGivenBirthdayGift;
public VillagerInfo()
{
this.hasGivenBirthdayGift = false;
this.hasGivenBirthdayWish = false;
}
public void reset()
{
this.hasGivenBirthdayGift = false;
this.hasGivenBirthdayWish = false;
}
}
}

View File

@ -43,7 +43,7 @@ namespace Omegasis.HappyBirthday
private bool HasChosenBirthday => !string.IsNullOrEmpty(this.PlayerData.BirthdaySeason) && this.PlayerData.BirthdayDay != 0;
/// <summary>The queue of villagers who haven't given a gift yet.</summary>
private List<string> VillagerQueue;
private Dictionary<string,VillagerInfo> VillagerQueue;
/// <summary>Whether we've already checked for and (if applicable) set up the player's birthday today.</summary>
private bool CheckedForBirthday;
@ -67,6 +67,8 @@ namespace Omegasis.HappyBirthday
public static HappyBirthday Instance;
private NPC lastSpeaker;
/*********
** Public methods
*********/
@ -102,7 +104,6 @@ namespace Omegasis.HappyBirthday
ModHelper.Events.Multiplayer.PeerDisconnected += this.Multiplayer_PeerDisconnected;
this.othersBirthdays = new Dictionary<long, PlayerData>();
}
@ -253,6 +254,8 @@ namespace Omegasis.HappyBirthday
IClickableMenu.drawHoverText(Game1.spriteBatch, hoverText, Game1.dialogueFont, 0, 0, -1, (string)null, -1, (string[])null, (Item)null, 0, -1, -1, -1, -1, 1f, (CraftingRecipe)null);
}
}
(Game1.activeClickableMenu).drawMouse(e.SpriteBatch);
}
}
@ -265,6 +268,20 @@ namespace Omegasis.HappyBirthday
{
case null:
this.isDailyQuestBoard = false;
//Validate the gift and give it to the player.
if (this.lastSpeaker != null)
{
if (this.giftManager.BirthdayGiftToReceive != null && this.VillagerQueue[this.lastSpeaker.Name].hasGivenBirthdayGift == false)
{
while (this.giftManager.BirthdayGiftToReceive.Name == "Error Item" || this.giftManager.BirthdayGiftToReceive.Name == "Rock" || this.giftManager.BirthdayGiftToReceive.Name == "???")
this.giftManager.SetNextBirthdayGift(this.lastSpeaker.Name);
Game1.player.addItemByMenuIfNecessaryElseHoldUp(this.giftManager.BirthdayGiftToReceive);
this.giftManager.BirthdayGiftToReceive = null;
this.VillagerQueue[this.lastSpeaker.Name].hasGivenBirthdayGift = true;
this.lastSpeaker = null;
}
}
return;
case Billboard billboard:
@ -297,9 +314,147 @@ namespace Omegasis.HappyBirthday
billboard.calendarDays.Add(new ClickableTextureComponent("", otherBirthdayRect, "", $"{Game1.getFarmer(pair.Key).Name}'s Birthday", text, new Rectangle(0, 0, 124, 124), 1f, false));
}
break;
}
case DialogueBox dBox:
{
if (Game1.eventUp) return;
//Hijack the dialogue box and ensure that birthday dialogue gets spoken.
if (Game1.currentSpeaker != null)
{
this.lastSpeaker = Game1.currentSpeaker;
if (Game1.activeClickableMenu != null && this.IsBirthday() && this.VillagerQueue.ContainsKey(Game1.currentSpeaker.Name))
{
if ((Game1.player.getFriendshipHeartLevelForNPC(Game1.currentSpeaker.Name) < Config.minimumFriendshipLevelForBirthdayWish)) return;
if (Game1.activeClickableMenu is StardewValley.Menus.DialogueBox && this.VillagerQueue[Game1.currentSpeaker.Name].hasGivenBirthdayWish==false && (Game1.player.getFriendshipHeartLevelForNPC(Game1.currentSpeaker.Name) >= Config.minimumFriendshipLevelForBirthdayWish))
{
IReflectedField < Dialogue > cDialogue= this.Helper.Reflection.GetField<Dialogue>((Game1.activeClickableMenu as DialogueBox), "characterDialogue", true);
IReflectedField<List<string>> dialogues = this.Helper.Reflection.GetField<List<string>>((Game1.activeClickableMenu as DialogueBox), "dialogues", true);
string dialogueMessage = "";
if (Game1.player.getSpouse() != null)
{
if (this.messages.spouseBirthdayWishes.ContainsKey(Game1.currentSpeaker.Name))
{
dialogueMessage = this.messages.spouseBirthdayWishes[Game1.currentSpeaker.Name];
}
else
{
dialogueMessage = "Happy Birthday @!";
}
}
else
{
if (this.messages.birthdayWishes.ContainsKey(Game1.currentSpeaker.Name))
{
dialogueMessage = this.messages.birthdayWishes[Game1.currentSpeaker.Name];
}
else
{
dialogueMessage = "Happy Birthday @!";
}
}
dialogueMessage = dialogueMessage.Replace("@", Game1.player.Name);
if (dialogues.GetValue().Contains(dialogueMessage))
{
string name = Game1.currentSpeaker.Name;
this.VillagerQueue[Game1.currentSpeaker.Name].hasGivenBirthdayWish = true;
/*
if (this.IsBirthday() && this.VillagerQueue[Game1.currentSpeaker.Name].hasGivenBirthdayGift==false && Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minNeutralFriendshipGiftLevel)
{
try
{
this.giftManager.SetNextBirthdayGift(Game1.currentSpeaker.Name);
this.Monitor.Log("Setting next birthday gift.");
}
catch (Exception ex)
{
this.Monitor.Log(ex.ToString(), LogLevel.Error);
}
}
*/
return;
}
if (cDialogue.GetValue() != null)
{
if (cDialogue.GetValue().getCurrentDialogue() == dialogueMessage)
{
string name = Game1.currentSpeaker.Name;
this.VillagerQueue[Game1.currentSpeaker.Name].hasGivenBirthdayWish = true;
if (this.IsBirthday() && this.VillagerQueue[Game1.currentSpeaker.Name].hasGivenBirthdayGift == false && Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minNeutralFriendshipGiftLevel)
{
try
{
this.giftManager.SetNextBirthdayGift(Game1.currentSpeaker.Name);
this.Monitor.Log("Setting next birthday gift. 3");
}
catch (Exception ex)
{
this.Monitor.Log(ex.ToString(), LogLevel.Error);
}
}
return;
}
}
Dialogue d;
if (Game1.player.getSpouse() != null)
{
if (this.messages.spouseBirthdayWishes.ContainsKey(Game1.currentSpeaker.Name))
{
d = new Dialogue(this.messages.spouseBirthdayWishes[Game1.currentSpeaker.Name], Game1.currentSpeaker);
}
else
{
d = new Dialogue("Happy Birthday @!", Game1.currentSpeaker);
}
}
else
{
if (this.messages.birthdayWishes.ContainsKey(Game1.currentSpeaker.Name))
{
d = new Dialogue(this.messages.birthdayWishes[Game1.currentSpeaker.Name], Game1.currentSpeaker);
}
else
{
d = new Dialogue("Happy Birthday @!", Game1.currentSpeaker);
}
}
Game1.currentSpeaker.resetCurrentDialogue();
Game1.currentSpeaker.resetSeasonalDialogue();
this.Helper.Reflection.GetMethod(Game1.currentSpeaker, "loadCurrentDialogue", true).Invoke();
Game1.npcDialogues[Game1.currentSpeaker.Name] = Game1.currentSpeaker.CurrentDialogue;
if (this.IsBirthday() && this.VillagerQueue[Game1.currentSpeaker.Name].hasGivenBirthdayGift == false && Game1.player.getFriendshipHeartLevelForNPC(Game1.currentSpeaker.Name) >= Config.minNeutralFriendshipGiftLevel)
{
try
{
this.giftManager.SetNextBirthdayGift(Game1.currentSpeaker.Name);
this.Monitor.Log("Setting next birthday gift. 1");
}
catch (Exception ex)
{
this.Monitor.Log(ex.ToString(), LogLevel.Error);
}
}
Game1.activeClickableMenu = new DialogueBox(d);
this.VillagerQueue[Game1.currentSpeaker.Name].hasGivenBirthdayWish = true;
// Set birthday gift for the player to recieve from the npc they are currently talking with.
}
}
}
break;
}
}
}
/// <summary>Raised after the game begins a new day (including when the player loads a save).</summary>
@ -307,6 +462,14 @@ namespace Omegasis.HappyBirthday
/// <param name="e">The event arguments.</param>
private void OnDayStarted(object sender, DayStartedEventArgs e)
{
try
{
this.ResetVillagerQueue();
}
catch (Exception ex)
{
this.Monitor.Log(ex.ToString(), LogLevel.Error);
}
this.CheckedForBirthday = false;
}
@ -329,7 +492,7 @@ namespace Omegasis.HappyBirthday
this.DataFilePath = Path.Combine("data", $"{Game1.player.Name}_{Game1.player.UniqueMultiplayerID}.json");
// reset state
this.VillagerQueue = new List<string>();
this.VillagerQueue = new Dictionary<string, VillagerInfo>();
this.CheckedForBirthday = false;
// load settings
@ -364,6 +527,7 @@ namespace Omegasis.HappyBirthday
if (!Context.IsWorldReady || Game1.eventUp || Game1.isFestival())
return;
if (!this.HasChosenBirthday && Game1.activeClickableMenu == null && Game1.player.Name.ToLower() != "unnamed farmhand")
{
Game1.activeClickableMenu = new BirthdayMenu(this.PlayerData.BirthdaySeason, this.PlayerData.BirthdayDay, this.SetBirthday);
@ -388,14 +552,7 @@ namespace Omegasis.HappyBirthday
Game1.player.mailbox.Add("birthdayMom");
Game1.player.mailbox.Add("birthdayDad");
try
{
this.ResetVillagerQueue();
}
catch (Exception ex)
{
this.Monitor.Log(ex.ToString(), LogLevel.Error);
}
foreach (GameLocation location in Game1.locations)
{
foreach (NPC npc in location.characters)
@ -429,7 +586,7 @@ namespace Omegasis.HappyBirthday
//Load in
Dialogue d = new Dialogue(this.messages.birthdayWishes[npc.Name], npc);
npc.CurrentDialogue.Push(d);
if (npc.CurrentDialogue.ElementAt(0) != d) npc.setNewDialogue(this.messages.birthdayWishes[npc.Name]);
if (npc.CurrentDialogue.Peek() != d) npc.setNewDialogue(this.messages.birthdayWishes[npc.Name]);
}
}
}
@ -439,7 +596,7 @@ namespace Omegasis.HappyBirthday
{
Dialogue d = new Dialogue("Happy Birthday @!", npc);
npc.CurrentDialogue.Push(d);
if (npc.CurrentDialogue.ElementAt(0) != d)
if (npc.CurrentDialogue.Peek() != d)
npc.setNewDialogue("Happy Birthday @!");
}
}
@ -459,33 +616,7 @@ namespace Omegasis.HappyBirthday
}
}
// Set birthday gift for the player to recieve from the npc they are currently talking with.
if (Game1.currentSpeaker != null)
{
string name = Game1.currentSpeaker.Name;
if (Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.minNeutralFriendshipGiftLevel) return;
if (this.IsBirthday() && this.VillagerQueue.Contains(name))
{
try
{
this.giftManager.SetNextBirthdayGift(Game1.currentSpeaker.Name);
this.VillagerQueue.Remove(Game1.currentSpeaker.Name);
}
catch (Exception ex)
{
this.Monitor.Log(ex.ToString(), LogLevel.Error);
}
}
//Validate the gift and give it to the player.
if (this.giftManager.BirthdayGiftToReceive != null)
{
while (this.giftManager.BirthdayGiftToReceive.Name == "Error Item" || this.giftManager.BirthdayGiftToReceive.Name == "Rock" || this.giftManager.BirthdayGiftToReceive.Name == "???")
this.giftManager.SetNextBirthdayGift(Game1.currentSpeaker.Name);
Game1.player.addItemByMenuIfNecessaryElseHoldUp(this.giftManager.BirthdayGiftToReceive);
this.giftManager.BirthdayGiftToReceive = null;
}
}
}
/// <summary>Set the player's birthday/</summary>
@ -508,9 +639,9 @@ namespace Omegasis.HappyBirthday
{
if (npc is Child || npc is Horse || npc is Junimo || npc is Monster || npc is Pet)
continue;
if (this.VillagerQueue.Contains(npc.Name))
if (this.VillagerQueue.ContainsKey(npc.Name))
continue;
this.VillagerQueue.Add(npc.Name);
this.VillagerQueue.Add(npc.Name,new VillagerInfo());
}
}
}

View File

@ -87,6 +87,7 @@
<Compile Include="Framework\MultiplayerSupport.cs" />
<Compile Include="Framework\PlayerData.cs" />
<Compile Include="Framework\TranslationInfo.cs" />
<Compile Include="Framework\VillagerInfo.cs" />
<Compile Include="HappyBirthday.cs" />
<Compile Include="Framework\Messages.cs" />
<Compile Include="Framework\ObjectUtility.cs" />

View File

@ -111,7 +111,6 @@ namespace StardewSymphonyRemastered.Framework.V2
StardewSymphony.ModMonitor.Log(dataFolder.FullName);
foreach (FileInfo file in dataFolder.GetFiles())
{
StardewSymphony.ModMonitor.Log("Delete the file!");
file.Delete();
}

View File

@ -1,7 +1,7 @@
{
"Name": "Stardew Symphony Remastered",
"Author": "Alpha_Omegasis",
"Version": "2.5.2",
"Version": "3.0.0",
"Description": "Adding more music to the game one beep at a time. Now with streaming!",
"UniqueID": "Omegasis.StardewSymphonyRemastered",
"EntryDll": "StardewSymphonyRemastered.dll",

View File

@ -1,8 +1,12 @@
using System.Collections.Generic;
namespace Omegasis.TimeFreeze.Framework
{
/// <summary>The mod configuration.</summary>
internal class ModConfig
{
public List<string> LocationsToIgnoreTimeFreeze { get; set; } = new List<string>();
/// <summary>Whether time should be unfrozen while the player is swimming.</summary>
public bool PassTimeWhileSwimming { get; set; } = true;
@ -15,6 +19,8 @@ namespace Omegasis.TimeFreeze.Framework
/// <summary>Whether time passes normally inside the skull cavern.</summary>
public bool PassTimeWhileInsideSkullCave { get; set; } = true;
public bool PassTimeWhileInNightMarketSubmarine { get; set; } = true;
/// <summary>Checks if just one player meets the conditions to freeze time, and then freeze time.</summary>
public bool freezeIfEvenOnePlayerMeetsTimeFreezeConditions { get; set; } = false;

View File

@ -122,6 +122,8 @@ namespace Omegasis.TimeFreeze
/// <param name="location">The location to check.</param>
private bool ShouldFreezeTime(Farmer player, GameLocation location)
{
if (this.Config.LocationsToIgnoreTimeFreeze.Contains(location.Name)) return false;
if (this.Config.PassTimeWhileInsideMine)
{
if (location.Name == "Mine" || location.Name.StartsWith("UndergroundMine"))
@ -133,6 +135,13 @@ namespace Omegasis.TimeFreeze
if (location.Name == "SkullCave" || location.Name.StartsWith("SkullCave"))
return false;
}
else
{
if (location.Name == "SkullCave" || location.Name.StartsWith("SkullCave"))
return true;
}
if (this.Config.PassTimeWhileInNightMarketSubmarine && location is Submarine) return false; //Pass time in the night market submarine.
if (location.IsOutdoors)
return false;

View File

@ -1,7 +1,7 @@
{
"Name": "Time Freeze",
"Author": "Alpha_Omegasis",
"Version": "1.7.0",
"Version": "1.8.0",
"Description": "Emulates old Harvest Moon-style games where time is frozen inside.",
"UniqueID": "Omegasis.TimeFreeze",
"EntryDll": "TimeFreeze.dll",