public static void runTaskList() { //myTask t = new myTask(StarAI.PathFindingCore.CropLogic.CropLogic.harvestSingleCrop); bool assignNewTask = true; while (ranAllTasks() == false) { //recalculate cost expenses every time a task runs because we don't know where we will be at any given moment. Kind of costly unfortunately but works. foreach (var task2 in taskList) { if (removalList.Contains(task2)) { continue; } object[] oArray = (object[])task2.objectParameterDataArray; TileNode t = (TileNode)oArray[0]; task2.taskMetaData.calculateTaskCost((t)); //task.taskMetaData = new TaskMetaData(task.taskMetaData.name, PathFindingCore.Utilities.calculatePathCost(task.objectParameterDataArray), task.taskMetaData.staminaPrerequisite, task.taskMetaData.toolPrerequisite); } //Some really cool delegate magic that sorts in place by the cost of the action!!!! taskList.Sort(delegate(CustomTask t1, CustomTask t2) { return(t1.taskMetaData.cost.CompareTo(t2.taskMetaData.cost)); }); CustomTask v = taskList.ElementAt(0); int i = 0; while (removalList.Contains(v)) { v = taskList.ElementAt(i); i++; } // v.Start(); if (v.taskMetaData.verifyAllPrerequisitesHit() == true) { v.runTask(); removalList.Add(v); } else { removalList.Add(v); } } taskList.Clear(); removalList.Clear(); }
public static bool interruptionTasks(CustomTask v) { if (v.taskMetaData.bedTimePrerequisite.enoughTimeToDoTask() == false) { CustomTask task = WayPoints.pathToWayPointReturnTask("bed"); if (task == null) { ModCore.CoreMonitor.Log("SOMETHING WENT WRONG WHEN TRYING TO GO TO BED", LogLevel.Error); return(false); } ModCore.CoreMonitor.Log("Not enough time remaining in day. Going home and removing tasks.", LogLevel.Alert); task.runTask(); return(true); } 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); Utilities.tileExceptionList.Clear(); CustomTask task = WarpGoal.getWarpChainReturnTask(Game1.player.currentLocation, v.taskMetaData.locationPrerequisite.location.name); if (task == null) { ModCore.CoreMonitor.Log("SOMETHING WENT WRONG WHEN TRYING TO GO TO" + v.taskMetaData.locationPrerequisite.location.name, LogLevel.Error); return(false); } task.runTask(); object[] arr = (object[])v.objectParameterDataArray; List <TileNode> path; try { 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); //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.player.currentLocation, Game1.player.getTileX(), Game1.player.getTileY()); path = Utilities.getIdealPath(tile, s); } catch (Exception err) { 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); Warp lastWarp = new Warp(-1, -1, "Grahm", -1, -1, false); GameLocation fakeLocation = Game1.getLocationFromName(Game1.player.currentLocation.name); foreach (var ok in fakeLocation.warps) { if (ok.X == Game1.player.getTileX() && ok.Y == Game1.player.getTileY() + 1) { lastWarp = ok; } } //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); //arr[1] = path; //v.objectParameterDataArray = arr; PathFindingLogic.calculateMovement(path); return(false); } if (v.taskMetaData.name == "Water Crop") { StardewValley.Tools.WateringCan w = new WateringCan(); bool found = false; foreach (var item in Game1.player.items) { if (item == null) { continue; } if (item.GetType() == typeof(StardewValley.Tools.WateringCan)) { w = (WateringCan)item; found = true; } } if (found == false) { removalList.Add(v); return(false); } if (w.WaterLeft == 0) { CustomTask waterRefill = WaterLogic.getAllWaterTilesTask(Game1.player.currentLocation); ModCore.CoreMonitor.Log("No water in can. Going to refil"); waterRefill.runTask(); return(true); } // } return(false); }
public static void runTaskList() { //myTask t = new myTask(StarAI.PathFindingCore.CropLogic.CropLogic.harvestSingleCrop); bool assignNewTask = true; if (TaskPrerequisites.BedTimePrerequisite.enoughTimeToDoTaskStatic() == false) { CustomTask task = WayPoints.pathToWayPointReturnTask("bed"); if (task == null) { ModCore.CoreMonitor.Log("SOMETHING WENT WRONG WHEN TRYING TO GO TO BED", LogLevel.Error); } ModCore.CoreMonitor.Log("Not enough time remaining in day. Going home.", LogLevel.Alert); task.runTask(); Utilities.tileExceptionList.Clear(); taskList.Clear(); removalList.Clear(); return; } while (ranAllTasks() == false || TaskPrerequisites.BedTimePrerequisite.enoughTimeToDoTaskStatic() == false) { Utilities.tileExceptionList.Clear(); foreach (var task2 in taskList) { if (removalList.Contains(task2)) { continue; } var temp = task2; recalculateTask(ref temp); //task.taskMetaData = new TaskMetaData(task.taskMetaData.name, PathFindingCore.Utilities.calculatePathCost(task.objectParameterDataArray), task.taskMetaData.staminaPrerequisite, task.taskMetaData.toolPrerequisite); } // ModCore.CoreMonitor.Log("DONE CALCULATING JUNK NOW RUNNING TASK"); //Some really cool delegate magic that sorts in place by the cost of the action!!!! taskList.Sort(delegate(CustomTask t1, CustomTask t2) { return(t1.taskMetaData.cost.CompareTo(t2.taskMetaData.cost)); }); CustomTask v = taskList.ElementAt(0); int i = 0; while (removalList.Contains(v)) { v = taskList.ElementAt(i); i++; } // v.Start(); bool recalculate = interruptionTasks(v); if (recalculate) { recalculateTask(ref v); } if (v.taskMetaData.verifyAllPrerequisitesHit() == true) { v.runTask(); Utilities.clearExceptionListWithName("Child"); Utilities.clearExceptionListWithName("Navigation"); removalList.Add(v); } else { removalList.Add(v); } } Utilities.tileExceptionList.Clear(); taskList.Clear(); removalList.Clear(); }