From b4d82f972a4f7a1362e2167ffe02ed7db9bb765c Mon Sep 17 00:00:00 2001 From: Date: Mon, 11 Dec 2017 14:54:59 -0800 Subject: [PATCH] Can now fall asleep and open the shipping menu if things have been shipped. --- StarAI/StarAI/DialogueCore/ReponseLogic.cs | 55 +++++++++++++++++++ StarAI/StarAI/InterfaceCore/InterfaceLogic.cs | 40 ++++++++++++++ .../StarAI/InterfaceCore/ShippingMenuCore.cs | 22 ++++++++ StarAI/StarAI/ModCore.cs | 18 ++++-- StarAI/StarAI/StarAI.csproj | 3 + .../TaskCore/MapTransitionLogic/WarpGoal.cs | 1 + 6 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 StarAI/StarAI/DialogueCore/ReponseLogic.cs create mode 100644 StarAI/StarAI/InterfaceCore/InterfaceLogic.cs create mode 100644 StarAI/StarAI/InterfaceCore/ShippingMenuCore.cs diff --git a/StarAI/StarAI/DialogueCore/ReponseLogic.cs b/StarAI/StarAI/DialogueCore/ReponseLogic.cs new file mode 100644 index 00000000..826664da --- /dev/null +++ b/StarAI/StarAI/DialogueCore/ReponseLogic.cs @@ -0,0 +1,55 @@ +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.DialogueCore +{ + public class ReponseLogic + { + public static void answerDialogueResponses() + { + if (Game1.player.currentLocation.lastQuestionKey != null) + { + ModCore.CoreMonitor.Log(Game1.player.currentLocation.lastQuestionKey); + while (Game1.player.currentLocation.lastQuestionKey == "Sleep") + { + //WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.ESCAPE); + Game1.player.currentLocation.lastQuestionKey = null; + ModCore.CoreMonitor.Log("GO TO SLEEP"); + answerDialogueSleep(); + //Game1.player.currentLocation.answerDialogue(new Response(Game1.player.currentLocation.lastQuestionKey, "Yes")); + } + } + } + + public static void answerDialogueSleep() + { + GameLocation location = Game1.player.currentLocation; + if ((double)location.LightLevel == 0.0 && Game1.timeOfDay < 2000) + { + location.LightLevel = 0.6f; + + Game1.playSound("openBox"); + Game1.NewDay(600f); + } + else if ((double)location.LightLevel > 0.0 && Game1.timeOfDay >= 2000) + { + location.LightLevel = 0.0f; + Game1.playSound("openBox"); + Game1.NewDay(600f); + } + else + Game1.NewDay(0.0f); + Game1.player.mostRecentBed = Game1.player.position; + Game1.player.doEmote(24); + Game1.player.freezePause = 2000; + + + } + + + } +} diff --git a/StarAI/StarAI/InterfaceCore/InterfaceLogic.cs b/StarAI/StarAI/InterfaceCore/InterfaceLogic.cs new file mode 100644 index 00000000..3cfd8cda --- /dev/null +++ b/StarAI/StarAI/InterfaceCore/InterfaceLogic.cs @@ -0,0 +1,40 @@ +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.InterfaceCore +{ + public class InterfaceLogic + { + public static void interactWithCurrentMenu() + { + + if (Game1.activeClickableMenu == null) + { + return; + } + + //WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.ESCAPE); + ModCore.CoreMonitor.Log(Game1.activeClickableMenu.ToString()); + while(Game1.activeClickableMenu is StardewValley.Menus.DialogueBox) + { + Game1.activeClickableMenu.exitThisMenu(true); + ModCore.CoreMonitor.Log("BYE"); + } + + while (Game1.activeClickableMenu is StardewValley.Menus.ShippingMenu) + { + //(Game1.activeClickableMenu as StardewValley.Menus.ShippingMenu).readyToClose + //Game1.activeClickableMenu.exitThisMenu(true); + ShippingMenuCore.closeMenu(); + ModCore.CoreMonitor.Log("Hello"); + } + + } + + + } +} diff --git a/StarAI/StarAI/InterfaceCore/ShippingMenuCore.cs b/StarAI/StarAI/InterfaceCore/ShippingMenuCore.cs new file mode 100644 index 00000000..a3a3abc0 --- /dev/null +++ b/StarAI/StarAI/InterfaceCore/ShippingMenuCore.cs @@ -0,0 +1,22 @@ +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.InterfaceCore +{ + class ShippingMenuCore + { + public static void closeMenu() + { + (Game1.activeClickableMenu as StardewValley.Menus.ShippingMenu).okButton.snapMouseCursorToCenter(); + if (Game1.activeClickableMenu is StardewValley.Menus.ShippingMenu) + { + ModCore.CoreMonitor.Log("PRESS ALREADY!"); + WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.ESCAPE); + } + } + } +} diff --git a/StarAI/StarAI/ModCore.cs b/StarAI/StarAI/ModCore.cs index 3de56ddb..58064a3e 100644 --- a/StarAI/StarAI/ModCore.cs +++ b/StarAI/StarAI/ModCore.cs @@ -27,6 +27,7 @@ namespace StarAI public static object[] obj = new object[3]; public static bool throwUpShippingMenu; + private bool playerHasLoadedGame; public override void Entry(IModHelper helper) { @@ -46,13 +47,25 @@ namespace StarAI StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave; StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave; + StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick; + playerHasLoadedGame = false; + StardustCore.ModCore.SerializationManager.acceptedTypes.Add("StarAI.PathFindingCore.TileNode", new StardustCore.Serialization.SerializerDataNode(new StardustCore.Serialization.SerializerDataNode.SerializingFunction(StarAI.PathFindingCore.TileNode.Serialize), new StardustCore.Serialization.SerializerDataNode.ParsingFunction(StarAI.PathFindingCore.TileNode.ParseIntoInventory), new StardustCore.Serialization.SerializerDataNode.WorldParsingFunction(StarAI.PathFindingCore.TileNode.SerializeFromWorld), new StardustCore.Serialization.SerializerDataNode.SerializingToContainerFunction(StarAI.PathFindingCore.TileNode.Serialize))); } + private void GameEvents_UpdateTick(object sender, EventArgs e) + { + if (playerHasLoadedGame == false) return; + DialogueCore.ReponseLogic.answerDialogueResponses(); + InterfaceCore.InterfaceLogic.interactWithCurrentMenu(); + } + private void SaveEvents_AfterSave(object sender, EventArgs e) { WayPoints.setUpBedWaypoint(); UtilityCore.SeedCropUtility.setUpCropUtilityDictionaryDaily(); + WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.ESCAPE); + } public void initializeEverything() @@ -100,7 +113,7 @@ namespace StarAI WayPoints.verifyWayPoints(); UtilityCore.SeedCropUtility.setUpUserCropUtilityDictionary(); //Runs once UtilityCore.SeedCropUtility.setUpCropUtilityDictionaryDaily(); //Runs daily - + playerHasLoadedGame = true; } private void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e) @@ -228,9 +241,6 @@ namespace StarAI } } } - - - private void LocationEvents_CurrentLocationChanged(object sender, StardewModdingAPI.Events.EventArgsCurrentLocationChanged e) { diff --git a/StarAI/StarAI/StarAI.csproj b/StarAI/StarAI/StarAI.csproj index 406a9b3a..a23b699d 100644 --- a/StarAI/StarAI/StarAI.csproj +++ b/StarAI/StarAI/StarAI.csproj @@ -58,6 +58,7 @@ + @@ -69,6 +70,8 @@ + + diff --git a/StarAI/StarAI/TaskCore/MapTransitionLogic/WarpGoal.cs b/StarAI/StarAI/TaskCore/MapTransitionLogic/WarpGoal.cs index f174b5ad..fc6b13cb 100644 --- a/StarAI/StarAI/TaskCore/MapTransitionLogic/WarpGoal.cs +++ b/StarAI/StarAI/TaskCore/MapTransitionLogic/WarpGoal.cs @@ -1126,6 +1126,7 @@ namespace StarAI.TaskCore.MapTransitionLogic { TaskCore.CropLogic.SeedLogic.buySeeds(); } + } }