Changed from system tasks system to delegate system that made more sense but not really??? Also still dealing with nasty issue of sprite batch error but atleast now I can harvest crops.
This commit is contained in:
parent
0c860a1516
commit
e51a8fbac5
|
@ -0,0 +1,25 @@
|
|||
using StardewValley;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StardustCore.DataNodes
|
||||
{
|
||||
public class PlacementNode
|
||||
{
|
||||
public CoreObject cObj;
|
||||
public GameLocation location;
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public PlacementNode(CoreObject C, GameLocation Location, int X, int Y) {
|
||||
cObj = C;
|
||||
location = Location;
|
||||
x = X;
|
||||
y = Y;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -36,6 +36,7 @@ namespace StardustCore
|
|||
StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave;
|
||||
StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad;
|
||||
|
||||
|
||||
IlluminateFramework.Colors.initializeColors();
|
||||
}
|
||||
|
||||
|
|
|
@ -700,5 +700,16 @@ namespace StardustCore.Serialization
|
|||
return new Microsoft.Xna.Framework.Rectangle(Convert.ToInt32(parsed[2]), Convert.ToInt32(parsed[4]), Convert.ToInt32(parsed[6]), Convert.ToInt32(parsed[8]));
|
||||
}
|
||||
|
||||
public void removeObjectWithCopy(CoreObject c)
|
||||
{
|
||||
foreach(var v in StardustCore.ModCore.SerializationManager.trackedObjectList)
|
||||
{
|
||||
if(c.tileLocation==v.tileLocation && c.thisLocation == v.thisLocation)
|
||||
{
|
||||
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Animations\Animation.cs" />
|
||||
<Compile Include="Animations\AnimationManager.cs" />
|
||||
<Compile Include="DataNodes\PlacementNode.cs" />
|
||||
<Compile Include="IlluminateFramework\Colors.cs" />
|
||||
<Compile Include="ModCore.cs" />
|
||||
<Compile Include="CoreObject.cs" />
|
||||
|
|
|
@ -8,6 +8,7 @@ using StardewValley.Objects;
|
|||
using StardewValley.TerrainFeatures;
|
||||
using StardewValley.Tools;
|
||||
using StardustCore;
|
||||
using StardustCore.DataNodes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -17,13 +18,19 @@ using xTile.Dimensions;
|
|||
|
||||
namespace StardustCore
|
||||
{
|
||||
|
||||
|
||||
public class Utilities
|
||||
{
|
||||
|
||||
|
||||
|
||||
public static int sellToStorePrice(CoreObject c)
|
||||
{
|
||||
return (int)((double)c.price * (1.0 + (double)c.quality * 0.25));
|
||||
}
|
||||
|
||||
|
||||
public static void createObjectDebris(Item I, int xTileOrigin, int yTileOrigin, int xTileTarget, int yTileTarget, int groundLevel = -1, int itemQuality = 0, float velocityMultiplyer = 1f, GameLocation location = null)
|
||||
{
|
||||
Debris debris = new Debris(I, new Vector2(xTileOrigin, yTileOrigin), new Vector2(xTileTarget, yTileTarget))
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace StarAI
|
|||
//ModCore.CoreHelper.ConsoleCommands.Add("execute", "Run tasks", new Action<string, string[]>(Commands.runTasks));
|
||||
ModCore.CoreHelper.ConsoleCommands.Add("runTasks", "Run tasks", new Action<string, string[]>(Commands.runTasks));
|
||||
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));
|
||||
|
||||
pathfind("Initialize Delay 0", new string[] {
|
||||
"setDelay",
|
||||
|
@ -34,6 +35,8 @@ namespace StarAI
|
|||
|
||||
public static void runTasks(string s, string[] args)
|
||||
{
|
||||
ExecutionCore.TaskList.runTaskList();
|
||||
/*
|
||||
ModCore.CoreMonitor.Log("EXECUTE TASKS");
|
||||
PathFindingLogic.source = null;
|
||||
PathFindingLogic.currentGoal = null;
|
||||
|
@ -77,6 +80,7 @@ namespace StarAI
|
|||
|
||||
return;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -86,6 +90,11 @@ namespace StarAI
|
|||
PathFindingCore.CropLogic.CropLogic.getAllCropsNeededToBeWatered();
|
||||
}
|
||||
|
||||
public static void harvestCrops(string s,string[] args)
|
||||
{
|
||||
PathFindingCore.CropLogic.CropLogic.getAllCropsNeededToBeHarvested();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 1.Set start position
|
||||
/// 2.set goal
|
||||
|
@ -297,34 +306,7 @@ namespace StarAI
|
|||
ModCore.CoreMonitor.Log("NO VALID START SET FOR PATH FINDING!", LogLevel.Error);
|
||||
}
|
||||
|
||||
if (ModCore.fun.Status == TaskStatus.Running)
|
||||
{
|
||||
ModCore.CoreMonitor.Log("TASK IS RUNNING CAN'T PATHFIND AT THE MOMENT", LogLevel.Alert);
|
||||
return;
|
||||
}
|
||||
if (ModCore.fun.Status == TaskStatus.RanToCompletion)
|
||||
{
|
||||
|
||||
ModCore.CoreMonitor.Log("TASK IS Finished PATHFINDING", LogLevel.Warn);
|
||||
ModCore.fun = new Task(new Action(PathFindingLogic.pathFindToAllGoals));
|
||||
// return;
|
||||
}
|
||||
|
||||
if (ModCore.fun.Status == TaskStatus.Created)
|
||||
{
|
||||
ModCore.CoreMonitor.Log("CREATE AND RUN A TASK!!! PATHFINDING!");
|
||||
ModCore.fun = new Task(new Action(PathFindingLogic.pathFindToAllGoals));
|
||||
|
||||
ModCore.fun.Start();
|
||||
return;
|
||||
}
|
||||
ModCore.CoreMonitor.Log(ModCore.fun.Status.ToString());
|
||||
if (ModCore.fun.Status == TaskStatus.Faulted)
|
||||
{
|
||||
ModCore.CoreMonitor.Log(ModCore.fun.Exception.ToString());
|
||||
ModCore.CoreMonitor.Log("CREATE AND RUN A TASK!!! PATHFINDING!");
|
||||
ModCore.fun = new Task(new Action(PathFindingLogic.pathFindToAllGoals));
|
||||
}
|
||||
PathFindingLogic.pathFindToAllGoals();
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
@ -352,7 +334,8 @@ namespace StarAI
|
|||
obj[1] = PathFindingLogic.currentGoal;
|
||||
PathFindingLogic.queue = new List<TileNode>();
|
||||
obj[2] = PathFindingLogic.queue;
|
||||
ExecutionCore.TaskList.taskList.Add(new Task(new Action<object>(PathFindingLogic.pathFindToSingleGoal),obj));
|
||||
ExecutionCore.TaskList.taskList.Add(new ExecutionCore.CustomTask(PathFindingLogic.pathFindToSingleGoal, obj));
|
||||
//ExecutionCore.TaskList.taskList.Add(new Task(new Action<object>(PathFindingLogic.pathFindToSingleGoal),obj));
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
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 CustomTask(ObjectTask objTask,object[] arrayData)
|
||||
{
|
||||
objectTask = objTask;
|
||||
objectParameterDataArray = arrayData;
|
||||
}
|
||||
|
||||
public CustomTask(VoidTask vTask)
|
||||
{
|
||||
voidTask = vTask;
|
||||
}
|
||||
|
||||
public void runTask()
|
||||
{
|
||||
if (objectTask != null) objectTask.Invoke(objectParameterDataArray);
|
||||
|
||||
if (voidTask != null) voidTask.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -9,65 +9,25 @@ namespace StarAI.ExecutionCore
|
|||
{
|
||||
class TaskList
|
||||
{
|
||||
public static List<Task> taskList = new List<Task>();
|
||||
public static List<CustomTask> taskList = new List<CustomTask>();
|
||||
public static Task executioner = new Task(new Action(runTaskList));
|
||||
|
||||
|
||||
public static void runTaskList()
|
||||
{
|
||||
|
||||
List<Task> removalList = new List<Task>();
|
||||
|
||||
//myTask t = new myTask(StarAI.PathFindingCore.CropLogic.CropLogic.harvestSingleCrop);
|
||||
|
||||
List<CustomTask> removalList = new List<CustomTask>();
|
||||
bool assignNewTask = true;
|
||||
for (int i= 0; i < taskList.Count;i++)
|
||||
{
|
||||
ModCore.CoreMonitor.Log("I value: " + i);
|
||||
ModCore.CoreMonitor.Log("Count: " + taskList.Count);
|
||||
ModCore.CoreMonitor.Log("GAOL AMOUNT: " + PathFindingCore.PathFindingLogic.goals.Count);
|
||||
Task v = taskList[i];
|
||||
CustomTask v = taskList[i];
|
||||
// v.Start();
|
||||
|
||||
if (assignNewTask)
|
||||
{
|
||||
//ModCore.CoreMonitor.Log("CREATE AND RUN A TASK!!! PATHFINDING!");
|
||||
ModCore.fun = v;
|
||||
ModCore.fun.Start();
|
||||
assignNewTask = false;
|
||||
//i--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ModCore.fun.Status == TaskStatus.Running)
|
||||
{
|
||||
assignNewTask = false;
|
||||
//ModCore.CoreMonitor.Log("TASK IS RUNNING CAN'T PATHFIND AT THE MOMENT", LogLevel.Alert);
|
||||
i--;
|
||||
continue;
|
||||
//return;
|
||||
}
|
||||
if (ModCore.fun.Status == TaskStatus.RanToCompletion)
|
||||
{
|
||||
|
||||
ModCore.fun = v;
|
||||
ModCore.fun.Start();
|
||||
assignNewTask = false;
|
||||
//i--;
|
||||
removalList.Add(v);
|
||||
continue;
|
||||
// return;
|
||||
}
|
||||
|
||||
if (ModCore.fun.Status == TaskStatus.Faulted)
|
||||
{
|
||||
ModCore.fun = v;
|
||||
ModCore.fun.Start();
|
||||
assignNewTask = false;
|
||||
//i--;
|
||||
removalList.Add(v);
|
||||
continue;
|
||||
//ModCore.CoreMonitor.Log(ModCore.fun.Exception.ToString());
|
||||
//ModCore.CoreMonitor.Log("CREATE AND RUN A TASK!!! PATHFINDING!");
|
||||
//ModCore.fun = v;
|
||||
//ModCore.fun.Start();
|
||||
}
|
||||
v.runTask();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StarAI.ExecutionCore
|
||||
{
|
||||
class TaskMetaData
|
||||
{
|
||||
string name;
|
||||
float priority;
|
||||
float cost;
|
||||
float utility;
|
||||
float frequency;
|
||||
|
||||
}
|
||||
}
|
|
@ -24,7 +24,6 @@ namespace StarAI
|
|||
public static List<Warp> warpGoals = new List<Warp>();
|
||||
public static object[] obj = new object[3];
|
||||
|
||||
public static Task fun;
|
||||
public override void Entry(IModHelper helper)
|
||||
{
|
||||
obj[0] = PathFindingLogic.source;
|
||||
|
|
|
@ -16,6 +16,7 @@ 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()
|
||||
{
|
||||
|
@ -28,10 +29,11 @@ namespace StarAI.PathFindingCore.CropLogic
|
|||
{
|
||||
//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).needsWatering() == true && (v.Value as StardewValley.TerrainFeatures.HoeDirt).crop.fullyGrown == false)
|
||||
if ((v.Value as StardewValley.TerrainFeatures.HoeDirt).state==0 && (v.Value as StardewValley.TerrainFeatures.HoeDirt).crop.fullyGrown == 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);
|
||||
}
|
||||
|
@ -44,8 +46,9 @@ namespace StarAI.PathFindingCore.CropLogic
|
|||
{
|
||||
object[] obj = new object[1];
|
||||
obj[0] = v;
|
||||
ExecutionCore.TaskList.taskList.Add(new Task(new Action<object>(waterSingleCrop), obj));
|
||||
// waterSingleCrop(v);
|
||||
// ExecutionCore.TaskList.taskList.Add(new Task(new Action<object>(waterSingleCrop), obj));
|
||||
ExecutionCore.TaskList.taskList.Add(new ExecutionCore.CustomTask(waterSingleCrop, obj));
|
||||
// waterSingleCrop(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,36 +93,48 @@ namespace StarAI.PathFindingCore.CropLogic
|
|||
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);
|
||||
//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);
|
||||
// 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);
|
||||
miniGoals.Add(t);
|
||||
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,"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));
|
||||
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>());
|
||||
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>());
|
||||
if (path != null)
|
||||
{
|
||||
ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn);
|
||||
//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.thisLocation.objects.Remove(someTile.tileLocation);
|
||||
//someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation);
|
||||
//StardustCore.Utilities.masterRemovalList.Add(someTile);
|
||||
//ModCore.CoreMonitor.Log("CAUGHT MY CULPERATE", LogLevel.Warn);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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)
|
||||
|
@ -132,8 +147,10 @@ namespace StarAI.PathFindingCore.CropLogic
|
|||
}
|
||||
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));
|
||||
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())
|
||||
{
|
||||
|
@ -185,33 +202,6 @@ namespace StarAI.PathFindingCore.CropLogic
|
|||
center = Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y-1);
|
||||
continue;
|
||||
}
|
||||
//Get center of destination tile and move player there.
|
||||
/*
|
||||
if (v.position.X < Game1.player.position.X)
|
||||
{
|
||||
Game1.player.position = new Vector2(Game1.player.position.X + .1f, Game1.player.position.Y);
|
||||
move = false;
|
||||
continue;
|
||||
}
|
||||
if (v.position.X > Game1.player.position.X)
|
||||
{
|
||||
Game1.player.position = new Vector2(Game1.player.position.X - .1f, Game1.player.position.Y);
|
||||
move = false;
|
||||
continue;
|
||||
}
|
||||
if (v.position.Y < Game1.player.position.Y)
|
||||
{
|
||||
Game1.player.position = new Vector2(Game1.player.position.X, Game1.player.position.Y + .1f);
|
||||
move = false;
|
||||
continue;
|
||||
}
|
||||
if (v.position.Y > Game1.player.position.Y)
|
||||
{
|
||||
Game1.player.position = new Vector2(Game1.player.position.X, Game1.player.position.Y - .1f);
|
||||
move = false;
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
Game1.player.position = center;
|
||||
|
||||
|
||||
|
@ -222,14 +212,246 @@ namespace StarAI.PathFindingCore.CropLogic
|
|||
}
|
||||
Utilities.cleanExceptionList(v);
|
||||
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v);
|
||||
v.thisLocation.objects.Remove(v.tileLocation);
|
||||
|
||||
WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_C);
|
||||
// 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));
|
||||
// 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, "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));
|
||||
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>());
|
||||
if (path != null)
|
||||
{
|
||||
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 < 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));
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,9 @@ namespace StarAI.PathFindingCore
|
|||
foreach (var tile in removalList)
|
||||
{
|
||||
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(tile);
|
||||
v.thisLocation.removeObject(v.tileLocation, false);
|
||||
//StardustCore.Utilities.masterRemovalList.Add(v);
|
||||
v.thisLocation.removeObject(v.tileLocation, false);
|
||||
//v.performRemoveAction(v.tileLocation, v.thisLocation);
|
||||
}
|
||||
cleanseGoals.Add(v);
|
||||
}
|
||||
|
@ -253,7 +255,9 @@ namespace StarAI.PathFindingCore
|
|||
foreach(var v in removalList)
|
||||
{
|
||||
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v);
|
||||
v.thisLocation.removeObject(v.tileLocation, false);
|
||||
v.thisLocation.removeObject(v.tileLocation, false);
|
||||
//v.performRemoveAction(v.tileLocation, v.thisLocation);
|
||||
//StardustCore.Utilities.masterRemovalList.Add(v);
|
||||
}
|
||||
|
||||
calculateMovement(path);
|
||||
|
@ -316,8 +320,10 @@ namespace StarAI.PathFindingCore
|
|||
if (x == -1 && y == 1) continue; //bottom left
|
||||
if (x == 1 && y == -1) continue; //upper right
|
||||
if (x == 1 && y == 1) continue; //bottom right
|
||||
//TileNode t = new TileNode(1, Vector2.Zero, Souce.texturePath,source.dataPath, source.drawColor);
|
||||
//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);
|
||||
//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)
|
||||
{
|
||||
|
@ -340,6 +346,7 @@ namespace StarAI.PathFindingCore
|
|||
List<TileNode> adjList = new List<TileNode>();
|
||||
foreach (var node in currentNode.children)
|
||||
{
|
||||
// ModCore.CoreMonitor.Log("MAYBE HERE",LogLevel.Warn);
|
||||
//TileNode t = new TileNode(1, Vector2.Zero, Souce.texturePath,source.dataPath, source.drawColor);
|
||||
//TileNode.setSingleTileAsChild(source, (int)source.tileLocation.X + x, (int)source.tileLocation.Y + y);
|
||||
if (node.parent == null)
|
||||
|
@ -458,7 +465,11 @@ namespace StarAI.PathFindingCore
|
|||
foreach (var v in removalList)
|
||||
{
|
||||
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v);
|
||||
//v.performRemoveAction(v.tileLocation, v.thisLocation);
|
||||
|
||||
|
||||
v.thisLocation.removeObject(v.tileLocation, false);
|
||||
//StardustCore.Utilities.masterRemovalList.Add(v);
|
||||
}
|
||||
return path;
|
||||
//calculateMovement(path);
|
||||
|
@ -592,6 +603,8 @@ namespace StarAI.PathFindingCore
|
|||
{
|
||||
//v.thisLocation.objects.Remove(v.tileLocation);
|
||||
v.thisLocation.removeObject(v.tileLocation, false);
|
||||
//v.performRemoveAction(v.tileLocation, v.thisLocation);
|
||||
//StardustCore.Utilities.masterRemovalList.Add(v);
|
||||
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v);
|
||||
}
|
||||
goals.Clear();
|
||||
|
|
|
@ -140,6 +140,7 @@ namespace StarAI.PathFindingCore
|
|||
child.seenState = (int)stateEnum.NotVisited;
|
||||
child.parent = t;
|
||||
child.placementAction(Game1.currentLocation, (int)pos.X, (int)pos.Y);
|
||||
//StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(child, Game1.currentLocation, (int)pos.X, (int)pos.Y));
|
||||
t.children.Add(child);
|
||||
}
|
||||
}
|
||||
|
@ -693,6 +694,7 @@ namespace StarAI.PathFindingCore
|
|||
try
|
||||
{
|
||||
bool f = StardustCore.Utilities.placementAction(this, location, x, y, StardustCore.ModCore.SerializationManager, who);
|
||||
|
||||
this.thisLocation = Game1.player.currentLocation;
|
||||
return f;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,9 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Commands.cs" />
|
||||
<Compile Include="ExecutionCore\CustomTask.cs" />
|
||||
<Compile Include="ExecutionCore\TaskList.cs" />
|
||||
<Compile Include="ExecutionCore\TaskMetaData.cs" />
|
||||
<Compile Include="ModCore.cs" />
|
||||
<Compile Include="PathFindingCore\CropLogic\CropLogic.cs" />
|
||||
<Compile Include="PathFindingCore\PathFindingLogic.cs" />
|
||||
|
|
Loading…
Reference in New Issue