From e4913d97203aa55a5ddd92ec6786b054d6c29874 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Fri, 6 Dec 2019 19:13:30 -0800 Subject: [PATCH] Got junimos to walk in circles. ._. --- GeneralMods/HappyBirthday/BirthdayMessages.cs | 67 ++++++-- .../HappyBirthday/Framework/BirthdayEvents.cs | 42 +++-- .../StardustCore/Events/EventHelper.cs | 75 +++++++-- .../Events/EventHelperExtensions.cs | 86 +++++++++- .../StardustCore/Events/EventManager.cs | 4 + .../StardustCore/Events/ExtraEventActions.cs | 90 +++++++++++ GeneralMods/StardustCore/StardustCore.csproj | 1 + .../Utilities/JunimoAdvanceMoveData.cs | 151 ++++++++++++++++++ 8 files changed, 481 insertions(+), 35 deletions(-) create mode 100644 GeneralMods/StardustCore/Utilities/JunimoAdvanceMoveData.cs diff --git a/GeneralMods/HappyBirthday/BirthdayMessages.cs b/GeneralMods/HappyBirthday/BirthdayMessages.cs index 134e98d5..10c20680 100644 --- a/GeneralMods/HappyBirthday/BirthdayMessages.cs +++ b/GeneralMods/HappyBirthday/BirthdayMessages.cs @@ -142,8 +142,11 @@ namespace Omegasis.HappyBirthday ["Mail:birthdayJunimos"] = "Please come to the community center. ^ Sincerly,^ -The Junimos", ["Happy Birthday: Star Message"] = "It's your birthday today! Happy birthday!", ["Happy Birthday: Farmhand Birthday Message"] = "It's @'s birthday! Happy birthday to them!", - ["Season"] ="Season", - ["Date"]="Date" + ["Season"] = "Season", + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "It looks like the junimos wanted to throw you a party!", + ["Event:JunimoBirthdayParty_1"] = "It looks like there was some cake left over too!", + ["Event:JunimoBirthdayParty_2"] = "That was a fun party. Back to work!" }, [StardewValley.LocalizedContentManager.LanguageCode.ja] = new Dictionary() @@ -154,7 +157,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "", ["Happy Birthday: Farmhand Birthday Message"] = "", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, [StardewValley.LocalizedContentManager.LanguageCode.ru] = new Dictionary() { @@ -164,7 +170,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "Ёто твой день рождени¤! — днем рождени¤!", ["Happy Birthday: Farmhand Birthday Message"] = "Ёто твой день рождени¤! ѕоздравл¤ю с этим!", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, [StardewValley.LocalizedContentManager.LanguageCode.zh] = new Dictionary() { @@ -174,7 +183,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "今天是你的生日!生日快乐!", ["Happy Birthday: Farmhand Birthday Message"] = "", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, [StardewValley.LocalizedContentManager.LanguageCode.pt] = new Dictionary() { @@ -184,7 +196,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "", ["Happy Birthday: Farmhand Birthday Message"] = "", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, [StardewValley.LocalizedContentManager.LanguageCode.es] = new Dictionary() { @@ -194,7 +209,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "", ["Happy Birthday: Farmhand Birthday Message"] = "", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, [StardewValley.LocalizedContentManager.LanguageCode.de] = new Dictionary() { @@ -204,7 +222,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "", ["Happy Birthday: Farmhand Birthday Message"] = "", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, [StardewValley.LocalizedContentManager.LanguageCode.th] = new Dictionary() { @@ -214,7 +235,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "", ["Happy Birthday: Farmhand Birthday Message"] = "", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, [StardewValley.LocalizedContentManager.LanguageCode.fr] = new Dictionary() { @@ -224,7 +248,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "", ["Happy Birthday: Farmhand Birthday Message"] = "", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, [StardewValley.LocalizedContentManager.LanguageCode.ko] = new Dictionary() { @@ -234,7 +261,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "", ["Happy Birthday: Farmhand Birthday Message"] = "", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, [StardewValley.LocalizedContentManager.LanguageCode.it] = new Dictionary() { @@ -244,7 +274,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "", ["Happy Birthday: Farmhand Birthday Message"] = "", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, [StardewValley.LocalizedContentManager.LanguageCode.tr] = new Dictionary() { @@ -254,7 +287,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "", ["Happy Birthday: Farmhand Birthday Message"] = "", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, [StardewValley.LocalizedContentManager.LanguageCode.hu] = new Dictionary() { @@ -264,7 +300,10 @@ namespace Omegasis.HappyBirthday ["Happy Birthday: Star Message"] = "", ["Happy Birthday: Farmhand Birthday Message"] = "", ["Season"] = "Season", - ["Date"] = "Date" + ["Date"] = "Date", + ["Event:JunimoBirthdayParty_0"] = "", + ["Event:JunimoBirthdayParty_1"] = "", + ["Event:JunimoBirthdayParty_2"] = "" }, }; diff --git a/GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs b/GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs index 3e4edb98..dde74403 100644 --- a/GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs +++ b/GeneralMods/HappyBirthday/Framework/BirthdayEvents.cs @@ -30,14 +30,36 @@ namespace Omegasis.HappyBirthday.Framework conditions.Add(new StardustCore.Events.Preconditions.PlayerSpecific.JojaMember(false)); conditions.Add(new CommunityCenterCompleted(false)); //conditions.Add(new HasUnlockedCommunityCenter()); //Infered by the fact that you must enter the community center to trigger this event anyways. - EventHelper e = new EventHelper("CommunityCenterBirthday",19950, conditions, new EventStartData("playful", 32, 16, new EventStartData.FarmerData(32, 22, EventHelper.FacingDirection.Up),new List())); + EventHelper e = new EventHelper("CommunityCenterBirthday",19950, conditions, new EventStartData("playful", 32, 12, new EventStartData.FarmerData(32, 22, EventHelper.FacingDirection.Up),new List())); - e.AddInJunimoActor("Juni", new Microsoft.Xna.Framework.Vector2(32, 14), StardustCore.IlluminateFramework.Colors.getRandomJunimoColor()); - e.AddInJunimoActor("Juni2", new Microsoft.Xna.Framework.Vector2(30, 15), StardustCore.IlluminateFramework.Colors.getRandomJunimoColor()); - e.AddInJunimoActor("Juni3", new Microsoft.Xna.Framework.Vector2(34, 15), StardustCore.IlluminateFramework.Colors.getRandomJunimoColor()); + e.AddInJunimoActor("Juni", new Microsoft.Xna.Framework.Vector2(32, 10), StardustCore.IlluminateFramework.Colors.getRandomJunimoColor()); + e.AddInJunimoActor("Juni2", new Microsoft.Xna.Framework.Vector2(30, 11), StardustCore.IlluminateFramework.Colors.getRandomJunimoColor()); + e.AddInJunimoActor("Juni3", new Microsoft.Xna.Framework.Vector2(34, 11), StardustCore.IlluminateFramework.Colors.getRandomJunimoColor()); + e.AddInJunimoActor("Juni4", new Microsoft.Xna.Framework.Vector2(26, 11), StardustCore.IlluminateFramework.Colors.getRandomJunimoColor()); + e.AddInJunimoActor("Juni5", new Microsoft.Xna.Framework.Vector2(28, 11), StardustCore.IlluminateFramework.Colors.getRandomJunimoColor()); + e.AddInJunimoActor("Juni6Tank", new Vector2(38, 10), StardustCore.IlluminateFramework.Colors.getRandomJunimoColor()); + e.AddJunimoAdvanceMoveTiles(new StardustCore.Utilities.JunimoAdvanceMoveData("Juni6Tank", new List() + { + new Point(38,10), + new Point(38,11), + new Point(39,11), + new Point(40,11), + new Point(41,11), + new Point(42,11), + new Point(42,10), + new Point(41,10), + new Point(40,10), + new Point(39,10), + + }, 60, 1, true)); ; + + e.FlipJunimoActor("Juni5", true); + e.junimoFaceDirection("Juni4", EventHelper.FacingDirection.Right); //Make a junimo face right. + e.junimoFaceDirection("Juni5", EventHelper.FacingDirection.Left); e.globalFadeIn(); - e.moveFarmerUp(6, EventHelper.FacingDirection.Up, true); + + e.moveFarmerUp(10, EventHelper.FacingDirection.Up, true); //e.moveActorLeft("Juni", 1, EventHelper.FacingDirection.Down, false); e.animate("Juni", true, true, 250, new List() @@ -48,17 +70,17 @@ namespace Omegasis.HappyBirthday.Framework 31 }); - // + e.junimoFaceDirection("Juni4", EventHelper.FacingDirection.Down); + e.junimoFaceDirection("Juni5", EventHelper.FacingDirection.Down); e.playSound("junimoMeep1"); - // e.emoteFarmer_ExclamationMark(); - e.showMessage("It looks like the junimos wanted to throw you a party!"); //TODO get this from translated strings. NOT hard coded. + e.showMessage(HappyBirthday.Config.translationInfo.getTranslatedString("Event:JunimoBirthdayParty_0")); e.emoteFarmer_Heart(); e.globalFadeOut(0.010); e.setViewportPosition(-100, -100); - e.showMessage("It looks like there was some cake left over too!");//TODO get this from translated strings. NOT hard coded. - e.showMessage("That was a fun party. Back to work!");//TODO get this from translated strings. NOT hard coded. + e.showMessage(HappyBirthday.Config.translationInfo.getTranslatedString("Event:JunimoBirthdayParty_1")); + e.showMessage(HappyBirthday.Config.translationInfo.getTranslatedString("Event:JunimoBirthdayParty_2")); e.addObjectToPlayersInventory(220, 1, false); e.end(); diff --git a/GeneralMods/StardustCore/Events/EventHelper.cs b/GeneralMods/StardustCore/Events/EventHelper.cs index 73204d21..8fbba693 100644 --- a/GeneralMods/StardustCore/Events/EventHelper.cs +++ b/GeneralMods/StardustCore/Events/EventHelper.cs @@ -622,6 +622,30 @@ namespace StardustCore.Events this.add(b); } + public virtual void advanceMove(string Actor, bool Loop, List TilePoints) + { + StringBuilder b = new StringBuilder(); + b.Append("advancedMove "); + b.Append(Actor); + b.Append(" "); + b.Append(Loop.ToString()); + b.Append(" "); + for (int i = 0; i < TilePoints.Count; i++) + { + b.Append(TilePoints[i].X); + b.Append(" "); + b.Append(TilePoints[i].Y); + if (i != TilePoints.Count - 1) + { + b.Append(" "); + } + } + + ModCore.ModMonitor.Log(b.ToString(), StardewModdingAPI.LogLevel.Info); + + this.add(b); + } + /// /// Modifies the ambient light level, with RGB values from 0 to 255. Note that it works by removing colors from the existing light ambience, so ambientLight 1 80 80 would reduce green and blue and leave the light with a reddish hue. /// @@ -1192,25 +1216,56 @@ namespace StardustCore.Events } public virtual void playerFaceDirection(FacingDirection Dir) + { + this.actorFaceDirection("farmer",Dir); + } + + public virtual void npcFaceDirection(NPC NPC, FacingDirection Dir) + { + this.actorFaceDirection(NPC.Name, Dir); + } + + public virtual void actorFaceDirection(string Actor, FacingDirection Dir) { StringBuilder b = new StringBuilder(); - b.Append("faceDirection farmer "); + b.Append("faceDirection "); + b.Append(Actor); + b.Append(" "); b.Append(this.getFacingDirectionNumber(Dir).ToString()); b.Append(" "); b.Append(true); this.add(b); } - public virtual void npcFaceDirection(NPC NPC, FacingDirection Dir) + + /// + /// Special code to make junimos face a direction because it doesn't work the same as npcs. + /// + /// The name of the junimo actor. + /// The direction for the junimo to face. + public virtual void junimoFaceDirection(string Actor,FacingDirection Dir) { - StringBuilder b = new StringBuilder(); - b.Append("faceDirection "); - b.Append(NPC.Name); - b.Append(" "); - b.Append(this.getFacingDirectionNumber(Dir).ToString()); - b.Append(" "); - b.Append(true); - this.add(b); + this.actorFaceDirection(Actor, Dir); + int frame = 0; + bool flip = false; + if(Dir.Equals(FacingDirection.Down)) + { + frame = 0; + } + else if(Dir.Equals(FacingDirection.Left)) + { + frame = 16; + flip = true; + } + else if (Dir.Equals(FacingDirection.Right)) + { + frame = 16; + } + else if(Dir.Equals(FacingDirection.Up)) + { + frame = 32; + } + this.animate(Actor, flip, true, 250, new List() { frame, frame }); } /// diff --git a/GeneralMods/StardustCore/Events/EventHelperExtensions.cs b/GeneralMods/StardustCore/Events/EventHelperExtensions.cs index 7a48ecd8..1f8cfdea 100644 --- a/GeneralMods/StardustCore/Events/EventHelperExtensions.cs +++ b/GeneralMods/StardustCore/Events/EventHelperExtensions.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.Xna.Framework; using StardewValley; using StardewValley.Characters; +using StardustCore.Utilities; namespace StardustCore.Events { @@ -81,7 +82,7 @@ namespace StardustCore.Events /// /// /// - public static void AddInJunimoActor(this EventHelper EventHelper,string ActorName,Vector2 Position,Color Color) + public static void AddInJunimoActor(this EventHelper EventHelper,string ActorName,Vector2 Position,Color Color,bool Flipped=false) { StringBuilder b = new StringBuilder(); @@ -97,9 +98,92 @@ namespace StardustCore.Events b.Append(Color.G); b.Append(" "); b.Append(Color.B); + b.Append(" "); + b.Append(Flipped); EventHelper.add(b); } + public static void FlipJunimoActor(this EventHelper EventHelper, string ActorName,bool Flipped = false) + { + StringBuilder b = new StringBuilder(); + b.Append("Omegasis.EventFramework.FlipJunimoActor "); + b.Append(ActorName); + b.Append(" "); + b.Append(Flipped); + EventHelper.add(b); + } + public static void SetUpJunimoAdvanceMove(this EventHelper EventHelper) + { + StringBuilder b = new StringBuilder(); + b.Append("Omegasis.EventFramework.SetUpAdvanceJunimoMovement"); + EventHelper.add(b); + } + + public static void FinishJunimoAdvanceMove(this EventHelper EventHelper) + { + StringBuilder b = new StringBuilder(); + b.Append("Omegasis.EventFramework.FinishAdvanceJunimoMovement"); + EventHelper.add(b); + } + + public static void AddJunimoAdvanceMove(this EventHelper EventHelper, JunimoAdvanceMoveData JunimoData) + { + StringBuilder b = new StringBuilder(); + b.Append("Omegasis.EventFramework.AddInJunimoAdvanceMove "); + + b.Append(JunimoData.junimoActorID); + b.Append(" "); + b.Append(JunimoData.maxFrames); + b.Append(" "); + b.Append(JunimoData.tickSpeed); + b.Append(" "); + b.Append(JunimoData.loop); + b.Append(" "); + for (int i = 0; i < JunimoData.points.Count; i++) + { + b.Append(JunimoData.points[i].X); + b.Append("_"); + b.Append(JunimoData.points[i].Y); + if (i != JunimoData.points.Count - 1) + { + b.Append(" "); + } + } + + EventHelper.add(b); + } + + /// + /// Same as above but allows for smaller tile position numbers instead. + /// + /// + /// + public static void AddJunimoAdvanceMoveTiles(this EventHelper EventHelper, JunimoAdvanceMoveData JunimoData) + { + StringBuilder b = new StringBuilder(); + b.Append("Omegasis.EventFramework.AddInJunimoAdvanceMove "); + + b.Append(JunimoData.junimoActorID); + b.Append(" "); + b.Append(JunimoData.maxFrames); + b.Append(" "); + b.Append(JunimoData.tickSpeed); + b.Append(" "); + b.Append(JunimoData.loop); + b.Append(" "); + for (int i = 0; i < JunimoData.points.Count; i++) + { + b.Append(JunimoData.points[i].X*Game1.tileSize); + b.Append("_"); + b.Append(JunimoData.points[i].Y * Game1.tileSize); + if (i != JunimoData.points.Count - 1) + { + b.Append(" "); + } + } + + EventHelper.add(b); + } } } diff --git a/GeneralMods/StardustCore/Events/EventManager.cs b/GeneralMods/StardustCore/Events/EventManager.cs index cff5fe2c..207c439a 100644 --- a/GeneralMods/StardustCore/Events/EventManager.cs +++ b/GeneralMods/StardustCore/Events/EventManager.cs @@ -31,6 +31,10 @@ namespace StardustCore.Events this.customEventLogic.Add("Omegasis.EventFramework.AddObjectToPlayersInventory", ExtraEventActions.addObjectToPlayerInventory); this.customEventLogic.Add("Omegasis.EventFramework.ViewportLerp", ExtraEventActions.ViewportLerp); this.customEventLogic.Add("Omegasis.EventFramework.AddInJunimoActor", ExtraEventActions.AddInJumimoActorForEvent); + this.customEventLogic.Add("Omegasis.EventFramework.FlipJunimoActor", ExtraEventActions.FlipJunimoActor); + this.customEventLogic.Add("Omegasis.EventFramework.SetUpAdvanceJunimoMovement", ExtraEventActions.SetUpAdvanceJunimoMovement); + this.customEventLogic.Add("Omegasis.EventFramework.FinishAdvanceJunimoMovement", ExtraEventActions.FinishAdvanceJunimoMovement); + this.customEventLogic.Add("Omegasis.EventFramework.AddInJunimoAdvanceMove", ExtraEventActions.AddInJunimoAdvanceMove); } /// diff --git a/GeneralMods/StardustCore/Events/ExtraEventActions.cs b/GeneralMods/StardustCore/Events/ExtraEventActions.cs index 6019652d..cd5e986f 100644 --- a/GeneralMods/StardustCore/Events/ExtraEventActions.cs +++ b/GeneralMods/StardustCore/Events/ExtraEventActions.cs @@ -8,6 +8,7 @@ using Netcode; using StardewModdingAPI; using StardewValley; using StardewValley.Characters; +using StardustCore.Utilities; namespace StardustCore.Events { @@ -21,6 +22,8 @@ namespace StardustCore.Events private static bool StartedLerp; private static int CurrentViewportLerpAmount; + public static Dictionary junimoLerpData = new Dictionary(); + /// /// Adds the item from Game1.ObjectInformation to the player's inventory from the given event string. /// @@ -102,11 +105,13 @@ namespace StardustCore.Events int xPos = Convert.ToInt32(splits[2]); int yPos = Convert.ToInt32(splits[3]); Color color = new Color(Convert.ToInt32(splits[4]), Convert.ToInt32(splits[5]), Convert.ToInt32(splits[6])); + bool flipped = Convert.ToBoolean(splits[7]); List actors = Game1.CurrentEvent.actors; Junimo junimo = new Junimo(new Vector2(xPos * 64, yPos * 64), -1, false); junimo.Name = actorName; junimo.EventActor = true; + junimo.flip = flipped; IReflectedField colorF=StardustCore.ModCore.ModHelper.Reflection.GetField(junimo, "color", true); NetColor c = colorF.GetValue(); @@ -118,5 +123,90 @@ namespace StardustCore.Events actors.Add((NPC)junimo); ++Game1.CurrentEvent.CurrentCommand; //I've been told ++ is more efficient than ++; } + + /// + /// Flip a given junimo actor. Necessary to make junimos face left. + /// + /// + /// + public static void FlipJunimoActor(EventManager EventManager, string EventData) + { + string[] splits = EventData.Split(' '); + string name = splits[0]; + string actorName = splits[1]; + bool flipped = Convert.ToBoolean(splits[2]); + NPC junimo=Game1.CurrentEvent.actors.Find(i => i.Name.Equals(actorName)); + junimo.flip = flipped; + ++Game1.CurrentEvent.CurrentCommand; //I've been told ++ is more efficient than ++; + } + + /// + /// Adds the concurrent event to handle junimo movement. + /// + /// + /// + public static void SetUpAdvanceJunimoMovement(EventManager EventManager, string EventData) + { + string[] splits = EventData.Split(' '); + string name = splits[0]; + ++Game1.CurrentEvent.CurrentCommand; //I've been told ++ is more efficient than ++; + EventManager.addConcurrentEvent(new ConcurrentEventInformation("AdvanceJunimoMove", "", EventManager, AdvanceJunimoMovement)); + } + + /// + /// Finishes handling advvance junimo movement. + /// + /// + /// + public static void FinishAdvanceJunimoMovement(EventManager EventManager, string EventData) + { + string[] splits = EventData.Split(' '); + string name = splits[0]; + ++Game1.CurrentEvent.CurrentCommand; //I've been told ++ is more efficient than ++; + EventManager.finishConcurrentEvent("AdvanceJunimoMove"); + } + + public static void AddInJunimoAdvanceMove(EventManager EventManager, string EventData) + { + + if (EventManager.concurrentEventActions.ContainsKey("Omegasis.EventFramework.SetUpAdvanceJunimoMovement")==false) + { + EventManager.addConcurrentEvent(new ConcurrentEventInformation("AdvanceJunimoMove", "", EventManager, AdvanceJunimoMovement)); + } + string[] splits = EventData.Split(' '); + string name = splits[0]; + + string actorName = splits[1]; + int MaxFrames = Convert.ToInt32(splits[2]); + int Speed = Convert.ToInt32(splits[3]); + bool Loop = Convert.ToBoolean(splits[4]); + + List points = new List(); + for(int i = 5; i < splits.Length; i++) + { + string pointData = splits[i]; + string[] point = pointData.Split('_'); + int x = Convert.ToInt32(point[0]); + int y = Convert.ToInt32(point[1]); + points.Add(new Point(x, y)); + } + + junimoLerpData.Add(actorName, new JunimoAdvanceMoveData(actorName,points,MaxFrames,Speed,Loop)); + + ++Game1.CurrentEvent.CurrentCommand; //I've been told ++ is more efficient than ++; + } + + /// + /// Updates all of the junimo movement logic. + /// + /// + /// + public static void AdvanceJunimoMovement(EventManager EventManager, string EventData) + { + foreach(KeyValuePair pair in junimoLerpData) + { + pair.Value.update(); + } + } } } diff --git a/GeneralMods/StardustCore/StardustCore.csproj b/GeneralMods/StardustCore/StardustCore.csproj index e276892e..2dd75a66 100644 --- a/GeneralMods/StardustCore/StardustCore.csproj +++ b/GeneralMods/StardustCore/StardustCore.csproj @@ -163,6 +163,7 @@ + diff --git a/GeneralMods/StardustCore/Utilities/JunimoAdvanceMoveData.cs b/GeneralMods/StardustCore/Utilities/JunimoAdvanceMoveData.cs new file mode 100644 index 00000000..9e0f4a57 --- /dev/null +++ b/GeneralMods/StardustCore/Utilities/JunimoAdvanceMoveData.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using StardewValley; +using StardewValley.Characters; + +namespace StardustCore.Utilities +{ + public class JunimoAdvanceMoveData + { + public string junimoActorID; + public int maxFrames; + public int tickSpeed; + public bool loop; + public List points; + + + private int currentIndex; + private int currentFrameAmount; + private bool finished; + + public JunimoAdvanceMoveData() + { + + } + + public JunimoAdvanceMoveData(string Actor, List Points, int FramesToPoint, int tickSpeed = 1,bool Loop=false) + { + this.junimoActorID = Actor; + this.points = Points; + this.maxFrames = FramesToPoint; + + this.tickSpeed = tickSpeed; + this.currentFrameAmount = 0; + this.currentIndex = 0; + this.loop = Loop; + } + + public void update() + { + if (Game1.CurrentEvent == null) return; + else + { + if (this.finished) return; + Junimo junimo=(Junimo)Game1.CurrentEvent.actors.Find(i => i.Name.Equals(this.junimoActorID)); + if (junimo == null) return; + Point nextPoint = this.getNextPoint(); + if (this.finished) return; + + if (nextPoint.X > this.getCurrentPoint().X) + { + junimo.flip = false; + + //junimo.Sprite.Animate(Game1.currentGameTime, 0, 8, 50f); + if (junimo.Sprite.CurrentAnimation==null) + { + junimo.Sprite.Animate(Game1.currentGameTime, 16, 7, 50f); + } + } + if (nextPoint.X < this.getCurrentPoint().X) + { + junimo.flip = true; + + //junimo.Sprite.Animate(Game1.currentGameTime, 0, 8, 50f); + if (junimo.Sprite.CurrentAnimation== null) + { + junimo.Sprite.Animate(Game1.currentGameTime, 16, 7 , 50f); + } + } + if (nextPoint.Y < this.getCurrentPoint().Y) + { + junimo.flip = false; + + //junimo.Sprite.Animate(Game1.currentGameTime, 0, 8, 50f); + if (junimo.Sprite.CurrentAnimation == null) + { + junimo.Sprite.Animate(Game1.currentGameTime, 32, 8, 50f); + } + } + if(nextPoint.Y > this.getCurrentPoint().Y) + { + junimo.flip = false; + + if (junimo.Sprite.CurrentAnimation==null) { + junimo.Sprite.Animate(Game1.currentGameTime, 0, 8, 50f); + } + } + + + + junimo.Position= Vector2.Lerp(new Vector2(this.getCurrentPoint().X,this.getCurrentPoint().Y),new Vector2(nextPoint.X,nextPoint.Y),(float)((float)this.currentFrameAmount/(float)this.maxFrames)); + + ++this.currentFrameAmount; + + if (this.currentFrameAmount >= this.maxFrames) + { + this.currentFrameAmount = 0; + this.currentIndex++; + junimo.Sprite.StopAnimation(); + if (this.currentIndex >= this.points.Count) + { + if (this.loop == false) + { + this.finished = true; + } + else + { + this.currentIndex = 0; + } + } + } + } + } + + Point getNextPoint() + { + if (this.currentIndex+1 >= this.points.Count) + { + if (this.loop == false) + { + this.finished=true; + return new Point(0, 0); + } + return this.points[0]; + } + else + { + return this.points[this.currentIndex+1]; + } + + } + + + Point getCurrentPoint() + { + if (this.currentIndex >= this.points.Count) + { + return this.points[0]; + } + else + { + return this.points[this.currentIndex]; + } + + } + + } +}