From cd0ac16a2272f64adefec3218a78b7a85c893c7f Mon Sep 17 00:00:00 2001 From: Date: Sun, 19 Nov 2017 17:00:12 -0800 Subject: [PATCH] Fined tuned some pathfinding stuff b adding pathTo and Delay functions. As long as I don't have to cross a bridge pathfinding works. --- .../Animations/AnimationManager.cs | 2 +- GeneralMods/StardustCore/Utilities.cs | 2 +- StarAI/StarAI/StarAI/Commands.cs | 243 +++++++++++ StarAI/StarAI/StarAI/ModCore.cs | 403 ++++-------------- .../PathFindingCore/PathFindingLogic.cs | 5 +- .../PathFindingCore/TileExceptionNode.cs | 43 ++ .../StarAI/PathFindingCore/TileNodeObject.cs | 55 +-- .../StarAI/PathFindingCore/Utilities.cs | 133 ++++++ StarAI/StarAI/StarAI/StarAI.csproj | 3 + 9 files changed, 538 insertions(+), 351 deletions(-) create mode 100644 StarAI/StarAI/StarAI/Commands.cs create mode 100644 StarAI/StarAI/StarAI/PathFindingCore/TileExceptionNode.cs create mode 100644 StarAI/StarAI/StarAI/PathFindingCore/Utilities.cs diff --git a/GeneralMods/StardustCore/Animations/AnimationManager.cs b/GeneralMods/StardustCore/Animations/AnimationManager.cs index 1633b655..4e3d7328 100644 --- a/GeneralMods/StardustCore/Animations/AnimationManager.cs +++ b/GeneralMods/StardustCore/Animations/AnimationManager.cs @@ -169,7 +169,7 @@ namespace StardustCore.Animations try { Animation ani = new Animation(new Rectangle(Convert.ToInt32(array[1]), Convert.ToInt32(array[2]), Convert.ToInt32(array[3]), Convert.ToInt32(array[4])), Convert.ToInt32(array[5])); - ModCore.ModMonitor.Log(ani.sourceRectangle.ToString()); + // ModCore.ModMonitor.Log(ani.sourceRectangle.ToString()); ok.Add(ani); } catch(Exception err) diff --git a/GeneralMods/StardustCore/Utilities.cs b/GeneralMods/StardustCore/Utilities.cs index a5b873c5..d76aea91 100644 --- a/GeneralMods/StardustCore/Utilities.cs +++ b/GeneralMods/StardustCore/Utilities.cs @@ -612,7 +612,7 @@ namespace StardustCore else { // Game1.showRedMessage("STEP 2"); - ModCore.ModMonitor.Log(vector.ToString()); + //ModCore.ModMonitor.Log(vector.ToString()); Vector2 newVec = new Vector2(vector.X, vector.Y); // cObj.boundingBox.Inflate(32, 32); diff --git a/StarAI/StarAI/StarAI/Commands.cs b/StarAI/StarAI/StarAI/Commands.cs new file mode 100644 index 00000000..255bf7c8 --- /dev/null +++ b/StarAI/StarAI/StarAI/Commands.cs @@ -0,0 +1,243 @@ +using Microsoft.Xna.Framework; +using StarAI.PathFindingCore; +using StardewModdingAPI; +using StardewValley; +using StardustCore; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using StarAI; + +namespace StarAI +{ + class Commands + { + + public static void initializeCommands() + { + ModCore.CoreHelper.ConsoleCommands.Add("hello", "Ok?", new Action(hello)); + ModCore.CoreHelper.ConsoleCommands.Add("pathfind", "pathy?", new Action(Commands.pathfind)); + ModCore.CoreHelper.ConsoleCommands.Add("pathfinding", "pathy?", new Action(Commands.pathfind)); + + pathfind("Initialize Delay 0", new string[] { + "setDelay", + "0" + }); + } + + + + public static void pathfind(string s, string[] args) + { + + if (args.Length < 1) + { + ModCore.CoreMonitor.Log("No args passed into path finding function", LogLevel.Error); + } + + //Set delay code + #region + if (args[0]=="setDelay"|| args[0]=="delay" || args[0]=="setdelay"|| args[0] == "SetDelay") + { + PathFindingLogic.delay = Convert.ToInt32(args[1]); + ModCore.CoreMonitor.Log("Pathfinding node delay set to: " + Convert.ToString(PathFindingLogic.delay) + " milliseconds."); + } + #endregion + + //PathTo Code + #region + if (args[0]=="pathTo"|| args[0]=="pathto"|| args[0]=="PathTo"|| args[0] == "Pathto") + { + pathfind(s,new string[]{ + + "setStart", + "currentPosition" + }); + int currentX = Game1.player.getTileX(); + int currentY = Game1.player.getTileY(); + int xOffset = Convert.ToInt32(args[1]); + int yOffset = Convert.ToInt32(args[2]); + int destX = currentX + xOffset; + int destY = currentY + yOffset; + pathfind(s, new string[] + { + "addGoal", + destX.ToString(), + destY.ToString() + + }); + + pathfind("pathfind restart", new string[] + { + "start" + }); + } + #endregion + + //Add goal code + #region + if (args[0] == "addGoal" || args[0] == "setGoal") + { + + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Green)); + Vector2 pos = new Vector2((int)(Convert.ToInt32(args[1]) * Game1.tileSize), Convert.ToInt32(args[2]) * Game1.tileSize); + bool ok = t.checkIfICanPlaceHere(t, new Vector2(pos.X, pos.Y), Game1.player.currentLocation); + if (ok == false) + { + ModCore.CoreMonitor.Log("Can't place a goal point here!!!", LogLevel.Error); + return; + } + t.placementAction(Game1.currentLocation, (int)pos.X, (int)pos.Y); + PathFindingLogic.currentGoal = t; + PathFindingLogic.goals.Add(t); + } + #endregion + + //Add start + #region + if (args[0] == "addStart" || args[0] == "setStart") + { + + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Magenta)); + Vector2 pos; + if (args[1] == "currentPosition") + { + pos = new Vector2((int)(Game1.player.getTileX() * Game1.tileSize), Game1.player.getTileY() * Game1.tileSize); + } + else + { + pos = new Vector2((int)(Convert.ToInt32(args[1]) * Game1.tileSize), Convert.ToInt32(args[2]) * Game1.tileSize); + } + + bool ok = t.checkIfICanPlaceHere(t, new Vector2(pos.X, pos.Y), Game1.player.currentLocation); + if (ok == false) + { + ModCore.CoreMonitor.Log("Can't place a start point here!!!", LogLevel.Error); + return; + } + t.placementAction(Game1.currentLocation, (int)pos.X, (int)pos.Y); + PathFindingLogic.source = t; + } + #endregion + + //Restart Code + #region + if (args[0] == "restart") + { + List removalList = new List(); + foreach (var v in StardustCore.ModCore.SerializationManager.trackedObjectList) + { + removalList.Add(v); + } + foreach (var v in removalList) + { + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v); + Game1.player.currentLocation.objects.Remove(v.TileLocation); + pathfind("pathfind restart", new string[] + { + "addGoal", + PathFindingLogic.currentGoal.tileLocation.X.ToString(), + PathFindingLogic.currentGoal.tileLocation.Y.ToString(), + } + ); + } + removalList.Clear(); + pathfind("pathfind restart", new string[] + { + "addStart", + PathFindingLogic.source.tileLocation.X.ToString(), + PathFindingLogic.source.tileLocation.Y.ToString(), + } + ); + pathfind("pathfind restart", new string[] + { + "start" + } + ); + + } + #endregion + + //start code + #region + if (args[0] == "start") + { + if (Game1.player == null) return; + if (Game1.hasLoadedGame == false) return; + // ModCore.CoreMonitor.Log(Game1.player.currentLocation.isTileLocationOpen(new xTile.Dimensions.Location((int)(Game1.player.getTileX() + 1)*Game1.tileSize, (int)(Game1.player.getTileY())*Game1.tileSize)).ToString()); + //CoreMonitor.Log(Convert.ToString(warpGoals.Count)); + if (PathFindingCore.PathFindingLogic.currentGoal == null) + { + ModCore.CoreMonitor.Log("NO VALID GOAL SET FOR PATH FINDING!", LogLevel.Error); + } + if (PathFindingCore.PathFindingLogic.source == null) + { + 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.obj[0] = PathFindingLogic.source; + ModCore.obj[1] = PathFindingLogic.currentGoal; + ModCore.obj[2] = PathFindingLogic.queue; + ModCore.fun = new Task(new Action(PathFindingLogic.pathFindToSingleGoal), ModCore.obj); + return; + } + + if (ModCore.fun.Status == TaskStatus.Created) + { + ModCore.CoreMonitor.Log("CREATE AND RUN A TASK!!! PATHFINDING!"); + ModCore.obj[0] = PathFindingLogic.source; + ModCore.obj[1] = PathFindingLogic.currentGoal; + ModCore.obj[2] = PathFindingLogic.queue; + ModCore.fun = new Task(new Action(PathFindingLogic.pathFindToSingleGoal), ModCore.obj); + + 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.obj[0] = PathFindingLogic.source; + ModCore.obj[1] = PathFindingLogic.currentGoal; + ModCore.obj[2] = PathFindingLogic.queue; + ModCore.fun = new Task(new Action(PathFindingLogic.pathFindToSingleGoal), ModCore.obj); + } + + } + #endregion + } + + /// + /// A test function. + /// + /// This is the command's name + /// This is the parameters that follow. + public static void hello(string s, string[] sarray) + { + ModCore.CoreMonitor.Log(s, LogLevel.Info); + + foreach (var word in sarray) + { + ModCore.CoreMonitor.Log(word, LogLevel.Info); + } + ModCore.CoreMonitor.Log("FUDGE"); + // Game1.player.tryToMoveInDirection(2, true, 0, false); + + } + } + +} + diff --git a/StarAI/StarAI/StarAI/ModCore.cs b/StarAI/StarAI/StarAI/ModCore.cs index adccb708..a7348327 100644 --- a/StarAI/StarAI/StarAI/ModCore.cs +++ b/StarAI/StarAI/StarAI/ModCore.cs @@ -21,176 +21,67 @@ namespace StarAI { public static StardewModdingAPI.IMonitor CoreMonitor; public static StardewModdingAPI.IModHelper CoreHelper; - public static List warpGoals= new List(); + public static List warpGoals = new List(); public static object[] obj = new object[3]; - - public static Task fun = new Task(new Action(PathFindingLogic.pathFindToSingleGoal),obj); + + public static Task fun = new Task(new Action(PathFindingLogic.pathFindToSingleGoal), obj); public override void Entry(IModHelper helper) { obj[0] = PathFindingLogic.source; obj[1] = PathFindingLogic.currentGoal; obj[2] = PathFindingLogic.queue; CoreHelper = helper; - helper.ConsoleCommands.Add("hello", "Ok?", new Action(hello)); - helper.ConsoleCommands.Add("pathfind", "pathy?", new Action(pathfind)); - string[] s = new string[10]; - + + // string[] s = new string[10]; + CoreMonitor = this.Monitor; CoreMonitor.Log("Hello AI WORLD!", LogLevel.Info); + Commands.initializeCommands(); + PathFindingCore.Utilities.initializeTileExceptionList(); //throw new NotImplementedException(); - StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; StardewModdingAPI.Events.LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged; StardewModdingAPI.Events.GameEvents.SecondUpdateTick += GameEvents_SecondUpdateTick; StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed; + StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; StardustCore.ModCore.SerializationManager.acceptedTypes.Add("StarAI.PathFindingCore.TileNode", new StardustCore.Serialization.SerializerDataNode(new StardustCore.Serialization.SerializerDataNode.SerializingFunction(TileNode.Serialize), new StardustCore.Serialization.SerializerDataNode.ParsingFunction(TileNode.ParseIntoInventory), new StardustCore.Serialization.SerializerDataNode.WorldParsingFunction(TileNode.SerializeFromWorld), new StardustCore.Serialization.SerializerDataNode.SerializingToContainerFunction(TileNode.Serialize))); } - public void pathfind(string s, string[] args) + private void SaveEvents_AfterLoad(object sender, EventArgs e) { - if (args.Length < 1) + loadExceptionTiles(); + } + + public void loadExceptionTiles() + { + + // Process the list of files found in the directory. + string[] fileEntries = Directory.GetFiles(Path.Combine(CoreHelper.DirectoryPath,PathFindingCore.Utilities.folderForExceptionTiles)); + foreach (string fileName in fileEntries) { - CoreMonitor.Log("No args passed into path finding function",LogLevel.Error); - } - if (args[0] == "addGoal") - { - - TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"),StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Green)); - Vector2 pos=new Vector2((int)(Convert.ToInt32(args[1]) * Game1.tileSize), Convert.ToInt32(args[2]) * Game1.tileSize); - bool ok = t.checkIfICanPlaceHere(t, new Vector2(pos.X,pos.Y), Game1.player.currentLocation); - if (ok == false) - { - CoreMonitor.Log("Can't place a goal point here!!!", LogLevel.Error); - return; - } - t.placementAction(Game1.currentLocation,(int) pos.X,(int) pos.Y); - PathFindingLogic.currentGoal = t; - PathFindingLogic.goals.Add(t); - } - - if (args[0] == "addStart") - { - - TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Magenta)); - Vector2 pos; - if (args[1] == "currentPosition") - { - pos = new Vector2((int)(Game1.player.getTileX() * Game1.tileSize), Game1.player.getTileY() * Game1.tileSize); - } - else - { - pos = new Vector2((int)(Convert.ToInt32(args[1]) * Game1.tileSize), Convert.ToInt32(args[2]) * Game1.tileSize); - } - - bool ok = t.checkIfICanPlaceHere(t, new Vector2(pos.X, pos.Y), Game1.player.currentLocation); - if (ok == false) - { - CoreMonitor.Log("Can't place a start point here!!!", LogLevel.Error); - return; - } - t.placementAction(Game1.currentLocation, (int)pos.X, (int)pos.Y); - PathFindingLogic.source = t; - } - - if (args[0] == "restart") - { - List removalList = new List(); - foreach(var v in StardustCore.ModCore.SerializationManager.trackedObjectList) - { - removalList.Add(v); - } - foreach (var v in removalList) - { - StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v); - Game1.player.currentLocation.objects.Remove(v.TileLocation); - pathfind("pathfind restart", new string[] - { - "addGoal", - PathFindingLogic.currentGoal.tileLocation.X.ToString(), - PathFindingLogic.currentGoal.tileLocation.Y.ToString(), - } - ); - } - removalList.Clear(); - pathfind("pathfind restart", new string[] - { - "addStart", - PathFindingLogic.source.tileLocation.X.ToString(), - PathFindingLogic.source.tileLocation.Y.ToString(), - } - ); - pathfind("pathfind restart", new string[] - { - "start" - } - ); - - } - - if (args[0] == "start") - { - if (Game1.player == null) return; - if (Game1.hasLoadedGame == false) return; - // ModCore.CoreMonitor.Log(Game1.player.currentLocation.isTileLocationOpen(new xTile.Dimensions.Location((int)(Game1.player.getTileX() + 1)*Game1.tileSize, (int)(Game1.player.getTileY())*Game1.tileSize)).ToString()); - //CoreMonitor.Log(Convert.ToString(warpGoals.Count)); - if (PathFindingCore.PathFindingLogic.currentGoal == null) - { - CoreMonitor.Log("NO VALID GOAL SET FOR PATH FINDING!",LogLevel.Error); - } - if (PathFindingCore.PathFindingLogic.source == null) - { - CoreMonitor.Log("NO VALID START SET FOR PATH FINDING!", LogLevel.Error); - } - - if (fun.Status == TaskStatus.Running) - { - CoreMonitor.Log("TASK IS RUNNING CAN'T PATHFIND AT THE MOMENT", LogLevel.Alert); - return; - } - if (fun.Status == TaskStatus.RanToCompletion) - { - - CoreMonitor.Log("TASK IS Finished PATHFINDING", LogLevel.Warn); - obj[0] = PathFindingLogic.source; - obj[1] = PathFindingLogic.currentGoal; - obj[2] = PathFindingLogic.queue; - fun = new Task(new Action(PathFindingLogic.pathFindToSingleGoal), obj); - return; - } - - if (fun.Status == TaskStatus.Created) - { - CoreMonitor.Log("CREATE AND RUN A TASK!!! PATHFINDING!"); - obj[0] = PathFindingLogic.source; - obj[1] = PathFindingLogic.currentGoal; - obj[2] = PathFindingLogic.queue; - fun = new Task(new Action(PathFindingLogic.pathFindToSingleGoal), obj); - - fun.Start(); - return; - } - CoreMonitor.Log(fun.Status.ToString()); - if (fun.Status == TaskStatus.Faulted) - { - CoreMonitor.Log(fun.Exception.ToString()); - CoreMonitor.Log("CREATE AND RUN A TASK!!! PATHFINDING!"); - obj[0] = PathFindingLogic.source; - obj[1] = PathFindingLogic.currentGoal; - obj[2] = PathFindingLogic.queue; - fun = new Task(new Action(PathFindingLogic.pathFindToSingleGoal), obj); - } - + try + { + TileExceptionNode t = TileExceptionNode.parseJson(fileName); + PathFindingCore.Utilities.tileExceptionList.Add(t); + } + catch(Exception err) + { + ModCore.CoreMonitor.Log(err.ToString(), LogLevel.Error); + } } + } private void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e) { + //J key for shop + #region if (e.KeyPressed == Microsoft.Xna.Framework.Input.Keys.J) { CoreMonitor.Log("OK THE J KEY WAS PRESSED!"); List shoppingList = new List(); - TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"),StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Aqua)); + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Aqua)); if (t == null) { CoreMonitor.Log("WTF?????"); @@ -203,17 +94,21 @@ namespace StarAI } shoppingList.Add((Item)t); Game1.activeClickableMenu = new StardewValley.Menus.ShopMenu(shoppingList); - }catch(Exception err) + } + catch (Exception err) { CoreMonitor.Log(Convert.ToString(err)); } - } + } + #endregion + //K key for placing a tile. + #region if (e.KeyPressed == Microsoft.Xna.Framework.Input.Keys.K) { CoreMonitor.Log("OK THE K KEY WAS PRESSED!"); - - TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"),StardustCore.IlluminateFramework.Colors.randomColor()); + + TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.randomColor()); if (t == null) { CoreMonitor.Log("WTF?????"); @@ -224,184 +119,72 @@ namespace StarAI { return; } - CoreMonitor.Log(new Vector2(Game1.player.getTileX()*Game1.tileSize,Game1.player.getTileY()*Game1.tileSize).ToString()); + CoreMonitor.Log(new Vector2(Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize).ToString()); int xPos = (int)(Game1.player.getTileX()) * Game1.tileSize; int yPos = (int)(Game1.player.getTileY()) * Game1.tileSize; Rectangle r = new Rectangle(xPos, yPos, Game1.tileSize, Game1.tileSize); Vector2 pos = new Vector2(r.X, r.Y); - bool ok = t.checkIfICanPlaceHere(t,pos,Game1.player.currentLocation); + bool ok = t.checkIfICanPlaceHere(t, pos, Game1.player.currentLocation); if (ok == false) return; - t.placementAction(Game1.currentLocation, Game1.player.getTileX()*Game1.tileSize, Game1.player.getTileY()*Game1.tileSize); - t.setAdjacentTiles(true); + t.placementAction(Game1.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize); + //t.setAdjacentTiles(true); } catch (Exception err) { CoreMonitor.Log(Convert.ToString(err)); } } - } + #endregion - public static Vector2 parseCenterFromTile(int tileX, int tileY) - { - int x = (tileX * Game1.tileSize) + Game1.tileSize / 2; - int y = (tileY * Game1.tileSize) + Game1.tileSize / 2; - return new Vector2(x, y); - } - - public static void calculateMovement() - { - bool xTargetReached = false; - bool yTargetReached = false; - while (warpGoals.Count > 0) + if (e.KeyPressed == Microsoft.Xna.Framework.Input.Keys.O) { - Warp w = warpGoals[0]; - if (Game1.player.getTileX() == w.X && Game1.player.getTileY() == w.Y) + + foreach (var v in Game1.player.currentLocation.map.TileSheets) { - warpGoals.Remove(w); - CoreMonitor.Log("LOOOP", LogLevel.Debug); - // return; - continue; - } - else - { - Vector2 center = parseCenterFromTile(w.X, w.Y); - while (Game1.player.position.X > center.X && xTargetReached==false) + foreach (var q in Game1.player.currentLocation.map.Layers) { - if (isWithinRange(Game1.player.position.X, center.X, 12) == true) + string[] s = q.ToString().Split(':'); + string layer = s[1].Trim(); + if (Game1.player.currentLocation.map.GetLayer(layer) == null) { - ModCore.CoreMonitor.Log("XXXXXXXtargetReached"); - xTargetReached = true; - InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_A); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_D); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.UP); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.DOWN); - //break; - continue; + + ModCore.CoreMonitor.Log("SHITTTTTT: " + layer, LogLevel.Error); } - //CoreMonitor.Log(Convert.ToString(Game1.player.position.X), LogLevel.Debug); - //CoreMonitor.Log(Convert.ToString(center.X), LogLevel.Warn); - InputSimulator.SimulateKeyDown(VirtualKeyCode.VK_A); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_D); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.UP); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.DOWN); - } - while (Game1.player.position.X < center.X && xTargetReached==false) - { - if (isWithinRange(Game1.player.position.X, center.X, 6) == true) + int tileIndex = Game1.player.currentLocation.getTileIndexAt((int)Game1.player.getTileX() / Game1.tileSize, (int)Game1.player.getTileY() / Game1.tileSize, layer); + if (tileIndex == -1) continue; + //ModCore.CoreMonitor.Log("Position: " + (Game1.player.getTileLocation() / Game1.tileSize).ToString(), LogLevel.Warn); + //ModCore.CoreMonitor.Log("Layer: " + layer, LogLevel.Warn); + //ModCore.CoreMonitor.Log("Index: " + tileIndex.ToString(), LogLevel.Warn); + //ModCore.CoreMonitor.Log("Image Source: " + v.ImageSource, LogLevel.Warn); + + if (layer == "Buildings") { - xTargetReached = true; - ModCore.CoreMonitor.Log("XXXXXXXtargetReached"); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_A); - InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_D); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.UP); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.DOWN); - //break; - continue; + TileExceptionNode tileException = new TileExceptionNode(v.ImageSource, tileIndex); + foreach(var tile in PathFindingCore.Utilities.tileExceptionList) + { + if (tile.imageSource == tileException.imageSource && tile.index == tileException.index) + { + ModCore.CoreMonitor.Log("Tile exception already initialized!"); + return; //tile is already initialized. + } + } + PathFindingCore.Utilities.tileExceptionList.Add(tileException); + tileException.serializeJson(Path.Combine(ModCore.CoreHelper.DirectoryPath, PathFindingCore.Utilities.folderForExceptionTiles)); + //StardustCore.ModCore.SerializationManager. } - //CoreMonitor.Log(Convert.ToString(Game1.player.position.X), LogLevel.Debug); - //CoreMonitor.Log(Convert.ToString(center.X), LogLevel.Warn); - InputSimulator.SimulateKeyDown(VirtualKeyCode.VK_D); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_A); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.UP); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.DOWN); } - ModCore.CoreMonitor.Log("Run???"); - while (Game1.player.position.Y < center.Y && yTargetReached==false) - { - ModCore.CoreMonitor.Log("banana"); - if (isWithinRange(Game1.player.position.Y, center.Y, 6) == true) - { - yTargetReached = true; - ModCore.CoreMonitor.Log("YYYYYYYYYtargetReached"); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_A); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_D); - InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_S); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.DOWN); - //break; - continue; - } - //CoreMonitor.Log(Convert.ToString(Game1.player.position.X), LogLevel.Debug); - //CoreMonitor.Log(Convert.ToString(center.X), LogLevel.Warn); - InputSimulator.SimulateKeyDown(VirtualKeyCode.VK_S); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_A); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_D); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.DOWN); - } - ModCore.CoreMonitor.Log("Or no???"); - while (Game1.player.position.Y > center.Y&& yTargetReached==false) - { - ModCore.CoreMonitor.Log("potato"); - if (isWithinRange(Game1.player.position.Y, center.Y, 6) == true) - { - yTargetReached = true; - ModCore.CoreMonitor.Log("YYYYYYYYYtargetReached"); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_A); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_D); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.UP); - InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_W); - //break; - continue; - } - //CoreMonitor.Log(Convert.ToString(Game1.player.position.X), LogLevel.Debug); - //CoreMonitor.Log(Convert.ToString(center.X), LogLevel.Warn); - InputSimulator.SimulateKeyDown(VirtualKeyCode.VK_W); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_A); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_D); - //InputSimulator.SimulateKeyUp(VirtualKeyCode.UP); - } - /* - while (Game1.player.getTileX() < w.X) - { - InputSimulator.SimulateKeyDown(VirtualKeyCode.VK_D); - } - - if (Game1.player.getTileX() == w.X) - { - warpGoals.Remove(w); - InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_A); - InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_D); - return; - } - */ - - if (xTargetReached == true && yTargetReached == true) - { - warpGoals.Remove(w); - InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_A); - InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_D); - InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_W); - InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_S); - //return; - CoreMonitor.Log("Reached goal!", LogLevel.Error); - continue; - } - - - CoreMonitor.Log("UNCAUGHT EXCEPTION", LogLevel.Error); } } } - /// - /// Used to calculate center of a tile with varience. - /// - /// - /// - /// - /// - public static bool isWithinRange(float position,float goal, int tolerance) - { - if (position >= goal - tolerance && position <= goal + tolerance) return true; - return false; - } private void GameEvents_SecondUpdateTick(object sender, EventArgs e) { if (Game1.player == null) return; if (Game1.hasLoadedGame == false) return; - // ModCore.CoreMonitor.Log(Game1.player.currentLocation.isTileLocationOpen(new xTile.Dimensions.Location((int)(Game1.player.getTileX() + 1)*Game1.tileSize, (int)(Game1.player.getTileY())*Game1.tileSize)).ToString()); + // ModCore.CoreMonitor.Log(Game1.player.currentLocation.isTileLocationOpen(new xTile.Dimensions.Location((int)(Game1.player.getTileX() + 1)*Game1.tileSize, (int)(Game1.player.getTileY())*Game1.tileSize)).ToString()); //CoreMonitor.Log(Convert.ToString(warpGoals.Count)); if (warpGoals.Count == 0) return; if (fun.Status == TaskStatus.Running) @@ -413,7 +196,7 @@ namespace StarAI { //CoreMonitor.Log("TASK IS Finished", LogLevel.Warn); - fun=new Task(new Action(calculateMovement)); + fun = new Task(new Action(PathFindingCore.Utilities.calculateMovement)); return; } @@ -423,45 +206,25 @@ namespace StarAI fun.Start(); return; } - + } private void LocationEvents_CurrentLocationChanged(object sender, StardewModdingAPI.Events.EventArgsCurrentLocationChanged e) { CoreMonitor.Log("LOCATION CHANGED!"); CoreMonitor.Log(Game1.player.currentLocation.name); - foreach(var v in Game1.player.currentLocation.warps) + foreach (var v in Game1.player.currentLocation.warps) { - string s ="X: " +Convert.ToString(v.X) + " Y: " + Convert.ToString(v.Y) + " TargetX: " + Convert.ToString(v.TargetX) + " TargetY: " + Convert.ToString(v.TargetY) + " TargetLocationName: " + Convert.ToString(v.TargetName); + string s = "X: " + Convert.ToString(v.X) + " Y: " + Convert.ToString(v.Y) + " TargetX: " + Convert.ToString(v.TargetX) + " TargetY: " + Convert.ToString(v.TargetY) + " TargetLocationName: " + Convert.ToString(v.TargetName); CoreMonitor.Log(s); //warpGoals.Add(v); Disabled for now } //GameLocation loc=Game1.getLocationFromName("location name") // } - - - private void SaveEvents_AfterLoad(object sender, EventArgs e) - { - - } - - /// - /// - /// - /// This is the command's name - /// This is the parameters that follow. - public void hello(string s,string[] sarray) - { - CoreMonitor.Log(s, LogLevel.Info); - - foreach(var word in sarray) - { - CoreMonitor.Log(word, LogLevel.Info); - } - CoreMonitor.Log("FUDGE"); - // Game1.player.tryToMoveInDirection(2, true, 0, false); - - } } } + + + + diff --git a/StarAI/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs b/StarAI/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs index fb9627b9..74e51c11 100644 --- a/StarAI/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs +++ b/StarAI/StarAI/StarAI/PathFindingCore/PathFindingLogic.cs @@ -17,6 +17,7 @@ namespace StarAI.PathFindingCore public static List queue=new List(); public static int totalPathCost; public static TileNode currentGoal; + public static int delay; public static List path=new List(); public static int index = 0; @@ -87,7 +88,7 @@ namespace StarAI.PathFindingCore if (node.parent == null) { ModCore.CoreMonitor.Log("I DONT UNDERSTAND!"); - System.Threading.Thread.Sleep(50); + System.Threading.Thread.Sleep(delay); } //ModCore.CoreMonitor.Log("ok checking adj:" + node.tileLocation.ToString()); @@ -169,7 +170,7 @@ namespace StarAI.PathFindingCore } currentNode.parent.animationManager.enableAnimation(); currentNode = currentNode.parent; - System.Threading.Thread.Sleep(200); + System.Threading.Thread.Sleep(delay); if (currentNode.parent == null) { currentNode.drawColor = StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Red); //Working diff --git a/StarAI/StarAI/StarAI/PathFindingCore/TileExceptionNode.cs b/StarAI/StarAI/StarAI/PathFindingCore/TileExceptionNode.cs new file mode 100644 index 00000000..8064e9f1 --- /dev/null +++ b/StarAI/StarAI/StarAI/PathFindingCore/TileExceptionNode.cs @@ -0,0 +1,43 @@ +using Newtonsoft.Json.Linq; +using StarAI.PathFindingCore; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StarAI.PathFindingCore +{ + public class TileExceptionNode + { + public string imageSource; + public int index; + + + public TileExceptionNode() + { + } + + public TileExceptionNode(string ImageSource, int TileIndex) + { + imageSource = ImageSource; + index = TileIndex; + } + + public static TileExceptionNode parseJson(string s) + { + dynamic obj = JObject.Parse(s); + TileExceptionNode t = new TileExceptionNode(); + t.imageSource = obj.imageSource; + t.index = obj.index; + return t; + } + + public void serializeJson(string s) + { + StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(s, "tileExceptionData"+ this.index.ToString() + ".json"), (TileExceptionNode)this); + } + + } +} diff --git a/StarAI/StarAI/StarAI/PathFindingCore/TileNodeObject.cs b/StarAI/StarAI/StarAI/PathFindingCore/TileNodeObject.cs index 3f44287c..4fddcb35 100644 --- a/StarAI/StarAI/StarAI/PathFindingCore/TileNodeObject.cs +++ b/StarAI/StarAI/StarAI/PathFindingCore/TileNodeObject.cs @@ -74,39 +74,38 @@ namespace StarAI.PathFindingCore cry = true; } + + if (t.thisLocation.isObjectAt((int)pos.X, (int)pos.Y)) { - ModCore.CoreMonitor.Log("F!: " + t.thisLocation.name, LogLevel.Warn); + ModCore.CoreMonitor.Log("Object at this tile position!: " + t.thisLocation.name, LogLevel.Warn); if (cry == true) this.thisLocation = null; return false; } if (t.thisLocation.isTileOccupied(pos / Game1.tileSize)) { - ModCore.CoreMonitor.Log("K!!!!: " + t.thisLocation.name, LogLevel.Error); + ModCore.CoreMonitor.Log("Tile occupied!: " + t.thisLocation.name, LogLevel.Error); if (cry == true) this.thisLocation = null; return false; } - if (t.thisLocation.isTilePlaceable(pos) == false) - { - ModCore.CoreMonitor.Log("C!!!!: " + t.thisLocation.name, LogLevel.Error); - if (cry == true) this.thisLocation = null; - return false; - } if (t.thisLocation.isTilePlaceable(pos / Game1.tileSize) == false) { - ModCore.CoreMonitor.Log("J!!!!: " + t.thisLocation.name, LogLevel.Error); + ModCore.CoreMonitor.Log("Tile Not placeable at location. " + t.thisLocation.name, LogLevel.Error); if (cry == true) this.thisLocation = null; return false; } + + if (t.thisLocation.isTilePassable(new xTile.Dimensions.Location((int)(pos.X/Game1.tileSize), (int)(pos.Y/Game1.tileSize)), Game1.viewport)==false) { - ModCore.CoreMonitor.Log("Y!!!!: " + t.thisLocation.name, LogLevel.Error); + ModCore.CoreMonitor.Log("Tile not passable check 2?????!!!!: " + t.thisLocation.name, LogLevel.Error); if (cry == true) this.thisLocation = null; return false; } + if (cry == true) this.thisLocation = null; @@ -120,8 +119,8 @@ namespace StarAI.PathFindingCore if (f == false) return; else { - ModCore.CoreMonitor.Log("Adding a child!"); - System.Threading.Thread.Sleep(50); + // ModCore.CoreMonitor.Log("Adding a child!"); + System.Threading.Thread.Sleep(PathFindingCore.PathFindingLogic.delay); TileNode child = new TileNode(1, Vector2.Zero, t.texturePath,t.dataPath,StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Cyan)); child.seenState = (int)stateEnum.NotVisited; child.parent = t; @@ -164,6 +163,8 @@ namespace StarAI.PathFindingCore } } + + //Unused???? public static void setAdjacentTiles(Vector2 position, GameLocation loc) { Vector2 startPosition = position; @@ -185,28 +186,28 @@ namespace StarAI.PathFindingCore ModCore.CoreMonitor.Log("THIS IS MY LOCATION!!!: " +loc.name); if (loc.isObjectAt((int)pos.X, (int)pos.Y)) { - ModCore.CoreMonitor.Log("F!: " + loc.name, LogLevel.Warn); + // ModCore.CoreMonitor.Log("F!: " + loc.name, LogLevel.Warn); continue; } if (loc.isTileOccupied(pos / Game1.tileSize)) { - ModCore.CoreMonitor.Log("K!!!!: " + loc.name, LogLevel.Error); + //ModCore.CoreMonitor.Log("K!!!!: " + loc.name, LogLevel.Error); continue; } if (loc.isTilePlaceable(pos) == false) { - ModCore.CoreMonitor.Log("C!!!!: " + loc.name, LogLevel.Error); - continue; + //ModCore.CoreMonitor.Log("C!!!!: " + loc.name, LogLevel.Error); + //continue; } if (loc.isTilePlaceable(pos / Game1.tileSize) == false) { - ModCore.CoreMonitor.Log("J!!!!: " + loc.name, LogLevel.Error); - continue; + // ModCore.CoreMonitor.Log("J!!!!: " + loc.name, LogLevel.Error); + // continue; } - if (loc.isTilePassable(new Rectangle(xPos, yPos, Game1.tileSize, Game1.tileSize), Game1.viewport) == true && loc.isTileLocationOpen(new xTile.Dimensions.Location((int)(pos.X), (int)(pos.Y))) == true && loc.isObjectAt((int)(pos.X), (int)(pos.Y)) == false) ; //&& Game1.currentLocation.isTileLocationOpen(new xTile.Dimensions.Location((int)startPosition.X+x,(int)startPosition.Y+y))) + if (loc.isTilePassable(new Rectangle(xPos, yPos, Game1.tileSize, Game1.tileSize), Game1.viewport) == true && loc.isTileLocationOpen(new xTile.Dimensions.Location((int)(pos.X), (int)(pos.Y)))) ; //&& Game1.currentLocation.isTileLocationOpen(new xTile.Dimensions.Location((int)startPosition.X+x,(int)startPosition.Y+y))) { //TileNode child = new TileNode(1, Vector2.Zero, this.texturePath, this.drawColor); //child.placementAction(Game1.currentLocation, xPos, yPos); @@ -462,7 +463,7 @@ namespace StarAI.PathFindingCore { // Game1.showRedMessage("Why2?"); // this.heldObject = new TileNode(parentSheetIndex, Vector2.Zero); - Utilities.addItemToInventoryAndCleanTrackedList(this,StardustCore.ModCore.SerializationManager); + StardustCore.Utilities.addItemToInventoryAndCleanTrackedList(this,StardustCore.ModCore.SerializationManager); this.flaggedForPickUp = true; this.thisLocation = null; this.locationsName = ""; @@ -480,7 +481,7 @@ namespace StarAI.PathFindingCore else { // this.heldObject = new TileNode(parentSheetIndex, Vector2.Zero); - Utilities.addItemToInventoryAndCleanTrackedList(this,StardustCore.ModCore.SerializationManager); + StardustCore.Utilities.addItemToInventoryAndCleanTrackedList(this,StardustCore.ModCore.SerializationManager); // this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation); // this.heldObject = null; Game1.playSound("coin"); @@ -496,7 +497,7 @@ namespace StarAI.PathFindingCore // Game1.showRedMessage("Why3?"); this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation); this.heldObject = null; - Utilities.addItemToInventoryAndCleanTrackedList(this,StardustCore.ModCore.SerializationManager); + StardustCore.Utilities.addItemToInventoryAndCleanTrackedList(this,StardustCore.ModCore.SerializationManager); Game1.playSound("coin"); this.thisLocation = null; this.locationsName = ""; @@ -751,7 +752,7 @@ namespace StarAI.PathFindingCore this.updateDrawPosition(); try { - bool f = Utilities.placementAction(this, location, x, y, StardustCore.ModCore.SerializationManager, who); + bool f = StardustCore.Utilities.placementAction(this, location, x, y, StardustCore.ModCore.SerializationManager, who); this.thisLocation = Game1.player.currentLocation; return f; } @@ -970,11 +971,11 @@ namespace StarAI.PathFindingCore d.rotations = obj.rotations; d.currentRotation = obj.currentRotation; string s1 = Convert.ToString(obj.sourceRect); - d.sourceRect = Utilities.parseRectFromJson(s1); + d.sourceRect = StardustCore.Utilities.parseRectFromJson(s1); string s2 = Convert.ToString(obj.defaultSourceRect); - d.defaultSourceRect = Utilities.parseRectFromJson(s2); + d.defaultSourceRect = StardustCore.Utilities.parseRectFromJson(s2); string s3 = Convert.ToString(obj.defaultBoundingBox); - d.defaultBoundingBox = Utilities.parseRectFromJson(s3); + d.defaultBoundingBox = StardustCore.Utilities.parseRectFromJson(s3); d.description = obj.description; d.flipped = obj.flipped; d.flaggedForPickUp = obj.flaggedForPickUp; @@ -1004,7 +1005,7 @@ namespace StarAI.PathFindingCore d.heldObject = obj.heldObject; d.minutesUntilReady = obj.minutesUntilReady; string s4 = Convert.ToString(obj.boundingBox); - d.boundingBox = Utilities.parseRectFromJson(s4); + d.boundingBox = StardustCore.Utilities.parseRectFromJson(s4); d.scale = obj.scale; d.lightSource = obj.lightSource; d.shakeTimer = obj.shakeTimer; diff --git a/StarAI/StarAI/StarAI/PathFindingCore/Utilities.cs b/StarAI/StarAI/StarAI/PathFindingCore/Utilities.cs new file mode 100644 index 00000000..6e8a7ec0 --- /dev/null +++ b/StarAI/StarAI/StarAI/PathFindingCore/Utilities.cs @@ -0,0 +1,133 @@ +using Microsoft.Xna.Framework; +using StardewModdingAPI; +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WindowsInput; + +namespace StarAI.PathFindingCore +{ + public class Utilities + { + + public static List tileExceptionList = new List(); + public static string folderForExceptionTiles="ExceptionTilesData"; + + public static Vector2 parseCenterFromTile(int tileX, int tileY) + { + int x = (tileX * Game1.tileSize) + Game1.tileSize / 2; + int y = (tileY * Game1.tileSize) + Game1.tileSize / 2; + return new Vector2(x, y); + } + + public static void initializeTileExceptionList() + { + + } + + + + public static void calculateMovement() + { + bool xTargetReached = false; + bool yTargetReached = false; + while (ModCore.warpGoals.Count > 0) + { + Warp w = ModCore.warpGoals[0]; + if (Game1.player.getTileX() == w.X && Game1.player.getTileY() == w.Y) + { + ModCore.warpGoals.Remove(w); + ModCore.CoreMonitor.Log("LOOOP", LogLevel.Debug); + // return; + continue; + } + else + { + Vector2 center = parseCenterFromTile(w.X, w.Y); + while (Game1.player.position.X > center.X && xTargetReached == false) + { + if (isWithinRange(Game1.player.position.X, center.X, 12) == true) + { + ModCore.CoreMonitor.Log("XXXXXXXtargetReached"); + xTargetReached = true; + InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_A); + //break; + continue; + } + InputSimulator.SimulateKeyDown(VirtualKeyCode.VK_A); + } + while (Game1.player.position.X < center.X && xTargetReached == false) + { + if (isWithinRange(Game1.player.position.X, center.X, 6) == true) + { + xTargetReached = true; + ModCore.CoreMonitor.Log("XXXXXXXtargetReached"); + InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_D); + continue; + } + InputSimulator.SimulateKeyDown(VirtualKeyCode.VK_D); + } + ModCore.CoreMonitor.Log("Run???"); + while (Game1.player.position.Y < center.Y && yTargetReached == false) + { + ModCore.CoreMonitor.Log("banana"); + if (isWithinRange(Game1.player.position.Y, center.Y, 6) == true) + { + yTargetReached = true; + ModCore.CoreMonitor.Log("YYYYYYYYYtargetReached"); + InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_S); + continue; + } + InputSimulator.SimulateKeyDown(VirtualKeyCode.VK_S); + } + ModCore.CoreMonitor.Log("Or no???"); + while (Game1.player.position.Y > center.Y && yTargetReached == false) + { + ModCore.CoreMonitor.Log("potato"); + if (isWithinRange(Game1.player.position.Y, center.Y, 6) == true) + { + yTargetReached = true; + ModCore.CoreMonitor.Log("YYYYYYYYYtargetReached"); + InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_W); + continue; + } + InputSimulator.SimulateKeyDown(VirtualKeyCode.VK_W); + } + + + if (xTargetReached == true && yTargetReached == true) + { + ModCore.warpGoals.Remove(w); + InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_A); + InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_D); + InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_W); + InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_S); + //return; + ModCore.CoreMonitor.Log("Reached goal!", LogLevel.Error); + continue; + } + + + ModCore.CoreMonitor.Log("UNCAUGHT EXCEPTION", LogLevel.Error); + } + } + } + + /// + /// Used to calculate center of a tile with varience. + /// + /// + /// + /// + /// + public static bool isWithinRange(float position, float goal, int tolerance) + { + if (position >= goal - tolerance && position <= goal + tolerance) return true; + return false; + } + + } +} diff --git a/StarAI/StarAI/StarAI/StarAI.csproj b/StarAI/StarAI/StarAI/StarAI.csproj index 7f026841..cd1a66b3 100644 --- a/StarAI/StarAI/StarAI/StarAI.csproj +++ b/StarAI/StarAI/StarAI/StarAI.csproj @@ -56,9 +56,12 @@ + + +