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.
This commit is contained in:
parent
edd769b151
commit
671eb1be49
|
@ -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
|
||||
|
|
|
@ -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<string, string[]>(Commands.waterCrops));
|
||||
ModCore.CoreHelper.ConsoleCommands.Add("Harvest", "Harvest the crops", new Action<string, string[]>(Commands.harvestCrops));
|
||||
ModCore.CoreHelper.ConsoleCommands.Add("getseeds", "Get Seeds From chests.", new Action<string, string[]>(Commands.getSeedsFromChests));
|
||||
|
||||
ModCore.CoreHelper.ConsoleCommands.Add("choptwigs", "Chop twigs.", new Action<string, string[]>(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<TileNode>();
|
||||
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<object>(PathFindingLogic.pathFindToSingleGoal),obj));
|
||||
}
|
||||
#endregion
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="objTask"></param>
|
||||
/// <param name="arrayData"></param>
|
||||
/// <param name="TaskMetaData"></param>
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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<CustomTask> taskList = new List<CustomTask>();
|
||||
public static Task executioner = new Task(new Action(runTaskList));
|
||||
|
||||
public static List<CustomTask> removalList = new List<CustomTask>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<TaskPrerequisites.GenericPrerequisite> prerequisitesList;
|
||||
|
||||
|
||||
public List<TileNode> path = new List<TileNode>();
|
||||
|
||||
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<TaskPrerequisites.GenericPrerequisite>();
|
||||
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<TaskPrerequisites.GenericPrerequisite>();
|
||||
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<TaskPrerequisites.GenericPrerequisite>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// This will be used to determine how much any given action, pathing distance, etc will have on the overall cost of a given task.
|
||||
/// </summary>
|
||||
public class TaskMetaDataHeuristics
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Multiplier to be used to multiply out pathCost on any given action. Higher numbers will mean more discrimination against actions with long manhattan distances.
|
||||
/// </summary>
|
||||
public static int pathCostMultiplier=1;
|
||||
/// <summary>
|
||||
/// This is a dictionary that holds the action cost for every tool when it is used.
|
||||
/// </summary>
|
||||
public static Dictionary<Type, int> toolCostDictionary = new Dictionary<Type, int>();
|
||||
|
||||
/// <summary>
|
||||
/// Used to set the values at the beginning.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to assign a weight to using a tool a single time.
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to calculate the weight of using a tool to add to the overall cost of a TaskMetaData cost.
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="numberOfTimesToolIsUsed"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The default here will give you 2 hrs which should be enough for bedTime.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
||||
}
|
||||
}
|
|
@ -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<Warp> warpGoals = new List<Warp>();
|
||||
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<Item> shoppingList = new List<Item>();
|
||||
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")
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -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<TileNode> chestsAtThisLocation = new List<TileNode>();
|
||||
|
||||
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<object>(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<TileNode> miniGoals = new List<TileNode>();
|
||||
List<List<TileNode>> paths = new List<List<TileNode>>();
|
||||
//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<TileNode> removalList = new List<TileNode>();
|
||||
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<TileNode> path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List<TileNode>(),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<TileNode> correctPath = new List<TileNode>();
|
||||
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<Item> removalListSeeds = new List<Item>();
|
||||
//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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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<TileNode> cropsToWater = new List<TileNode>();
|
||||
public static List<TileNode> cropsToHarvest = new List<TileNode>();
|
||||
|
||||
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<object>(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<TileNode> miniGoals = new List<TileNode>();
|
||||
List<List<TileNode>> paths = new List<List<TileNode>>();
|
||||
//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<TileNode> removalList = new List<TileNode>();
|
||||
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<TileNode> path= PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource,nav,new List<TileNode>(),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<TileNode> correctPath = new List<TileNode>();
|
||||
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<object>(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<TileNode> miniGoals = new List<TileNode>();
|
||||
List<List<TileNode>> paths = new List<List<TileNode>>();
|
||||
//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<TileNode> removalList = new List<TileNode>();
|
||||
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<TileNode> path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List<TileNode>(),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<TileNode> correctPath = new List<TileNode>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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<TileNode> sticksToChop = new List<TileNode>();
|
||||
|
||||
|
||||
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<object>(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<object>(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<TileNode> miniGoals = new List<TileNode>();
|
||||
List<List<TileNode>> paths = new List<List<TileNode>>();
|
||||
//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<TileNode> removalList = new List<TileNode>();
|
||||
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<TileNode> path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List<TileNode>(), 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<TileNode> correctPath = new List<TileNode>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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
|
|||
/// <param name="Queue">Depreciated for further builds.</param>
|
||||
/// <param name="Placement">Whether or not tiles are actually going to be placed</param>
|
||||
/// <returns></returns>
|
||||
public static List<TileNode> pathFindToSingleGoalReturnPath(TileNode Source, TileNode Goal, List<TileNode> Queue,bool Placement)
|
||||
public static List<TileNode> pathFindToSingleGoalReturnPath(TileNode Source, TileNode Goal, List<TileNode> 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;
|
||||
|
@ -338,7 +340,7 @@ namespace StarAI.PathFindingCore
|
|||
//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<TileNode> removalList = new List<TileNode>();
|
||||
List<TileNode> ignoreList = new List<TileNode>();
|
||||
foreach (var v in StardustCore.ModCore.SerializationManager.trackedObjectList)
|
||||
{
|
||||
if (v is TileNode)
|
||||
|
@ -469,17 +472,31 @@ namespace StarAI.PathFindingCore
|
|||
|
||||
foreach (var exc in Utilities.tileExceptionList)
|
||||
{
|
||||
if (exc.tile == (v as TileNode)) continue;
|
||||
}
|
||||
|
||||
if (path.Contains(v) || goals.Contains(v) || v.drawColor == StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Red))
|
||||
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<TileNode> idk = new List<TileNode>();
|
||||
foreach (var q in removalList)
|
||||
{
|
||||
if (exc.tile.tileLocation == q.tileLocation)
|
||||
{
|
||||
idk.Add(q);
|
||||
//removalList.Remove(exc.tile);
|
||||
ignoreList.Add(exc.tile);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
removalList.Add((TileNode)v);
|
||||
}
|
||||
foreach(var h in idk)
|
||||
{
|
||||
removalList.Remove(exc.tile);
|
||||
}
|
||||
|
||||
}
|
||||
else removalList.Add((TileNode)v);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
foreach (var v in removalList)
|
||||
|
@ -487,7 +504,20 @@ namespace StarAI.PathFindingCore
|
|||
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;
|
File diff suppressed because it is too large
Load Diff
|
@ -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<TileExceptionMetaData> tileExceptionList = new List<TileExceptionMetaData>();
|
||||
|
||||
public static List<TileExceptionNode> ignoreCheckTiles = new List<TileExceptionNode>();
|
||||
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<TileNode> removalList = new List<TileNode>();
|
||||
List<TileExceptionMetaData> removalList2 = new List<TileExceptionMetaData>();
|
||||
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<TileNode> removalList = new List<TileNode>();
|
||||
List<TileExceptionMetaData> removalList2 = new List<TileExceptionMetaData>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Used to calculate center of a tile with varience.
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <param name="goal"></param>
|
||||
/// <param name="tolerance"></param>
|
||||
/// <returns></returns>
|
||||
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<TileNode> miniGoals = new List<TileNode>();
|
||||
List<List<TileNode>> paths = new List<List<TileNode>>();
|
||||
//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<TileNode> removalList = new List<TileNode>();
|
||||
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<TileNode> path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List<TileNode>(),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<TileNode> correctPath = new List<TileNode>();
|
||||
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<TileNode> calculatePath(TileNode v, bool Placement = true)
|
||||
{
|
||||
object[] obj = new object[2];
|
||||
obj[0] = v;
|
||||
obj[1] = Placement;
|
||||
return calculatePath(obj);
|
||||
}
|
||||
|
||||
public static List<TileNode> 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<TileNode> miniGoals = new List<TileNode>();
|
||||
List<List<TileNode>> paths = new List<List<TileNode>>();
|
||||
//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<TileNode> removalList = new List<TileNode>();
|
||||
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<TileNode> path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List<TileNode>(), 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<TileNode> correctPath = new List<TileNode>();
|
||||
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<TileNode>();
|
||||
return correctPath;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{93632675-991D-425B-96F9-9C2B6BFC4EFE}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>StarAI</RootNamespace>
|
||||
<AssemblyName>StarAI</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ConsoleCommands">
|
||||
<HintPath>..\..\..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Stardew Valley\Mods\ConsoleCommands\ConsoleCommands.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="InputSimulator">
|
||||
<HintPath>..\..\..\..\..\..\..\Downloads\InputSimulator.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\GeneralMods\StardustCore\bin\Release\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="StardustCore">
|
||||
<HintPath>..\..\GeneralMods\StardustCore\bin\Release\StardustCore.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Commands.cs" />
|
||||
<Compile Include="ExecutionCore\CustomTask.cs" />
|
||||
<Compile Include="ExecutionCore\TaskList.cs" />
|
||||
<Compile Include="ExecutionCore\TaskMetaData.cs" />
|
||||
<Compile Include="ExecutionCore\TaskMetaDataHeuristics.cs" />
|
||||
<Compile Include="ExecutionCore\TaskPrerequisites\BedTimePrerequisite.cs" />
|
||||
<Compile Include="ExecutionCore\TaskPrerequisites\GenericPrerequisite.cs" />
|
||||
<Compile Include="ExecutionCore\TaskPrerequisites\InventoryFullPrerequisite.cs" />
|
||||
<Compile Include="ExecutionCore\TaskPrerequisites\StaminaPrerequisite.cs" />
|
||||
<Compile Include="ExecutionCore\TaskPrerequisites\ToolPrerequisite.cs" />
|
||||
<Compile Include="ModCore.cs" />
|
||||
<Compile Include="PathFindingCore\ChestLogic.cs" />
|
||||
<Compile Include="PathFindingCore\CropLogic\CropLogic.cs" />
|
||||
<Compile Include="PathFindingCore\DebrisLogic\DebrisLogic.cs" />
|
||||
<Compile Include="PathFindingCore\PathFindingLogic.cs" />
|
||||
<Compile Include="PathFindingCore\PlacementNode.cs" />
|
||||
<Compile Include="PathFindingCore\TileExceptionMetaData.cs" />
|
||||
<Compile Include="PathFindingCore\TileExceptionNode.cs" />
|
||||
<Compile Include="PathFindingCore\TileNodeObject.cs" />
|
||||
<Compile Include="PathFindingCore\Utilities.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>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}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>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}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\..\GeneralMods\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\..\GeneralMods\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets')" />
|
||||
</Project>
|
|
@ -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<TileExceptionMetaData> tileExceptionList = new List<TileExceptionMetaData>();
|
||||
|
||||
public static List<TileExceptionNode> ignoreCheckTiles = new List<TileExceptionNode>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Used to calculate center of a tile with varience.
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <param name="goal"></param>
|
||||
/// <param name="tolerance"></param>
|
||||
/// <returns></returns>
|
||||
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<TileNode> miniGoals = new List<TileNode>();
|
||||
List<List<TileNode>> paths = new List<List<TileNode>>();
|
||||
//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<TileNode> removalList = new List<TileNode>();
|
||||
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<TileNode> path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List<TileNode>(), 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<TileNode> correctPath = new List<TileNode>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue