Updated the AI to dig dirt and plant seeds.

This commit is contained in:
2017-12-11 13:39:48 -08:00
parent 2f6d4978da
commit ce355fd2c0
8 changed files with 380 additions and 139 deletions

View File

@ -47,6 +47,13 @@ namespace StarAI
ModCore.CoreHelper.ConsoleCommands.Add("watercan", "Fill my watering can.", new Action<string, string[]>(Commands.fillWateringCan));
ModCore.CoreHelper.ConsoleCommands.Add("fillcan", "Fill my watering can.", new Action<string, string[]>(Commands.fillWateringCan));
ModCore.CoreHelper.ConsoleCommands.Add("digdirt", "Dig out dirt on the farm.", new Action<string, string[]>(Commands.hoeDirtAmount));
ModCore.CoreHelper.ConsoleCommands.Add("tillsoil", "Dig out dirt on the farm.", new Action<string, string[]>(Commands.hoeDirtAmount));
ModCore.CoreHelper.ConsoleCommands.Add("hoedirt", "Dig out dirt on the farm.", new Action<string, string[]>(Commands.hoeDirtAmount));
ModCore.CoreHelper.ConsoleCommands.Add("plant", "Plant Seeds", new Action<string, string[]>(Commands.plantSeeds));
ModCore.CoreHelper.ConsoleCommands.Add("plantseeds", "Plant Seeds", new Action<string, string[]>(Commands.plantSeeds));
ModCore.CoreHelper.ConsoleCommands.Add("shippingbin", "Goto shipping bin", new Action<string, string[]>(Commands.goToShippingBin));
ModCore.CoreHelper.ConsoleCommands.Add("shipItem", "Ship an Item", new Action<string, string[]>(Commands.shipItem));
@ -63,6 +70,20 @@ namespace StarAI
});
}
public static void hoeDirtAmount(string s, string[] args)
{
if (args.Length !=2)
{
ModCore.CoreMonitor.Log("Error, need to specify 2 paramaters: <Number of tiles to dig.>, <Radius to search around farmer>");
return;
}
SeedLogic.makeAsMuchDirtAsSpecifiedAroundFarmer(Game1.player.currentLocation, Convert.ToInt32(args[0]), Convert.ToInt32(args[1]));
}
public static void plantSeeds(string s, string[] args)
{
SeedLogic.plantSeeds(Game1.player.currentLocation);
}
public static void taskListCommands(string s, string[] args)
{

View File

@ -55,7 +55,7 @@ namespace StarAI.ExecutionCore
}
catch(Exception err)
{
ModCore.CoreMonitor.Log(err.ToString());
//ModCore.CoreMonitor.Log(err.ToString());
}
}

View File

