From 5c8a7d8abb3dc4947946fed01e0c07c5052b37fb Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Sun, 7 Jul 2019 17:09:28 -0700 Subject: [PATCH] Updated time freeze, and fixed many happy birthday bugs regarding gifts and dialogue. --- .../HappyBirthday/Framework/VillagerInfo.cs | 27 +++ GeneralMods/HappyBirthday/HappyBirthday.cs | 213 ++++++++++++++---- .../HappyBirthday/HappyBirthday.csproj | 1 + .../Framework/V2/MusicPackV2.cs | 1 - .../StardewSymphonyRemastered/manifest.json | 2 +- GeneralMods/TimeFreeze/Framework/ModConfig.cs | 6 + GeneralMods/TimeFreeze/TimeFreeze.cs | 9 + GeneralMods/TimeFreeze/manifest.json | 2 +- 8 files changed, 217 insertions(+), 44 deletions(-) create mode 100644 GeneralMods/HappyBirthday/Framework/VillagerInfo.cs diff --git a/GeneralMods/HappyBirthday/Framework/VillagerInfo.cs b/GeneralMods/HappyBirthday/Framework/VillagerInfo.cs new file mode 100644 index 00000000..32731a19 --- /dev/null +++ b/GeneralMods/HappyBirthday/Framework/VillagerInfo.cs @@ -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; + } + + } +} diff --git a/GeneralMods/HappyBirthday/HappyBirthday.cs b/GeneralMods/HappyBirthday/HappyBirthday.cs index 81a222d5..f212612c 100644 --- a/GeneralMods/HappyBirthday/HappyBirthday.cs +++ b/GeneralMods/HappyBirthday/HappyBirthday.cs @@ -43,7 +43,7 @@ namespace Omegasis.HappyBirthday private bool HasChosenBirthday => !string.IsNullOrEmpty(this.PlayerData.BirthdaySeason) && this.PlayerData.BirthdayDay != 0; /// The queue of villagers who haven't given a gift yet. - private List VillagerQueue; + private Dictionary VillagerQueue; /// Whether we've already checked for and (if applicable) set up the player's birthday today. 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(); - } @@ -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((Game1.activeClickableMenu as DialogueBox), "characterDialogue", true); + IReflectedField> dialogues = this.Helper.Reflection.GetField>((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; } } + } /// Raised after the game begins a new day (including when the player loads a save). @@ -307,6 +462,14 @@ namespace Omegasis.HappyBirthday /// The event arguments. 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(); + this.VillagerQueue = new Dictionary(); 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; - } - } } /// Set the player's birthday/ @@ -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()); } } } diff --git a/GeneralMods/HappyBirthday/HappyBirthday.csproj b/GeneralMods/HappyBirthday/HappyBirthday.csproj index a5e12e85..6f54c1d7 100644 --- a/GeneralMods/HappyBirthday/HappyBirthday.csproj +++ b/GeneralMods/HappyBirthday/HappyBirthday.csproj @@ -87,6 +87,7 @@ + diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/V2/MusicPackV2.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/V2/MusicPackV2.cs index 9246649b..099cc2a2 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/V2/MusicPackV2.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/V2/MusicPackV2.cs @@ -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(); } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json index 05adbe38..6964a140 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json @@ -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", diff --git a/GeneralMods/TimeFreeze/Framework/ModConfig.cs b/GeneralMods/TimeFreeze/Framework/ModConfig.cs index 1cd813ff..f4d1c87e 100644 --- a/GeneralMods/TimeFreeze/Framework/ModConfig.cs +++ b/GeneralMods/TimeFreeze/Framework/ModConfig.cs @@ -1,8 +1,12 @@ +using System.Collections.Generic; + namespace Omegasis.TimeFreeze.Framework { /// The mod configuration. internal class ModConfig { + public List LocationsToIgnoreTimeFreeze { get; set; } = new List(); + /// Whether time should be unfrozen while the player is swimming. public bool PassTimeWhileSwimming { get; set; } = true; @@ -15,6 +19,8 @@ namespace Omegasis.TimeFreeze.Framework /// Whether time passes normally inside the skull cavern. public bool PassTimeWhileInsideSkullCave { get; set; } = true; + public bool PassTimeWhileInNightMarketSubmarine { get; set; } = true; + /// Checks if just one player meets the conditions to freeze time, and then freeze time. public bool freezeIfEvenOnePlayerMeetsTimeFreezeConditions { get; set; } = false; diff --git a/GeneralMods/TimeFreeze/TimeFreeze.cs b/GeneralMods/TimeFreeze/TimeFreeze.cs index 2dd9dc90..aea713e1 100644 --- a/GeneralMods/TimeFreeze/TimeFreeze.cs +++ b/GeneralMods/TimeFreeze/TimeFreeze.cs @@ -122,6 +122,8 @@ namespace Omegasis.TimeFreeze /// The location to check. 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; diff --git a/GeneralMods/TimeFreeze/manifest.json b/GeneralMods/TimeFreeze/manifest.json index 2b596628..38608f8e 100644 --- a/GeneralMods/TimeFreeze/manifest.json +++ b/GeneralMods/TimeFreeze/manifest.json @@ -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",