From f5db7501f4036a9946b4263eb2a0ccf17ac54021 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Wed, 4 Dec 2019 18:14:45 -0800 Subject: [PATCH] Got the set up for events! Now to make them!. --- GeneralMods/HappyBirthday/BirthdayEvents.cs | 26 ---------- .../HappyBirthday/Framework/BirthdayEvents.cs | 31 ++++++++++++ .../HappyBirthday/Framework/BirthdayMenu.cs | 2 +- .../Framework/Events/EventHelper.cs | 24 ++++++---- .../Framework/Events/EventManager.cs | 48 +++++++++++++++++++ .../Framework/Events/EventStartData.cs | 3 +- .../Framework/TranslationInfo.cs | 2 +- GeneralMods/HappyBirthday/HappyBirthday.cs | 34 +++++++++---- .../HappyBirthday/HappyBirthday.csproj | 3 +- 9 files changed, 125 insertions(+), 48 deletions(-) delete mode 100644 GeneralMods/HappyBirthday/BirthdayEvents.cs create mode 100644 GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs create mode 100644 GeneralMods/HappyBirthday/Framework/Events/EventManager.cs diff --git a/GeneralMods/HappyBirthday/BirthdayEvents.cs b/GeneralMods/HappyBirthday/BirthdayEvents.cs deleted file mode 100644 index 8da384ae..00000000 --- a/GeneralMods/HappyBirthday/BirthdayEvents.cs +++ /dev/null @@ -1,26 +0,0 @@ -using StardewValley; - -namespace Omegasis.HappyBirthday -{ - // TODO: Make all the events - // Resources:https://stardewvalleywiki.com/Modding:Event_data - public class BirthdayEvents - { - public Event communityCenterJunimoEvent; - public Event marriedNoKidsEvent; - public Event surpriseBirthdayPartyEvent; - public Event marriedWithOneKidEvent; - public Event marriedWithTwoKidsEvent; - - public BirthdayEvents() - { - this.initializeEvents(); - } - - public void initializeEvents() - { - Event e = new Event("", -1, Game1.player); - Game1.player.currentLocation.currentEvent = new Event(); - } - } -} diff --git a/GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs b/GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs new file mode 100644 index 00000000..bc68afdd --- /dev/null +++ b/GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Omegasis.HappyBirthday.Framework.Events; +using Omegasis.HappyBirthday.Framework.Events.Preconditions; +using Omegasis.HappyBirthday.Framework.Events.Preconditions.TimeSpecific; +using Omegasis.HappyBirthday.Framework.Events.SpecialPreconditions; +using StardewValley; + +namespace Omegasis.HappyBirthday.Framework +{ + public class BirthdayEvents + { + + public static EventHelper CommunityCenterBirthday() + { + List conditions = new List(); + conditions.Add(new FarmerBirthdayPrecondition()); + conditions.Add(new LocationPrecondition(Game1.getLocationFromName("CommunityCenter"))); + conditions.Add(new TimePrecondition(600, 2600)); + EventHelper e = new EventHelper("CommunityCenterBirthday",19950, conditions, new EventStartData(EventStartData.MusicToPlayType.Continue, 10, 10, new EventStartData.FarmerData(10, 10, EventHelper.FacingDirection.Up),new List())); + + e.showMessage("Community center birthday here."); + e.end(); + + return e; + } + } +} diff --git a/GeneralMods/HappyBirthday/Framework/BirthdayMenu.cs b/GeneralMods/HappyBirthday/Framework/BirthdayMenu.cs index 6f226e21..c9931ecf 100644 --- a/GeneralMods/HappyBirthday/Framework/BirthdayMenu.cs +++ b/GeneralMods/HappyBirthday/Framework/BirthdayMenu.cs @@ -45,7 +45,7 @@ namespace Omegasis.HappyBirthday.Framework public BirthdayMenu(string season, int day, Action onChanged) : base(Game1.viewport.Width / 2 - (632 + IClickableMenu.borderWidth * 2) / 2, Game1.viewport.Height / 2 - (600 + IClickableMenu.borderWidth * 2) / 2 - Game1.tileSize, 632 + IClickableMenu.borderWidth * 2, 600 + IClickableMenu.borderWidth * 2 + Game1.tileSize) { - this.BirthdaySeason = season; + this.BirthdaySeason = HappyBirthday.Config.translationInfo.getTranslatedString(season); this.BirthdayDay = day; this.OnChanged = onChanged; this.SetUpPositions(); diff --git a/GeneralMods/HappyBirthday/Framework/Events/EventHelper.cs b/GeneralMods/HappyBirthday/Framework/Events/EventHelper.cs index 9ca4570e..1b0440e8 100644 --- a/GeneralMods/HappyBirthday/Framework/Events/EventHelper.cs +++ b/GeneralMods/HappyBirthday/Framework/Events/EventHelper.cs @@ -63,6 +63,8 @@ namespace Omegasis.HappyBirthday.Framework.Events protected List eventPreconditions; protected int eventID; + public string eventName; + public EventHelper() { this.eventData = new StringBuilder(); @@ -70,8 +72,9 @@ namespace Omegasis.HappyBirthday.Framework.Events this.eventPreconditions = new List(); } - public EventHelper(int ID, LocationPrecondition Location, TimePrecondition Time, EventDayExclusionPrecondition NotTheseDays, EventStartData StartData) + public EventHelper(string EventName,int ID, LocationPrecondition Location, TimePrecondition Time, EventDayExclusionPrecondition NotTheseDays, EventStartData StartData) { + this.eventName = EventName; this.eventData = new StringBuilder(); this.eventPreconditionData = new StringBuilder(); this.eventPreconditions = new List(); @@ -82,8 +85,10 @@ namespace Omegasis.HappyBirthday.Framework.Events this.add(StartData.ToString()); } - public EventHelper(List Conditions, EventStartData StartData) + public EventHelper(string EventName,int ID,List Conditions, EventStartData StartData) { + this.eventName = EventName; + this.eventID = ID; this.eventData = new StringBuilder(); this.eventPreconditions = new List(); this.eventPreconditionData = new StringBuilder(); @@ -176,9 +181,9 @@ namespace Omegasis.HappyBirthday.Framework.Events return s.Substring(0, 4); } - protected virtual string getEventID() + public virtual int getEventID() { - return this.getUniqueEventStartID() + this.eventID.ToString(); + return Convert.ToInt32(this.getUniqueEventStartID() + this.eventID.ToString()); } /// @@ -203,7 +208,7 @@ namespace Omegasis.HappyBirthday.Framework.Events else return true; } - protected virtual string getEventString() + public virtual string getEventString() { return this.eventData.ToString(); } @@ -216,7 +221,7 @@ namespace Omegasis.HappyBirthday.Framework.Events /// /// Checks to see if all of the event preconditions have been met and starts the event if so. /// - protected virtual void startEventAtLocationifPossible() + public virtual void startEventAtLocationifPossible() { if (this.canEventOccur()) { @@ -224,6 +229,7 @@ namespace Omegasis.HappyBirthday.Framework.Events Game1.player.currentLocation.startEvent(this.getEvent()); } } + //~~~~~~~~~~~~~~~~// // Validation // @@ -233,7 +239,7 @@ namespace Omegasis.HappyBirthday.Framework.Events /// Checks to see if the event can occur. /// /// - protected virtual bool canEventOccur() + public virtual bool canEventOccur() { foreach (EventPrecondition eve in this.eventPreconditions) { @@ -1139,9 +1145,9 @@ namespace Omegasis.HappyBirthday.Framework.Events { StringBuilder b = new StringBuilder(); b.Append("message "); - b.Append('"'); + b.Append("\\\""); b.Append(Message); - b.Append('"'); + b.Append("\""); this.add(b); } diff --git a/GeneralMods/HappyBirthday/Framework/Events/EventManager.cs b/GeneralMods/HappyBirthday/Framework/Events/EventManager.cs new file mode 100644 index 00000000..fe26e0de --- /dev/null +++ b/GeneralMods/HappyBirthday/Framework/Events/EventManager.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using StardewValley; + +namespace Omegasis.HappyBirthday.Framework.Events +{ + public class EventManager + { + + + public Dictionary events; + + + public EventManager() + { + this.events = new Dictionary(); + } + + public void addEvent(EventHelper Event) + { + this.events.Add(Event.eventName, Event); + } + + public EventHelper getEvent(string Name) + { + if (this.events.ContainsKey(Name)) + { + return this.events[Name]; + } + else + { + return null; + } + } + + + public void clearEventFromFarmer(string EventName) + { + + this.events.TryGetValue(EventName, out EventHelper e); + if (e == null) return; + Game1.player.eventsSeen.Remove(e.getEventID()); + } + } +} diff --git a/GeneralMods/HappyBirthday/Framework/Events/EventStartData.cs b/GeneralMods/HappyBirthday/Framework/Events/EventStartData.cs index df16c167..285e73b2 100644 --- a/GeneralMods/HappyBirthday/Framework/Events/EventStartData.cs +++ b/GeneralMods/HappyBirthday/Framework/Events/EventStartData.cs @@ -118,7 +118,8 @@ namespace Omegasis.HappyBirthday.Framework.Events } this.add(CameraTileX.ToString()); - this.add(CameraTileY.ToString()); + this.builder.Append(" "); + this.builder.Append(CameraTileY.ToString()); StringBuilder npcData = new StringBuilder(); diff --git a/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs b/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs index 792c51a0..74c6f537 100644 --- a/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs +++ b/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs @@ -113,7 +113,7 @@ namespace Omegasis.HappyBirthday.Framework { return this.getFileExtensionForFileType(File); } - return this.TranslationFileExtensions[language] + this.getFileExtensionForFileType(File); + return "."+this.TranslationFileExtensions[language] + this.getFileExtensionForFileType(File); } catch (Exception err) { diff --git a/GeneralMods/HappyBirthday/HappyBirthday.cs b/GeneralMods/HappyBirthday/HappyBirthday.cs index 6912666c..e68ad0bc 100644 --- a/GeneralMods/HappyBirthday/HappyBirthday.cs +++ b/GeneralMods/HappyBirthday/HappyBirthday.cs @@ -5,6 +5,7 @@ using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Omegasis.HappyBirthday.Framework; +using Omegasis.HappyBirthday.Framework.Events; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; @@ -69,6 +70,8 @@ namespace Omegasis.HappyBirthday private NPC lastSpeaker; + private EventManager eventManager; + /********* ** Public methods *********/ @@ -91,11 +94,28 @@ namespace Omegasis.HappyBirthday helper.Events.Multiplayer.ModMessageReceived += this.Multiplayer_ModMessageReceived; helper.Events.Multiplayer.PeerDisconnected += this.Multiplayer_PeerDisconnected; helper.Events.GameLoop.GameLaunched += this.GameLoop_GameLaunched; + helper.Events.Player.Warped += this.Player_Warped; ModHelper = this.Helper; ModMonitor = this.Monitor; this.othersBirthdays = new Dictionary(); - + + this.eventManager = new EventManager(); + + } + + private void Player_Warped(object sender, WarpedEventArgs e) + { + if (e.NewLocation == Game1.getLocationFromName("CommunityCenter")) + { + EventHelper eve=this.eventManager.getEvent("CommunityCenterBirthday"); + this.Monitor.Log("Birthday event can occur: " + eve.canEventOccur(), LogLevel.Info); + + + this.Monitor.Log("Birthday event info: " + eve.getEventString(), LogLevel.Info); + + eve.startEventAtLocationifPossible(); + } } private void GameLoop_GameLaunched(object sender, GameLaunchedEventArgs e) @@ -103,6 +123,7 @@ namespace Omegasis.HappyBirthday this.messages = new BirthdayMessages(); this.giftManager = new GiftManager(); this.isDailyQuestBoard = false; + } /// Get whether this instance can edit the given asset. @@ -528,20 +549,15 @@ namespace Omegasis.HappyBirthday this.MigrateLegacyData(); this.PlayerData = this.Helper.Data.ReadJsonFile(this.DataFilePath) ?? new PlayerData(); - ; + if (PlayerBirthdayData != null) { ModMonitor.Log("Send all birthday information from " + Game1.player.Name); MultiplayerSupport.SendBirthdayInfoToOtherPlayers(); } - //this.SeenEvent = false; - //this.Dialogue = new Dictionary(); - - //Game1.player.addItemToInventoryBool(new StardewValley.Object(388, 999)); - //Game1.player.addItemToInventoryBool(new StardewValley.Object(390, 999)); - //Game1.player.Money = 999999; + this.eventManager.addEvent(BirthdayEvents.CommunityCenterBirthday()); } /// Raised before the game begins writes data to the save file (except the initial save creation). @@ -702,7 +718,7 @@ namespace Omegasis.HappyBirthday { return this.PlayerData.BirthdayDay == Game1.dayOfMonth - && this.PlayerData.BirthdaySeason .Equals(HappyBirthday.Config.translationInfo.getTranslatedString(Game1.currentSeason)); + && this.PlayerData.BirthdaySeason.Equals(Game1.currentSeason); } /// Migrate the legacy settings for the current player. diff --git a/GeneralMods/HappyBirthday/HappyBirthday.csproj b/GeneralMods/HappyBirthday/HappyBirthday.csproj index 2471572f..e9fbded4 100644 --- a/GeneralMods/HappyBirthday/HappyBirthday.csproj +++ b/GeneralMods/HappyBirthday/HappyBirthday.csproj @@ -80,9 +80,10 @@ Properties\GlobalAssemblyInfo.cs - + +