@ -92,12 +92,12 @@ namespace StarAI.ExecutionCore
public static void recalculateTask(ref CustomTask v)
{
object[] oArray = (object[])v.objectParameterDataArray;
ModCore.CoreMonitor.Log("RECALCULATING: "+ v.taskMetaData.name);
// ModCore.CoreMonitor.Log("RECALCULATING: "+ v.taskMetaData.name);
if (v.taskMetaData.name.Contains("Path to "))
{
Utilities.tileExceptionList.Clear();
ModCore.CoreMonitor.Log("POKE DEW VALLEY: " + v.taskMetaData.name);
// ModCore.CoreMonitor.Log("POKE DEW VALLEY: " + v.taskMetaData.name);
string[] s = v.taskMetaData.name.Split(' ');
ModCore.CoreMonitor.Log(s.ElementAt(s.Length-1));
List<List<TileNode>> newPaths = new List<List<TileNode>>();
@ -112,7 +112,7 @@ namespace StarAI.ExecutionCore
arr[3] = newPaths;
v.taskMetaData.cost = value;
v.taskMetaData.pathsToTake = newPaths;
ModCore.CoreMonitor.Log("IDK ANY MORE: " + v.taskMetaData.cost);
//ModCore.CoreMonitor.Log("IDK ANY MORE: " + v.taskMetaData.cost);
return;
}
Utilities.tileExceptionList.Clear();
@ -121,8 +121,8 @@ namespace StarAI.ExecutionCore
Utilities.tileExceptionList.Clear();
TileNode t = (TileNode)oArray[0];
Utilities.tileExceptionList.Clear();
ModCore.CoreMonitor.Log("Premtive calculate 1");
ModCore.CoreMonitor.Log("Valaue before???:" + v.taskMetaData.pathsToTake[0].Count);
//ModCore.CoreMonitor.Log("Premtive calculate 1");
//ModCore.CoreMonitor.Log("Valaue before???:" + v.taskMetaData.pathsToTake[0].Count);
v.taskMetaData.calculateTaskCost(t, false);
//v.taskMetaData.pathsToTake = new List<List<TileNode>>();
//v.taskMetaData.pathsToTake.Add(StarAI.PathFindingCore.Utilities.getIdealPath(v));
@ -131,7 +131,7 @@ namespace StarAI.ExecutionCore
object[] objArr = new object[10];
objArr[0] = (object)t;
objArr[1] = (object)v.taskMetaData.pathsToTake[0];
ModCore.CoreMonitor.Log("HMM SO WHAT'S HAPPENING???:" + v.taskMetaData.pathsToTake[0].Count);
//ModCore.CoreMonitor.Log("HMM SO WHAT'S HAPPENING???:" + v.taskMetaData.pathsToTake[0].Count);
int malcolm = 0;
objArr[2] = (object)v.taskMetaData.pathsToTake[0].ElementAt(malcolm); //source of whatever is hit.
try
@ -170,7 +170,7 @@ namespace StarAI.ExecutionCore
{
Utilities.tileExceptionList.Clear();
List<TileNode> t = (List<TileNode>)oArray[0];
ModCore.CoreMonitor.Log("Premtive calculate 2");
// ModCore.CoreMonitor.Log("Premtive calculate 2");
foreach (var s in Utilities.tileExceptionList)
{
ModCore.CoreMonitor.Log(s.actionType);
@ -180,7 +180,7 @@ namespace StarAI.ExecutionCore
objArr[0] = (object)t; //List of trees to use for path calculations
objArr[1] = (object)v.taskMetaData.pathsToTake[0]; //The path itself.
int malcolm = 0;
ModCore.CoreMonitor.Log("THIS IS MALCOLM:" + malcolm);
// ModCore.CoreMonitor.Log("THIS IS MALCOLM:" + malcolm);
objArr[2] = (object)v.taskMetaData.pathsToTake[0].ElementAt(malcolm); //source of whatever is hit.
try
{
@ -219,7 +219,7 @@ namespace StarAI.ExecutionCore
{
Utilities.tileExceptionList.Clear();
List<List<TileNode>> t = (List<List<TileNode>>)oArray[3];
ModCore.CoreMonitor.Log("Premtive calculate 3");
// ModCore.CoreMonitor.Log("Premtive calculate 3");
foreach (var s in Utilities.tileExceptionList)
{
ModCore.CoreMonitor.Log(s.actionType);
@ -229,7 +229,7 @@ namespace StarAI.ExecutionCore
objArr[0] = (object)t; //List of trees to use for path calculations
objArr[1] = (object)v.taskMetaData.pathsToTake; //The path itself.
int malcolm = 0;
ModCore.CoreMonitor.Log("THIS IS MALCOLM:" + malcolm);
// ModCore.CoreMonitor.Log("THIS IS MALCOLM:" + malcolm);
objArr[2] = (object)v.taskMetaData.pathsToTake[0].ElementAt(malcolm); //source of whatever is hit.
try
{
@ -284,7 +284,7 @@ namespace StarAI.ExecutionCore
if (v.taskMetaData.locationPrerequisite.isPlayerAtLocation() == false)
{
//Force player to move to that location, but also need the cost again....
ModCore.CoreMonitor.Log("PLAYERS LOCATION:"+Game1.player.currentLocation.name);
// ModCore.CoreMonitor.Log("PLAYERS LOCATION:"+Game1.player.currentLocation.name);
Utilities.tileExceptionList.Clear();
CustomTask task= WarpGoal.getWarpChainReturnTask(Game1.player.currentLocation, v.taskMetaData.locationPrerequisite.location.name);
if (task == null)
@ -298,11 +298,7 @@ namespace StarAI.ExecutionCore
List<TileNode> path;
try
{
foreach (var thing in arr)
{
if (thing == null) continue;
ModCore.CoreMonitor.Log("Thing:" + thing.ToString());
}
List<List<TileNode>> okList = (arr[0] as List<List<TileNode>>);
List<TileNode> smallList = okList.ElementAt(okList.Count - 1);
TileNode tile = smallList.ElementAt(smallList.Count - 1);
@ -314,15 +310,11 @@ namespace StarAI.ExecutionCore
}
catch(Exception err)
{
foreach(var thing in arr)
{
if (thing == null) continue;
ModCore.CoreMonitor.Log("Thing2:"+thing.ToString());
}
Utilities.tileExceptionList.Clear();
List<TileNode> smallList = (arr[1] as List<TileNode>);
TileNode tile = smallList.ElementAt(smallList.Count-1);
ModCore.CoreMonitor.Log("LOC:" + tile.thisLocation + tile.thisLocation);
//ModCore.CoreMonitor.Log("LOC:" + tile.thisLocation + tile.thisLocation);
Warp lastWarp = new Warp(-1, -1, "Grahm", -1, -1, false);
@ -332,30 +324,16 @@ namespace StarAI.ExecutionCore
if (ok.X == Game1.player.getTileX() && ok.Y == Game1.player.getTileY() + 1) lastWarp = ok;
}
ModCore.CoreMonitor.Log("MYLOC:" + lastWarp.TargetName + lastWarp.TargetX +" "+lastWarp.TargetY);
//ModCore.CoreMonitor.Log("MYLOC:" + lastWarp.TargetName + lastWarp.TargetX +" "+lastWarp.TargetY);
//arr[0] = WarpGoal.pathToWorldTileReturnTask(Game1.player.currentLocation, v.taskMetaData.locationPrerequisite.location.name,(int) tile.tileLocation.X,(int) tile.tileLocation.Y);
TileNode s = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Brown));
s.fakePlacementAction(Game1.getLocationFromName(lastWarp.TargetName), lastWarp.TargetX, lastWarp.TargetY);
path = Utilities.getIdealPath(tile, s);
//arr[0] = s;
}
ModCore.CoreMonitor.Log("PATHCOUNT:"+path.Count);
foreach (var piece in path)
{
ModCore.CoreMonitor.Log("Location: "+piece.thisLocation +" TilePoisition: "+ piece.tileLocation);
}
// ModCore.CoreMonitor.Log("PATHCOUNT:"+path.Count);
//arr[1] = path;
//v.objectParameterDataArray = arr;

View File

@ -74,7 +74,7 @@ namespace StarAI.PathFindingCore
int index = 0;
List<TileNode> path = new List<TileNode>();
//path.Clear();
ModCore.CoreMonitor.Log("LET'S GO!!!!", LogLevel.Error);
//ModCore.CoreMonitor.Log("LET'S GO!!!!", LogLevel.Error);
object[] obj = (object[])data;
TileNode Source =(TileNode) obj[0];
@ -190,13 +190,13 @@ namespace StarAI.PathFindingCore
if (currentNode.tileLocation != Goal.tileLocation)
{
ModCore.CoreMonitor.Log("NO PATH FOUND", LogLevel.Error);
// ModCore.CoreMonitor.Log("NO PATH FOUND", LogLevel.Error);
return;
}
if (currentNode.tileLocation == Goal.tileLocation)
{
ModCore.CoreMonitor.Log("SWEET BEANS!!!!!!", LogLevel.Error);
// ModCore.CoreMonitor.Log("SWEET BEANS!!!!!!", LogLevel.Error);
queue.Clear();
index = 0;
//ModCore.CoreMonitor.Log(currentNode.parent.ToString(), LogLevel.Error);
@ -431,7 +431,7 @@ namespace StarAI.PathFindingCore
if (currentNode.tileLocation != Goal.tileLocation)
{
ModCore.CoreMonitor.Log("NO PATH FOUND", LogLevel.Error);
// ModCore.CoreMonitor.Log("NO PATH FOUND", LogLevel.Error);
return new List<TileNode>();
}
@ -537,7 +537,7 @@ namespace StarAI.PathFindingCore
int index = 0;
List<TileNode> path = new List<TileNode>();
//path.Clear();
ModCore.CoreMonitor.Log("LET'S GO 2222!!!!", LogLevel.Error);
//ModCore.CoreMonitor.Log("LET'S GO 2222!!!!", LogLevel.Error);
object[] obj = (object[])data;
TileNode Source = (TileNode)obj[0];
@ -608,7 +608,7 @@ namespace StarAI.PathFindingCore
if (goalFound == true)
{
currentNode = doesNodeEqualGoal(currentNode, Goals).Value;
ModCore.CoreMonitor.Log("FOUND YOU!!!");
// ModCore.CoreMonitor.Log("FOUND YOU!!!");
// path.Add(currentNode);
//System.Threading.Thread.Sleep(2000);
@ -662,7 +662,7 @@ namespace StarAI.PathFindingCore
catch (Exception err)
{
ModCore.CoreMonitor.Log("INDEX ERROR:"+index, LogLevel.Error);
//ModCore.CoreMonitor.Log("INDEX ERROR:"+index, LogLevel.Error);
break;
}
currentNode.drawColor = StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Blue); //Working
@ -672,7 +672,7 @@ namespace StarAI.PathFindingCore
if (doesNodeEqualGoal(currentNode,Goals).Key==false)
{
ModCore.CoreMonitor.Log("NO PATH FOUND", LogLevel.Error);
// ModCore.CoreMonitor.Log("NO PATH FOUND", LogLevel.Error);
return new List<TileNode>();
}
@ -770,7 +770,7 @@ namespace StarAI.PathFindingCore
{
path.Reverse();
ModCore.CoreMonitor.Log("PATH COUNT TIME!!!!: " + path.Count);
// ModCore.CoreMonitor.Log("PATH COUNT TIME!!!!: " + path.Count);
bool xTargetReached = false;
bool yTargetReached = false;
List<TileNode> removalList = new List<TileNode>();

View File

@ -344,7 +344,7 @@ namespace StarAI.PathFindingCore
{
s = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown));
s.fakePlacementAction(Game1.player.currentLocation, Game1.player.getTileX(), Game1.player.getTileY());
ModCore.CoreMonitor.Log("WHUT???????");
// ModCore.CoreMonitor.Log("WHUT???????");
}
}
catch(Exception err)
@ -382,7 +382,7 @@ namespace StarAI.PathFindingCore
bool f = PathFindingCore.TileNode.checkIfICanPlaceHere(v, pos * Game1.tileSize, v.thisLocation, true, utility);
if (f == false)
{
ModCore.CoreMonitor.Log("FAILED TO PUT DOWN A GOAL????");
// ModCore.CoreMonitor.Log("FAILED TO PUT DOWN A GOAL????");
ModCore.CoreMonitor.Log(v.thisLocation.ToString()+pos.ToString());
}
// ModCore.CoreMonitor.Log("OK THIS IS THE RESULT F: " + f, LogLevel.Alert);

View File

@ -1,5 +1,7 @@
using Microsoft.Xna.Framework;
using StarAI.ExecutionCore.TaskPrerequisites;
using StarAI.PathFindingCore;
using StardewModdingAPI;
using StardewValley;
using System;
using System.Collections.Generic;
@ -14,27 +16,146 @@ namespace StarAI.TaskCore.CropLogic
class SeedLogic
{
public static void makeAsMuchDirtAsPossible(GameLocation location)
public static void makeAsMuchDirtAsSpecifiedAroundFarmer(GameLocation location, int amount, int radius)
{
List<TileNode> hoeDirtThings = new List<TileNode>();
for(int i = 0; i <= location.map.Layers[0].LayerSize.Width;i++)
for(int i = -radius; i <= radius;i++)
{
for (int j = 0; j <= location.map.Layers[0].LayerSize.Height;j++)
for (int j = -radius; j <= radius;j++)
{
if(canBeHoeDirt(location, new Vector2(i, j)))
Vector2 position = new Vector2(Game1.player.getTileX() + i, Game1.player.getTileY() + j);
//if (hoeDirtThings.Count >= amount) continue;
if(canBeHoeDirt(location, position))
{
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)i* Game1.tileSize, (int)j * Game1.tileSize);
//t.placementAction(Game1.currentLocation, (int)i* Game1.tileSize, (int)j * Game1.tileSize);
t.fakePlacementAction(location, (int)position.X,(int)position.Y);
//StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(t, Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize));
PathFindingCore.Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "HoeDirt"));
hoeDirtThings.Add(t);
}
}
}
int taskAmount = 0;
foreach (var v in hoeDirtThings)
{
if (taskAmount >= amount) break;
object[] obj = new object[2];
obj[0] = v;
// ExecutionCore.TaskList.taskList.Add(new Task(new Action<object>(waterSingleCrop), obj));
StardewValley.Tools.Hoe w = new StardewValley.Tools.Hoe();
ExecutionCore.CustomTask task = new ExecutionCore.CustomTask(hoeSingleTileOfDirt, obj, new ExecutionCore.TaskMetaData("Dig Dirt", new LocationPrerequisite(v.thisLocation), new StaminaPrerequisite(true, 3), new ToolPrerequisite(true, w.GetType(), 1)));
if (task.taskMetaData.cost == Int32.MaxValue)
{
StarAI.PathFindingCore.Utilities.clearExceptionListWithNames(true);
Utilities.tileExceptionList.Clear();
continue;
}
ExecutionCore.TaskList.taskList.Add(task);
taskAmount++;
obj[1] = task.taskMetaData.pathsToTake[0];
task.objectParameterDataArray = obj;
// waterSingleCrop(v);
StarAI.PathFindingCore.Utilities.clearExceptionListWithName("Child");
}
hoeDirtThings.Clear();
}
public static void hoeSingleTileOfDirt(object obj)
{
object[] objArray = (object[])obj;
TileNode v = (TileNode)objArray[0];
//List<TileNode> correctPath = Utilities.pathStuff(v);//(List<TileNode>)objArray[1];
List<TileNode> correctPath = (List<TileNode>)objArray[1];
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.Hoe)
{
Game1.player.CurrentToolIndex = Game1.player.getIndexOfInventoryItem(item);
}
}
bool move = false;
while (Game1.player.currentLocation.isTileHoeDirt(v.tileLocation)==false)
{
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 = StarAI.PathFindingCore.Utilities.parseCenterFromTile((int)v.tileLocation.X + 1, (int)v.tileLocation.Y);
continue;
}
if (Game1.player.facingDirection == 1)
{
center = StarAI.PathFindingCore.Utilities.parseCenterFromTile((int)v.tileLocation.X - 1, (int)v.tileLocation.Y);
continue;
}
if (Game1.player.facingDirection == 0)
{
center = StarAI.PathFindingCore.Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y + 1);
continue;
}
if (Game1.player.facingDirection == 3)
{
center = StarAI.PathFindingCore.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 Dig dirt 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);
}
StarAI.PathFindingCore.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 bool canBeHoeDirt(GameLocation location, Vector2 tileLocation)
{
@ -68,5 +189,181 @@ namespace StarAI.TaskCore.CropLogic
}
public static void plantSeeds(GameLocation location)
{
List<TileNode> seedsToPlant = new List<TileNode>();
string name = "";
foreach (var seed in Game1.player.items)
{
if (seed == null) continue;
if (seed.getCategoryName() == "Seed")
{
if (parseCropFromSeedIndex(seed.parentSheetIndex).seasonsToGrowIn.Contains(Game1.currentSeason))
{
name = seed.Name;
}
}
}
if (name == "")
{
ModCore.CoreMonitor.Log("Error: No valid seeds to plant found in inventory. Try to go buy some");
Utilities.tileExceptionList.Clear();
return;
}
foreach (var terrain in location.terrainFeatures)
{
if (terrain.Value is StardewValley.TerrainFeatures.HoeDirt)
{
//Vector2 position = new Vector2(Game1.player.getTileX() + i, Game1.player.getTileY() + j);
//if (hoeDirtThings.Count >= amount) continue;
if ((terrain.Value as StardewValley.TerrainFeatures.HoeDirt).crop != null) continue;
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)i* Game1.tileSize, (int)j * Game1.tileSize);
t.fakePlacementAction(location, (int)terrain.Key.X, (int)terrain.Key.Y);
//StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(t, Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize));
PathFindingCore.Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "PlantSeeds"));
seedsToPlant.Add(t);
}
}
int taskAmount = 0;
foreach (var v in seedsToPlant)
{
object[] obj = new object[2];
obj[0] = v;
// ExecutionCore.TaskList.taskList.Add(new Task(new Action<object>(waterSingleCrop), obj));
ExecutionCore.CustomTask task = new ExecutionCore.CustomTask(plantSingleSeedPacket, obj, new ExecutionCore.TaskMetaData("Plant "+name, new LocationPrerequisite(v.thisLocation), null, null));
if (task.taskMetaData.cost == Int32.MaxValue)
{
StarAI.PathFindingCore.Utilities.clearExceptionListWithNames(true);
Utilities.tileExceptionList.Clear();
continue;
}
ExecutionCore.TaskList.taskList.Add(task);
taskAmount++;
obj[1] = task.taskMetaData.pathsToTake[0];
task.objectParameterDataArray = obj;
// waterSingleCrop(v);
StarAI.PathFindingCore.Utilities.clearExceptionListWithName("Child");
Utilities.tileExceptionList.Clear();
}
seedsToPlant.Clear();
}
public static void plantSingleSeedPacket(object obj)
{
object[] objArray = (object[])obj;
TileNode v = (TileNode)objArray[0];
//List<TileNode> correctPath = Utilities.pathStuff(v);//(List<TileNode>)objArray[1];
List<TileNode> correctPath = (List<TileNode>)objArray[1];
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 == null) continue;
if (item.getCategoryName()=="Seed")
{
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 = StarAI.PathFindingCore.Utilities.parseCenterFromTile((int)v.tileLocation.X + 1, (int)v.tileLocation.Y);
//continue;
}
if (Game1.player.facingDirection == 1)
{
center = StarAI.PathFindingCore.Utilities.parseCenterFromTile((int)v.tileLocation.X - 1, (int)v.tileLocation.Y);
// continue;
}
if (Game1.player.facingDirection == 0)
{
center = StarAI.PathFindingCore.Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y + 1);
//continue;
}
if (Game1.player.facingDirection == 3)
{
center = StarAI.PathFindingCore.Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y - 1);
// continue;
}
//Game1.player.position = center;
Crop c= parseCropFromSeedIndex(Game1.player.ActiveObject.parentSheetIndex);
(v.thisLocation.terrainFeatures[v.tileLocation] as StardewValley.TerrainFeatures.HoeDirt).crop = c;
if (Game1.player.ActiveObject.stack > 1)
{
Game1.player.reduceActiveItemByOne();
// Game1.player.ActiveObject.stack--;
}
else
{
Game1.player.items.Remove(Game1.player.ActiveObject);
Game1.player.ActiveObject = null;
}
//Game1.setMousePosition((int)v.tileLocation.X*Game1.tileSize/2,(int)v.tileLocation.Y*Game1.tileSize/2);
ModCore.CoreMonitor.Log("DOESNT Plant Seeds 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);
}
StarAI.PathFindingCore.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_X);
}
}
}

