From ce355fd2c065ba7dfdd85b72ff75c9376ab44d7e Mon Sep 17 00:00:00 2001 From: Date: Mon, 11 Dec 2017 13:39:48 -0800 Subject: [PATCH] Updated the AI to dig dirt and plant seeds. --- StarAI/StarAI/Commands.cs | 21 ++ StarAI/StarAI/ExecutionCore/CustomTask.cs | 2 +- StarAI/StarAI/ExecutionCore/TaskList.cs | 54 +-- .../PathFindingCore/PathFindingLogic.cs | 18 +- StarAI/StarAI/PathFindingCore/Utilities.cs | 4 +- StarAI/StarAI/TaskCore/CropLogic/SeedLogic.cs | 307 +++++++++++++++++- .../TaskCore/MapTransitionLogic/WarpGoal.cs | 111 ++----- StarAI/StarAI/UtilityCore/SeedCropUtility.cs | 2 +- 8 files changed, 380 insertions(+), 139 deletions(-) diff --git a/StarAI/StarAI/Commands.cs b/StarAI/StarAI/Commands.cs index 20f725aa..33236cb5 100644 --- a/StarAI/StarAI/Commands.cs +++ b/StarAI/StarAI/Commands.cs @@ -47,6 +47,13 @@ namespace StarAI ModCore.CoreHelper.ConsoleCommands.Add("watercan", "Fill my watering can.", new Action(Commands.fillWateringCan)); ModCore.CoreHelper.ConsoleCommands.Add("fillcan", "Fill my watering can.", new Action(Commands.fillWateringCan)); + ModCore.CoreHelper.ConsoleCommands.Add("digdirt", "Dig out dirt on the farm.", new Action(Commands.hoeDirtAmount)); + ModCore.CoreHelper.ConsoleCommands.Add("tillsoil", "Dig out dirt on the farm.", new Action(Commands.hoeDirtAmount)); + ModCore.CoreHelper.ConsoleCommands.Add("hoedirt", "Dig out dirt on the farm.", new Action(Commands.hoeDirtAmount)); + + ModCore.CoreHelper.ConsoleCommands.Add("plant", "Plant Seeds", new Action(Commands.plantSeeds)); + ModCore.CoreHelper.ConsoleCommands.Add("plantseeds", "Plant Seeds", new Action(Commands.plantSeeds)); + ModCore.CoreHelper.ConsoleCommands.Add("shippingbin", "Goto shipping bin", new Action(Commands.goToShippingBin)); ModCore.CoreHelper.ConsoleCommands.Add("shipItem", "Ship an Item", new Action(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: , "); + 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) { diff --git a/StarAI/StarAI/ExecutionCore/CustomTask.cs b/StarAI/StarAI/ExecutionCore/CustomTask.cs index 01018608..2f1241a5 100644 --- a/StarAI/StarAI/ExecutionCore/CustomTask.cs +++ b/StarAI/StarAI/ExecutionCore/CustomTask.cs @@ -55,7 +55,7 @@ namespace StarAI.ExecutionCore } catch(Exception err) { - ModCore.CoreMonitor.Log(err.ToString()); + //ModCore.CoreMonitor.Log(err.ToString()); } } diff --git a/StarAI/StarAI/ExecutionCore/TaskList.cs b/StarAI/StarAI/ExecutionCore/TaskList.cs index 226fdb92..ffbdef85 100644 --- a/StarAI/StarAI/ExecutionCore/TaskList.cs +++ b/StarAI/StarAI/ExecutionCore/TaskList.cs @@ -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> newPaths = new List>(); @@ -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>(); //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 t = (List)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> t = (List>)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 path; try { - foreach (var thing in arr) - { - if (thing == null) continue; - ModCore.CoreMonitor.Log("Thing:" + thing.ToString()); - } + List> okList = (arr[0] as List>); List 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 smallList = (arr[1] as List); 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; diff --git a/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs b/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs index aec627cd..58e3ca71 100644 --- a/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs +++ b/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs @@ -74,7 +74,7 @@ namespace StarAI.PathFindingCore int index = 0; List path = new List(); //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(); } @@ -537,7 +537,7 @@ namespace StarAI.PathFindingCore int index = 0; List path = new List(); //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(); } @@ -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 removalList = new List(); diff --git a/StarAI/StarAI/PathFindingCore/Utilities.cs b/StarAI/StarAI/PathFindingCore/Utilities.cs index 6428331b..02817451 100644 --- a/StarAI/StarAI/PathFindingCore/Utilities.cs +++ b/StarAI/StarAI/PathFindingCore/Utilities.cs @@ -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); diff --git a/StarAI/StarAI/TaskCore/CropLogic/SeedLogic.cs b/StarAI/StarAI/TaskCore/CropLogic/SeedLogic.cs index 70d66ef9..33e0d61b 100644 --- a/StarAI/StarAI/TaskCore/CropLogic/SeedLogic.cs +++ b/StarAI/StarAI/TaskCore/CropLogic/SeedLogic.cs @@ -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 hoeDirtThings = new List(); - 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(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 correctPath = Utilities.pathStuff(v);//(List)objArray[1]; + List correctPath = (List)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 seedsToPlant = new List(); + + 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(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 correctPath = Utilities.pathStuff(v);//(List)objArray[1]; + List correctPath = (List)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); + } + + } } diff --git a/StarAI/StarAI/TaskCore/MapTransitionLogic/WarpGoal.cs b/StarAI/StarAI/TaskCore/MapTransitionLogic/WarpGoal.cs index 15e751d9..f174b5ad 100644 --- a/StarAI/StarAI/TaskCore/MapTransitionLogic/WarpGoal.cs +++ b/StarAI/StarAI/TaskCore/MapTransitionLogic/WarpGoal.cs @@ -55,7 +55,7 @@ namespace StarAI.TaskCore.MapTransitionLogic //keep chaining children //exploredLocations.Add(location); checkedLocations.Add(location); - List warpChain = okBye(startinggoals, mapName, location,checkedLocations); + List 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 warpChain = okBye(startinggoals, mapName, location, checkedLocations); + List 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 warpChain= okBye(startinggoals, mapName,location,checkedLocations); + List 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 okByeGOODLOCATION(List param, string targetMapName, GameLocation lastCheckedLocation) - { - - List placesToExplore = new List(); - List placesIHaveBeen = new List(); - - 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(); - } - */ - public static List okBye(List param, string targetMapName, GameLocation lastCheckedLocation,List place) + public static List getRecursiveWarpChain(List param, string targetMapName, GameLocation lastCheckedLocation,List place) { // List placesToExplore = new List(); @@ -687,7 +628,7 @@ namespace StarAI.TaskCore.MapTransitionLogic warpGoal.childrenWarps.Add(fun); } placesIHaveBeen.Add(targetLocation); - List idk = okBye(lastWarp.childrenWarps, targetMapName, targetLocation,placesIHaveBeen); + List 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 warpChain = okBye(startinggoals, mapName, location, checkedLocations); + List 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 warpChain = okBye(startinggoals, mapName, location, checkedLocations); + List 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) diff --git a/StarAI/StarAI/UtilityCore/SeedCropUtility.cs b/StarAI/StarAI/UtilityCore/SeedCropUtility.cs index 82426498..106826dd 100644 --- a/StarAI/StarAI/UtilityCore/SeedCropUtility.cs +++ b/StarAI/StarAI/UtilityCore/SeedCropUtility.cs @@ -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) {