From 671eb1be49480afb21d59ef92345021c7f2fdf8a Mon Sep 17 00:00:00 2001 From: Date: Wed, 29 Nov 2017 18:34:53 -0800 Subject: [PATCH] RIP can now chop sticks but took HOURS to figure out how. Also if I can't find the path my code becomes vunerable to crash. --- GeneralMods/StardewMods.sln | 5 +- StarAI/{StarAI => }/StarAI.sln | 0 StarAI/StarAI/{StarAI => }/Commands.cs | 10 +- StarAI/StarAI/ExecutionCore/CustomTask.cs | 52 + StarAI/StarAI/ExecutionCore/TaskList.cs | 88 ++ StarAI/StarAI/ExecutionCore/TaskMetaData.cs | 151 +++ .../ExecutionCore/TaskMetaDataHeuristics.cs | 77 ++ .../TaskPrerequisites/BedTimePrerequisite.cs | 56 + .../TaskPrerequisites/GenericPrerequisite.cs | 0 .../InventoryFullPrerequisite.cs | 39 + .../TaskPrerequisites/ToolPrerequisite.cs | 55 + .../TaskPrerequisites/staminaPrerequisite.cs | 0 StarAI/StarAI/ModCore.cs | 211 ++++ StarAI/StarAI/PathFindingCore/ChestLogic.cs | 282 +++++ .../PathFindingCore/CropLogic/CropLogic.cs | 473 ++++++++ .../DebrisLogic/DebrisLogic.cs | 366 ++++++ .../PathFindingCore/PathFindingLogic.cs | 66 +- .../PathFindingCore/PlacementNode.cs | 0 .../PathFindingCore/TileExceptionMetaData.cs | 0 .../PathFindingCore/TileExceptionNode.cs | 0 .../StarAI/PathFindingCore/TileNodeObject.cs | 1038 +++++++++++++++++ StarAI/StarAI/PathFindingCore/Utilities.cs | 408 +++++++ .../{StarAI => }/Properties/AssemblyInfo.cs | 0 StarAI/StarAI/StarAI.csproj | 105 ++ .../StarAI/PathFindingCore/Utilities.cs | 188 --- StarAI/StarAI/{StarAI => }/manifest.json | 0 StarAI/StarAI/{StarAI => }/packages.config | 0 27 files changed, 3459 insertions(+), 211 deletions(-) rename StarAI/{StarAI => }/StarAI.sln (100%) rename StarAI/StarAI/{StarAI => }/Commands.cs (97%) create mode 100644 StarAI/StarAI/ExecutionCore/CustomTask.cs create mode 100644 StarAI/StarAI/ExecutionCore/TaskList.cs create mode 100644 StarAI/StarAI/ExecutionCore/TaskMetaData.cs create mode 100644 StarAI/StarAI/ExecutionCore/TaskMetaDataHeuristics.cs create mode 100644 StarAI/StarAI/ExecutionCore/TaskPrerequisites/BedTimePrerequisite.cs rename StarAI/StarAI/{StarAI => }/ExecutionCore/TaskPrerequisites/GenericPrerequisite.cs (100%) create mode 100644 StarAI/StarAI/ExecutionCore/TaskPrerequisites/InventoryFullPrerequisite.cs create mode 100644 StarAI/StarAI/ExecutionCore/TaskPrerequisites/ToolPrerequisite.cs rename StarAI/StarAI/{StarAI => }/ExecutionCore/TaskPrerequisites/staminaPrerequisite.cs (100%) create mode 100644 StarAI/StarAI/ModCore.cs create mode 100644 StarAI/StarAI/PathFindingCore/ChestLogic.cs create mode 100644 StarAI/StarAI/PathFindingCore/CropLogic/CropLogic.cs create mode 100644 StarAI/StarAI/PathFindingCore/DebrisLogic/DebrisLogic.cs rename StarAI/StarAI/{StarAI => }/PathFindingCore/PathFindingLogic.cs (92%) rename StarAI/StarAI/{StarAI => }/PathFindingCore/PlacementNode.cs (100%) rename StarAI/StarAI/{StarAI => }/PathFindingCore/TileExceptionMetaData.cs (100%) rename StarAI/StarAI/{StarAI => }/PathFindingCore/TileExceptionNode.cs (100%) create mode 100644 StarAI/StarAI/PathFindingCore/TileNodeObject.cs create mode 100644 StarAI/StarAI/PathFindingCore/Utilities.cs rename StarAI/StarAI/{StarAI => }/Properties/AssemblyInfo.cs (100%) create mode 100644 StarAI/StarAI/StarAI.csproj delete mode 100644 StarAI/StarAI/StarAI/PathFindingCore/Utilities.cs rename StarAI/StarAI/{StarAI => }/manifest.json (100%) rename StarAI/StarAI/{StarAI => }/packages.config (100%) diff --git a/GeneralMods/StardewMods.sln b/GeneralMods/StardewMods.sln index a815af24..60a2adb8 100644 --- a/GeneralMods/StardewMods.sln +++ b/GeneralMods/StardewMods.sln @@ -61,10 +61,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RuneFactoryCropsMod", "Rune {C5F88D48-EA20-40CD-91E2-C8725DC11795} = {C5F88D48-EA20-40CD-91E2-C8725DC11795} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StarAI", "..\StarAI\StarAI\StarAI\StarAI.csproj", "{93632675-991D-425B-96F9-9C2B6BFC4EFE}" - ProjectSection(ProjectDependencies) = postProject - {0756D36A-95C8-480D-8EA6-4584C03010C6} = {0756D36A-95C8-480D-8EA6-4584C03010C6} - EndProjectSection +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StarAI", "..\StarAI\StarAI\StarAI.csproj", "{93632675-991D-425B-96F9-9C2B6BFC4EFE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/StarAI/StarAI/StarAI.sln b/StarAI/StarAI.sln similarity index 100% rename from StarAI/StarAI/StarAI.sln rename to StarAI/StarAI.sln diff --git a/StarAI/StarAI/StarAI/Commands.cs b/StarAI/StarAI/Commands.cs similarity index 97% rename from StarAI/StarAI/StarAI/Commands.cs rename to StarAI/StarAI/Commands.cs index 9bd29773..6ff53002 100644 --- a/StarAI/StarAI/StarAI/Commands.cs +++ b/StarAI/StarAI/Commands.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using StarAI; +using StarAI.PathFindingCore.DebrisLogic; namespace StarAI { @@ -27,6 +28,8 @@ namespace StarAI ModCore.CoreHelper.ConsoleCommands.Add("Water", "Water the crops", new Action(Commands.waterCrops)); ModCore.CoreHelper.ConsoleCommands.Add("Harvest", "Harvest the crops", new Action(Commands.harvestCrops)); ModCore.CoreHelper.ConsoleCommands.Add("getseeds", "Get Seeds From chests.", new Action(Commands.getSeedsFromChests)); + + ModCore.CoreHelper.ConsoleCommands.Add("choptwigs", "Chop twigs.", new Action(Commands.chopAllTwigs)); pathfind("Initialize Delay 0", new string[] { "setDelay", "0" @@ -38,6 +41,11 @@ namespace StarAI ChestLogic.getAllSeasonalSeedsFromAllChestsAtLocation(Game1.player.currentLocation); } + public static void chopAllTwigs(string s, string[] args) + { + DebrisLogic.getAllSticksToChopRadius(Game1.player.currentLocation); + } + public static void runTasks(string s, string[] args) { ExecutionCore.TaskList.runTaskList(); @@ -339,7 +347,7 @@ namespace StarAI obj[1] = PathFindingLogic.currentGoal; PathFindingLogic.queue = new List(); obj[2] = PathFindingLogic.queue; - ExecutionCore.TaskList.taskList.Add(new ExecutionCore.CustomTask(PathFindingLogic.pathFindToSingleGoal, obj,new ExecutionCore.TaskMetaData("Pathfind Command",PathFindingCore.Utilities.calculatePathCost(PathFindingLogic.source)))); + ExecutionCore.TaskList.taskList.Add(new ExecutionCore.CustomTask(PathFindingLogic.pathFindToSingleGoal, obj,new ExecutionCore.TaskMetaData("Pathfind Command",PathFindingCore.Utilities.calculatePathCost(PathFindingLogic.source,false)))); //ExecutionCore.TaskList.taskList.Add(new Task(new Action(PathFindingLogic.pathFindToSingleGoal),obj)); } #endregion diff --git a/StarAI/StarAI/ExecutionCore/CustomTask.cs b/StarAI/StarAI/ExecutionCore/CustomTask.cs new file mode 100644 index 00000000..68c2c5b7 --- /dev/null +++ b/StarAI/StarAI/ExecutionCore/CustomTask.cs @@ -0,0 +1,52 @@ +using StarAI.PathFindingCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.ExecutionCore +{ + public class CustomTask + { + public delegate void ObjectTask(object obj); + public delegate void VoidTask(); + + + public ObjectTask objectTask; + public object objectParameterDataArray; + public VoidTask voidTask; + + public TaskMetaData taskMetaData; + + /// + /// Create a custom task and calculate cost of the action automatically without having to pass cost to the meta data. Saves a lot of code space and memory. + /// + /// + /// + /// + public CustomTask(ObjectTask objTask,object[] arrayData, TaskMetaData TaskMetaData) + { + objectTask = objTask; + objectParameterDataArray = arrayData; + this.taskMetaData = TaskMetaData; + this.taskMetaData.calculateTaskCost((TileNode)arrayData[0]); + } + + public CustomTask(VoidTask vTask, TaskMetaData TaskMetaData) + { + voidTask = vTask; + this.taskMetaData = TaskMetaData; + } + + public void runTask() + { + + //Check Before running task if all prerequisites are working + if (objectTask != null) objectTask.Invoke(objectParameterDataArray); + + if (voidTask != null) voidTask.Invoke(); + } + + } +} diff --git a/StarAI/StarAI/ExecutionCore/TaskList.cs b/StarAI/StarAI/ExecutionCore/TaskList.cs new file mode 100644 index 00000000..a6976d1a --- /dev/null +++ b/StarAI/StarAI/ExecutionCore/TaskList.cs @@ -0,0 +1,88 @@ +using StarAI.PathFindingCore; +using StardewModdingAPI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.ExecutionCore +{ + class TaskList + { + public static List taskList = new List(); + public static Task executioner = new Task(new Action(runTaskList)); + + public static List removalList = new List(); + public static void runTaskList() + { + + //myTask t = new myTask(StarAI.PathFindingCore.CropLogic.CropLogic.harvestSingleCrop); + + bool assignNewTask = true; + + while(ranAllTasks()==false) + { + + + //recalculate cost expenses every time a task runs because we don't know where we will be at any given moment. Kind of costly unfortunately but works. + foreach(var task2 in taskList) + { + if (removalList.Contains(task2)) continue; + object[] oArray = (object[])task2.objectParameterDataArray; + TileNode t =(TileNode) oArray[0]; + task2.taskMetaData.calculateTaskCost((t)); + //task.taskMetaData = new TaskMetaData(task.taskMetaData.name, PathFindingCore.Utilities.calculatePathCost(task.objectParameterDataArray), task.taskMetaData.staminaPrerequisite, task.taskMetaData.toolPrerequisite); + } + + //Some really cool delegate magic that sorts in place by the cost of the action!!!! + taskList.Sort(delegate (CustomTask t1, CustomTask t2) + { + return t1.taskMetaData.cost.CompareTo(t2.taskMetaData.cost); + }); + CustomTask v = taskList.ElementAt(0); + int i = 0; + while (removalList.Contains(v)) + { + v = taskList.ElementAt(i); + i++; + } + // v.Start(); + + if (v.taskMetaData.verifyAllPrerequisitesHit() == true) + { + v.runTask(); + removalList.Add(v); + } + else + { + removalList.Add(v); + } + } + + + taskList.Clear(); + removalList.Clear(); + + } + + public static bool ranAllTasks() + { + foreach(CustomTask task in taskList) + { + if (removalList.Contains(task)) continue; + else return false; + } + return true; + } + + public static void printAllTaskMetaData() + { + ModCore.CoreMonitor.Log(taskList.Count.ToString()); + foreach (var task in taskList) + { + task.taskMetaData.printMetaData(); + } + } + } +} diff --git a/StarAI/StarAI/ExecutionCore/TaskMetaData.cs b/StarAI/StarAI/ExecutionCore/TaskMetaData.cs new file mode 100644 index 00000000..a3d4339a --- /dev/null +++ b/StarAI/StarAI/ExecutionCore/TaskMetaData.cs @@ -0,0 +1,151 @@ +using StarAI.PathFindingCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.ExecutionCore +{ + public class TaskMetaData + { + public string name; + public float priority; + public float cost; + public float utility; + public float frequency; + public StarAI.ExecutionCore.TaskPrerequisites.StaminaPrerequisite staminaPrerequisite; + public StarAI.ExecutionCore.TaskPrerequisites.ToolPrerequisite toolPrerequisite; + public TaskPrerequisites.InventoryFullPrerequisite inventoryPrerequisite; + + public TaskPrerequisites.BedTimePrerequisite bedTimePrerequisite; + + public List prerequisitesList; + + + public List path = new List(); + + public TaskMetaData(string Name, float Priority, float Cost, float Utility, float Frequency, TaskPrerequisites.StaminaPrerequisite StaminaPrerequisite=null, TaskPrerequisites.ToolPrerequisite ToolPrerequisite=null, TaskPrerequisites.InventoryFullPrerequisite InventoryFull = null, TaskPrerequisites.BedTimePrerequisite BedTimePrereq=null) + { + this.name = Name; + this.priority = Priority; + this.cost = Cost; + this.utility = Utility; + this.frequency = Frequency; + this.staminaPrerequisite = StaminaPrerequisite; + this.toolPrerequisite = ToolPrerequisite; + this.inventoryPrerequisite = InventoryFull; + this.bedTimePrerequisite = BedTimePrereq; + //Make sure to set values correctly incase of null + setUpStaminaPrerequisiteIfNull(); + setUpToolPrerequisiteIfNull(); + setUpInventoryPrerequisiteIfNull(); + setUpBedTimeIfNull(); + this.prerequisitesList = new List(); + this.prerequisitesList.Add(this.staminaPrerequisite); + this.prerequisitesList.Add(this.toolPrerequisite); + this.prerequisitesList.Add(this.inventoryPrerequisite); + + this.prerequisitesList.Add(this.bedTimePrerequisite); + } + + public TaskMetaData(string Name,float Cost,TaskPrerequisites.StaminaPrerequisite StaminaPrerequisite = null, TaskPrerequisites.ToolPrerequisite ToolPrerequisite = null, TaskPrerequisites.InventoryFullPrerequisite InventoryFull = null,TaskPrerequisites.BedTimePrerequisite BedTimePrereq=null) + { + this.name = Name; + this.cost = Cost; + this.staminaPrerequisite = StaminaPrerequisite; + this.toolPrerequisite = ToolPrerequisite; + this.inventoryPrerequisite = InventoryFull; + + this.bedTimePrerequisite = BedTimePrereq; + //Make sure to set values correctly incase of null + setUpStaminaPrerequisiteIfNull(); + setUpToolPrerequisiteIfNull(); + setUpInventoryPrerequisiteIfNull(); + setUpBedTimeIfNull(); + this.prerequisitesList = new List(); + this.prerequisitesList.Add(this.staminaPrerequisite); + this.prerequisitesList.Add(this.toolPrerequisite); + this.prerequisitesList.Add(this.inventoryPrerequisite); + this.prerequisitesList.Add(this.bedTimePrerequisite); + } + + public TaskMetaData(string Name, TaskPrerequisites.StaminaPrerequisite StaminaPrerequisite = null, TaskPrerequisites.ToolPrerequisite ToolPrerequisite = null, TaskPrerequisites.InventoryFullPrerequisite InventoryFull=null,TaskPrerequisites.BedTimePrerequisite bedTimePrereq=null) + { + this.name = Name; + this.staminaPrerequisite = StaminaPrerequisite; + this.toolPrerequisite = ToolPrerequisite; + this.inventoryPrerequisite = InventoryFull; + + this.bedTimePrerequisite = bedTimePrereq; + //Make sure to set values correctly incase of null + setUpStaminaPrerequisiteIfNull(); + setUpToolPrerequisiteIfNull(); + setUpInventoryPrerequisiteIfNull(); + setUpBedTimeIfNull(); + this.prerequisitesList = new List(); + this.prerequisitesList.Add(this.staminaPrerequisite); + this.prerequisitesList.Add(this.toolPrerequisite); + this.prerequisitesList.Add(this.inventoryPrerequisite); + this.prerequisitesList.Add(this.bedTimePrerequisite); + } + + public void calculateTaskCost(TileNode source) + { + this.cost=TaskMetaDataHeuristics.calculateTaskCost(source, this.toolPrerequisite); + //this.path = Utilities.calculatePath(source, false); + } + + private void setUpToolPrerequisiteIfNull() + { + if (this.toolPrerequisite == null) + { + this.toolPrerequisite = new TaskPrerequisites.ToolPrerequisite(false, null,0); + } + } + private void setUpStaminaPrerequisiteIfNull() + { + if (this.staminaPrerequisite == null) + { + this.staminaPrerequisite = new TaskPrerequisites.StaminaPrerequisite(false, 0); + } + } + + private void setUpInventoryPrerequisiteIfNull() + { + if (this.inventoryPrerequisite == null) this.inventoryPrerequisite = new TaskPrerequisites.InventoryFullPrerequisite(false); + } + + private void setUpBedTimeIfNull() + { + if (this.bedTimePrerequisite == null) this.bedTimePrerequisite = new TaskPrerequisites.BedTimePrerequisite(true); + } + + + public bool verifyAllPrerequisitesHit() + { + foreach(var prerequisite in this.prerequisitesList) + { + if (prerequisite.checkAllPrerequisites() == false) return false; + } + return true; + } + + public void printMetaData() + { + string s = ""; + s += "Queued Task:"+"\n"; + s += " TaskName: " + this.name + "\n"; + s += " TaskCost: " + this.cost + "\n"; + + s += " Task Requires Stamina: " + this.staminaPrerequisite.requiresStamina + "\n"; + if(this.staminaPrerequisite.requiresStamina==true) s += " Requires : " + this.staminaPrerequisite.staminaCost + "Stamina.\n"; + s += " Task Requires Tool: " + this.toolPrerequisite.requiresTool + "\n"; + if (this.toolPrerequisite.requiresTool == true) s += " Requires a : " + this.toolPrerequisite.requiredTool + "\n"; + s += " Task Requires Tool: " + this.toolPrerequisite.requiresTool + "\n"; + s += " Checks if inventory full: "+this.inventoryPrerequisite.doesTaskRequireInventorySpace.ToString() + "\n"; + ModCore.CoreMonitor.Log(s); + } + + } +} diff --git a/StarAI/StarAI/ExecutionCore/TaskMetaDataHeuristics.cs b/StarAI/StarAI/ExecutionCore/TaskMetaDataHeuristics.cs new file mode 100644 index 00000000..017a9bcd --- /dev/null +++ b/StarAI/StarAI/ExecutionCore/TaskMetaDataHeuristics.cs @@ -0,0 +1,77 @@ +using StarAI.ExecutionCore.TaskPrerequisites; +using StarAI.PathFindingCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.ExecutionCore +{ + /// + /// This will be used to determine how much any given action, pathing distance, etc will have on the overall cost of a given task. + /// + public class TaskMetaDataHeuristics + { + + /// + /// Multiplier to be used to multiply out pathCost on any given action. Higher numbers will mean more discrimination against actions with long manhattan distances. + /// + public static int pathCostMultiplier=1; + /// + /// This is a dictionary that holds the action cost for every tool when it is used. + /// + public static Dictionary toolCostDictionary = new Dictionary(); + + /// + /// Used to set the values at the beginning. + /// + public static void initializeToolCostDictionary() + { + toolCostDictionary.Add(typeof(StardewValley.Tools.WateringCan), 2); + toolCostDictionary.Add(typeof(StardewValley.Tools.Axe), 4); + toolCostDictionary.Add(typeof(StardewValley.Tools.Pickaxe), 3); + toolCostDictionary.Add(typeof(StardewValley.Tools.FishingRod), 5); + toolCostDictionary.Add(typeof(StardewValley.Tools.Hoe), 2); + toolCostDictionary.Add(typeof(StardewValley.Tools.MeleeWeapon), 1); + toolCostDictionary.Add(typeof(StardewValley.Tools.Sword), 1); + } + + /// + /// Used to assign a weight to using a tool a single time. + /// + /// + /// + public static int parseToolCostMultiplier(TaskPrerequisites.ToolPrerequisite t) + { + Type tool = t.requiredTool; + int value=2; + bool f = toolCostDictionary.TryGetValue(tool,out value); + if (f == true) return value; + else return 2; + } + + /// + /// Used to calculate the weight of using a tool to add to the overall cost of a TaskMetaData cost. + /// + /// + /// + /// + public static int calculateToolCostMultiplier(TaskPrerequisites.ToolPrerequisite t) + { + if (t.requiresTool == false || t.requiredTool==null) return 0; //Default tool not used. + return (parseToolCostMultiplier(t) * t.estimatedNumberOfUses); + } + + public static float calculateTaskCost(TileNode v,ToolPrerequisite t) + { + PathFindingLogic.delay = 18; + int costCalculation = StarAI.PathFindingCore.Utilities.calculatePathCost(v,true); + if (costCalculation == Int32.MaxValue) return Int32.MaxValue; + float pathCost= costCalculation* pathCostMultiplier; + float toolCost = calculateToolCostMultiplier(t); + return (pathCost + toolCost); + } + + } +} diff --git a/StarAI/StarAI/ExecutionCore/TaskPrerequisites/BedTimePrerequisite.cs b/StarAI/StarAI/ExecutionCore/TaskPrerequisites/BedTimePrerequisite.cs new file mode 100644 index 00000000..200a8672 --- /dev/null +++ b/StarAI/StarAI/ExecutionCore/TaskPrerequisites/BedTimePrerequisite.cs @@ -0,0 +1,56 @@ +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.ExecutionCore.TaskPrerequisites +{ + public class BedTimePrerequisite : GenericPrerequisite + { + + public bool checkIfEnoughTimeRemaining; + public BedTimePrerequisite(bool CheckForBedtime) + { + this.checkIfEnoughTimeRemaining = CheckForBedtime; + } + + public int timeRemainingInDay() + { + int passOutTime = 2600; + return passOutTime - Game1.timeOfDay; + } + + /// + /// The default here will give you 2 hrs which should be enough for bedTime. + /// + /// + public bool enoughTimeToDoTask() + { + int timeRemaining = timeRemainingInDay(); + if (timeRemaining > 200) return true; + else return false; + } + + public bool enoughTimeToDoTask(int timeToDoTask) + { + int timeRemaining = timeRemainingInDay(); + if (timeRemaining > timeToDoTask) return true; + else return false; + } + + public override bool checkAllPrerequisites() + { + if (this.checkIfEnoughTimeRemaining == false) return true; + if (enoughTimeToDoTask()) return true; + else + { + ModCore.CoreMonitor.Log("Not enough time remaining in the day. You should go home."); + //Add functionality here to return home. + return false; + } + } + + } +} diff --git a/StarAI/StarAI/StarAI/ExecutionCore/TaskPrerequisites/GenericPrerequisite.cs b/StarAI/StarAI/ExecutionCore/TaskPrerequisites/GenericPrerequisite.cs similarity index 100% rename from StarAI/StarAI/StarAI/ExecutionCore/TaskPrerequisites/GenericPrerequisite.cs rename to StarAI/StarAI/ExecutionCore/TaskPrerequisites/GenericPrerequisite.cs diff --git a/StarAI/StarAI/ExecutionCore/TaskPrerequisites/InventoryFullPrerequisite.cs b/StarAI/StarAI/ExecutionCore/TaskPrerequisites/InventoryFullPrerequisite.cs new file mode 100644 index 00000000..e9118f37 --- /dev/null +++ b/StarAI/StarAI/ExecutionCore/TaskPrerequisites/InventoryFullPrerequisite.cs @@ -0,0 +1,39 @@ +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.ExecutionCore.TaskPrerequisites +{ + /// + /// Weirdly enough this will be empty because it's just a placeholder prerequisite. Doesn't need to hold any more data since the player will always have an updated inventory. + /// + public class InventoryFullPrerequisite:GenericPrerequisite + { + public bool doesTaskRequireInventorySpace; + public InventoryFullPrerequisite(bool RequiresInventorySpace) + { + this.doesTaskRequireInventorySpace = RequiresInventorySpace; + } + + public bool isPlayerInventoryFull() + { + + return Game1.player.isInventoryFull(); + } + + public override bool checkAllPrerequisites() + { + if (this.doesTaskRequireInventorySpace == false) return true; + if (isPlayerInventoryFull() == false) return true; + else//player inventory is full + { + ModCore.CoreMonitor.Log("Player inventory is full failed the task prerequisite"); + return false; + } + } + + } +} diff --git a/StarAI/StarAI/ExecutionCore/TaskPrerequisites/ToolPrerequisite.cs b/StarAI/StarAI/ExecutionCore/TaskPrerequisites/ToolPrerequisite.cs new file mode 100644 index 00000000..45a5480e --- /dev/null +++ b/StarAI/StarAI/ExecutionCore/TaskPrerequisites/ToolPrerequisite.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.ExecutionCore.TaskPrerequisites +{ + public class ToolPrerequisite:GenericPrerequisite + { + public bool requiresTool; + public Type requiredTool; + public int estimatedNumberOfUses; + + public ToolPrerequisite(bool TaskNeedsTool, Type RequiredTool, int EstimatedNumberOfUses) + { + requiresTool = TaskNeedsTool; + requiredTool = RequiredTool; + this.estimatedNumberOfUses = EstimatedNumberOfUses; + verifyToolSetUp(); + } + + public void verifyToolSetUp() + { + if (requiresTool == false) + { + requiredTool = null; + estimatedNumberOfUses = 0; + } + } + + public bool isToolInInventory() + { + if (requiresTool == false) return true; + foreach (var item in Game1.player.items) { + Type t = requiredTool.GetType(); + if ( item.GetType()==requiredTool) return true; + } + return false; + } + + public override bool checkAllPrerequisites() + { + if (isToolInInventory()) return true; + else + { + ModCore.CoreMonitor.Log("A task failed due to not having the required tool: "+this.requiredTool); + return false; + } + } + //istoolinanychests???? Needs function to be able to request an item from any given chest and go fetch it which can require moving across maps. + + } +} diff --git a/StarAI/StarAI/StarAI/ExecutionCore/TaskPrerequisites/staminaPrerequisite.cs b/StarAI/StarAI/ExecutionCore/TaskPrerequisites/staminaPrerequisite.cs similarity index 100% rename from StarAI/StarAI/StarAI/ExecutionCore/TaskPrerequisites/staminaPrerequisite.cs rename to StarAI/StarAI/ExecutionCore/TaskPrerequisites/staminaPrerequisite.cs diff --git a/StarAI/StarAI/ModCore.cs b/StarAI/StarAI/ModCore.cs new file mode 100644 index 00000000..18514c91 --- /dev/null +++ b/StarAI/StarAI/ModCore.cs @@ -0,0 +1,211 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using StardewValley; +using StardewModdingAPI; +using WindowsInput; +using Microsoft.Xna.Framework; +using StarAI.PathFindingCore; +using System.IO; +using StardustCore; + +namespace StarAI +{ + //TODO: Clean up initial code + //Make sure pathos doesn't update this once since it's a homework assignment. Sorry Pathos! + //Work on dijakstra's algorithm for path finding on this one? Make sure obstacles are included. + //Question how this is all going to work. + public class ModCore : Mod + { + public static StardewModdingAPI.IMonitor CoreMonitor; + public static StardewModdingAPI.IModHelper CoreHelper; + public static List warpGoals = new List(); + public static object[] obj = new object[3]; + + public override void Entry(IModHelper helper) + { + obj[0] = PathFindingLogic.source; + obj[1] = PathFindingLogic.currentGoal; + obj[2] = PathFindingLogic.queue; + CoreHelper = helper; + + // string[] s = new string[10]; + + CoreMonitor = this.Monitor; + CoreMonitor.Log("Hello AI WORLD!", LogLevel.Info); + Commands.initializeCommands(); + PathFindingCore.Utilities.initializeTileExceptionList(); + ExecutionCore.TaskMetaDataHeuristics.initializeToolCostDictionary(); + //throw new NotImplementedException(); + StardewModdingAPI.Events.LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged; + + StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed; + StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; + // StardewModdingAPI.Events.GraphicsEvents.OnPreRenderEvent += PathFindingCore.Utilities.addFromPlacementListBeforeDraw; + + + 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 SaveEvents_AfterLoad(object sender, EventArgs e) + { + loadExceptionTiles(); + } + + public void loadExceptionTiles() + { + if (!Directory.Exists(Path.Combine(CoreHelper.DirectoryPath, PathFindingCore.Utilities.folderForExceptionTiles))) + { + Directory.CreateDirectory(Path.Combine(CoreHelper.DirectoryPath, PathFindingCore.Utilities.folderForExceptionTiles)); + } + // Process the list of files found in the directory. + string[] fileEntries = Directory.GetFiles(Path.Combine(CoreHelper.DirectoryPath,PathFindingCore.Utilities.folderForExceptionTiles)); + foreach (string fileName in fileEntries) + { + try + { + TileExceptionNode t = TileExceptionNode.parseJson(fileName); + PathFindingCore.Utilities.ignoreCheckTiles.Add(t); + } + catch(Exception err) + { + ModCore.CoreMonitor.Log(err.ToString(), LogLevel.Error); + } + } + + } + + private void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e) + { + //J key for shop + #region + if (e.KeyPressed == Microsoft.Xna.Framework.Input.Keys.J) + { + CoreMonitor.Log("OK THE J KEY WAS PRESSED!"); + List shoppingList = new List(); + StarAI.PathFindingCore.TileNode t = new StarAI.PathFindingCore.TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Aqua)); + if (t == null) + { + CoreMonitor.Log("WTF?????"); + } + try + { + if (t == null) + { + return; + } + shoppingList.Add((Item)t); + Game1.activeClickableMenu = new StardewValley.Menus.ShopMenu(shoppingList); + } + catch (Exception err) + { + CoreMonitor.Log(Convert.ToString(err)); + } + } + #endregion + + //K key for placing a tile. + #region + if (e.KeyPressed == Microsoft.Xna.Framework.Input.Keys.K) + { + CoreMonitor.Log("OK THE K KEY WAS PRESSED!"); + + StarAI.PathFindingCore.TileNode t = new StarAI.PathFindingCore.TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.randomColor()); + if (t == null) + { + CoreMonitor.Log("WTF?????"); + } + try + { + if (t == null) + { + return; + } + CoreMonitor.Log(new Vector2(Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize).ToString()); + + int xPos = (int)(Game1.player.getTileX()) * Game1.tileSize; + int yPos = (int)(Game1.player.getTileY()) * Game1.tileSize; + Rectangle r = new Rectangle(xPos, yPos, Game1.tileSize, Game1.tileSize); + Vector2 pos = new Vector2(r.X, r.Y); + bool ok = StarAI.PathFindingCore.TileNode.checkIfICanPlaceHere(t, pos, Game1.player.currentLocation); + if (ok == false) return; + t.placementAction(Game1.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize); + //t.setAdjacentTiles(true); + } + catch (Exception err) + { + CoreMonitor.Log(Convert.ToString(err)); + } + } + #endregion + + if (e.KeyPressed == Microsoft.Xna.Framework.Input.Keys.U) + { + ExecutionCore.TaskList.printAllTaskMetaData(); + } + + if (e.KeyPressed == Microsoft.Xna.Framework.Input.Keys.O) + { + + foreach (var v in Game1.player.currentLocation.map.TileSheets) + { + foreach (var q in Game1.player.currentLocation.map.Layers) + { + string[] s = q.ToString().Split(':'); + string layer = s[1].Trim(); + if (Game1.player.currentLocation.map.GetLayer(layer) == null) + { + + ModCore.CoreMonitor.Log("SHITTTTTT: " + layer, LogLevel.Error); + } + int tileIndex = Game1.player.currentLocation.getTileIndexAt((int)Game1.player.getTileX() / Game1.tileSize, (int)Game1.player.getTileY() / Game1.tileSize, layer); + if (tileIndex == -1) continue; + //ModCore.CoreMonitor.Log("Position: " + (Game1.player.getTileLocation() / Game1.tileSize).ToString(), LogLevel.Warn); + //ModCore.CoreMonitor.Log("Layer: " + layer, LogLevel.Warn); + //ModCore.CoreMonitor.Log("Index: " + tileIndex.ToString(), LogLevel.Warn); + //ModCore.CoreMonitor.Log("Image Source: " + v.ImageSource, LogLevel.Warn); + + if (layer == "Buildings") + { + TileExceptionNode tileException = new TileExceptionNode(v.ImageSource, tileIndex); + foreach(var tile in PathFindingCore.Utilities.ignoreCheckTiles) + { + if (tile.imageSource == tileException.imageSource && tile.index == tileException.index) + { + ModCore.CoreMonitor.Log("Tile exception already initialized!"); + return; //tile is already initialized. + } + } + PathFindingCore.Utilities.ignoreCheckTiles.Add(tileException); + tileException.serializeJson(Path.Combine(ModCore.CoreHelper.DirectoryPath, PathFindingCore.Utilities.folderForExceptionTiles)); + //StardustCore.ModCore.SerializationManager. + } + } + } + } + } + + + + + private void LocationEvents_CurrentLocationChanged(object sender, StardewModdingAPI.Events.EventArgsCurrentLocationChanged e) + { + CoreMonitor.Log("LOCATION CHANGED!"); + CoreMonitor.Log(Game1.player.currentLocation.name); + foreach (var v in Game1.player.currentLocation.warps) + { + string s = "X: " + Convert.ToString(v.X) + " Y: " + Convert.ToString(v.Y) + " TargetX: " + Convert.ToString(v.TargetX) + " TargetY: " + Convert.ToString(v.TargetY) + " TargetLocationName: " + Convert.ToString(v.TargetName); + CoreMonitor.Log(s); + //warpGoals.Add(v); Disabled for now + } + //GameLocation loc=Game1.getLocationFromName("location name") + // + } + } +} + + + + diff --git a/StarAI/StarAI/PathFindingCore/ChestLogic.cs b/StarAI/StarAI/PathFindingCore/ChestLogic.cs new file mode 100644 index 00000000..241667b5 --- /dev/null +++ b/StarAI/StarAI/PathFindingCore/ChestLogic.cs @@ -0,0 +1,282 @@ +using Microsoft.Xna.Framework; +using StardewModdingAPI; +using StardewValley; +using StardewValley.Objects; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.PathFindingCore +{ + class ChestLogic + { + public static List chestsAtThisLocation = new List(); + + public static void getAllSeasonalSeedsFromAllChestsAtLocation(GameLocation location) + { + object[] arr = new object[1]; + arr[0] = location; + getAllSeasonalSeedsFromAllChestsAtLocation(arr); + } + + public static void getAllSeasonalSeedsFromAllChestsAtLocation(object obj) + { + object[] objArr = (object[])obj; + GameLocation location = (GameLocation)objArr[0]; + foreach (var v in location.objects) + { + ModCore.CoreMonitor.Log(v.Value.name); + if (v.Value is StardewValley.Objects.Chest) + { + //if contains seeds that can be planted this season. + foreach(var item in (v.Value as StardewValley.Objects.Chest).items) + { + if (item.getCategoryName() == "Seed") + { + + StardewValley.Crop c = new Crop(item.parentSheetIndex, 0, 0); + if (c.seasonsToGrowIn.Contains(Game1.currentSeason)) + { + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Brown)); + //t.placementAction(Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize); + t.tileLocation=new Vector2((int)v.Key.X, (int)v.Key.Y); + t.position = new Vector2(v.Key.X*Game1.tileSize, v.Key.Y*Game1.tileSize); + t.thisLocation = location; + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(t, Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize)); + Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "Chest")); + chestsAtThisLocation.Add(t); + } + } + } + + } + + } + + foreach (var v in chestsAtThisLocation) + { + object[] objList = new object[1]; + objList[0] = v; + // ExecutionCore.TaskList.taskList.Add(new Task(new Action(waterSingleCrop), obj)); + ExecutionCore.CustomTask task = new ExecutionCore.CustomTask(pathToSingleChest, objList, new ExecutionCore.TaskMetaData("Path to chest for seeds", null, null, new ExecutionCore.TaskPrerequisites.InventoryFullPrerequisite(true))); + if (task.taskMetaData.cost == Int32.MaxValue) + { + Utilities.clearExceptionListWithNames(true); + continue; + } + ExecutionCore.TaskList.taskList.Add(task); + Utilities.clearExceptionListWithName(true, "Child"); + // waterSingleCrop(v); + } + } + + public static void pathToSingleChest(object obj) + { + object[] objArr = (object[])obj; + TileNode v = (TileNode)objArr[0]; + bool moveOn = false; + foreach (var q in Utilities.tileExceptionList) + { + if (q.tile == v && q.actionType == "Chest") + { + moveOn = true; + } + } + if (moveOn == false) return; + + WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_C); + int xMin = -1; + int yMin = -1; + int xMax = 1; + int yMax = 1; + List miniGoals = new List(); + List> paths = new List>(); + //try to set children to tiles where children haven't been before + for (int x = xMin; x <= xMax; x++) + { + for (int y = yMin; y <= yMax; y++) + { + if (x == 0 && y == 0) continue; + + //Include these 4 checks for just left right up down movement. Remove them to enable 8 direction path finding + if (x == -1 && y == -1) continue; //upper left + if (x == -1 && y == 1) continue; //bottom left + if (x == 1 && y == -1) continue; //upper right + if (x == 1 && y == 1) continue; //bottom right + + Vector2 pos = new Vector2(v.tileLocation.X + x, v.tileLocation.Y + y); + //ModCore.CoreMonitor.Log("AHHHHHHH POSITION: " + pos.ToString(), LogLevel.Alert); + bool f = PathFindingCore.TileNode.checkIfICanPlaceHere(v, pos * Game1.tileSize, v.thisLocation, true,false); + // ModCore.CoreMonitor.Log("OK THIS IS THE RESULT F: " + f, LogLevel.Alert); + if (f == true) + { + + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + t.placementAction(Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode( t, Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize)); + miniGoals.Add(t); + Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "Navigation")); + } + } + } + List removalList = new List(); + foreach (var nav in miniGoals) + { + TileNode tempSource = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize); + //StaardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(tempSource, Game1.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize)); + List path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List(),true,false); + + if (path.Count != 0) + { + //ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn); + paths.Add(path); + foreach (var someTile in path) + { + if (someTile == nav) removalList.Add(someTile); + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(someTile); + someTile.thisLocation.objects.Remove(someTile.tileLocation); + //someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation); + //StardustCore.Utilities.masterRemovalList.Add(someTile); + //ModCore.CoreMonitor.Log("CAUGHT MY CULPERATE", LogLevel.Warn); + } + } + + } + Console.WriteLine("GOALS COUNT:" + miniGoals.Count); + foreach (var q in removalList) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(q); + q.thisLocation.objects.Remove(q.tileLocation); + } + removalList.Clear(); + int pathCost = 999999999; + List correctPath = new List(); + ModCore.CoreMonitor.Log("PATH COUNT:"+paths.Count.ToString()); + foreach (var potentialPath in paths) + { + if (potentialPath.Count == 0) continue; + if (potentialPath.Count < pathCost) + { + + pathCost = potentialPath.Count; + correctPath = potentialPath; + } + } + + foreach (var goodTile in correctPath) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Add(goodTile); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(goodTile, Game1.currentLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize)); + goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize); + + } + PathFindingLogic.calculateMovement(correctPath); + if (v.tileLocation.X < Game1.player.getTileX()) + { + Game1.player.faceDirection(3); + } + else if (v.tileLocation.X > Game1.player.getTileX()) + { + Game1.player.faceDirection(1); + } + else if (v.tileLocation.Y < Game1.player.getTileY()) + { + Game1.player.faceDirection(0); + } + else if (v.tileLocation.Y > Game1.player.getTileY()) + { + Game1.player.faceDirection(2); + } + + bool move = false; + Chest chest =(Chest) v.thisLocation.objects[v.tileLocation]; + List removalListSeeds = new List(); + //Try to grab all the seeds I can from the chest. + while (Game1.player.isInventoryFull()==false&&chest.items.Count>0) + { + + if (chest.giftbox) + { + ModCore.CoreMonitor.Log("GIFT BOX", LogLevel.Warn); + v.thisLocation.objects.Remove(v.tileLocation); + } + foreach (var item in chest.items) + { + if (item.getCategoryName() == "Seed") + { + int seedIndex = item.parentSheetIndex; + + if (seedIndex == 770) + { + seedIndex = Crop.getRandomLowGradeCropForThisSeason(Game1.currentSeason); + if (seedIndex == 473) + --seedIndex; + } + + StardewValley.Crop c = new Crop(seedIndex, 0, 0); + + if (c.seasonsToGrowIn.Contains(Game1.currentSeason)) + { + Game1.player.addItemByMenuIfNecessary(item); + removalListSeeds.Add(item); + break; + } + } + } + + + foreach(var remove in removalListSeeds) + { + chest.items.Remove(remove); + } + // if (WindowsInput.InputSimulator.IsKeyDown(WindowsInput.VirtualKeyCode.VK_C) == false) WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.VK_C); + + + + Vector2 center = new Vector2(); + if (Game1.player.facingDirection == 2) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X + 1, (int)v.tileLocation.Y); + continue; + } + if (Game1.player.facingDirection == 1) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X - 1, (int)v.tileLocation.Y); + continue; + } + if (Game1.player.facingDirection == 0) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y + 1); + continue; + + } + if (Game1.player.facingDirection == 3) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y - 1); + continue; + } + Game1.player.position = center; + + } + Utilities.cleanExceptionList(v); + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v); + // StardustCore.Utilities.masterRemovalList.Add(v); + //v.performRemoveAction(v.tileLocation, v.thisLocation); + // v.thisLocation.objects.Remove(v.tileLocation); + foreach (var goodTile in correctPath) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(goodTile); + //StardustCore.Utilities.masterRemovalList.Add(v); + goodTile.performRemoveAction(goodTile.tileLocation, goodTile.thisLocation); + //goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize); + } + //WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_C); + } + + + } +} diff --git a/StarAI/StarAI/PathFindingCore/CropLogic/CropLogic.cs b/StarAI/StarAI/PathFindingCore/CropLogic/CropLogic.cs new file mode 100644 index 00000000..733035ad --- /dev/null +++ b/StarAI/StarAI/PathFindingCore/CropLogic/CropLogic.cs @@ -0,0 +1,473 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using StardewModdingAPI; +using StardustCore; +using StardewValley; +using Microsoft.Xna.Framework; +using System.IO; +using StarAI.ExecutionCore.TaskPrerequisites; + +namespace StarAI.PathFindingCore.CropLogic +{ + + + class CropLogic + { + public static List cropsToWater = new List(); + public static List cropsToHarvest = new List(); + + public static void getAllCropsNeededToBeWatered() + { + foreach (var v in Game1.player.currentLocation.terrainFeatures) + { + + if (v.Value is StardewValley.TerrainFeatures.HoeDirt) + { + if ((v.Value as StardewValley.TerrainFeatures.HoeDirt).crop != null) + { + //cropsToWater.Add(v.Key); + //If my dirt needs to be watered and the crop isn't fully grown. + if ((v.Value as StardewValley.TerrainFeatures.HoeDirt).state==0 && isCropFullGrown((v.Value as StardewValley.TerrainFeatures.HoeDirt).crop) == false) + { + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.LightSkyBlue)); + t.placementAction(Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(t, Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize)); + Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "Water")); + cropsToWater.Add(t); + } + } + } + } + + //Instead of just running this function I should add it to my execution queue. + foreach(var v in cropsToWater) + { + object[] obj = new object[1]; + obj[0] = v; + // ExecutionCore.TaskList.taskList.Add(new Task(new Action(waterSingleCrop), obj)); + StardewValley.Tools.WateringCan w = new StardewValley.Tools.WateringCan(); + ExecutionCore.TaskList.taskList.Add(new ExecutionCore.CustomTask(waterSingleCrop, obj,new ExecutionCore.TaskMetaData("Water Crop", new StaminaPrerequisite(true,3),new ToolPrerequisite(true,w.GetType(),1)))); + // waterSingleCrop(v); + } + } + + public static void waterSingleCrop(TileNode v) + { + object[] obj = new object[1]; + obj[0] = v; + waterSingleCrop(obj); + } + + + public static void waterSingleCrop(object obj) { + object[] objArr =(object[]) obj; + TileNode v =(TileNode) objArr[0]; + bool moveOn = false; + foreach (var q in Utilities.tileExceptionList) + { + if(q.tile==v && q.actionType=="Water") + { + moveOn = true; + } + } + if (moveOn == false) return; + + WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_C); + int xMin = -1; + int yMin = -1; + int xMax = 1; + int yMax = 1; + List miniGoals = new List(); + List> paths = new List>(); + //try to set children to tiles where children haven't been before + for (int x = xMin; x <= xMax; x++) + { for (int y = yMin; y <= yMax; y++) + { + if (x == 0 && y == 0) continue; + + //Include these 4 checks for just left right up down movement. Remove them to enable 8 direction path finding + if (x == -1 && y == -1) continue; //upper left + if (x == -1 && y == 1) continue; //bottom left + if (x == 1 && y == -1) continue; //upper right + if (x == 1 && y == 1) continue; //bottom right + + Vector2 pos = new Vector2(v.tileLocation.X + x, v.tileLocation.Y + y); + //ModCore.CoreMonitor.Log("AHHHHHHH POSITION: " + pos.ToString(), LogLevel.Alert); + bool f= PathFindingCore.TileNode.checkIfICanPlaceHere(v, pos*Game1.tileSize, v.thisLocation,true); + // ModCore.CoreMonitor.Log("OK THIS IS THE RESULT F: " + f, LogLevel.Alert); + if (f == true) + { + + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + t.placementAction(Game1.currentLocation,(int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode( t, Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize)); + miniGoals.Add(t); + Utilities.tileExceptionList.Add(new TileExceptionMetaData(t,"Navigation")); + } + } + } + List removalList = new List(); + foreach(var nav in miniGoals) + { + TileNode tempSource= new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX()*Game1.tileSize, Game1.player.getTileY()*Game1.tileSize); + //StaardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(tempSource, Game1.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize)); + List path= PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource,nav,new List(),true,false); + + if (path.Count!=0) + { + //ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn); + paths.Add(path); + foreach(var someTile in path) + { + if (someTile == nav) removalList.Add(someTile); + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(someTile); + someTile.thisLocation.objects.Remove(someTile.tileLocation); + //someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation); + //StardustCore.Utilities.masterRemovalList.Add(someTile); + //ModCore.CoreMonitor.Log("CAUGHT MY CULPERATE", LogLevel.Warn); + } + } + + } + Console.WriteLine("GOALS COUNT:" + miniGoals.Count); + foreach(var q in removalList) { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(q); + q.thisLocation.objects.Remove(q.tileLocation); + } + removalList.Clear(); + int pathCost = 999999999; + List correctPath = new List(); + foreach(var potentialPath in paths) + { + if (potentialPath.Count == 0) continue; + if (potentialPath.Count < pathCost) + { + + pathCost = potentialPath.Count; + correctPath = potentialPath; + } + } + + foreach (var goodTile in correctPath) { + StardustCore.ModCore.SerializationManager.trackedObjectList.Add(goodTile); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(goodTile, Game1.currentLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize)); + goodTile.placementAction(goodTile.thisLocation,(int) goodTile.tileLocation.X*Game1.tileSize, (int)goodTile.tileLocation.Y*Game1.tileSize); + + } + PathFindingLogic.calculateMovement(correctPath); + + + + if (v.tileLocation.X < Game1.player.getTileX()) + { + Game1.player.faceDirection(3); + } + else if (v.tileLocation.X > Game1.player.getTileX()) + { + Game1.player.faceDirection(1); + } + else if (v.tileLocation.Y < Game1.player.getTileY()) + { + Game1.player.faceDirection(0); + } + else if (v.tileLocation.Y > Game1.player.getTileY()) + { + Game1.player.faceDirection(2); + } + foreach (var item in Game1.player.items) + { + if(item is StardewValley.Tools.WateringCan) + { + Game1.player.CurrentToolIndex = Game1.player.getIndexOfInventoryItem(item); + } + } + bool move = false; + while ((v.thisLocation.terrainFeatures[v.tileLocation] as StardewValley.TerrainFeatures.HoeDirt).state==0) + { + if(WindowsInput.InputSimulator.IsKeyDown(WindowsInput.VirtualKeyCode.VK_C)==false) WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.VK_C); + + Vector2 center=new Vector2(); + if (Game1.player.facingDirection == 2) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X+1, (int)v.tileLocation.Y); + continue; + } + if (Game1.player.facingDirection == 1) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X-1, (int)v.tileLocation.Y); + continue; + } + if (Game1.player.facingDirection == 0) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y+1); + continue; + + } + if (Game1.player.facingDirection == 3) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y-1); + continue; + } + Game1.player.position = center; + + + //Game1.setMousePosition((int)v.tileLocation.X*Game1.tileSize/2,(int)v.tileLocation.Y*Game1.tileSize/2); + ModCore.CoreMonitor.Log("DOESNT WATER LIKE YOU THINK IT SHOULD"); + ModCore.CoreMonitor.Log("player pos: "+Game1.player.position.ToString(),LogLevel.Warn); + ModCore.CoreMonitor.Log("TilePos: "+v.position.ToString(), LogLevel.Error); + } + Utilities.cleanExceptionList(v); + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v); + // StardustCore.Utilities.masterRemovalList.Add(v); + //v.performRemoveAction(v.tileLocation, v.thisLocation); + v.thisLocation.objects.Remove(v.tileLocation); + foreach (var goodTile in correctPath) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(goodTile); + //StardustCore.Utilities.masterRemovalList.Add(v); + goodTile.performRemoveAction(goodTile.tileLocation, goodTile.thisLocation); + //goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize); + } + WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_C); + } + + + + + + public static void getAllCropsNeededToBeHarvested() + { + foreach (var v in Game1.player.currentLocation.terrainFeatures) + { + + if (v.Value is StardewValley.TerrainFeatures.HoeDirt) + { + if ((v.Value as StardewValley.TerrainFeatures.HoeDirt).crop != null) + { + + + //If my dirt needs to be watered and the crop isn't fully grown. + + if (isCropFullGrown((v.Value as StardewValley.TerrainFeatures.HoeDirt).crop)) + { + ModCore.CoreMonitor.Log("OK!!!!"); + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.LimeGreen)); + t.placementAction(Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(t, Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize)); + Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "Harvest")); + cropsToHarvest.Add(t); + } + } + } + } + + //Instead of just running this function I should add it to my execution queue. + foreach (var v in cropsToHarvest) + { + object[] obj = new object[1]; + obj[0] = v; + //ExecutionCore.TaskList.taskList.Add(new Task(new Action(harvestSingleCrop), obj)); + ExecutionCore.TaskList.taskList.Add(new ExecutionCore.CustomTask(harvestSingleCrop, obj,new ExecutionCore.TaskMetaData("HarvestSingleCrop",null,null,new ExecutionCore.TaskPrerequisites.InventoryFullPrerequisite(true)))); + + // waterSingleCrop(v); + } + } + + public static void harvestSingleCrop(TileNode v) + { + object[] obj = new object[1]; + obj[0] = v; + harvestSingleCrop(obj); + } + + + + public static void harvestSingleCrop(object obj) + { + object[] objArr = (object[])obj; + TileNode v = (TileNode)objArr[0]; + foreach (var q in objArr){ + ModCore.CoreMonitor.Log("OK THIS IS THE RESULT !: " + q, LogLevel.Alert); + } + if(v==null) ModCore.CoreMonitor.Log("WTF MARK!!!!!!: ", LogLevel.Alert); + bool moveOn = false; + foreach (var q in Utilities.tileExceptionList) + { + if (q.tile == v && q.actionType == "Harvest") + { + moveOn = true; + } + } + if (moveOn == false) return; + + WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_X); + int xMin = -1; + int yMin = -1; + int xMax = 1; + int yMax = 1; + List miniGoals = new List(); + List> paths = new List>(); + //try to set children to tiles where children haven't been before + for (int x = xMin; x <= xMax; x++) + { + for (int y = yMin; y <= yMax; y++) + { + if (x == 0 && y == 0) continue; + + //Include these 4 checks for just left right up down movement. Remove them to enable 8 direction path finding + if (x == -1 && y == -1) continue; //upper left + if (x == -1 && y == 1) continue; //bottom left + if (x == 1 && y == -1) continue; //upper right + if (x == 1 && y == 1) continue; //bottom right + + Vector2 pos = new Vector2(v.tileLocation.X + x, v.tileLocation.Y + y); + //ModCore.CoreMonitor.Log("AHHHHHHH POSITION: " + pos.ToString(), LogLevel.Alert); + bool f = PathFindingCore.TileNode.checkIfICanPlaceHere(v, pos * Game1.tileSize, v.thisLocation, true); + ModCore.CoreMonitor.Log("OK THIS IS THE RESULT F: " + f, LogLevel.Alert); + if (f == true) + { + + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + t.placementAction(Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(t, Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize)); + miniGoals.Add(t); + Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "Navigation")); + } + } + } + List removalList = new List(); + foreach (var nav in miniGoals) + { + TileNode tempSource = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize); + List path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List(),true,false); + if (path.Count!=0) + { + ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn); + paths.Add(path); + foreach (var someTile in path) + { + if (someTile == nav) removalList.Add(someTile); + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(someTile); + someTile.thisLocation.objects.Remove(someTile.tileLocation); + //someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation); + //StardustCore.Utilities.masterRemovalList.Add(v); + } + } + + } + foreach (var q in removalList) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(q); + q.thisLocation.objects.Remove(q.tileLocation); + } + removalList.Clear(); + int pathCost = 999999999; + List correctPath = new List(); + foreach (var potentialPath in paths) + { + if (potentialPath.Count == 0) continue; + if (potentialPath.Count < pathCost) + { + pathCost = potentialPath.Count; + correctPath = potentialPath; + } + } + + foreach (var goodTile in correctPath) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Add(goodTile); + goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(goodTile, Game1.currentLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize)); + } + //END HERE FOR JUST CALCULATING PATH COST + + PathFindingLogic.calculateMovement(correctPath); + if (v.tileLocation.X < Game1.player.getTileX()) + { + Game1.player.faceDirection(3); + } + else if (v.tileLocation.X > Game1.player.getTileX()) + { + Game1.player.faceDirection(1); + } + else if (v.tileLocation.Y < Game1.player.getTileY()) + { + Game1.player.faceDirection(0); + } + else if (v.tileLocation.Y > Game1.player.getTileY()) + { + Game1.player.faceDirection(2); + } + /* + foreach (var item in Game1.player.items) + { + //if (item is StardewValley.Tools.WateringCan) + //{ + // Game1.player.CurrentToolIndex = Game1.player.getIndexOfInventoryItem(item); + //} + } + */ + bool move = false; + while ((v.thisLocation.terrainFeatures[v.tileLocation] as StardewValley.TerrainFeatures.HoeDirt).crop !=null) + { + if (WindowsInput.InputSimulator.IsKeyDown(WindowsInput.VirtualKeyCode.VK_X) == false) WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.VK_X); + + Vector2 center = new Vector2(); + if (Game1.player.facingDirection == 2) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X + 1, (int)v.tileLocation.Y); + continue; + } + if (Game1.player.facingDirection == 1) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X - 1, (int)v.tileLocation.Y); + continue; + } + if (Game1.player.facingDirection == 0) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y + 1); + continue; + + } + if (Game1.player.facingDirection == 3) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y - 1); + continue; + } + Game1.player.position = center; + } + Utilities.cleanExceptionList(v); + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v); + v.thisLocation.objects.Remove(v.tileLocation); + //v.performRemoveAction(v.tileLocation, v.thisLocation); + //StardustCore.Utilities.masterRemovalList.Add(v); + foreach (var goodTile in correctPath) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Add(goodTile); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(goodTile, Game1.currentLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize)); + goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize); + } + WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_X); + } + + + public static bool isCropFullGrown(Crop c) + { + + if (c.currentPhase >= c.phaseDays.Count - 1) + { + c.currentPhase = c.phaseDays.Count - 1; + c.dayOfCurrentPhase = 0; + return true; + } + return false; + } + + + } +} diff --git a/StarAI/StarAI/PathFindingCore/DebrisLogic/DebrisLogic.cs b/StarAI/StarAI/PathFindingCore/DebrisLogic/DebrisLogic.cs new file mode 100644 index 00000000..a08c14c9 --- /dev/null +++ b/StarAI/StarAI/PathFindingCore/DebrisLogic/DebrisLogic.cs @@ -0,0 +1,366 @@ +using Microsoft.Xna.Framework; +using StarAI.ExecutionCore.TaskPrerequisites; +using StardewModdingAPI; +using StardewValley; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.PathFindingCore.DebrisLogic +{ + class DebrisLogic + { + public static List sticksToChop = new List(); + + + public static void getAllSticksToChop(GameLocation location) + { + object[] arr = new object[1]; + arr[0] = location; + getAllSticksToChop(arr); + } + + public static void getAllSticksToChop(object obj) + { + int twingCount = 0; + object[] objArr = (object[])obj; + GameLocation location = (GameLocation)objArr[0]; + foreach (var v in location.objects) + { + ModCore.CoreMonitor.Log(v.Value.name); + + if (v.Value.name == "Twig") + { + ModCore.CoreMonitor.Log(v.Value.name,LogLevel.Warn); + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Brown)); + //t.placementAction(Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize); + t.fakePlacementAction(Game1.currentLocation, (int)v.Key.X, (int)v.Key.Y); + //t.tileLocation = new Vector2((int)v.Key.X, (int)v.Key.Y); + //t.position = new Vector2(v.Key.X * Game1.tileSize, v.Key.Y * Game1.tileSize); + //t.thisLocation = location; + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(t, Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize)); + Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "ChopStick")); + sticksToChop.Add(t); + twingCount++; + } + } + + + int ok = 0; + foreach (var v in sticksToChop) + { + + object[] objList = new object[1]; + objList[0] = v; + // ExecutionCore.TaskList.taskList.Add(new Task(new Action(waterSingleCrop), obj)); + StardewValley.Tools.Axe w = new StardewValley.Tools.Axe(); + ModCore.CoreMonitor.Log("Processing twig:" + ok.ToString() + " / " + twingCount.ToString()); + ok++; + ExecutionCore.CustomTask task= new ExecutionCore.CustomTask(chopSingleStick, objList, new ExecutionCore.TaskMetaData("Chop Single Stick", new StaminaPrerequisite(true, 3), new ToolPrerequisite(true, w.GetType(), 1))); + if (task.taskMetaData.cost == Int32.MaxValue) + { + Utilities.clearExceptionListWithNames(true); + continue; + } + + ModCore.CoreMonitor.Log("TASK COST:"+task.taskMetaData.cost.ToString()); + + ExecutionCore.TaskList.taskList.Add(task); + ModCore.CoreMonitor.Log("TASK LIST COUNT:"+ExecutionCore.TaskList.taskList.Count.ToString()); + Utilities.clearExceptionListWithName(true, "Child"); + // waterSingleCrop(v); + } + } + + + public static void getAllSticksToChopRadius(GameLocation location) + { + object[] arr = new object[1]; + arr[0] = location; + getAllSticksToChopRadius(arr); + } + + + public static StardewValley.Object checkRadiusForObject(int radius,string name) + { + for(int x = -radius; x <= radius; x++) + { + for (int y = -radius; y <= radius; y++) + { + + StardewValley.Object obj = Game1.player.currentLocation.getObjectAt((Game1.player.getTileX() + x)*Game1.tileSize, (Game1.player.getTileY() + y)*Game1.tileSize); + if (obj == null) continue; + if (obj.name==name) + { + return obj; + } + } + } + return null; + } + + public static bool doesLocationContainObject(GameLocation location, string name) + { + foreach(var v in location.objects) + { + if (name == v.Value.name) return true; + } + return false; + } + + public static void getAllSticksToChopRadius(object obj) + { + int radius = 1; + int twingCount = 0; + object[] objArr = (object[])obj; + GameLocation location = (GameLocation)objArr[0]; + if (doesLocationContainObject(location, "Twig")) { + StardewValley.Object twig = checkRadiusForObject(radius, "Twig"); + while (twig == null) + { + radius++; + twig = checkRadiusForObject(radius, "Twig"); + } + + + ModCore.CoreMonitor.Log(twig.name); + + if (twig.name == "Twig") + { + ModCore.CoreMonitor.Log(twig.name, LogLevel.Warn); + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Brown)); + //t.placementAction(Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize); + t.fakePlacementAction(Game1.currentLocation, (int)twig.tileLocation.X, (int)twig.tileLocation.Y); + //t.tileLocation = new Vector2((int)v.Key.X, (int)v.Key.Y); + //t.position = new Vector2(v.Key.X * Game1.tileSize, v.Key.Y * Game1.tileSize); + //t.thisLocation = location; + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(t, Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize)); + Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "ChopStick")); + sticksToChop.Add(t); + twingCount++; + } + } + else + { + ModCore.CoreMonitor.Log("Twig is not found at location."); + } + + + + int ok = 0; + foreach (var v in sticksToChop) + { + + object[] objList = new object[1]; + objList[0] = v; + // ExecutionCore.TaskList.taskList.Add(new Task(new Action(waterSingleCrop), obj)); + StardewValley.Tools.Axe w = new StardewValley.Tools.Axe(); + ModCore.CoreMonitor.Log("Processing twig:" + ok.ToString() + " / " + twingCount.ToString()); + ok++; + ExecutionCore.CustomTask task = new ExecutionCore.CustomTask(chopSingleStick, objList, new ExecutionCore.TaskMetaData("Chop Single Stick", new StaminaPrerequisite(true, 3), new ToolPrerequisite(true, w.GetType(), 1))); + + + ModCore.CoreMonitor.Log("TASK COST:" + task.taskMetaData.cost.ToString()); + + ExecutionCore.TaskList.taskList.Add(task); + ModCore.CoreMonitor.Log("TASK LIST COUNT:" + ExecutionCore.TaskList.taskList.Count.ToString()); + //Utilities.clearExceptionListWithName(true, "Child"); + // waterSingleCrop(v); + } + } + + + public static void chopSingleStick(TileNode v) + { + object[] obj = new object[1]; + obj[0] = v; + chopSingleStick(obj); + } + + + + public static void chopSingleStick(object obj) + { + object[] objArr = (object[])obj; + TileNode v = (TileNode)objArr[0]; + bool moveOn = false; + foreach (var q in Utilities.tileExceptionList) + { + if (q.tile == v && q.actionType == "ChopStick") + { + moveOn = true; + } + } + if (moveOn == false) return; + + WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_C); + int xMin = -1; + int yMin = -1; + int xMax = 1; + int yMax = 1; + List miniGoals = new List(); + List> paths = new List>(); + //try to set children to tiles where children haven't been before + for (int x = xMin; x <= xMax; x++) + { + for (int y = yMin; y <= yMax; y++) + { + if (x == 0 && y == 0) continue; + + //Include these 4 checks for just left right up down movement. Remove them to enable 8 direction path finding + if (x == -1 && y == -1) continue; //upper left + if (x == -1 && y == 1) continue; //bottom left + if (x == 1 && y == -1) continue; //upper right + if (x == 1 && y == 1) continue; //bottom right + + Vector2 pos = new Vector2(v.tileLocation.X + x, v.tileLocation.Y + y); + //ModCore.CoreMonitor.Log("AHHHHHHH POSITION: " + pos.ToString(), LogLevel.Alert); + bool f = PathFindingCore.TileNode.checkIfICanPlaceHere(v, pos * Game1.tileSize, v.thisLocation, true); + // ModCore.CoreMonitor.Log("OK THIS IS THE RESULT F: " + f, LogLevel.Alert); + if (f == true) + { + + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + t.placementAction(Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode( t, Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize)); + miniGoals.Add(t); + Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "Navigation")); + } + } + } + List removalList = new List(); + foreach (var nav in miniGoals) + { + TileNode tempSource = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize); + //StaardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(tempSource, Game1.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize)); + List path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List(), true, false); + + if (path.Count != 0) + { + //ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn); + paths.Add(path); + foreach (var someTile in path) + { + if (someTile == nav) removalList.Add(someTile); + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(someTile); + someTile.thisLocation.objects.Remove(someTile.tileLocation); + //someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation); + //StardustCore.Utilities.masterRemovalList.Add(someTile); + //ModCore.CoreMonitor.Log("CAUGHT MY CULPERATE", LogLevel.Warn); + } + } + + } + Console.WriteLine("GOALS COUNT:" + miniGoals.Count); + foreach (var q in removalList) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(q); + q.thisLocation.objects.Remove(q.tileLocation); + } + removalList.Clear(); + int pathCost = 999999999; + List correctPath = new List(); + foreach (var potentialPath in paths) + { + if (potentialPath.Count == 0) continue; + if (potentialPath.Count < pathCost) + { + + pathCost = potentialPath.Count; + correctPath = potentialPath; + } + } + + foreach (var goodTile in correctPath) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Add(goodTile); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(goodTile, Game1.currentLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize)); + goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize); + + } + PathFindingLogic.calculateMovement(correctPath); + + + + if (v.tileLocation.X < Game1.player.getTileX()) + { + Game1.player.faceDirection(3); + } + else if (v.tileLocation.X > Game1.player.getTileX()) + { + Game1.player.faceDirection(1); + } + else if (v.tileLocation.Y < Game1.player.getTileY()) + { + Game1.player.faceDirection(0); + } + else if (v.tileLocation.Y > Game1.player.getTileY()) + { + Game1.player.faceDirection(2); + } + foreach (var item in Game1.player.items) + { + if (item is StardewValley.Tools.Axe) + { + Game1.player.CurrentToolIndex = Game1.player.getIndexOfInventoryItem(item); + } + } + bool move = false; + StardewValley.Object twig = v.thisLocation.objects[v.tileLocation]; + while ((twig.name=="Twig")) + { + if (!v.thisLocation.isObjectAt((int)v.tileLocation.X*Game1.tileSize, (int)v.tileLocation.Y*Game1.tileSize)) break; + if (WindowsInput.InputSimulator.IsKeyDown(WindowsInput.VirtualKeyCode.VK_C) == false) WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.VK_C); + + Vector2 center = new Vector2(); + if (Game1.player.facingDirection == 2) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X + 1, (int)v.tileLocation.Y); + continue; + } + if (Game1.player.facingDirection == 1) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X - 1, (int)v.tileLocation.Y); + continue; + } + if (Game1.player.facingDirection == 0) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y + 1); + continue; + + } + if (Game1.player.facingDirection == 3) + { + center = Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y - 1); + continue; + } + Game1.player.position = center; + + + //Game1.setMousePosition((int)v.tileLocation.X*Game1.tileSize/2,(int)v.tileLocation.Y*Game1.tileSize/2); + ModCore.CoreMonitor.Log("DOESNT Axe LIKE YOU THINK IT SHOULD"); + ModCore.CoreMonitor.Log("player pos: " + Game1.player.position.ToString(), LogLevel.Warn); + ModCore.CoreMonitor.Log("TilePos: " + v.position.ToString(), LogLevel.Error); + } + Utilities.cleanExceptionList(v); + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v); + // StardustCore.Utilities.masterRemovalList.Add(v); + //v.performRemoveAction(v.tileLocation, v.thisLocation); + // v.thisLocation.objects.Remove(v.tileLocation); + foreach (var goodTile in correctPath) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(goodTile); + //StardustCore.Utilities.masterRemovalList.Add(v); + goodTile.performRemoveAction(goodTile.tileLocation, goodTile.thisLocation); + //goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize); + } + WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_C); + } + + + } +} diff --git a/StarAI/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs b/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs similarity index 92% rename from StarAI/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs rename to StarAI/StarAI/PathFindingCore/PathFindingLogic.cs index 58382abc..dd3cc037 100644 --- a/StarAI/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs +++ b/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs @@ -116,7 +116,7 @@ namespace StarAI.PathFindingCore if (x == 1 && y == 1) continue; //bottom right //TileNode t = new TileNode(1, Vector2.Zero, Souce.texturePath,source.dataPath, source.drawColor); - TileNode.setSingleTileAsChild(currentNode, (int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y); + TileNode.setSingleTileAsChild(currentNode, (int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y,false); Vector2 check = new Vector2((int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y); if(check.X==Goal.tileLocation.X && check.Y == Goal.tileLocation.Y) { @@ -275,13 +275,14 @@ namespace StarAI.PathFindingCore /// Depreciated for further builds. /// Whether or not tiles are actually going to be placed /// - public static List pathFindToSingleGoalReturnPath(TileNode Source, TileNode Goal, List Queue,bool Placement) + public static List pathFindToSingleGoalReturnPath(TileNode Source, TileNode Goal, List Queue,bool Placement,bool CheckForUtility) { - object[] obj = new object[4]; + object[] obj = new object[5]; obj[0] = Source; obj[1] = Goal; obj[2] = Queue; obj[3] = Placement; + obj[4] = CheckForUtility; return pathFindToSingleGoalReturnPath(obj); } @@ -308,14 +309,15 @@ namespace StarAI.PathFindingCore TileNode currentNode = Source; bool placement = (bool)obj[3]; + bool checkForUtility = (bool)obj[4]; queue.Add(currentNode); index++; bool goalFound = false; while (currentNode.tileLocation != Goal.tileLocation && queue.Count != 0) { // ModCore.CoreMonitor.Log("LET'S GO PATH!!!!", LogLevel.Error); - // ModCore.CoreMonitor.Log("PATH FROM SOURCE: " + currentNode.tileLocation, LogLevel.Error); - // ModCore.CoreMonitor.Log("PATH To GOAL: " + Goal.tileLocation, LogLevel.Error); + //ModCore.CoreMonitor.Log("PATH FROM SOURCE: " + currentNode.tileLocation, LogLevel.Error); + //ModCore.CoreMonitor.Log("PATH To GOAL: " + Goal.tileLocation, LogLevel.Error); //Console.WriteLine("OK WTF IS GOING ON????"); //Add children to current node int xMin = -1; @@ -337,8 +339,8 @@ namespace StarAI.PathFindingCore if (x == 1 && y == 1) continue; //bottom right //TileNode t = new TileNode(1, Vector2.Zero, Souce.texturePath,source.dataPath, source.drawColor); //ModCore.CoreMonitor.Log("HERE1", LogLevel.Error); - - TileNode.setSingleTileAsChild(currentNode, (int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y,placement); + + TileNode.setSingleTileAsChild(currentNode, (int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y, checkForUtility,true); //ModCore.CoreMonitor.Log("OR NO?", LogLevel.Error); Vector2 check = new Vector2((int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y); if (check.X == Goal.tileLocation.X && check.Y == Goal.tileLocation.Y) @@ -462,6 +464,7 @@ namespace StarAI.PathFindingCore } } List removalList = new List(); + List ignoreList = new List(); foreach (var v in StardustCore.ModCore.SerializationManager.trackedObjectList) { if (v is TileNode) @@ -469,25 +472,52 @@ namespace StarAI.PathFindingCore foreach (var exc in Utilities.tileExceptionList) { - if (exc.tile == (v as TileNode)) continue; + if (ignoreList.Contains(exc.tile)) continue; + // if ( (exc.tile == (v as TileNode)&&(exc.actionType!="Child"||exc.actionType!="Navigation"||exc.actionType!="CostCalculation"))|| path.Contains(v)) continue; + if (exc.actionType == "ChopStick") + { + List idk = new List(); + foreach (var q in removalList) + { + if (exc.tile.tileLocation == q.tileLocation) + { + idk.Add(q); + //removalList.Remove(exc.tile); + ignoreList.Add(exc.tile); + continue; + } + } + foreach(var h in idk) + { + removalList.Remove(exc.tile); + } + + } + else removalList.Add((TileNode)v); } - if (path.Contains(v) || goals.Contains(v) || v.drawColor == StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Red)) - { - continue; - } - else - { - removalList.Add((TileNode)v); - } + } } foreach (var v in removalList) { StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v); //v.performRemoveAction(v.tileLocation, v.thisLocation); - - if(placement)v.thisLocation.removeObject(v.tileLocation, false); + + try + { + StardewValley.Object ob = v.thisLocation.objects[v.tileLocation]; + + ModCore.CoreMonitor.Log(ob.name); + if (v.name != "Generic Colored Tile") continue;// ModCore.CoreMonitor.Log("Culperate 3"); + if (placement) v.thisLocation.removeObject(v.tileLocation, false); + } + catch(Exception err) + { + + } + + //StardustCore.Utilities.masterRemovalList.Add(v); } return path; diff --git a/StarAI/StarAI/StarAI/PathFindingCore/PlacementNode.cs b/StarAI/StarAI/PathFindingCore/PlacementNode.cs similarity index 100% rename from StarAI/StarAI/StarAI/PathFindingCore/PlacementNode.cs rename to StarAI/StarAI/PathFindingCore/PlacementNode.cs diff --git a/StarAI/StarAI/StarAI/PathFindingCore/TileExceptionMetaData.cs b/StarAI/StarAI/PathFindingCore/TileExceptionMetaData.cs similarity index 100% rename from StarAI/StarAI/StarAI/PathFindingCore/TileExceptionMetaData.cs rename to StarAI/StarAI/PathFindingCore/TileExceptionMetaData.cs diff --git a/StarAI/StarAI/StarAI/PathFindingCore/TileExceptionNode.cs b/StarAI/StarAI/PathFindingCore/TileExceptionNode.cs similarity index 100% rename from StarAI/StarAI/StarAI/PathFindingCore/TileExceptionNode.cs rename to StarAI/StarAI/PathFindingCore/TileExceptionNode.cs diff --git a/StarAI/StarAI/PathFindingCore/TileNodeObject.cs b/StarAI/StarAI/PathFindingCore/TileNodeObject.cs new file mode 100644 index 00000000..a089b7f9 --- /dev/null +++ b/StarAI/StarAI/PathFindingCore/TileNodeObject.cs @@ -0,0 +1,1038 @@ + +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json.Linq; +using StardewModdingAPI; +using StardewValley; +using StardewValley.Locations; +using StardewValley.Menus; +using StardewValley.Objects; +using StardewValley.TerrainFeatures; +using StardustCore; +using StardustCore.Animations; +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml.Serialization; + +namespace StarAI.PathFindingCore +{ + /// + /// Original Stardew Furniture Class but rewritten to be placed anywhere. + /// + public class TileNode : CoreObject + { + public Vector2 position; + public List children = new List(); + public enum stateEnum { NotVisited, Seen, Visited }; + public int seenState; + + + public int Decoration_type; + + public int rotations; + + public int currentRotation; + + private int sourceIndexOffset; + + public Vector2 drawPosition; + + public Rectangle sourceRect; + + public Rectangle defaultSourceRect; + + public Rectangle defaultBoundingBox; + + + public string description; + + public Texture2D TextureSheet; + + public new bool flipped; + + [XmlIgnore] + public bool flaggedForPickUp; + + private bool lightGlowAdded; + + public string texturePath; + public string dataPath; + + public bool IsSolid; + + public int cost; + public int costToThisPoint; + + public TileNode parent; + + public static bool checkIfICanPlaceHere(TileNode t, Vector2 pos, GameLocation loc = null,bool idk=true, bool utilityCheck=false) + { + bool cry = false; + if (t.thisLocation == null) + { + t.thisLocation = loc; + cry = true; + } + + + if (t == null) + { + Console.WriteLine("OK T IS NULL"); + } + if (t.thisLocation == null) + { + Console.WriteLine("OK T LOCATION IS NULL"); + } + + + if (t.thisLocation.isObjectAt((int)pos.X, (int)pos.Y)) + { + //ModCore.CoreMonitor.Log("Object at this tile position!: " + t.thisLocation.objects[new Vector2(pos.X/Game1.tileSize,pos.Y/Game1.tileSize)].name, LogLevel.Warn); + if (cry == true) t.thisLocation = null; + return false; + } + /* + if (utilityCheck) { + foreach (var v in Utilities.tileExceptionList) + { + // ModCore.CoreMonitor.Log(v.actionType); + if (v.tile.position == pos) return false; + if (v.tile.tileLocation == pos / Game1.tileSize) return false; + } + }*/ + + bool terrainFeature = t.thisLocation.terrainFeatures.ContainsKey(pos / Game1.tileSize); + if (terrainFeature) + { + TerrainFeature terrain = t.thisLocation.terrainFeatures[pos / Game1.tileSize]; + if (terrain.isPassable()) return true; + } + + if (t.thisLocation.isTileOccupied(pos / Game1.tileSize)) + { + // ModCore.CoreMonitor.Log("Tile occupied!: " + t.thisLocation.name, LogLevel.Error); + if (cry == true) t.thisLocation = null; + return false; + } + + if (t.thisLocation.isTilePlaceable(pos / Game1.tileSize) == false) + { + //ModCore.CoreMonitor.Log("Tile Not placeable at location. " + t.thisLocation.name, LogLevel.Error); + if (cry == true) t.thisLocation = null; + return false; + } + + + + if (t.thisLocation.isTilePassable(new xTile.Dimensions.Location((int)(pos.X/Game1.tileSize), (int)(pos.Y/Game1.tileSize)), Game1.viewport)==false) + { + // ModCore.CoreMonitor.Log("Tile not passable check 2?????!!!!: " + t.thisLocation.name, LogLevel.Error); + if (cry == true) t.thisLocation = null; + return false; + } + + + + if (cry == true) t.thisLocation = null; + return true; + } + + public static void setSingleTileAsChild(TileNode t,int x, int y,bool checkForUtility,bool placementAction=true) + { + + Vector2 pos = new Vector2(x * Game1.tileSize, y * Game1.tileSize); + + bool f= checkIfICanPlaceHere(t, new Vector2(pos.X,pos.Y),null,true,checkForUtility); + if (f == false) return; + else + { + + // ModCore.CoreMonitor.Log("Adding a child!"); + System.Threading.Thread.Sleep(PathFindingCore.PathFindingLogic.delay); + TileNode child = new TileNode(1, Vector2.Zero, t.texturePath,t.dataPath,StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Cyan)); + child.seenState = (int)stateEnum.NotVisited; + child.parent = t; + child.placementAction(t.thisLocation, (int)pos.X, (int)pos.Y); + //else child.fakePlacementAction(t.thisLocation, x, y); + Utilities.tileExceptionList.Add(new TileExceptionMetaData(child, "Child")); + //StarAI.PathFindingCore.Utilities.masterAdditionList.Add(new StarAI.PathFindingCore.PlacementNode(child, Game1.currentLocation, (int)pos.X, (int)pos.Y)); + t.children.Add(child); + } + } + + + + public override string Name + { + get + { + return this.name; + } + } + + public TileNode() + { + this.updateDrawPosition(); + } + + public TileNode(bool f) + { + //does nothng + } + + /// + /// TileNode Constructor. Does not use an animation manager. + /// + /// + /// + /// + /// + /// + /// + public TileNode(int which, Vector2 tile, string ObjectTexture, Color DrawColor, bool isRemovable = true, int price = 0, bool isSolid = false,int Cost=1) + { + this.cost = Cost; + Color c=DrawColor; + if (c == null) + { + c = StardustCore.IlluminateFramework.ColorsList.White; + } + this.drawColor = c; + + removable = isRemovable; + this.serializationName = Convert.ToString(GetType()); + // this.thisType = GetType(); + this.tileLocation = tile; + this.InitializeBasics(0, tile); + if (TextureSheet == null) + { + TextureSheet = ModCore.CoreHelper.Content.Load(ObjectTexture); //Game1.content.Load("TileSheets\\furniture"); + texturePath = ObjectTexture; + } + this.dataPath = ""; + + this.name = "Tile Node"; + + this.description = "A tile that is used to depict information."; + + + + + this.defaultSourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, 1, 1); + + this.defaultSourceRect.Width = 1; + this.defaultSourceRect.Height = 1; + this.sourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, this.defaultSourceRect.Width * 16, this.defaultSourceRect.Height * 16); + this.defaultSourceRect = this.sourceRect; + + this.defaultBoundingBox = new Rectangle((int)this.tileLocation.X, (int)this.tileLocation.Y, 1, 1); + + this.defaultBoundingBox.Width = 1; + this.defaultBoundingBox.Height = 1; + IsSolid = isSolid; + if (isSolid == true) + { + this.boundingBox = new Rectangle((int)this.tileLocation.X * Game1.tileSize, (int)this.tileLocation.Y * Game1.tileSize, this.defaultBoundingBox.Width * Game1.tileSize, this.defaultBoundingBox.Height * Game1.tileSize); + } + else + { + this.boundingBox = new Rectangle(int.MinValue, (int)this.tileLocation.Y * Game1.tileSize, 0, 0); //Throw the bounding box away as far as possible. + } + this.defaultBoundingBox = this.boundingBox; + this.updateDrawPosition(); + this.price = price; + this.parentSheetIndex = which; + } + + + public TileNode(int which, Vector2 tile, string ObjectTexture, string DataPath, Color DrawColor, bool isRemovable = true, bool isSolid = false,int Cost=1) + { + try + { + this.cost = Cost; + Color c = DrawColor; + if (c == null) + { + c = StardustCore.IlluminateFramework.ColorsList.White; + } + this.drawColor = c; + this.serializationName = Convert.ToString(GetType()); + removable = isRemovable; + // this.thisType = GetType(); + this.tileLocation = tile; + this.InitializeBasics(0, tile); + TextureSheet = ModCore.CoreHelper.Content.Load(ObjectTexture); //Game1.content.Load("TileSheets\\furniture"); + texturePath = ObjectTexture; + Dictionary dictionary; + try + { + + dictionary = ModCore.CoreHelper.Content.Load>(DataPath); + dataPath = DataPath; + + + string s = ""; + dictionary.TryGetValue(which, out s); + string[] array = s.Split('/'); + this.name = array[0]; + this.displayName = array[0]; + + this.description = array[1]; + this.defaultSourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, 1, 1); + + this.defaultSourceRect.Width = 1; + this.defaultSourceRect.Height = 1; + this.sourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, this.defaultSourceRect.Width * 16, this.defaultSourceRect.Height * 16); + this.defaultSourceRect = this.sourceRect; + try + { + this.animationManager = new StardustCore.Animations.AnimationManager(this.TextureSheet, new StardustCore.Animations.Animation(this.defaultSourceRect, -1), AnimationManager.parseAnimationsFromXNB(array[3]), "Default"); + this.animationManager.setAnimation("Default", 0); + //Log.AsyncC("Using animation manager"); + } + catch (Exception errr) + { + this.animationManager = new StardustCore.Animations.AnimationManager(this.TextureSheet, new StardustCore.Animations.Animation(this.defaultSourceRect, -1)); + ModCore.CoreMonitor.Log(errr.ToString()); + } + this.defaultBoundingBox = new Rectangle((int)this.tileLocation.X, (int)this.tileLocation.Y, 1, 1); + + this.defaultBoundingBox.Width = 1; + this.defaultBoundingBox.Height = 1; + IsSolid = isSolid; + if (isSolid == true) + { + this.boundingBox = new Rectangle((int)this.tileLocation.X * Game1.tileSize, (int)this.tileLocation.Y * Game1.tileSize, this.defaultBoundingBox.Width * Game1.tileSize, this.defaultBoundingBox.Height * Game1.tileSize); + } + else + { + this.boundingBox = new Rectangle(int.MinValue, (int)this.tileLocation.Y * Game1.tileSize, 0, 0); //Throw the bounding box away as far as possible. + } + this.defaultBoundingBox = this.boundingBox; + this.updateDrawPosition(); + this.price = Convert.ToInt32(array[2]); + this.parentSheetIndex = which; + + + + } + catch (Exception e) + { + ModCore.CoreMonitor.Log(e.ToString()); + // Log.AsyncC(e); + } + + } + catch(Exception fu) + { + ModCore.CoreMonitor.Log(fu.ToString()); + } + } + + + public override string getDescription() + { + return this.description; + } + + public override bool performDropDownAction(StardewValley.Farmer who) + { + this.resetOnPlayerEntry((who == null) ? Game1.currentLocation : who.currentLocation); + return false; + } + + public override void hoverAction() + { + base.hoverAction(); + } + + public override bool checkForAction(StardewValley.Farmer who, bool justCheckingForActivity = false) + { + var mState = Microsoft.Xna.Framework.Input.Mouse.GetState(); + if (mState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) + { + // Game1.showRedMessage("YOOO"); + //do some stuff when the right button is down + // rotate(); + return true; + } + + if (justCheckingForActivity) + { + return true; + } + + return this.clicked(who); //check for left clicked action. + } + + public override bool clicked(StardewValley.Farmer who) + { + int range = 2; + if (StardustCore.Utilities.isWithinRange(range, this.tileLocation) == false) return false; + + if (StardustCore.Utilities.isWithinDirectionRange(Game1.player.FacingDirection, range, this.tileLocation)) + { + if (Game1.player.CurrentItem != null) + { + if (Game1.player.getToolFromName(Game1.player.CurrentItem.Name) is StardewValley.Tools.WateringCan) + { + //this.animationManager.setAnimation("Watered", 0); + //TileExceptionMetaData t = new TileExceptionMetaData(this, "Water"); + bool foundRemoval = false; + foreach(var exc in Utilities.tileExceptionList) + { + if (exc.tile == this && exc.actionType=="Water") + { + this.thisLocation.objects.Remove(this.tileLocation); + foundRemoval = true; + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(this); + } + } + if(foundRemoval==true) PathFindingCore.Utilities.cleanExceptionList(this); + return false; + } + } + + if (Game1.player.CurrentItem != null) + { + if (Game1.player.CurrentItem is StardewValley.Tools.MeleeWeapon || Game1.player.CurrentItem is StardewValley.Tools.Sword) + { + + } + } + } + + + + + if (removable == false) return false; + // Game1.showRedMessage("THIS IS CLICKED!!!"); + Game1.haltAfterCheck = false; + if (this.Decoration_type == 11 && who.ActiveObject != null && who.ActiveObject != null && this.heldObject == null) + { + // Game1.showRedMessage("Why1?"); + return false; + } + if (this.heldObject == null && (who.ActiveObject == null || !(who.ActiveObject is TileNode))) + { + if (Game1.player.currentLocation is FarmHouse) + { + // Game1.showRedMessage("Why2?"); + // this.heldObject = new TileNode(parentSheetIndex, Vector2.Zero); + StardustCore.Utilities.addItemToInventoryAndCleanTrackedList(this,StardustCore.ModCore.SerializationManager); + this.flaggedForPickUp = true; + this.thisLocation = null; + this.locationsName = ""; + return true; + } + else + { + // return true; + + this.flaggedForPickUp = true; + if (this is TV) + { + this.heldObject = new TV(parentSheetIndex, Vector2.Zero); + } + else + { + // this.heldObject = new TileNode(parentSheetIndex, Vector2.Zero); + StardustCore.Utilities.addItemToInventoryAndCleanTrackedList(this,StardustCore.ModCore.SerializationManager); + // this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation); + // this.heldObject = null; + Game1.playSound("coin"); + this.thisLocation = null; + this.locationsName = ""; + return true; + } + + } + } + if (this.heldObject != null && who.addItemToInventoryBool(this.heldObject, false)) + { + // Game1.showRedMessage("Why3?"); + this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation); + this.heldObject = null; + StardustCore.Utilities.addItemToInventoryAndCleanTrackedList(this,StardustCore.ModCore.SerializationManager); + Game1.playSound("coin"); + this.thisLocation = null; + this.locationsName = ""; + return true; + } + + + + return false; + } + + public override void DayUpdate(GameLocation location) + { + base.DayUpdate(location); + this.lightGlowAdded = false; + if (!Game1.isDarkOut() || (Game1.newDay && !Game1.isRaining)) + { + this.removeLights(location); + return; + } + this.addLights(location); + + } + + public void dayUpdate() + { + + } + + public void resetOnPlayerEntry(GameLocation environment) + { + this.removeLights(environment); + if (Game1.isDarkOut()) + { + this.addLights(environment); + } + } + + public override bool performObjectDropInAction(StardewValley.Object dropIn, bool probe, StardewValley.Farmer who) + { + if ((this.Decoration_type == 11 || this.Decoration_type == 5) && this.heldObject == null && !dropIn.bigCraftable && (!(dropIn is TileNode) || ((dropIn as TileNode).getTilesWide() == 1 && (dropIn as TileNode).getTilesHigh() == 1))) + { + this.heldObject = (StardewValley.Object)dropIn.getOne(); + this.heldObject.tileLocation = this.tileLocation; + this.heldObject.boundingBox.X = this.boundingBox.X; + this.heldObject.boundingBox.Y = this.boundingBox.Y; + // Log.AsyncO(getDefaultBoundingBoxForType((dropIn as TileNode).Decoration_type)); + this.heldObject.performDropDownAction(who); + if (!probe) + { + Game1.playSound("woodyStep"); + // Log.AsyncC("HUH?"); + if (who != null) + { + who.reduceActiveItemByOne(); + } + } + return true; + } + return false; + } + + private void addLights(GameLocation environment) + { + // this.lightSource.lightTexture = Game1.content.Load("LooseSprites\\Lighting\\lantern"); + + if (this.Decoration_type == 7) + { + if (this.sourceIndexOffset == 0) + { + this.sourceRect = this.defaultSourceRect; + this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; + } + this.sourceIndexOffset = 1; + if (this.lightSource == null) + { + Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + this.lightSource = new LightSource(4, new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y - Game1.tileSize)), 2f, Color.Black, (int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + Game1.currentLightSources.Add(this.lightSource); + return; + } + } + else if (this.Decoration_type == 13) + { + if (this.sourceIndexOffset == 0) + { + this.sourceRect = this.defaultSourceRect; + this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; + } + this.sourceIndexOffset = 1; + if (this.lightGlowAdded) + { + environment.lightGlows.Remove(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize))); + this.lightGlowAdded = false; + } + } + } + + public override bool minutesElapsed(int minutes, GameLocation environment) + { + if (Game1.isDarkOut()) + { + this.addLights(environment); + } + else + { + this.removeLights(environment); + } + return false; + } + + public override void performRemoveAction(Vector2 tileLocation, GameLocation environment) + { + this.removeLights(environment); + if (this.Decoration_type == 13 && this.lightGlowAdded) + { + environment.lightGlows.Remove(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize))); + this.lightGlowAdded = false; + } + base.performRemoveAction(tileLocation, environment); + } + public bool isGroundFurniture() + { + return this.Decoration_type != 13 && this.Decoration_type != 6 && this.Decoration_type != 13; + } + + public override bool canBeGivenAsGift() + { + return false; + } + + public override bool canBePlacedHere(GameLocation l, Vector2 tile) + { + if ((l is FarmHouse)) + { + for (int i = 0; i < this.boundingBox.Width / Game1.tileSize; i++) + { + for (int j = 0; j < this.boundingBox.Height / Game1.tileSize; j++) + { + Vector2 vector = tile * (float)Game1.tileSize + new Vector2((float)i, (float)j) * (float)Game1.tileSize; + vector.X += (float)(Game1.tileSize / 2); + vector.Y += (float)(Game1.tileSize / 2); + foreach (KeyValuePair something in l.objects) + { + StardewValley.Object obj = something.Value; + if ((obj.GetType()).ToString().Contains("TileNode")) + { + TileNode current = (TileNode)obj; + if (current.Decoration_type == 11 && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y) && current.heldObject == null && this.getTilesWide() == 1) + { + bool result = true; + return result; + } + if ((current.Decoration_type != 12 || this.Decoration_type == 12) && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y)) + { + bool result = false; + return result; + } + } + } + } + } + return base.canBePlacedHere(l, tile); + } + else + { + // Game1.showRedMessage("NOT FARMHOUSE"); + for (int i = 0; i < this.boundingBox.Width / Game1.tileSize; i++) + { + for (int j = 0; j < this.boundingBox.Height / Game1.tileSize; j++) + { + Vector2 vector = tile * (float)Game1.tileSize + new Vector2((float)i, (float)j) * (float)Game1.tileSize; + vector.X += (float)(Game1.tileSize / 2); + vector.Y += (float)(Game1.tileSize / 2); + /* + foreach (TileNode current in (l as FarmHouse).TileNode) + { + if (current.Decoration_type == 11 && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y) && current.heldObject == null && this.getTilesWide() == 1) + { + bool result = true; + return result; + } + if ((current.Decoration_type != 12 || this.Decoration_type == 12) && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y)) + { + bool result = false; + return result; + } + } + */ + } + } + return base.canBePlacedHere(l, tile); + } + } + + public void updateDrawPosition() + { + this.drawPosition = new Vector2((float)this.boundingBox.X, (float)(this.boundingBox.Y - (this.sourceRect.Height * Game1.pixelZoom - this.boundingBox.Height))); + } + + public int getTilesWide() + { + return this.boundingBox.Width / Game1.tileSize; + } + + public int getTilesHigh() + { + return this.boundingBox.Height / Game1.tileSize; + } + + public override bool placementAction(GameLocation location, int x, int y, StardewValley.Farmer who = null) + { + + Point point = new Point(x / Game1.tileSize, y / Game1.tileSize); + this.position = new Vector2(x, y); + + this.tileLocation = new Vector2((float)point.X, (float)point.Y); + bool flag = false; + + if (this.IsSolid) + { + this.boundingBox = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height); + } + else + { + this.boundingBox = new Rectangle(int.MinValue, y / Game1.tileSize * Game1.tileSize, 0, 0); + } + + /* + foreach (Furniture current2 in (location as DecoratableLocation).furniture) + { + if (current2.furniture_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox)) + { + current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who); + bool result = true; + return result; + } + } + */ + using (List.Enumerator enumerator3 = location.getFarmers().GetEnumerator()) + { + while (enumerator3.MoveNext()) + { + if (enumerator3.Current.GetBoundingBox().Intersects(this.boundingBox)) + { + Game1.showRedMessage("Can't place on top of a person."); + bool result = false; + return result; + } + } + } + this.updateDrawPosition(); + try + { + bool f = StardustCore.Utilities.placementAction(this, location, x, y, StardustCore.ModCore.SerializationManager, who); + + this.thisLocation = Game1.player.currentLocation; + return f; + } + catch(Exception err) + { + ModCore.CoreMonitor.Log(err.ToString()); + return false; + } + + // Game1.showRedMessage("Can only be placed in House"); + // return false; + } + + public override bool isPlaceable() + { + return true; + } + + public override Rectangle getBoundingBox(Vector2 tileLocation) + { + return this.boundingBox; + } + + public override int salePrice() + { + return this.price; + } + + public override int maximumStackSize() + { + return 1; + } + + public override int getStack() + { + return this.stack; + } + + public override int addToStack(int amount) + { + return 1; + } + + public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, StardewValley.Farmer f) + { + if (animationManager == null) + { + spriteBatch.Draw(this.TextureSheet, objectPosition, new Microsoft.Xna.Framework.Rectangle?(Game1.currentLocation.getSourceRectForObject(f.ActiveObject.ParentSheetIndex)), this.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + } + else + { + spriteBatch.Draw(this.TextureSheet, objectPosition, this.animationManager.currentAnimation.sourceRectangle, this.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + } + + if (f.ActiveObject != null && f.ActiveObject.Name.Contains("=")) + { + spriteBatch.Draw(this.TextureSheet, objectPosition + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Microsoft.Xna.Framework.Rectangle?(Game1.currentLocation.getSourceRectForObject(f.ActiveObject.ParentSheetIndex)), this.drawColor, 0f, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), (float)Game1.pixelZoom + Math.Abs(Game1.starCropShimmerPause) / 8f, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + if (Math.Abs(Game1.starCropShimmerPause) <= 0.05f && Game1.random.NextDouble() < 0.97) + { + return; + } + Game1.starCropShimmerPause += 0.04f; + if (Game1.starCropShimmerPause >= 0.8f) + { + Game1.starCropShimmerPause = -0.8f; + } + } + //base.drawWhenHeld(spriteBatch, objectPosition, f); + } + + public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber) + { + try + { + if (animationManager == null) spriteBatch.Draw(TextureSheet, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Rectangle?(this.defaultSourceRect), this.drawColor * transparency, 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height / 2)), 1f * (3) * scaleSize, SpriteEffects.None, layerDepth); + else + { + spriteBatch.Draw(animationManager.objectTexture, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Rectangle?(animationManager.currentAnimation.sourceRectangle), this.drawColor * transparency, 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height / 2)), 1f * (3) * scaleSize, SpriteEffects.None, layerDepth); + + + //this.modularCrop.drawInMenu(spriteBatch, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), this.drawColor, 0f,true); + + if (Game1.player.CurrentItem != this) animationManager.tickAnimation(); + } + Vector2 v = location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)); + } + catch(Exception err) + { + ModCore.CoreMonitor.Log(err.ToString()); + } + } + + + + public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f) + { + try + { + //The actual planter box being drawn. + if (animationManager == null) + { + spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.sourceRect), this.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0); + // Log.AsyncG("ANIMATION IS NULL?!?!?!?!"); + } + + else + { + //Log.AsyncC("Animation Manager is working!"); + spriteBatch.Draw(animationManager.objectTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(animationManager.currentAnimation.sourceRectangle), this.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0); + try + { + this.animationManager.tickAnimation(); + // Log.AsyncC("Tick animation"); + } + catch (Exception err) + { + ModCore.CoreMonitor.Log(err.ToString()); + } + } + + // spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)((double)tileLocation.X * (double)Game1.tileSize + (((double)tileLocation.X * 11.0 + (double)tileLocation.Y * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2), (float)((double)tileLocation.Y * (double)Game1.tileSize + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2))), new Rectangle?(new Rectangle((int)((double)tileLocation.X * 51.0 + (double)tileLocation.Y * 77.0) % 3 * 16, 128 + this.whichForageCrop * 16, 16, 16)), this.drawColor, 0.0f, new Vector2(8f, 8f), (float)Game1.pixelZoom, SpriteEffects.None, (float)(((double)tileLocation.Y * (double)Game1.tileSize + (double)(Game1.tileSize / 2) + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) / 10000.0)); + + if (this.heldObject != null) + { + if (this.heldObject is TileNode) + { + (this.heldObject as TileNode).drawAtNonTileSpot(spriteBatch, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - (this.heldObject as TileNode).sourceRect.Height * Game1.pixelZoom - Game1.tileSize / 4))), (float)(this.boundingBox.Bottom - 7) / 10000f, alpha); + return; + } + spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))) + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 5 / 6)), new Rectangle?(Game1.shadowTexture.Bounds), this.drawColor * alpha, 0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, (float)this.boundingBox.Bottom / 10000f); + spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))), new Rectangle?(Game1.currentLocation.getSourceRectForObject(this.heldObject.ParentSheetIndex)), this.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, (float)(this.boundingBox.Bottom + 1) / 10000f); + } + + + + } + catch(Exception err) + { + ModCore.CoreMonitor.Log(err.ToString()); + } + } + + + + public new void drawAtNonTileSpot(SpriteBatch spriteBatch, Vector2 location, float layerDepth, float alpha = 1f) + { + try + { + spriteBatch.Draw(TextureSheet, location, new Rectangle?(this.sourceRect), this.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); + } + catch(Exception err) + { + ModCore.CoreMonitor.Log(err.ToString()); + + } + // this.drawCrops(spriteBatch, (int)location.X*Game1.tileSize, (int)location.Y*Game1.tileSize, 1, true); + } + + public override Item getOne() + { + try + { + if (this.dataPath == "") return new TileNode(this.parentSheetIndex, this.tileLocation, this.texturePath,this.drawColor, this.removable, this.price, this.IsSolid); + else return new TileNode(this.parentSheetIndex, this.tileLocation, this.texturePath, this.dataPath,this.drawColor, this.removable, this.IsSolid); + } + catch (Exception err) + { + ModCore.CoreMonitor.Log(err.ToString()); + return null; + } + /* + drawPosition = this.drawPosition; + defaultBoundingBox = this.defaultBoundingBox; + boundingBox = this.boundingBox; + currentRotation = this.currentRotation - 1; + rotations = this.rotations; + rotate(); + */ + } + + public override string getCategoryName() + { + return "Tile Node"; + // return base.getCategoryName(); + } + + public override Color getCategoryColor() + { + return Color.Purple; + } + + public static new void Serialize(Item I) + { + StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.playerInventoryPath, I.Name + ".json"), (TileNode)I); + } + + public static void Serialize(Item I, string s) + { + StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(s, I.Name + ".json"), (TileNode)I); + } + + public static Item ParseIntoInventory(string s) + { + // TileNode p = new TileNode(); + // return p; + + + + dynamic obj = JObject.Parse(s); + + TileNode d = new TileNode(); + + d.dataPath = obj.dataPath; + d.price = obj.price; + d.Decoration_type = obj.Decoration_type; + d.rotations = obj.rotations; + d.currentRotation = obj.currentRotation; + string s1 = Convert.ToString(obj.sourceRect); + d.sourceRect = StardustCore.Utilities.parseRectFromJson(s1); + string s2 = Convert.ToString(obj.defaultSourceRect); + d.defaultSourceRect = StardustCore.Utilities.parseRectFromJson(s2); + string s3 = Convert.ToString(obj.defaultBoundingBox); + d.defaultBoundingBox = StardustCore.Utilities.parseRectFromJson(s3); + d.description = obj.description; + d.flipped = obj.flipped; + d.flaggedForPickUp = obj.flaggedForPickUp; + d.tileLocation = obj.tileLocation; + d.parentSheetIndex = obj.parentSheetIndex; + d.owner = obj.owner; + d.name = obj.name; + d.type = obj.type; + d.canBeSetDown = obj.canBeSetDown; + d.canBeGrabbed = obj.canBeGrabbed; + d.isHoedirt = obj.isHoedirt; + d.isSpawnedObject = obj.isSpawnedObject; + d.questItem = obj.questItem; + d.isOn = obj.isOn; + d.fragility = obj.fragility; + d.edibility = obj.edibility; + d.stack = obj.stack; + d.quality = obj.quality; + d.bigCraftable = obj.bigCraftable; + d.setOutdoors = obj.setOutdoors; + d.setIndoors = obj.setIndoors; + d.readyForHarvest = obj.readyForHarvest; + d.showNextIndex = obj.showNextIndex; + d.hasBeenPickedUpByFarmer = obj.hasBeenPickedUpByFarmer; + d.isRecipe = obj.isRecipe; + d.isLamp = obj.isLamp; + d.heldObject = obj.heldObject; + d.minutesUntilReady = obj.minutesUntilReady; + string s4 = Convert.ToString(obj.boundingBox); + d.boundingBox = StardustCore.Utilities.parseRectFromJson(s4); + d.scale = obj.scale; + d.lightSource = obj.lightSource; + d.shakeTimer = obj.shakeTimer; + d.internalSound = obj.internalSound; + d.specialVariable = obj.specialVariable; + d.category = obj.category; + d.specialItem = obj.specialItem; + d.hasBeenInInventory = obj.hasBeenInInventory; + + + string t = obj.texturePath; + d.TextureSheet = ModCore.CoreHelper.Content.Load(t); + d.texturePath = t; + JArray array = obj.inventory; + d.inventory = array.ToObject>(); + d.inventoryMaxSize = obj.inventoryMaxSize; + d.itemReadyForHarvest = obj.itemReadyForHarvest; + d.lightsOn = obj.lightsOn; + d.lightColor = obj.lightColor; + d.thisType = obj.thisType; + d.removable = obj.removable; + d.locationsName = obj.locationsName; + + d.drawColor = obj.drawColor; + + d.serializationName = obj.serializationName; + d.IsSolid = obj.IsSolid; + + string IsWatered = obj.isWatered; + // Log.AsyncC("AM I WATERED OR NOT?!?!?: "+IsWatered); + //ANIMATIONS + var q = obj.animationManager; + dynamic obj1 = q; + string name = Convert.ToString(obj1.currentAnimationName); + int frame = Convert.ToInt32(obj1.currentAnimationListIndex); + TileNode dummy = new TileNode(d.parentSheetIndex, d.tileLocation, d.texturePath, d.dataPath,d.drawColor, d.removable, d.IsSolid); + d.animationManager = dummy.animationManager; + bool f = d.animationManager.setAnimation(name, frame); + bool f2; + if (f == false) + { + f2 = d.animationManager.setAnimation(name, 0); + if (f2 == false) d.animationManager.currentAnimation = d.animationManager.defaultDrawFrame; + } + + + try + { + return d; + } + catch (Exception e) + { + // Log.AsyncM(e); + return null; + } + + //return base.ParseIntoInventory(); + } + + public static void SerializeFromWorld(Item I) + { + //makeCropInformationString(I); + // ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.objectsInWorldPath, (c as CoreObject).thisLocation.name, c.Name + ".json"), (TileNode)c); + StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.objectsInWorldPath, I.Name + ".json"), (TileNode)I); + } + + + + + + } +} \ No newline at end of file diff --git a/StarAI/StarAI/PathFindingCore/Utilities.cs b/StarAI/StarAI/PathFindingCore/Utilities.cs new file mode 100644 index 00000000..daaaa486 --- /dev/null +++ b/StarAI/StarAI/PathFindingCore/Utilities.cs @@ -0,0 +1,408 @@ +using Microsoft.Xna.Framework; +using StardewModdingAPI; +using StardewValley; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WindowsInput; + +namespace StarAI.PathFindingCore +{ + public class Utilities + { + + + public static List tileExceptionList = new List(); + + public static List ignoreCheckTiles = new List(); + public static string folderForExceptionTiles="ExceptionTilesData"; + + + + + public static Vector2 parseCenterFromTile(int tileX, int tileY) + { + //int x = (tileX * Game1.tileSize) + Game1.tileSize / 2; + //int y = (tileY * Game1.tileSize) + Game1.tileSize / 2; + int x = (tileX * Game1.tileSize); + int y = (tileY * Game1.tileSize); + return new Vector2(x, y); + } + + public static void initializeTileExceptionList() + { + + } + + + public static void cleanExceptionList(TileNode t) + { + TileExceptionMetaData err= new TileExceptionMetaData(null,""); + foreach (var v in tileExceptionList) + { + if (v.tile == t) err = v; + } + if(err.tile != null) + { + tileExceptionList.Remove(err); + } + } + + public static TileExceptionMetaData getExceptionFromTile(TileNode t) + { + foreach(var v in tileExceptionList) + { + if (t == v.tile) return v; + } + return null; + } + + public static void clearExceptionListWithNames(bool removeFromWorld) + { + List removalList = new List(); + List removalList2 = new List(); + foreach (var v in StardustCore.ModCore.SerializationManager.trackedObjectList) + { + TileExceptionMetaData exc = getExceptionFromTile((v as TileNode)); + if (exc != null) + { + if (exc.actionType == "Navigation" || exc.actionType == "CostCalculation" || exc.actionType == "Child") + { + removalList.Add(exc.tile); + removalList2.Add(exc); + } + } + + } + + foreach(var v in removalList) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v); + if (removeFromWorld) v.thisLocation.objects.Remove(v.tileLocation); + + } + foreach(var v in removalList2) + { + tileExceptionList.Remove(v); + } + } + + + public static void clearExceptionListWithName(bool removeFromWorld,string name) + { + List removalList = new List(); + List removalList2 = new List(); + foreach (var v in StardustCore.ModCore.SerializationManager.trackedObjectList) + { + TileExceptionMetaData exc = getExceptionFromTile((v as TileNode)); + if (exc != null) + { + if (exc.actionType == name) + { + removalList.Add(exc.tile); + removalList2.Add(exc); + } + } + + } + + foreach (var v in removalList) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v); + if (removeFromWorld) v.thisLocation.objects.Remove(v.tileLocation); + + } + foreach (var v in removalList2) + { + tileExceptionList.Remove(v); + } + } + /// + /// Used to calculate center of a tile with varience. + /// + /// + /// + /// + /// + public static bool isWithinRange(float position, float goal, int tolerance) + { + if (position >= goal - tolerance && position <= goal + tolerance) return true; + return false; + } + + + public static int calculatePathCost(TileNode v, bool Placement = true) + { + object[] obj = new object[2]; + obj[0] = v; + obj[1] = Placement; + return calculatePathCost(obj); + } + + public static int calculatePathCost(object obj) + { + object[] objArr = (object[])obj; + TileNode v = (TileNode)objArr[0]; + bool placement; + try + { + placement = (bool)objArr[1]; + } + catch(Exception err) + { + placement = true; + } + foreach (var q in objArr) + { + ModCore.CoreMonitor.Log("OK THIS IS THE RESULT !: " + q, LogLevel.Alert); + } + if (v == null) ModCore.CoreMonitor.Log("WTF MARK!!!!!!: ", LogLevel.Alert); + bool moveOn = false; + + WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_X); + int xMin = -1; + int yMin = -1; + int xMax = 1; + int yMax = 1; + List miniGoals = new List(); + List> paths = new List>(); + //try to set children to tiles where children haven't been before + for (int x = xMin; x <= xMax; x++) + { + for (int y = yMin; y <= yMax; y++) + { + if (x == 0 && y == 0) continue; + + //Include these 4 checks for just left right up down movement. Remove them to enable 8 direction path finding + if (x == -1 && y == -1) continue; //upper left + if (x == -1 && y == 1) continue; //bottom left + if (x == 1 && y == -1) continue; //upper right + if (x == 1 && y == 1) continue; //bottom right + + Vector2 pos = new Vector2(v.tileLocation.X + x, v.tileLocation.Y + y); + //ModCore.CoreMonitor.Log("AHHHHHHH POSITION: " + pos.ToString(), LogLevel.Alert); + bool f = PathFindingCore.TileNode.checkIfICanPlaceHere(v, pos * Game1.tileSize, v.thisLocation, true,true); + ModCore.CoreMonitor.Log("OK THIS IS THE RESULT F: " + f, LogLevel.Alert); + if (f == true) + { + + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + if(placement)t.placementAction(Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize); + else t.fakePlacementAction(v.thisLocation, (int)pos.X, (int)pos.Y); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(t, Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize)); + miniGoals.Add(t); + //Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "CostCalculation")); + } + } + } + List removalList = new List(); + foreach (var nav in miniGoals) + { + TileNode tempSource = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + if(placement)tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize); + else tempSource.fakePlacementAction(Game1.player.currentLocation, Game1.player.getTileX(), Game1.player.getTileY()); + + List path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List(),true,true); + + Utilities.clearExceptionListWithName(placement, "Child"); + + ModCore.CoreMonitor.Log(tempSource.tileLocation.ToString()+tempSource.tileLocation.ToString()); + ModCore.CoreMonitor.Log(nav.tileLocation.ToString() + nav.tileLocation.ToString()); + + if (path.Count != 0) + { + ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn); + paths.Add(path); + foreach (var someTile in path) + { + if (someTile == nav) removalList.Add(someTile); + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(someTile); + if (placement) + { + try + { + StardewValley.Object ob = someTile.thisLocation.objects[someTile.tileLocation]; + ModCore.CoreMonitor.Log(ob.name); + if (ob.name == "Twig") ModCore.CoreMonitor.Log("Culperate 2"); + someTile.thisLocation.objects.Remove(someTile.tileLocation); + } + catch(Exception err) + { + + } + } + //someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation); + //StardustCore.Utilities.masterRemovalList.Add(v); + } + } + + } + foreach (var q in removalList) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(q); + if (placement) + { + try + { + StardewValley.Object ob = q.thisLocation.objects[q.tileLocation]; + ModCore.CoreMonitor.Log(ob.name); + if (ob.name == "Twig") ModCore.CoreMonitor.Log("Culperate 1"); + q.thisLocation.objects.Remove(q.tileLocation); + } + catch(Exception err) + { + + } + } + } + removalList.Clear(); + int pathCost = 999999999; + List correctPath = new List(); + foreach (var potentialPath in paths) + { + if (potentialPath.Count == 0) continue; + if (potentialPath.Count < pathCost) + { + pathCost = potentialPath.Count; + correctPath = potentialPath; + } + } + + foreach (var goodTile in correctPath) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Add(goodTile); + //goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(goodTile, Game1.currentLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize)); + } + //END HERE FOR JUST CALCULATING PATH COST + if (paths.Count == 0) return Int32.MaxValue; + return correctPath.Count; + } + + public static List calculatePath(TileNode v, bool Placement = true) + { + object[] obj = new object[2]; + obj[0] = v; + obj[1] = Placement; + return calculatePath(obj); + } + + public static List calculatePath(object obj) + { + object[] objArr = (object[])obj; + TileNode v = (TileNode)objArr[0]; + bool placement; + try + { + placement = (bool)objArr[1]; + } + catch (Exception err) + { + placement = true; + } + foreach (var q in objArr) + { + ModCore.CoreMonitor.Log("OK THIS IS THE RESULT !: " + q, LogLevel.Alert); + } + if (v == null) ModCore.CoreMonitor.Log("WTF MARK!!!!!!: ", LogLevel.Alert); + bool moveOn = false; + + WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_X); + int xMin = -1; + int yMin = -1; + int xMax = 1; + int yMax = 1; + List miniGoals = new List(); + List> paths = new List>(); + //try to set children to tiles where children haven't been before + for (int x = xMin; x <= xMax; x++) + { + for (int y = yMin; y <= yMax; y++) + { + if (x == 0 && y == 0) continue; + + //Include these 4 checks for just left right up down movement. Remove them to enable 8 direction path finding + if (x == -1 && y == -1) continue; //upper left + if (x == -1 && y == 1) continue; //bottom left + if (x == 1 && y == -1) continue; //upper right + if (x == 1 && y == 1) continue; //bottom right + + Vector2 pos = new Vector2(v.tileLocation.X + x, v.tileLocation.Y + y); + //ModCore.CoreMonitor.Log("AHHHHHHH POSITION: " + pos.ToString(), LogLevel.Alert); + bool f = PathFindingCore.TileNode.checkIfICanPlaceHere(v, pos * Game1.tileSize, v.thisLocation, true, true); + ModCore.CoreMonitor.Log("OK THIS IS THE RESULT F: " + f, LogLevel.Alert); + if (f == true) + { + + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + if (placement) t.placementAction(Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize); + else t.fakePlacementAction(v.thisLocation, (int)pos.X, (int)pos.Y); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(t, Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize)); + miniGoals.Add(t); + //Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "CostCalculation")); + } + } + } + List removalList = new List(); + foreach (var nav in miniGoals) + { + TileNode tempSource = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); + if (placement) tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize); + else tempSource.fakePlacementAction(Game1.player.currentLocation, Game1.player.getTileX(), Game1.player.getTileY()); + + List path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List(), false, true); + + Utilities.clearExceptionListWithName(placement, "Child"); + + ModCore.CoreMonitor.Log(tempSource.tileLocation.ToString() + tempSource.tileLocation.ToString()); + ModCore.CoreMonitor.Log(nav.tileLocation.ToString() + nav.tileLocation.ToString()); + + if (path.Count != 0) + { + ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn); + paths.Add(path); + foreach (var someTile in path) + { + if (someTile == nav) removalList.Add(someTile); + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(someTile); + if (placement) someTile.thisLocation.objects.Remove(someTile.tileLocation); + //someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation); + //StardustCore.Utilities.masterRemovalList.Add(v); + } + } + + } + foreach (var q in removalList) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(q); + if (placement) q.thisLocation.objects.Remove(q.tileLocation); + } + removalList.Clear(); + int pathCost = 999999999; + List correctPath = new List(); + foreach (var potentialPath in paths) + { + if (potentialPath.Count == 0) continue; + if (potentialPath.Count < pathCost) + { + pathCost = potentialPath.Count; + correctPath = potentialPath; + } + } + + foreach (var goodTile in correctPath) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Add(goodTile); + //goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize); + //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(goodTile, Game1.currentLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize)); + } + //END HERE FOR JUST CALCULATING PATH COST + if (correctPath.Count==0)return new List(); + return correctPath; + } + + } +} diff --git a/StarAI/StarAI/StarAI/Properties/AssemblyInfo.cs b/StarAI/StarAI/Properties/AssemblyInfo.cs similarity index 100% rename from StarAI/StarAI/StarAI/Properties/AssemblyInfo.cs rename to StarAI/StarAI/Properties/AssemblyInfo.cs diff --git a/StarAI/StarAI/StarAI.csproj b/StarAI/StarAI/StarAI.csproj new file mode 100644 index 00000000..5dc26067 --- /dev/null +++ b/StarAI/StarAI/StarAI.csproj @@ -0,0 +1,105 @@ + + + + + Debug + AnyCPU + {93632675-991D-425B-96F9-9C2B6BFC4EFE} + Library + Properties + StarAI + StarAI + v4.5 + 512 + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Stardew Valley\Mods\ConsoleCommands\ConsoleCommands.dll + + + ..\..\..\..\..\..\..\Downloads\InputSimulator.dll + + + False + ..\..\..\GeneralMods\StardustCore\bin\Release\Newtonsoft.Json.dll + + + ..\..\GeneralMods\StardustCore\bin\Release\StardustCore.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/StarAI/StarAI/StarAI/PathFindingCore/Utilities.cs b/StarAI/StarAI/StarAI/PathFindingCore/Utilities.cs deleted file mode 100644 index 41cde8fe..00000000 --- a/StarAI/StarAI/StarAI/PathFindingCore/Utilities.cs +++ /dev/null @@ -1,188 +0,0 @@ -using Microsoft.Xna.Framework; -using StardewModdingAPI; -using StardewValley; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using WindowsInput; - -namespace StarAI.PathFindingCore -{ - public class Utilities - { - - - public static List tileExceptionList = new List(); - - public static List ignoreCheckTiles = new List(); - public static string folderForExceptionTiles="ExceptionTilesData"; - - - - - public static Vector2 parseCenterFromTile(int tileX, int tileY) - { - //int x = (tileX * Game1.tileSize) + Game1.tileSize / 2; - //int y = (tileY * Game1.tileSize) + Game1.tileSize / 2; - int x = (tileX * Game1.tileSize); - int y = (tileY * Game1.tileSize); - return new Vector2(x, y); - } - - public static void initializeTileExceptionList() - { - - } - - - public static void cleanExceptionList(TileNode t) - { - TileExceptionMetaData err= new TileExceptionMetaData(null,""); - foreach (var v in tileExceptionList) - { - if (v.tile == t) err = v; - } - if(err.tile != null) - { - tileExceptionList.Remove(err); - } - } - /// - /// Used to calculate center of a tile with varience. - /// - /// - /// - /// - /// - public static bool isWithinRange(float position, float goal, int tolerance) - { - if (position >= goal - tolerance && position <= goal + tolerance) return true; - return false; - } - - - public static int calculatePathCost(TileNode v, bool Placement = true) - { - object[] obj = new object[2]; - obj[0] = v; - obj[1] = Placement; - return calculatePathCost(obj); - } - - public static int calculatePathCost(object obj) - { - object[] objArr = (object[])obj; - TileNode v = (TileNode)objArr[0]; - bool placement; - try - { - placement = (bool)objArr[1]; - } - catch(Exception err) - { - placement = true; - } - foreach (var q in objArr) - { - ModCore.CoreMonitor.Log("OK THIS IS THE RESULT !: " + q, LogLevel.Alert); - } - if (v == null) ModCore.CoreMonitor.Log("WTF MARK!!!!!!: ", LogLevel.Alert); - bool moveOn = false; - - WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_X); - int xMin = -1; - int yMin = -1; - int xMax = 1; - int yMax = 1; - List miniGoals = new List(); - List> paths = new List>(); - //try to set children to tiles where children haven't been before - for (int x = xMin; x <= xMax; x++) - { - for (int y = yMin; y <= yMax; y++) - { - if (x == 0 && y == 0) continue; - - //Include these 4 checks for just left right up down movement. Remove them to enable 8 direction path finding - if (x == -1 && y == -1) continue; //upper left - if (x == -1 && y == 1) continue; //bottom left - if (x == 1 && y == -1) continue; //upper right - if (x == 1 && y == 1) continue; //bottom right - - Vector2 pos = new Vector2(v.tileLocation.X + x, v.tileLocation.Y + y); - //ModCore.CoreMonitor.Log("AHHHHHHH POSITION: " + pos.ToString(), LogLevel.Alert); - bool f = PathFindingCore.TileNode.checkIfICanPlaceHere(v, pos * Game1.tileSize, v.thisLocation, true); - ModCore.CoreMonitor.Log("OK THIS IS THE RESULT F: " + f, LogLevel.Alert); - if (f == true) - { - - TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); - if(placement)t.placementAction(Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize); - else t.fakePlacementAction(v.thisLocation, (int)pos.X, (int)pos.Y); - //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(t, Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize)); - miniGoals.Add(t); - Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "CropNavigation")); - } - } - } - List removalList = new List(); - foreach (var nav in miniGoals) - { - TileNode tempSource = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown)); - if(placement)tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize); - else tempSource.fakePlacementAction(Game1.player.currentLocation, Game1.player.getTileX(), Game1.player.getTileY()); - - List path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List(), placement); - - ModCore.CoreMonitor.Log(tempSource.tileLocation.ToString()+tempSource.tileLocation.ToString()); - ModCore.CoreMonitor.Log(nav.tileLocation.ToString() + nav.tileLocation.ToString()); - - if (path.Count != 0) - { - ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn); - paths.Add(path); - foreach (var someTile in path) - { - if (someTile == nav) removalList.Add(someTile); - StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(someTile); - if(placement)someTile.thisLocation.objects.Remove(someTile.tileLocation); - //someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation); - //StardustCore.Utilities.masterRemovalList.Add(v); - } - } - - } - foreach (var q in removalList) - { - StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(q); - if(placement)q.thisLocation.objects.Remove(q.tileLocation); - } - removalList.Clear(); - int pathCost = 999999999; - List correctPath = new List(); - foreach (var potentialPath in paths) - { - if (potentialPath.Count == 0) continue; - if (potentialPath.Count < pathCost) - { - pathCost = potentialPath.Count; - correctPath = potentialPath; - } - } - - foreach (var goodTile in correctPath) - { - StardustCore.ModCore.SerializationManager.trackedObjectList.Add(goodTile); - //goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize); - //StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(goodTile, Game1.currentLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize)); - } - //END HERE FOR JUST CALCULATING PATH COST - if (paths.Count == 0) return Int32.MaxValue; - return correctPath.Count; - } - - } -} diff --git a/StarAI/StarAI/StarAI/manifest.json b/StarAI/StarAI/manifest.json similarity index 100% rename from StarAI/StarAI/StarAI/manifest.json rename to StarAI/StarAI/manifest.json diff --git a/StarAI/StarAI/StarAI/packages.config b/StarAI/StarAI/packages.config similarity index 100% rename from StarAI/StarAI/StarAI/packages.config rename to StarAI/StarAI/packages.config