public PathFindController(Character c, GameLocation location, PathFindController.isAtEnd endFunction, int finalFacingDirection, bool eraseOldPathController, PathFindController.endBehavior endBehaviorFunction, int limit, Point endPoint) { this.limit = limit; this.character = c; if (c is NPC && (c as NPC).CurrentDialogue.Count > 0 && (c as NPC).CurrentDialogue.Peek().removeOnNextMove) { (c as NPC).CurrentDialogue.Pop(); } this.location = location; this.endFunction = endFunction == null ? new PathFindController.isAtEnd(PathFindController.isAtEndPoint) : endFunction; this.endBehaviorFunction = endBehaviorFunction; if (endPoint == Point.Zero) { endPoint = new Point((int)c.getTileLocation().X, (int)c.getTileLocation().Y); } this.finalFacingDirection = finalFacingDirection; if (!(this.character is NPC) && !Game1.currentLocation.Name.Equals(location.Name) && (endFunction == new PathFindController.isAtEnd(PathFindController.isAtEndPoint) && endPoint.X > 0) && endPoint.Y > 0) { this.character.position = new Vector2((float)(endPoint.X * Game1.tileSize), (float)(endPoint.Y * Game1.tileSize - Game1.tileSize / 2)); } else { this.pathToEndPoint = PathFindController.findPath(new Point((int)c.getTileLocation().X, (int)c.getTileLocation().Y), endPoint, endFunction, location, this.character, limit); if (this.pathToEndPoint != null) { return; } FarmHouse farmHouse = location as FarmHouse; } }
public static Stack <Point> findPath(Point startPoint, Point endPoint, PathFindController.isAtEnd endPointFunction, GameLocation location, Character character, int limit) { sbyte[,] numArray = new sbyte[4, 2] { { (sbyte)-1, (sbyte)0 }, { (sbyte)1, (sbyte)0 }, { (sbyte)0, (sbyte)1 }, { (sbyte)0, (sbyte)-1 } }; PriorityQueue priorityQueue = new PriorityQueue(); Dictionary <PathNode, PathNode> closedList = new Dictionary <PathNode, PathNode>(); int num = 0; priorityQueue.Enqueue(new PathNode(startPoint.X, startPoint.Y, (byte)0, (PathNode)null), Math.Abs(endPoint.X - startPoint.X) + Math.Abs(endPoint.Y - startPoint.Y)); while (!priorityQueue.IsEmpty()) { PathNode pathNode1 = priorityQueue.Dequeue(); if (endPointFunction(pathNode1, endPoint, location, character)) { return(PathFindController.reconstructPath(pathNode1, closedList)); } if (!closedList.ContainsKey(pathNode1)) { closedList.Add(pathNode1, pathNode1.parent); } for (int index = 0; index < 4; ++index) { PathNode pathNode2 = new PathNode(pathNode1.x + (int)numArray[index, 0], pathNode1.y + (int)numArray[index, 1], pathNode1); pathNode2.g = (byte)((uint)pathNode1.g + 1U); if (!closedList.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)) && !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)) { int priority = (int)pathNode2.g + (Math.Abs(endPoint.X - pathNode2.x) + Math.Abs(endPoint.Y - pathNode2.y)); if (!priorityQueue.Contains(pathNode2, priority)) { priorityQueue.Enqueue(pathNode2, priority); } } } ++num; if (num >= limit) { return((Stack <Point>)null); } } return((Stack <Point>)null); }
public static 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 = pathNode.g + 1; 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)) && !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)) { int priority = (int)pathNode2.g + (Math.Abs(endPoint.X - pathNode2.x) + Math.Abs(endPoint.Y - pathNode2.y)); if (!priorityQueue.Contains(pathNode2, priority)) { priorityQueue.Enqueue(pathNode2, priority); } } } num++; if (num >= limit) { return(null); } } return(null); }
// Token: 0x060002E9 RID: 745 RVA: 0x0003B7F0 File Offset: 0x000399F0 public static Stack <Point> findPath(Point startPoint, Point endPoint, PathFindController.isAtEnd endPointFunction, GameLocation location, Character character, int limit) { sbyte[,] directions = new sbyte[, ] { { -1, 0 }, { 1, 0 }, { 0, 1 }, { 0, -1 } }; PriorityQueue openList = new PriorityQueue(); Dictionary <PathNode, PathNode> closedList = new Dictionary <PathNode, PathNode>(); int iterations = 0; openList.Enqueue(new PathNode(startPoint.X, startPoint.Y, 0, null), Math.Abs(endPoint.X - startPoint.X) + Math.Abs(endPoint.Y - startPoint.Y)); while (!openList.IsEmpty()) { PathNode currentNode = openList.Dequeue(); if (endPointFunction(currentNode, endPoint, location, character)) { return(PathFindController.reconstructPath(currentNode, closedList)); } if (!closedList.ContainsKey(currentNode)) { closedList.Add(currentNode, currentNode.parent); } for (int i = 0; i < 4; i++) { PathNode neighbor = new PathNode(currentNode.x + (int)directions[i, 0], currentNode.y + (int)directions[i, 1], currentNode); neighbor.g = currentNode.g + 1; if (!closedList.ContainsKey(neighbor) && ((neighbor.x == endPoint.X && neighbor.y == endPoint.Y) || (neighbor.x >= 0 && neighbor.y >= 0 && neighbor.x < location.map.Layers[0].LayerWidth && neighbor.y < location.map.Layers[0].LayerHeight)) && !location.isCollidingPosition(new Rectangle(neighbor.x * Game1.tileSize + 1, neighbor.y * Game1.tileSize + 1, Game1.tileSize - 2, Game1.tileSize - 2), Game1.viewport, false, 0, false, character, true, false, false)) { int f = (int)neighbor.g + (Math.Abs(endPoint.X - neighbor.x) + Math.Abs(endPoint.Y - neighbor.y)); if (!openList.Contains(neighbor, f)) { openList.Enqueue(neighbor, f); } } } iterations++; if (iterations >= limit) { return(null); } } return(null); }
public virtual void update(GameTime time, GameLocation location, long id, bool move) { position.UpdateExtrapolation(speed + addedSpeed); currentLocation = location; faceTowardFarmerEvent.Poll(); if (yJumpOffset != 0) { yJumpVelocity += yJumpGravity; yJumpOffset -= (int)yJumpVelocity; if (yJumpOffset >= 0) { yJumpOffset = 0; yJumpVelocity = 0f; if (!IsMonster && (location == null || location.Equals(Game1.currentLocation)) && wasJumpWithSound) { checkForFootstep(); } } } if (forceUpdateTimer > 0) { forceUpdateTimer -= time.ElapsedGameTime.Milliseconds; } updateGlow(); updateEmote(time); updateFaceTowardsFarmer(time, location); bool is_event_controlled_character = false; if (location.currentEvent != null) { if (location.isTemp()) { is_event_controlled_character = true; } else if (location.currentEvent.actors.Contains(this)) { is_event_controlled_character = true; } } if (Game1.IsMasterGame | is_event_controlled_character) { if (controller == null && move && !freezeMotion) { updateMovement(location, time); } if (controller != null && !freezeMotion && controller.update(time)) { controller = null; } } else { updateSlaveAnimation(time); } hasJustStartedFacingPlayer = false; }
public virtual void update(GameTime time, GameLocation location, long id, bool move) { if (this.yJumpOffset != 0) { this.yJumpVelocity -= 0.5f; this.yJumpOffset -= (int)this.yJumpVelocity; if (this.yJumpOffset >= 0) { this.yJumpOffset = 0; this.yJumpVelocity = 0f; if (!this.IsMonster && (location == null || location.Equals(Game1.currentLocation))) { FarmerSprite.checkForFootstep(this); } } } if (this.faceTowardFarmerTimer > 0) { this.faceTowardFarmerTimer -= time.ElapsedGameTime.Milliseconds; if (!this.faceTowardFarmer && this.faceTowardFarmerTimer > 0 && Utility.tileWithinRadiusOfPlayer((int)this.getTileLocation().X, (int)this.getTileLocation().Y, this.faceTowardFarmerRadius, this.whoToFace)) { this.faceTowardFarmer = true; } else if (!Utility.tileWithinRadiusOfPlayer((int)this.getTileLocation().X, (int)this.getTileLocation().Y, this.faceTowardFarmerRadius, this.whoToFace) || this.faceTowardFarmerTimer <= 0) { this.faceDirection(this.facingDirectionBeforeSpeakingToPlayer); if (this.faceTowardFarmerTimer <= 0) { this.facingDirectionBeforeSpeakingToPlayer = -1; this.faceTowardFarmer = false; this.faceAwayFromFarmer = false; this.faceTowardFarmerTimer = 0; } } } if (this.forceUpdateTimer > 0) { this.forceUpdateTimer -= time.ElapsedGameTime.Milliseconds; } this.updateGlow(); this.updateEmote(time); if (!Game1.IsMultiplayer || Game1.IsServer || this.ignoreMultiplayerUpdates) { if (this.faceTowardFarmer && this.whoToFace != null) { this.faceGeneralDirection(this.whoToFace.getStandingPosition(), 0); if (this.faceAwayFromFarmer) { this.faceDirection((this.facingDirection + 2) % 4); } } if ((this.controller == null & move) && !this.freezeMotion) { this.updateMovement(location, time); } if (this.controller != null && !this.freezeMotion && this.controller.update(time)) { this.controller = null; } if (Game1.IsServer && !Game1.isFestival() && Game1.random.NextDouble() < 0.2) { MultiplayerUtility.broadcastNPCMove((int)this.position.X, (int)this.position.Y, id, location); return; } } else if (!Game1.eventUp) { this.lerpPosition(this.positionToLerpTo); if (this.distanceFromLastServerPosition() >= 8f) { this.animateInFacingDirection(time); } } }
public static Stack <Point> findPathForNPCSchedules(Point startPoint, Point endPoint, GameLocation location, int limit) { sbyte[,] numArray = new sbyte[4, 2] { { (sbyte)-1, (sbyte)0 }, { (sbyte)1, (sbyte)0 }, { (sbyte)0, (sbyte)1 }, { (sbyte)0, (sbyte)-1 } }; PriorityQueue priorityQueue = new PriorityQueue(); Dictionary <PathNode, PathNode> closedList = new Dictionary <PathNode, PathNode>(); int num = 0; priorityQueue.Enqueue(new PathNode(startPoint.X, startPoint.Y, (byte)0, (PathNode)null), Math.Abs(endPoint.X - startPoint.X) + Math.Abs(endPoint.Y - startPoint.Y)); PathNode pathNode1 = (PathNode)priorityQueue.Peek(); while (!priorityQueue.IsEmpty()) { PathNode pathNode2 = priorityQueue.Dequeue(); if (pathNode2.x == endPoint.X && pathNode2.y == endPoint.Y) { return(PathFindController.reconstructPath(pathNode2, closedList)); } if (pathNode2.x == 79) { int y = pathNode2.y; } if (!closedList.ContainsKey(pathNode2)) { closedList.Add(pathNode2, pathNode2.parent); } for (int index = 0; index < 4; ++index) { PathNode pathNode3 = new PathNode(pathNode2.x + (int)numArray[index, 0], pathNode2.y + (int)numArray[index, 1], pathNode2); pathNode3.g = (byte)((uint)pathNode2.g + 1U); if (!closedList.ContainsKey(pathNode3) && (pathNode3.x == endPoint.X && pathNode3.y == endPoint.Y || pathNode3.x >= 0 && pathNode3.y >= 0 && (pathNode3.x < location.map.Layers[0].LayerWidth && pathNode3.y < location.map.Layers[0].LayerHeight) && !PathFindController.isPositionImpassableForNPCSchedule(location, pathNode3.x, pathNode3.y))) { int priority = (int)pathNode3.g + PathFindController.getPreferenceValueForTerrainType(location, pathNode3.x, pathNode3.y) + (Math.Abs(endPoint.X - pathNode3.x) + Math.Abs(endPoint.Y - pathNode3.y) + (pathNode3.x == pathNode2.x && pathNode3.x == pathNode1.x || pathNode3.y == pathNode2.y && pathNode3.y == pathNode1.y ? -2 : 0)); if (!priorityQueue.Contains(pathNode3, priority)) { priorityQueue.Enqueue(pathNode3, priority); } } } pathNode1 = pathNode2; ++num; if (num >= limit) { return((Stack <Point>)null); } } return((Stack <Point>)null); }
public static Stack <Point> findPathForNPCSchedules(Point startPoint, Point endPoint, GameLocation location, 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)); PathNode pathNode = (PathNode)priorityQueue.Peek(); while (!priorityQueue.IsEmpty()) { PathNode pathNode2 = priorityQueue.Dequeue(); if (pathNode2.x == endPoint.X && pathNode2.y == endPoint.Y) { return(PathFindController.reconstructPath(pathNode2, dictionary)); } if (pathNode2.x == 79) { int arg_B2_0 = pathNode2.y; } if (!dictionary.ContainsKey(pathNode2)) { dictionary.Add(pathNode2, pathNode2.parent); } for (int i = 0; i < 4; i++) { PathNode pathNode3 = new PathNode(pathNode2.x + (int)array[i, 0], pathNode2.y + (int)array[i, 1], pathNode2); pathNode3.g = pathNode2.g + 1; if (!dictionary.ContainsKey(pathNode3) && ((pathNode3.x == endPoint.X && pathNode3.y == endPoint.Y) || (pathNode3.x >= 0 && pathNode3.y >= 0 && pathNode3.x < location.map.Layers[0].LayerWidth && pathNode3.y < location.map.Layers[0].LayerHeight && !PathFindController.isPositionImpassableForNPCSchedule(location, pathNode3.x, pathNode3.y)))) { int priority = (int)pathNode3.g + PathFindController.getPreferenceValueForTerrainType(location, pathNode3.x, pathNode3.y) + (Math.Abs(endPoint.X - pathNode3.x) + Math.Abs(endPoint.Y - pathNode3.y) + (((pathNode3.x == pathNode2.x && pathNode3.x == pathNode.x) || (pathNode3.y == pathNode2.y && pathNode3.y == pathNode.y)) ? -2 : 0)); if (!priorityQueue.Contains(pathNode3, priority)) { priorityQueue.Enqueue(pathNode3, priority); } } } pathNode = pathNode2; num++; if (num >= limit) { return(null); } } return(null); }
public virtual void update(GameTime time, GameLocation location, long id, bool move) { position.UpdateExtrapolation(speed + addedSpeed); currentLocation = location; faceTowardFarmerEvent.Poll(); if (yJumpOffset != 0) { yJumpVelocity -= 0.5f; yJumpOffset -= (int)yJumpVelocity; if (yJumpOffset >= 0) { yJumpOffset = 0; yJumpVelocity = 0f; if (!IsMonster && (location == null || location.Equals(Game1.currentLocation))) { checkForFootstep(); } } } if (faceTowardFarmerTimer > 0) { faceTowardFarmerTimer -= time.ElapsedGameTime.Milliseconds; if (whoToFace.Value != null) { if (!faceTowardFarmer && faceTowardFarmerTimer > 0 && Utility.tileWithinRadiusOfPlayer((int)getTileLocation().X, (int)getTileLocation().Y, faceTowardFarmerRadius, whoToFace)) { faceTowardFarmer = true; } else if (!Utility.tileWithinRadiusOfPlayer((int)getTileLocation().X, (int)getTileLocation().Y, faceTowardFarmerRadius, whoToFace) || faceTowardFarmerTimer <= 0) { faceDirection(facingDirectionBeforeSpeakingToPlayer.Value); if (faceTowardFarmerTimer <= 0) { facingDirectionBeforeSpeakingToPlayer.Value = -1; faceTowardFarmer = false; faceAwayFromFarmer.Value = false; faceTowardFarmerTimer = 0; } } } } if (forceUpdateTimer > 0) { forceUpdateTimer -= time.ElapsedGameTime.Milliseconds; } updateGlow(); updateEmote(time); if (Game1.IsMasterGame || location.currentEvent != null) { if (faceTowardFarmer && whoToFace.Value != null) { faceGeneralDirection(whoToFace.Value.getStandingPosition()); if ((bool)faceAwayFromFarmer) { faceDirection((FacingDirection + 2) % 4); } } if (controller == null && move && !freezeMotion) { updateMovement(location, time); } if (controller != null && !freezeMotion && controller.update(time)) { controller = null; } } else { updateSlaveAnimation(time); } }
// Token: 0x060002ED RID: 749 RVA: 0x0003C128 File Offset: 0x0003A328 public static Stack <Point> findPathForNPCSchedules(Point startPoint, Point endPoint, GameLocation location, int limit) { sbyte[,] directions = new sbyte[, ] { { -1, 0 }, { 1, 0 }, { 0, 1 }, { 0, -1 } }; PriorityQueue openList = new PriorityQueue(); Dictionary <PathNode, PathNode> closedList = new Dictionary <PathNode, PathNode>(); int iterations = 0; openList.Enqueue(new PathNode(startPoint.X, startPoint.Y, 0, null), Math.Abs(endPoint.X - startPoint.X) + Math.Abs(endPoint.Y - startPoint.Y)); PathNode previousNode = (PathNode)openList.Peek(); while (!openList.IsEmpty()) { PathNode currentNode = openList.Dequeue(); if (currentNode.x == endPoint.X && currentNode.y == endPoint.Y) { return(PathFindController.reconstructPath(currentNode, closedList)); } if (currentNode.x == 79) { int arg_B2_0 = currentNode.y; } if (!closedList.ContainsKey(currentNode)) { closedList.Add(currentNode, currentNode.parent); } for (int i = 0; i < 4; i++) { PathNode neighbor = new PathNode(currentNode.x + (int)directions[i, 0], currentNode.y + (int)directions[i, 1], currentNode); neighbor.g = currentNode.g + 1; if (!closedList.ContainsKey(neighbor) && ((neighbor.x == endPoint.X && neighbor.y == endPoint.Y) || (neighbor.x >= 0 && neighbor.y >= 0 && neighbor.x < location.map.Layers[0].LayerWidth && neighbor.y < location.map.Layers[0].LayerHeight && !PathFindController.isPositionImpassableForNPCSchedule(location, neighbor.x, neighbor.y)))) { int f = (int)neighbor.g + PathFindController.getPreferenceValueForTerrainType(location, neighbor.x, neighbor.y) + (Math.Abs(endPoint.X - neighbor.x) + Math.Abs(endPoint.Y - neighbor.y) + (((neighbor.x == currentNode.x && neighbor.x == previousNode.x) || (neighbor.y == currentNode.y && neighbor.y == previousNode.y)) ? -2 : 0)); if (!openList.Contains(neighbor, f)) { openList.Enqueue(neighbor, f); } } } previousNode = currentNode; iterations++; if (iterations >= limit) { return(null); } } return(null); }