private void setReturnToJunimoHutToFetchStarController() { if (Game1.IsMasterGame) { controller = new PathFindController(this, base.currentLocation, new Point(25, 10), 0, junimoReachedHutToFetchStar); } }
public override void behaviorAtGameTick(GameTime time) { base.behaviorAtGameTick(time); base.addedSpeed = 0; base.speed = 3; if (howLongOnThisPosition > 500 && controller == null) { base.IsWalkingTowardPlayer = false; controller = new PathFindController(this, base.currentLocation, new Point((int)base.Player.getTileLocation().X, (int)base.Player.getTileLocation().Y), Game1.random.Next(4), null, 300); timeBeforeAIMovementAgain = 2000f; howLongOnThisPosition = 0; } else if (controller == null) { base.IsWalkingTowardPlayer = true; } if (base.Position.Equals(lastPosition)) { howLongOnThisPosition += time.ElapsedGameTime.Milliseconds; } else { howLongOnThisPosition = 0; } lastPosition = base.Position; }
public override void behaviorAtGameTick(GameTime time) { if (!throwing) { base.behaviorAtGameTick(time); } if (!spottedPlayer && !base.wildernessFarmMonster && Utility.doesPointHaveLineOfSightInMine(base.currentLocation, getTileLocation(), base.Player.getTileLocation(), 8)) { controller = new PathFindController(this, base.currentLocation, new Point(base.Player.getStandingX() / 64, base.Player.getStandingY() / 64), Game1.random.Next(4), null, 200); spottedPlayer = true; Halt(); facePlayer(base.Player); base.currentLocation.playSound("skeletonStep"); base.IsWalkingTowardPlayer = true; } else if ((bool)throwing) { if (invincibleCountdown > 0) { invincibleCountdown -= time.ElapsedGameTime.Milliseconds; if (invincibleCountdown <= 0) { stopGlowing(); } } Sprite.Animate(time, 20, 5, 150f); if (Sprite.currentFrame == 24) { throwing.Value = false; Sprite.currentFrame = 0; faceDirection(2); Vector2 v = Utility.getVelocityTowardPlayer(new Point((int)base.Position.X, (int)base.Position.Y), 8f, base.Player); base.currentLocation.projectiles.Add(new BasicProjectile(base.DamageToFarmer, 4, 0, 0, (float)Math.PI / 16f, v.X, v.Y, new Vector2(base.Position.X, base.Position.Y), "skeletonHit", "skeletonStep", explode: false, damagesMonsters: false, base.currentLocation, this)); } } else if (spottedPlayer && controller == null && Game1.random.NextDouble() < 0.002 && !base.wildernessFarmMonster && Utility.doesPointHaveLineOfSightInMine(base.currentLocation, getTileLocation(), base.Player.getTileLocation(), 8)) { throwing.Value = true; Halt(); Sprite.currentFrame = 20; shake(750); } else if (withinPlayerThreshold(2)) { controller = null; } else if (spottedPlayer && controller == null && controllerAttemptTimer <= 0) { controller = new PathFindController(this, base.currentLocation, new Point(base.Player.getStandingX() / 64, base.Player.getStandingY() / 64), Game1.random.Next(4), null, 200); Halt(); facePlayer(base.Player); controllerAttemptTimer = (base.wildernessFarmMonster ? 2000 : 1000); } else if (base.wildernessFarmMonster) { spottedPlayer = true; base.IsWalkingTowardPlayer = true; } controllerAttemptTimer -= time.ElapsedGameTime.Milliseconds; }
private void setBringBundleBackToHutController() { if (Game1.IsMasterGame) { controller = new PathFindController(this, base.currentLocation, new Point(25, 10), 0, junimoReachedHutToReturnBundle); } }
private void setJunimoReachedHutToFetchStarController() { if (Game1.IsMasterGame) { controller = new PathFindController(this, base.currentLocation, new Point(32, 9), 2, placeStar); } }
private static SchedulePathDescription pathfindToNextScheduleLocation(NPC npc, string startingLocation, int startingX, int startingY, string endingLocation, int endingX, int endingY, int finalFacingDirection, string endBehavior, string endMessage) { Stack <Point> stack = new Stack <Point>(); Point startPoint = new Point(startingX, startingY); List <string> list = startingLocation.Equals(endingLocation) ? (List <string>)null : getLocationRoute(npc, startingLocation, endingLocation); if (list != null) { for (int index = 0; index < Enumerable.Count <string>((IEnumerable <string>)list); ++index) { GameLocation locationFromName = Game1.getLocationFromName(list[index]); if (index < Enumerable.Count <string>((IEnumerable <string>)list) - 1) { Point warpPointTo = locationFromName.getWarpPointTo(list[index + 1]); if (warpPointTo.Equals(Point.Zero) || startPoint.Equals(Point.Zero)) { throw new Exception("schedule pathing tried to find a warp point that doesn't exist."); } stack = addToStackForSchedule(stack, PathFindController.findPathForNPCSchedules(startPoint, warpPointTo, locationFromName, 30000)); startPoint = locationFromName.getWarpPointTarget(warpPointTo); } else { stack = addToStackForSchedule(stack, PathFindController.findPathForNPCSchedules(startPoint, new Point(endingX, endingY), locationFromName, 30000)); } } } else if (startingLocation.Equals(endingLocation)) { stack = PathFindController.findPathForNPCSchedules(startPoint, new Point(endingX, endingY), Game1.getLocationFromName(startingLocation), 30000); } return(new SchedulePathDescription(stack, finalFacingDirection, endBehavior, endMessage)); }
private void setBringBundleBackToHutController() { if (!Game1.IsMasterGame) { return; } controller = new PathFindController(this, currentLocation, new Point(25, 10), 0, new PathFindController.endBehavior(junimoReachedHutToReturnBundle)); }
private void setJunimoReachedHutToFetchStarController() { if (!Game1.IsMasterGame) { return; } controller = new PathFindController(this, currentLocation, new Point(32, 9), 2, new PathFindController.endBehavior(placeStar)); }
public void returnToJunimoHut(GameLocation location) { base.currentLocation = location; jump(); collidesWithOtherCharacters.Value = false; controller = new PathFindController(this, location, new Point(25, 10), 0, junimoReachedHut); location.playSound("junimoMeep1"); }
private void setReturnToJunimoHutToFetchStarController() { if (!Game1.IsMasterGame) { return; } controller = new PathFindController(this, currentLocation, new Point(25, 10), 0, new PathFindController.endBehavior(junimoReachedHutToFetchStar)); }
public override void behaviorAtGameTick(GameTime time) { base.behaviorAtGameTick(time); if (yJumpOffset == 0) { if (Game1.random.NextDouble() < 0.01) { Game1.multiplayer.broadcastSprites(base.currentLocation, new TemporaryAnimatedSprite("TileSheets\\animations", new Rectangle(0, 128, 64, 64), 40f, 4, 0, getStandingPosition(), flicker: false, flipped: false)); foreach (Vector2 v2 in Utility.getAdjacentTileLocations(getTileLocation())) { if (base.currentLocation.objects.ContainsKey(v2) && base.currentLocation.objects[v2].Name.Contains("Stone")) { base.currentLocation.destroyObject(v2, null); } } yJumpVelocity *= 2f; } if (!chargingFarmer) { xVelocity = (float)Game1.random.Next(-20, 21) / 5f; } } if (chargingFarmer) { base.Slipperiness = 10; Vector2 v = Utility.getAwayFromPlayerTrajectory(GetBoundingBox(), base.Player); xVelocity += (0f - v.X) / 150f + ((Game1.random.NextDouble() < 0.01) ? ((float)Game1.random.Next(-50, 50) / 10f) : 0f); if (Math.Abs(xVelocity) > 5f) { xVelocity = Math.Sign(xVelocity) * 5; } yVelocity += (0f - v.Y) / 150f + ((Game1.random.NextDouble() < 0.01) ? ((float)Game1.random.Next(-50, 50) / 10f) : 0f); if (Math.Abs(yVelocity) > 5f) { yVelocity = Math.Sign(yVelocity) * 5; } if (Game1.random.NextDouble() < 0.0001) { controller = new PathFindController(this, base.currentLocation, new Point((int)base.Player.getTileLocation().X, (int)base.Player.getTileLocation().Y), Game1.random.Next(4), null, 300); chargingFarmer = false; } } else if (!seenFarmer && Utility.doesPointHaveLineOfSightInMine(base.currentLocation, getStandingPosition() / 64f, base.Player.getStandingPosition() / 64f, 8)) { seenFarmer = true; } else if (seenFarmer && controller == null && !runningAwayFromFarmer) { base.addedSpeed = 2; controller = new PathFindController(this, base.currentLocation, Utility.isOffScreenEndFunction, -1, eraseOldPathController: false, offScreenBehavior, 350, Point.Zero); runningAwayFromFarmer = true; } else if (controller == null && runningAwayFromFarmer) { chargingFarmer = true; } }
private void runAway() { addedSpeed = 2; controller = new PathFindController(this, currentLocation, Utility.isOffScreenEndFunction, -1, eraseOldPathController: false, delegate {}, 350, Point.Zero); chargingFarmer = false; runningAwayFromFarmer = true; }
public JunimoHarvester(Vector2 position, JunimoHut myHome, int whichJunimoNumberFromThisHut, Color?c) : base(new AnimatedSprite("Characters\\Junimo", 0, 16, 16), position, 2, "Junimo") { home = myHome; whichJunimoFromThisHut = whichJunimoNumberFromThisHut; if (!c.HasValue) { pickColor(); } else { color.Value = c.Value; } nextPosition = GetBoundingBox(); base.Breather = false; base.speed = 3; forceUpdateTimer = 9999; collidesWithOtherCharacters.Value = true; ignoreMovementAnimation = true; farmerPassesThrough = true; base.Scale = 0.75f; base.willDestroyObjectsUnderfoot = false; base.currentLocation = Game1.getFarm(); Vector2 tileToPathfindTo = Vector2.Zero; switch (whichJunimoNumberFromThisHut) { case 0: tileToPathfindTo = Utility.recursiveFindOpenTileForCharacter(this, base.currentLocation, new Vector2((int)home.tileX + 1, (int)home.tileY + (int)home.tilesHigh + 1), 30); break; case 1: tileToPathfindTo = Utility.recursiveFindOpenTileForCharacter(this, base.currentLocation, new Vector2((int)home.tileX - 1, (int)home.tileY), 30); break; case 2: tileToPathfindTo = Utility.recursiveFindOpenTileForCharacter(this, base.currentLocation, new Vector2((int)home.tileX + (int)home.tilesWide, (int)home.tileY), 30); break; } if (tileToPathfindTo != Vector2.Zero) { controller = new PathFindController(this, base.currentLocation, Utility.Vector2ToPoint(tileToPathfindTo), -1, reachFirstDestinationFromHut, 100); } if ((controller == null || controller.pathToEndPoint == null) && Game1.IsMasterGame) { pathfindToRandomSpotAroundHut(); if (controller == null || controller.pathToEndPoint == null) { destroy = true; } } collidesWithOtherCharacters.Value = false; }
// Start is called before the first frame update void Awake() { if (PathFindController.pathFinder == null) { PathFindController.pathFinder = this; } else { Destroy(this.gameObject); } openList = new List <AStarNode>(); closedList = new List <AStarNode>(); }
public void tenMinuteUpdate() { if (Game1.IsMasterGame && base.Age == 2) { setCrawlerInNewDirection(); } else if (Game1.IsMasterGame && Game1.timeOfDay % 100 == 0 && base.Age == 3 && Game1.timeOfDay < 1900) { base.IsWalkingInSquare = false; Halt(); FarmHouse farmHouse2 = base.currentLocation as FarmHouse; if (farmHouse2.characters.Contains(this)) { controller = new PathFindController(this, farmHouse2, farmHouse2.getRandomOpenPointInHouse(Game1.random, 1), -1, toddlerReachedDestination); if (controller.pathToEndPoint == null || !farmHouse2.isTileOnMap(controller.pathToEndPoint.Last().X, controller.pathToEndPoint.Last().Y)) { controller = null; } } } else { if (!Game1.IsMasterGame || base.Age != 3 || Game1.timeOfDay != 1900) { return; } base.IsWalkingInSquare = false; Halt(); FarmHouse farmHouse = base.currentLocation as FarmHouse; if (!farmHouse.characters.Contains(this)) { return; } int child_index = GetChildIndex(); BedFurniture bed = farmHouse.GetChildBed(child_index); Point bed_point = farmHouse.GetChildBedSpot(child_index); if (!bed_point.Equals(Point.Zero)) { controller = new PathFindController(this, farmHouse, bed_point, -1, toddlerReachedDestination); if (controller.pathToEndPoint == null || !farmHouse.isTileOnMap(controller.pathToEndPoint.Last().X, controller.pathToEndPoint.Last().Y)) { controller = null; } else { bed?.ReserveForNPC(); } } } }
private void Dbg1(string command, string[] args) { List <Vector2> openSpaces = this.planer.AnalyzeLocationInfo(Game1.currentLocation); this.controller = new PathFindController(this.junimo, Game1.currentLocation, StardewValley.Utility.Vector2ToPoint(openSpaces[0]), 2); this.locationInformationHelper = new LocationInformationHelper(); IEnumerable <Building> animalBuildings = this.locationInformationHelper.GetAnimalFarmBuildings(); this.locationInformationHelper.GetFarmAnimals(Game1.getFarm()); this.locationInformationHelper.GetNearestChestsToFarmBuilding(animalBuildings.First()); }
private void startAutoWalking() { PathFindController controller = new PathFindController(Game1.player, Game1.currentLocation, this.GetViewingTile().ToPoint(), Game1.player.FacingDirection); controller.allowPlayerPathingInEvent = true; if (controller.pathToEndPoint != null && controller.pathToEndPoint.Count > 0) { Game1.player.controller = controller; this.isAutoWalking = true; this.finalTile = this.GetViewingTile(); MainClass.ReadTileFeature.pause(); MainClass.ScreenReader.Say($"Moving to {this.finalTile.X}x {this.finalTile.Y}y", true); } else { MainClass.ScreenReader.Say($"Cannot move to {this.finalTile.X}x {this.finalTile.Y}y", true); } }
public void returnToJunimoHut(GameLocation location) { if (Utility.isOnScreen(Utility.Vector2ToPoint(position.Value / 64f), 64, base.currentLocation)) { jump(); } collidesWithOtherCharacters.Value = false; if (Game1.IsMasterGame) { controller = new PathFindController(this, location, new Point((int)home.tileX + 1, (int)home.tileY + 1), 0, junimoReachedHut); if (controller.pathToEndPoint == null || controller.pathToEndPoint.Count == 0 || location.isCollidingPosition(nextPosition, Game1.viewport, isFarmer: false, 0, glider: false, this)) { destroy = true; } } if (Utility.isOnScreen(Utility.Vector2ToPoint(position.Value / 64f), 64, base.currentLocation)) { location.playSound("junimoMeep1"); } }
public override void behaviorAtGameTick(GameTime time) { if (base.IsWalkingTowardPlayer) { base.behaviorAtGameTick(time); } if (!seenPlayer) { if (withinPlayerThreshold()) { base.currentLocation.playSound("rockGolemSpawn"); seenPlayer.Value = true; } else { Sprite.currentFrame = 16; Sprite.loop = false; Sprite.UpdateSourceRect(); } } else if (Sprite.currentFrame >= 16) { Sprite.Animate(time, 16, 8, 75f); if (Sprite.currentFrame >= 24) { Sprite.loop = true; Sprite.currentFrame = 0; moveTowardPlayerThreshold.Value = 16; base.IsWalkingTowardPlayer = true; jitteriness.Value = 0.01; base.HideShadow = false; } } else if (base.IsWalkingTowardPlayer && Game1.random.NextDouble() < 0.001 && Utility.isOnScreen(getStandingPosition(), 0)) { controller = new PathFindController(this, base.currentLocation, new Point((int)base.Player.getTileLocation().X, (int)base.Player.getTileLocation().Y), -1, null, 200); } }
public void pathFindToNewCrop_doWork() { if (Game1.timeOfDay > 1900) { if (controller == null) { returnToJunimoHut(base.currentLocation); } return; } if (Game1.random.NextDouble() < 0.035 || (bool)home.noHarvest) { pathfindToRandomSpotAroundHut(); return; } controller = new PathFindController(this, base.currentLocation, foundCropEndFunction, -1, eraseOldPathController: false, reachFirstDestinationFromHut, 100, Point.Zero); if (controller.pathToEndPoint == null || Math.Abs(controller.pathToEndPoint.Last().X - ((int)home.tileX + 1)) > 8 || Math.Abs(controller.pathToEndPoint.Last().Y - ((int)home.tileY + 1)) > 8) { if (Game1.random.NextDouble() < 0.5 && !home.lastKnownCropLocation.Equals(Point.Zero)) { controller = new PathFindController(this, base.currentLocation, home.lastKnownCropLocation, -1, reachFirstDestinationFromHut, 100); } else if (Game1.random.NextDouble() < 0.25) { netAnimationEvent.Fire(0); returnToJunimoHut(base.currentLocation); } else { pathfindToRandomSpotAroundHut(); } } else { netAnimationEvent.Fire(0); } }
public static bool Prefix(ref PathFindController __instance, Character ___character, GameTime time) { if (!ModEntry.IsChildNPC(___character)) { return(true); } Rectangle rectangle = new Rectangle(__instance.pathToEndPoint.Peek().X * 64, __instance.pathToEndPoint.Peek().Y * 64, 64, 64); rectangle.Inflate(-2, 0); Rectangle boundingBox = ___character.GetBoundingBox(); if ((rectangle.Contains(boundingBox) || boundingBox.Width > rectangle.Width && rectangle.Contains(boundingBox.Center)) && rectangle.Bottom - boundingBox.Bottom >= 2) { __instance.timerSinceLastCheckPoint = 0; __instance.pathToEndPoint.Pop(); ___character.stopWithoutChangingFrame(); if (__instance.pathToEndPoint.Count != 0) { return(false); } ___character.Halt(); if (__instance.finalFacingDirection != -1) { ___character.faceDirection(__instance.finalFacingDirection); } if (__instance.NPCSchedule) { (___character as NPC).DirectionsToNewLocation = null; (___character as NPC).endOfRouteMessage.Value = (___character as NPC).nextEndOfRouteMessage; } if (__instance.endBehaviorFunction == null) { return(false); } __instance.endBehaviorFunction(___character, __instance.location); return(false); } else { foreach (NPC character in __instance.location.characters) { if (!character.Equals(___character) && character.GetBoundingBox().Intersects(boundingBox) && character.isMoving() && string.Compare(character.Name, ___character.Name) < 0) { ___character.Halt(); return(false); } } if (boundingBox.Left < rectangle.Left && boundingBox.Right < rectangle.Right) { ___character.SetMovingRight(true); } else if (boundingBox.Right > rectangle.Right && boundingBox.Left > rectangle.Left) { ___character.SetMovingLeft(true); } else if (boundingBox.Top <= rectangle.Top) { ___character.SetMovingDown(true); } else if (boundingBox.Bottom >= rectangle.Bottom - 2) { ___character.SetMovingUp(true); } ___character.MovePosition(time, Game1.viewport, __instance.location); if (!__instance.NPCSchedule) { return(false); } Warp warp = __instance.location.isCollidingWithWarpOrDoor(___character.nextPosition(___character.getDirection())); if (warp == null) { return(false); } //This is the point where character needs to be married, I'm fixing. if (___character is NPC /*&& (___character as NPC).isMarried() */ && (___character as NPC).followSchedule) { NPC character = ___character as NPC; if (__instance.location is FarmHouse) { warp = new Warp(warp.X, warp.Y, "BusStop", 0, 23, false); } if (__instance.location is BusStop && warp.X <= 0) { warp = new Warp(warp.X, warp.Y, character.getHome().Name, (character.getHome() as FarmHouse).getEntryLocation().X, (character.getHome() as FarmHouse).getEntryLocation().Y, false); } if (character.temporaryController != null && character.controller != null) { character.controller.location = Game1.getLocationFromName(warp.TargetName); } } Game1.warpCharacter(___character as NPC, warp.TargetName, new Vector2((float)warp.TargetX, (float)warp.TargetY)); if (__instance.isPlayerPresent() && __instance.location.doors.ContainsKey(new Point(warp.X, warp.Y))) { __instance.location.playSoundAt("doorClose", new Vector2((float)warp.X, (float)warp.Y)); } __instance.location = Game1.getLocationFromName(warp.TargetName); if (__instance.isPlayerPresent() && __instance.location.doors.ContainsKey(new Point(warp.TargetX, warp.TargetY - 1))) { __instance.location.playSoundAt("doorClose", new Vector2((float)warp.TargetX, (float)warp.TargetY)); } if (__instance.pathToEndPoint.Count > 0) { __instance.pathToEndPoint.Pop(); } while (__instance.pathToEndPoint.Count > 0 && (Math.Abs(__instance.pathToEndPoint.Peek().X - ___character.getTileX()) > 1 || Math.Abs(__instance.pathToEndPoint.Peek().Y - ___character.getTileY()) > 1)) { __instance.pathToEndPoint.Pop(); } return(false); } }
public PathFindControllerWrapper(PathFindController item) => GetBaseType = item;
public override void behaviorAtGameTick(GameTime time) { base.behaviorAtGameTick(time); if (yJumpOffset == 0) { if (Game1.random.NextDouble() < 0.05) { Utilities.MP.broadcastSprites(currentLocation, new TemporaryAnimatedSprite("TileSheets\\animations", new Rectangle(0, 128, 64, 64), 40f, 4, 0, getStandingPosition(), false, false) { color = primaryColor.Value }); yJumpVelocity *= 2f; } if (!chargingFarmer) { xVelocity = Game1.random.Next(-20, 21) / 5f; } } if (chargingFarmer) { Slipperiness = 10; Vector2 trajectory = Utility.getAwayFromPlayerTrajectory (GetBoundingBox(), Player); xVelocity += (0f - trajectory.X) / 150f + ((Game1.random.NextDouble() < 0.01) ? Game1.random.Next(-50, 50) / 10f : 0f); if (Math.Abs(xVelocity) > 5f) { xVelocity = Math.Sign(xVelocity) * 5; } yVelocity += (0f - trajectory.Y) / 150f + ((Game1.random.NextDouble() < 0.01) ? Game1.random.Next(-50, 50) / 10f : 0f); if (Math.Abs(yVelocity) > 5f) { yVelocity = Math.Sign(yVelocity) * 5; } if (Game1.random.NextDouble() < 0.0001) { controller = new PathFindController(this, currentLocation, new Point((int)Player.getTileLocation().X, (int)Player.getTileLocation().Y), Game1.random.Next(4), null, 300); chargingFarmer = false; } } else if (controller == null && !runningAwayFromFarmer) { runAway(); } else if (controller == null && runningAwayFromFarmer) { chargingFarmer = true; } }
public Stack <Point> findPath(Point startPoint, Point endPoint, PathFindController.isAtEnd endPointFunction, GameLocation location, Character character, int limit) { sbyte[,] array = new sbyte[, ] { { -1, 0 }, { 1, 0 }, { 0, 1 }, { 0, -1 } }; PriorityQueue priorityQueue = new PriorityQueue(); Dictionary <PathNode, PathNode> dictionary = new Dictionary <PathNode, PathNode>(); int num = 0; priorityQueue.Enqueue(new PathNode(startPoint.X, startPoint.Y, 0, null), Math.Abs(endPoint.X - startPoint.X) + Math.Abs(endPoint.Y - startPoint.Y)); while (!priorityQueue.IsEmpty()) { PathNode pathNode = priorityQueue.Dequeue(); if (endPointFunction(pathNode, endPoint, location, character)) { return(PathFindController.reconstructPath(pathNode, dictionary)); } if (!dictionary.ContainsKey(pathNode)) { dictionary.Add(pathNode, pathNode.parent); } for (int i = 0; i < 4; i++) { PathNode pathNode2 = new PathNode(pathNode.x + (int)array[i, 0], pathNode.y + (int)array[i, 1], pathNode); pathNode2.g = (byte)(pathNode.g + 1); bool colliding = location.isCollidingPosition(new Rectangle(pathNode2.x * Game1.tileSize + 1, pathNode2.y * Game1.tileSize + 1, Game1.tileSize - 2, Game1.tileSize - 2), Game1.viewport, false, 0, false, character, true, false, false); //bool colliding = location.isTilePassable(new Rectangle(pathNode2.x * Game1.tileSize + 1, pathNode2.y * Game1.tileSize + 1, Game1.tileSize - 2, Game1.tileSize - 2), Game1.viewport); //bool colliding = false; if (!dictionary.ContainsKey(pathNode2) && ((pathNode2.x == endPoint.X && pathNode2.y == endPoint.Y) || (pathNode2.x >= 0 && pathNode2.y >= 0 && pathNode2.x < location.map.Layers[0].LayerWidth && pathNode2.y < location.map.Layers[0].LayerHeight)) && !colliding) { int priority = (int)pathNode2.g + (Math.Abs(endPoint.X - pathNode2.x) + Math.Abs(endPoint.Y - pathNode2.y)); if (!priorityQueue.Contains(pathNode2, priority)) { if (!this.DebugPointsSearched.ContainsKey(new Point(pathNode2.x, pathNode2.y))) { this.DebugPointsSearched.Add(new Point(pathNode2.x, pathNode2.y), true); } priorityQueue.Enqueue(pathNode2, priority); } } else if (!this.DebugPointsSearched.ContainsKey(new Point(pathNode2.x, pathNode2.y))) { this.DebugPointsSearched.Add(new Point(pathNode2.x, pathNode2.y), false); } } num++; if (num >= limit) { return(null); } } return(null); }
public void Create() { var a = Game1.currentLocation.warps; foreach (GameLocation loc in Game1.locations) { //graph.AddVertex(loc.Name); } partialGraphs = new Dictionary <GameLocation, PartialGraph>(); //var edgeCosts = new List<Dictionary<Edge<ExtendedWarp>, double>>(); foreach (GameLocation loc in Game1.locations) { if (loc.Name == "Farm") { // TODO Connect barns/coops } // TODO add player and target vertex and connect every node to it var partialGraph = new PartialGraph(loc); // Calculate which warps should correspond to a vertex. Dont add warps which are very close. var extWarpsToInclude = new List <ExtendedWarp>(); for (int i = 0; i < loc.warps.Count; i++) { var extWarpNew = new ExtendedWarp(loc.warps.ElementAt(i), loc); bool shouldAdd = true; foreach (ExtendedWarp extWarpIncluded in extWarpsToInclude) { if (extWarpNew.TargetLocation == extWarpIncluded.TargetLocation && ExtendedWarp.Distance(extWarpNew, extWarpIncluded) < 5) { shouldAdd = false; break; } } if (shouldAdd) { extWarpsToInclude.Add(extWarpNew); partialGraph.AddVertex(extWarpsToInclude.Last()); } } // Create edges for partial graphs for (int i = 0; i < extWarpsToInclude.Count; i++) { var extWarp1 = extWarpsToInclude.ElementAt(i); for (int j = 0; j < extWarpsToInclude.Count; j++) { var LocTo = Game1.getLocationFromName(loc.warps.ElementAt(j).TargetName); var extWarp2 = extWarpsToInclude.ElementAt(j); var path = PathFindController.findPath(new Point(extWarp1.X, extWarp1.Y), new Point(extWarp2.X, extWarp2.Y), new PathFindController.isAtEnd(PathFindController.isAtEndPoint), loc, Game1.player, 9999); double dist; string edgeLabel; if (path != null) { dist = (float)path.Count; // TODO Player can run diagonally. Account for that. edgeLabel = loc.Name + " - " + dist + "c"; } else { dist = (int)Vector2.Distance(new Vector2(extWarp1.X, extWarp1.Y), new Vector2(extWarp2.X, extWarp2.Y)); edgeLabel = loc.Name + " - " + dist + "d"; } var edge = new LabelledEdge <ExtendedWarp>(extWarp1, extWarp2, edgeLabel, new GraphvizColor(255, 255, 255, 255), dist); partialGraph.AddEdge(edge); } partialGraph.AddVertex(extWarp1); } partialGraph.AddPlayerVertex(new ExtendedWarp(new Warp(0, 0, "None", 0, 0, false), loc)); partialGraph.ConnectPlayerVertex(); partialGraphs.Add(loc, partialGraph); } // Combine partial graphs into one foreach (var partialGraph in partialGraphs.Values) { this.AddVertexRange(partialGraph.Vertices); this.AddEdgeRange(partialGraph.Edges); } for (int i = 0; i < partialGraphs.Count; i++) { var graph1 = partialGraphs.Values.ElementAt(i); for (int j = 0; j < partialGraphs.Count; j++) { var graph2 = partialGraphs.Values.ElementAt(j); foreach (ExtendedWarp warp1 in graph1.Vertices) { if (warp1.OriginLocation.name == "Saloon") { } if (graph2.VertexCount > 0 && warp1.TargetLocation == graph2.Vertices.ElementAt(0).OriginLocation) { var copyVertex = new ExtendedWarp((Warp)warp1, warp1.OriginLocation);// copy to make the graph visually clearer var edgeToCopy = new LabelledEdge <ExtendedWarp>(warp1, copyVertex, "Warp", new GraphvizColor(255, 255, 255, 255), 0); this.AddVertex(copyVertex); this.AddEdge(edgeToCopy); foreach (ExtendedWarp warp2 in graph2.Vertices) { var newEdge = new LabelledEdge <ExtendedWarp>(copyVertex, warp2, warp2.OriginLocation.Name, new GraphvizColor(255, 255, 255, 255), ExtendedWarp.Distance(copyVertex, warp2)); // TODO: Calculate cost this.AddEdge(newEdge); if (warp2.TargetLocation?.Name == "Saloon") { } } } } } } GraphvizAlgorithm <ExtendedWarp, LabelledEdge <ExtendedWarp> > graphviz = new GraphvizAlgorithm <ExtendedWarp, LabelledEdge <ExtendedWarp> >(this); graphviz.FormatVertex += (sender2, args) => args.VertexFormatter.Label = args.Vertex.Label; graphviz.FormatEdge += (sender2, args) => { args.EdgeFormatter.Label.Value = args.Edge.Label; }; graphviz.FormatEdge += (sender2, args) => { args.EdgeFormatter.FontGraphvizColor = args.Edge.Color; }; graphviz.ImageType = GraphvizImageType.Jpeg; graphviz.Generate(new FileDotEngine(), "C:\\Users\\Gunnar\\Desktop\\graph123.jpeg"); //var alg = new QuickGraph.Algorithms.ShortestPath.UndirectedDijkstraShortestPathAlgorithm<ExtendedWarp, Edge<ExtendedWarp>>; }
public void pathfindToRandomSpotAroundHut() { controller = new PathFindController(endPoint: Utility.Vector2ToPoint(new Vector2((int)home.tileX + 1 + Game1.random.Next(-8, 9), (int)home.tileY + 1 + Game1.random.Next(-8, 9))), c: this, location: base.currentLocation, finalFacingDirection: -1, endBehaviorFunction: reachFirstDestinationFromHut, limit: 100); }
public void Populate() { var vertexToInclude = new List <WarpVertex>(); List <Warp> warps = new List <Warp>(this.Location.warps); // Shallow copy to allow adding to list without changing original list if (this.Location is Farm) { var farmBuildings = ((Farm)this.Location).buildings; var greenhouse = Game1.getLocationFromName("Greenhouse"); var w = greenhouse.warps[0]; warps.Add(new Warp(w.TargetX, w.TargetY, "Greenhouse", 0, 0, false)); foreach (Building building in farmBuildings) { var indoors = building.indoors.Value; if (indoors != null && indoors is AnimalHouse) { var doorLoc = new Vector2(building.tileX.Value + building.humanDoor.X, building.tileY.Value + building.humanDoor.Y); // Target location does not matter since an animal house is always at the end of the path var vertexNew = new WarpVertex(this.Location, doorLoc, indoors, new Vector2(0, 0)); this.AddVertex(vertexNew); } } } for (int i = 0; i < warps.Count; i++) { var warp = warps.ElementAt(i); var vertexNew = new WarpVertex(this.Location, new Vector2(warp.X, warp.Y), Game1.getLocationFromName(warp.TargetName), new Vector2(warp.TargetX, warp.TargetY)); bool shouldAdd = true; foreach (WarpVertex extWarpIncluded in vertexToInclude) { if (vertexNew.TargetLocation == extWarpIncluded.TargetLocation && StardewVertex.Distance(vertexNew, extWarpIncluded) < 5) { shouldAdd = false; break; } } if (shouldAdd) { vertexToInclude.Add(vertexNew); this.AddVertex(vertexToInclude.Last()); } } for (int i = 0; i < vertexToInclude.Count; i++) { var vertex1 = vertexToInclude.ElementAt(i); for (int j = 0; j < vertexToInclude.Count; j++) { var locTo = Game1.getLocationFromName(this.Location.warps.ElementAt(j).TargetName); var vertex2 = vertexToInclude.ElementAt(j); var path = PathFindController.findPath(new Point((int)vertex1.Position.X, (int)vertex1.Position.Y), new Point((int)vertex2.Position.X, (int)vertex2.Position.Y), new PathFindController.isAtEnd(PathFindController.isAtEndPoint), this.Location, Game1.player, 9999); // TODO Use Pathfinder distance double dist; string edgeLabel; if (path != null) { dist = (float)path.Count; // TODO Player can run diagonally. Account for that. edgeLabel = this.Location.Name + " - " + dist + "c"; } else { dist = (int)StardewVertex.Distance(vertex1, vertex2); edgeLabel = this.Location.Name + " - " + dist + "d"; } var edge = new StardewEdge(vertex1, vertex2, edgeLabel); this.AddEdge(edge); } this.AddVertex(vertex1); } this.AddPlayerVertex(new MovableVertex(this.Location, new Vector2(0, 0))); this.AddTargetVertex(new MovableVertex(this.Location, new Vector2(0, 0))); this.ConnectPlayerVertex(); }
public override void behaviorAtGameTick(GameTime time) { base.behaviorAtGameTick(time); if (timeBeforeAIMovementAgain <= 0f) { base.IsInvisible = false; } if (!spottedPlayer && Utility.couldSeePlayerInPeripheralVision(base.Player, this) && Utility.doesPointHaveLineOfSightInMine(base.currentLocation, getTileLocation(), base.Player.getTileLocation(), 8)) { controller = null; spottedPlayer = true; Halt(); facePlayer(base.Player); if (Game1.random.NextDouble() < 0.3) { base.currentLocation.playSound("shadowpeep"); } } else if ((bool)casting) { base.IsWalkingTowardPlayer = false; Sprite.Animate(time, 16, 4, 200f); rotationTimer = (float)((double)((float)time.TotalGameTime.Milliseconds * ((float)Math.PI / 128f) / 24f) % (Math.PI * 1024.0)); coolDown -= time.ElapsedGameTime.Milliseconds; if (coolDown > 0) { return; } base.Scale = 1f; Vector2 velocityTowardPlayer = Utility.getVelocityTowardPlayer(GetBoundingBox().Center, 15f, base.Player); if (base.Player.attack >= 0 && Game1.random.NextDouble() < 0.6) { base.currentLocation.projectiles.Add(new DebuffingProjectile(14, 7, 4, 4, (float)Math.PI / 16f, velocityTowardPlayer.X, velocityTowardPlayer.Y, new Vector2(GetBoundingBox().X, GetBoundingBox().Y), base.currentLocation, this)); } else { List <Monster> monstersNearPlayer = new List <Monster>(); foreach (NPC i in base.currentLocation.characters) { if (i is Monster && (i as Monster).withinPlayerThreshold(6)) { monstersNearPlayer.Add((Monster)i); } } Monster lowestHealthMonster = null; double lowestHealth = 1.0; foreach (Monster j in monstersNearPlayer) { if ((double)j.Health / (double)j.MaxHealth <= lowestHealth) { lowestHealthMonster = j; lowestHealth = (double)j.Health / (double)j.MaxHealth; } } if (lowestHealthMonster != null) { int amountToHeal = 60; lowestHealthMonster.Health = Math.Min(lowestHealthMonster.MaxHealth, lowestHealthMonster.Health + amountToHeal); base.currentLocation.playSound("healSound"); Game1.multiplayer.broadcastSprites(base.currentLocation, new TemporaryAnimatedSprite("TileSheets\\animations", new Rectangle(0, 256, 64, 64), 40f, 8, 0, lowestHealthMonster.Position + new Vector2(32f, 64f), flicker: false, flipped: false)); base.currentLocation.debris.Add(new Debris(amountToHeal, new Vector2(lowestHealthMonster.GetBoundingBox().Center.X, lowestHealthMonster.GetBoundingBox().Center.Y), Color.Green, 1f, lowestHealthMonster)); } } casting.Value = false; coolDown = 1500; base.IsWalkingTowardPlayer = true; } else if (spottedPlayer && withinPlayerThreshold(8)) { if (base.Health < 30) { if (Math.Abs(base.Player.GetBoundingBox().Center.Y - GetBoundingBox().Center.Y) > 192) { if (base.Player.GetBoundingBox().Center.X - GetBoundingBox().Center.X > 0) { SetMovingLeft(b: true); } else { SetMovingRight(b: true); } } else if (base.Player.GetBoundingBox().Center.Y - GetBoundingBox().Center.Y > 0) { SetMovingUp(b: true); } else { SetMovingDown(b: true); } } else if (controller == null && !Utility.doesPointHaveLineOfSightInMine(base.currentLocation, getTileLocation(), base.Player.getTileLocation(), 8)) { controller = new PathFindController(this, base.currentLocation, new Point((int)base.Player.getTileLocation().X, (int)base.Player.getTileLocation().Y), -1, null, 300); if (controller == null || controller.pathToEndPoint == null || controller.pathToEndPoint.Count == 0) { spottedPlayer = false; Halt(); controller = null; base.addedSpeed = 0; } } else if (coolDown <= 0 && Game1.random.NextDouble() < 0.02) { casting.Value = true; Halt(); coolDown = 500; } coolDown -= time.ElapsedGameTime.Milliseconds; } else if (spottedPlayer) { base.IsWalkingTowardPlayer = false; spottedPlayer = false; controller = null; base.addedSpeed = 0; } else { defaultMovementBehavior(time); } }
public override void behaviorAtGameTick(GameTime time) { invincibleCountdown = 1000; if (timeBeforeAIMovementAgain > 0f) { timeBeforeAIMovementAgain -= (float)time.ElapsedGameTime.Milliseconds; } if (yJumpOffset == 0) { if (Game1.random.NextDouble() < DestroyRockChance()) { ModEntry.SHelper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue().broadcastSprites(base.currentLocation, new TemporaryAnimatedSprite[] { new TemporaryAnimatedSprite("TileSheets\\animations", new Rectangle(0, 128, 64, 64), 40f, 4, 0, base.getStandingPosition(), false, false) }); foreach (Vector2 v in Utility.getAdjacentTileLocations(base.getTileLocation())) { if (currentLocation is MineShaft && currentLocation.objects.ContainsKey(v) && base.currentLocation.objects[v].Name.Equals("Stone")) { AddExp(1); currentLocation.destroyObject(v, null); } } yJumpVelocity *= 2f; } if (!chargingFarmer && !chargingMonster) { xVelocity = (float)Game1.random.Next(-20, 21) / 5f; } } if (lastHitCounter >= 0) { lastHitCounter.Value -= time.ElapsedGameTime.Milliseconds; } chargingMonster = false; if (lastHitCounter < 0) { foreach (NPC npc in currentLocation.characters) { if (npc is Familiar) { continue; } if (npc is Monster && FamiliarsUtils.monstersColliding(this, (Monster)npc) && Game1.random.NextDouble() < StealChance()) { ModEntry.SMonitor.Log("Stealing loot"); FamiliarsUtils.monsterDrop(this, (Monster)npc, GetOwner()); lastHitCounter.Value = StealInterval(); chargingMonster = false; AddExp(1); break; } else if (npc is Monster && FamiliarsUtils.withinMonsterThreshold(this, (Monster)npc, 5)) { chargingMonster = true; if (currentTarget == null || Vector2.Distance(npc.position, position) < Vector2.Distance(currentTarget.position, position)) { currentTarget = (Monster)npc; } } } } if (chargingMonster && currentTarget != null) { base.Slipperiness = 10; Vector2 v2 = FamiliarsUtils.getAwayFromNPCTrajectory(GetBoundingBox(), currentTarget); xVelocity += -v2.X / 150f + ((Game1.random.NextDouble() < 0.01) ? ((float)Game1.random.Next(-50, 50) / 10f) : 0f); if (Math.Abs(xVelocity) > 5f) { xVelocity = (float)(Math.Sign(xVelocity) * 5); } yVelocity += -v2.Y / 150f + ((Game1.random.NextDouble() < 0.01) ? ((float)Game1.random.Next(-50, 50) / 10f) : 0f); if (Math.Abs(yVelocity) > 5f) { yVelocity = (float)(Math.Sign(yVelocity) * 5); } return; } chargingFarmer = false; if (!followingOwner) { return; } if (!seenFarmer && withinPlayerThreshold()) { seenFarmer = true; return; } if (seenFarmer && controller == null && !runningAwayFromFarmer) { base.addedSpeed = 2; controller = new PathFindController(this, base.currentLocation, new PathFindController.isAtEnd(Utility.isOffScreenEndFunction), -1, false, new PathFindController.endBehavior(offScreenBehavior), 350, Point.Zero, true); runningAwayFromFarmer = true; return; } if (controller == null && runningAwayFromFarmer) { chargingFarmer = true; } if (chargingFarmer) { base.Slipperiness = 10; Vector2 v2 = Utility.getAwayFromPlayerTrajectory(GetBoundingBox(), GetOwner()); xVelocity += -v2.X / 150f + ((Game1.random.NextDouble() < 0.01) ? ((float)Game1.random.Next(-50, 50) / 10f) : 0f); if (Math.Abs(xVelocity) > 5f) { xVelocity = (float)(Math.Sign(xVelocity) * 5); } yVelocity += -v2.Y / 150f + ((Game1.random.NextDouble() < 0.01) ? ((float)Game1.random.Next(-50, 50) / 10f) : 0f); if (Math.Abs(yVelocity) > 5f) { yVelocity = (float)(Math.Sign(yVelocity) * 5); } if (Game1.random.NextDouble() < 0.0001) { controller = new PathFindController(this, base.currentLocation, new Point((int)GetOwner().getTileLocation().X, (int)GetOwner().getTileLocation().Y), Game1.random.Next(4), null, 300); chargingFarmer = false; return; } } }
public override void behaviorAtGameTick(GameTime time) { base.behaviorAtGameTick(time); if (timeBeforeAIMovementAgain <= 0f) { base.IsInvisible = false; } if (teleporting) { coolDown -= time.ElapsedGameTime.Milliseconds; if (coolDown <= 0) { if (teleportationPath.MoveNext()) { Game1.multiplayer.broadcastSprites(base.currentLocation, new TemporaryAnimatedSprite(Sprite.textureName, Sprite.SourceRect, base.Position, flipped: false, 0.04f, Color.White)); base.Position = new Vector2(teleportationPath.Current.X * 64 + 4, teleportationPath.Current.Y * 64 - 32 - 4); coolDown = 20; } else { teleporting = false; coolDown = 500; } } } else if (!spottedPlayer && Utility.couldSeePlayerInPeripheralVision(base.Player, this) && Utility.doesPointHaveLineOfSightInMine(base.currentLocation, getTileLocation(), base.Player.getTileLocation(), 8)) { controller = null; spottedPlayer = true; Halt(); facePlayer(base.Player); if (Game1.random.NextDouble() < 0.3) { base.currentLocation.playSound("shadowpeep"); } } else if (casting) { Halt(); base.IsWalkingTowardPlayer = false; rotationTimer = (float)((double)((float)time.TotalGameTime.Milliseconds * ((float)Math.PI / 128f) / 24f) % (Math.PI * 1024.0)); coolDown -= time.ElapsedGameTime.Milliseconds; if (coolDown <= 0) { base.Scale = 1f; Vector2 velocityTowardPlayer = Utility.getVelocityTowardPlayer(GetBoundingBox().Center, 15f, base.Player); if (base.Player.attack >= 0 && Game1.random.NextDouble() < 0.6) { base.currentLocation.projectiles.Add(new DebuffingProjectile(18, 2, 4, 4, (float)Math.PI / 16f, velocityTowardPlayer.X, velocityTowardPlayer.Y, new Vector2(GetBoundingBox().X, GetBoundingBox().Y))); } else { base.currentLocation.playSound("fireball"); base.currentLocation.projectiles.Add(new BasicProjectile(10, 3, 0, 3, 0f, velocityTowardPlayer.X, velocityTowardPlayer.Y, new Vector2(GetBoundingBox().X, GetBoundingBox().Y))); } casting = false; coolDown = 1500; base.IsWalkingTowardPlayer = true; } } else if (spottedPlayer && withinPlayerThreshold(8)) { if (base.Health < 30) { if (Math.Abs(base.Player.GetBoundingBox().Center.Y - GetBoundingBox().Center.Y) > 192) { if (base.Player.GetBoundingBox().Center.X - GetBoundingBox().Center.X > 0) { SetMovingLeft(b: true); } else { SetMovingRight(b: true); } } else if (base.Player.GetBoundingBox().Center.Y - GetBoundingBox().Center.Y > 0) { SetMovingUp(b: true); } else { SetMovingDown(b: true); } } else if (controller == null && !Utility.doesPointHaveLineOfSightInMine(base.currentLocation, getTileLocation(), base.Player.getTileLocation(), 8)) { controller = new PathFindController(this, base.currentLocation, new Point((int)base.Player.getTileLocation().X, (int)base.Player.getTileLocation().Y), -1, null, 300); if (controller == null || controller.pathToEndPoint == null || controller.pathToEndPoint.Count == 0) { spottedPlayer = false; Halt(); controller = null; base.addedSpeed = 0; } } else if (coolDown <= 0 && Game1.random.NextDouble() < 0.02) { casting = true; Halt(); coolDown = 500; } coolDown -= time.ElapsedGameTime.Milliseconds; } else if (spottedPlayer) { base.IsWalkingTowardPlayer = false; spottedPlayer = false; controller = null; base.addedSpeed = 0; } else { defaultMovementBehavior(time); } }