View File

@ -55,7 +55,7 @@ namespace StarAI.TaskCore.MapTransitionLogic
//keep chaining children
//exploredLocations.Add(location);
checkedLocations.Add(location);
List<WarpGoal> warpChain = okBye(startinggoals, mapName, location,checkedLocations);
List<WarpGoal> warpChain = getRecursiveWarpChain(startinggoals, mapName, location,checkedLocations);
checkedLocations.Clear();
exploredLocations.Clear();
@ -209,7 +209,7 @@ namespace StarAI.TaskCore.MapTransitionLogic
//keep chaining children
//exploredLocations.Add(location);
checkedLocations.Add(location);
List<WarpGoal> warpChain = okBye(startinggoals, mapName, location, checkedLocations);
List<WarpGoal> warpChain = getRecursiveWarpChain(startinggoals, mapName, location, checkedLocations);
checkedLocations.Clear();
exploredLocations.Clear();
@ -372,7 +372,7 @@ namespace StarAI.TaskCore.MapTransitionLogic
//keep chaining children
// exploredLocations.Add(location);
checkedLocations.Add(location);
List<WarpGoal> warpChain= okBye(startinggoals, mapName,location,checkedLocations);
List<WarpGoal> warpChain= getRecursiveWarpChain(startinggoals, mapName,location,checkedLocations);
checkedLocations.Clear();
exploredLocations.Clear();
if (warpChain == null)
@ -510,10 +510,7 @@ namespace StarAI.TaskCore.MapTransitionLogic
if (once == false)
{
foreach (var v in pathMaster.ElementAt(0))
{
ModCore.CoreMonitor.Log("This is my path:" + v.thisLocation.ToString() + v.tileLocation.ToString());
}
//pathMaster.ElementAt(0).Remove(pathMaster.ElementAt(0).ElementAt(0));
PathFindingLogic.calculateMovement(pathMaster.ElementAt(0));
ModCore.CoreMonitor.Log("WTF???");
@ -529,15 +526,22 @@ namespace StarAI.TaskCore.MapTransitionLogic
temp.Add(pathMaster.ElementAt(0).ElementAt(i));
}
ModCore.CoreMonitor.Log("Pathing from FIX:" + temp.ElementAt(temp.Count - 1).thisLocation.ToString() + temp.ElementAt(temp.Count - 1).tileLocation.ToString());
//ModCore.CoreMonitor.Log("Pathing from FIX:" + temp.ElementAt(temp.Count - 1).thisLocation.ToString() + temp.ElementAt(temp.Count - 1).tileLocation.ToString());
foreach (var v in temp)
foreach (var goodTile in temp)
{
ModCore.CoreMonitor.Log("This is my path modified:" + v.thisLocation.ToString() + v.tileLocation.ToString() + v.position.ToString());
StardustCore.ModCore.SerializationManager.trackedObjectList.Add(goodTile);
goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize);
}
// temp.Remove(temp.ElementAt(0));
Game1.player.position = temp.ElementAt(temp.Count - 1).position;
PathFindingLogic.calculateMovement(temp);
foreach (var goodTile in temp)
{
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(goodTile);
goodTile.performRemoveAction(goodTile.tileLocation, goodTile.thisLocation);
}
}
bool warped = false;
@ -569,70 +573,7 @@ namespace StarAI.TaskCore.MapTransitionLogic
//Do final location walk to stuff here.
}
/*
public static List<WarpGoal> okByeGOODLOCATION(List<WarpGoal> param, string targetMapName, GameLocation lastCheckedLocation)
{
List<GameLocation> placesToExplore = new List<GameLocation>();
List<GameLocation> placesIHaveBeen = new List<GameLocation>();
foreach(var warpGoal in param)
{
ModCore.CoreMonitor.Log(warpGoal.warp.TargetName);
placesToExplore.Add(Game1.getLocationFromName(warpGoal.warp.TargetName));
}
placesIHaveBeen.Add(lastCheckedLocation);
while (placesToExplore.Count != 0)
{
GameLocation currentCheckingLocation = placesToExplore.ElementAt(0);
while(checkedLocations.Contains(currentCheckingLocation))
{
placesToExplore.Remove(currentCheckingLocation);
currentCheckingLocation = placesToExplore.ElementAt(0);
ModCore.CoreMonitor.Log("REMOVING " + currentCheckingLocation.name, StardewModdingAPI.LogLevel.Warn);
}
foreach(var warp in currentCheckingLocation.warps)
{
bool addNewLocation = true;
foreach (var checkedPlace in placesIHaveBeen)
{
if (checkedPlace.name == warp.TargetName)
{
addNewLocation = false;
continue;
}
}
foreach(var location in placesToExplore)
{
if(location.name== warp.TargetName)
{
addNewLocation = false;
continue;
}
}
if (addNewLocation == true)
{
placesToExplore.Add(Game1.getLocationFromName(warp.TargetName));
ModCore.CoreMonitor.Log("ADDING NEW LOCATION" + warp.TargetName, StardewModdingAPI.LogLevel.Error);
}
else
{
ModCore.CoreMonitor.Log("ALREADY BEEN AT THIS LOCATION: " + currentCheckingLocation.name, StardewModdingAPI.LogLevel.Warn);
}
}
placesIHaveBeen.Add(currentCheckingLocation);
placesToExplore.Remove(currentCheckingLocation);
ModCore.CoreMonitor.Log("CHECKING LOCATION: " + currentCheckingLocation.name,StardewModdingAPI.LogLevel.Alert);
}
return new List<WarpGoal>();
}
*/
public static List<WarpGoal> okBye(List<WarpGoal> param, string targetMapName, GameLocation lastCheckedLocation,List<GameLocation> place)
public static List<WarpGoal> getRecursiveWarpChain(List<WarpGoal> param, string targetMapName, GameLocation lastCheckedLocation,List<GameLocation> place)
{
// List<GameLocation> placesToExplore = new List<GameLocation>();
@ -687,7 +628,7 @@ namespace StarAI.TaskCore.MapTransitionLogic
warpGoal.childrenWarps.Add(fun);
}
placesIHaveBeen.Add(targetLocation);
List<WarpGoal> idk = okBye(lastWarp.childrenWarps, targetMapName, targetLocation,placesIHaveBeen);
List<WarpGoal> idk = getRecursiveWarpChain(lastWarp.childrenWarps, targetMapName, targetLocation,placesIHaveBeen);
if (idk.Count == 0) continue;
if (idk.ElementAt(0).warp.TargetName == targetMapName) return idk;
// placesIHaveBeen.Clear();
@ -753,7 +694,7 @@ namespace StarAI.TaskCore.MapTransitionLogic
//keep chaining children
//exploredLocations.Add(location);
checkedLocations.Add(location);
List<WarpGoal> warpChain = okBye(startinggoals, mapName, location, checkedLocations);
List<WarpGoal> warpChain = getRecursiveWarpChain(startinggoals, mapName, location, checkedLocations);
checkedLocations.Clear();
exploredLocations.Clear();
@ -940,7 +881,7 @@ namespace StarAI.TaskCore.MapTransitionLogic
//keep chaining children
//exploredLocations.Add(location);
checkedLocations.Add(location);
List<WarpGoal> warpChain = okBye(startinggoals, mapName, location, checkedLocations);
List<WarpGoal> warpChain = getRecursiveWarpChain(startinggoals, mapName, location, checkedLocations);
checkedLocations.Clear();
exploredLocations.Clear();
@ -1100,15 +1041,19 @@ namespace StarAI.TaskCore.MapTransitionLogic
if (once == false)
{
foreach (var v in pathMaster.ElementAt(0))
{
ModCore.CoreMonitor.Log("This is my path:" + v.thisLocation.ToString() + v.tileLocation.ToString());
}
//pathMaster.ElementAt(0).Remove(pathMaster.ElementAt(0).ElementAt(0));
foreach (var goodTile in pathMaster.ElementAt(0))
{
StardustCore.ModCore.SerializationManager.trackedObjectList.Add(goodTile);
goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize);
}
PathFindingLogic.calculateMovement(pathMaster.ElementAt(0));
ModCore.CoreMonitor.Log("WTF???");
once = true;
foreach (var goodTile in pathMaster.ElementAt(0))
{
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(goodTile);
goodTile.performRemoveAction(goodTile.tileLocation, goodTile.thisLocation);
}
//warped = false;
}
else if (once == true)

View File

@ -154,7 +154,7 @@ namespace StarAI.UtilityCore
recalculateAllUtilityValues();
}
//AI cares about money, user might care about other things.
//Doesn't recalculate crops that regrow. Favors crops with mutiple yields. Quantity over quality I suppose.
public static float averageGoldPerDay(Crop c,Item seeds)
{