public void UpdatePathToFarmer() { isNearFarmer = (getTileX() - activeFarmer.getTileX()) * (getTileX() - activeFarmer.getTileX()) + (getTileY() - activeFarmer.getTileY()) * (getTileY() - activeFarmer.getTileY()) < proximity * proximity; if (isNearFarmer || currentLocation != activeFarmer.currentLocation) { return; } if (prevFarmerPos == activeFarmer.getTileLocation()) { return; } prevFarmerPos = activeFarmer.getTileLocation(); pathingIndex = 0; Vector2 tile = activeFarmer.getTileLocation(); // Get nearest tile adjacent to farmer if (activeFarmer.getTileX() < getTileX()) { if (!currentLocation.isCollidingPosition(activeFarmer.nextPosition(3), Game1.viewport, false, 0, false, this)) { tile = new Vector2(activeFarmer.nextPosition(3).X / Game1.tileSize, activeFarmer.nextPosition(3).Y / Game1.tileSize); } } else { if (!currentLocation.isCollidingPosition(activeFarmer.nextPosition(1), Game1.viewport, false, 0, false, this)) { tile = new Vector2(activeFarmer.nextPosition(1).X / Game1.tileSize, activeFarmer.nextPosition(1).Y / Game1.tileSize); } } if (activeFarmer.getTileY() < getTileY()) { if (!currentLocation.isCollidingPosition(activeFarmer.nextPosition(2), Game1.viewport, false, 0, false, this)) { tile = new Vector2(activeFarmer.nextPosition(2).X / Game1.tileSize, activeFarmer.nextPosition(2).Y / Game1.tileSize); } } else { if (!currentLocation.isCollidingPosition(activeFarmer.nextPosition(0), Game1.viewport, false, 0, false, this)) { tile = new Vector2(activeFarmer.nextPosition(0).X / Game1.tileSize, activeFarmer.nextPosition(0).Y / Game1.tileSize); } } start = getStandingPosition(); pathToFarmer = ModUtil.GetPath(currentLocation, new Vector2((int)Math.Ceiling(Position.X / Game1.tileSize), (int)Math.Ceiling(Position.Y / Game1.tileSize)), new Vector2((int)Math.Ceiling(activeFarmer.Position.X / Game1.tileSize), (int)Math.Ceiling(activeFarmer.Position.Y / Game1.tileSize)), this); }
public override void update(GameTime time, GameLocation location) { base.update(time, location); if (!isNearFarmer) { return; } if (base.currentLocation == null) { base.currentLocation = location; } if (!Game1.eventUp && !Game1.IsClient) { if (sprintTimer > 0) { Sprite.loop = true; sprintTimer -= time.ElapsedGameTime.Milliseconds; base.speed = 6; tryToMoveInDirection(base.FacingDirection, false, -1, false); if (sprintTimer <= 0) { Sprite.CurrentAnimation = null; Halt(); faceDirection(base.FacingDirection); base.speed = 2; base.CurrentBehavior = 0; } } else { if (Game1.timeOfDay > 2000 && Sprite.CurrentAnimation == null && xVelocity == 0f && yVelocity == 0f) { base.CurrentBehavior = 1; } if (commandBehavior != null) { setCommandBehavior(); } switch (base.CurrentBehavior) { case 1: if (Game1.timeOfDay < 2000 && Game1.random.NextDouble() < 0.001) { base.CurrentBehavior = 0; } else if (Game1.random.NextDouble() < 0.002) { doEmote(24, true); } return; case 2: if (Sprite.currentFrame != 18 && Sprite.CurrentAnimation == null) { base.CurrentBehavior = 2; } else if (Sprite.currentFrame == 18 && Game1.random.NextDouble() < 0.01) { switch (Game1.random.Next(4)) { case 0: base.CurrentBehavior = 0; Halt(); faceDirection(2); Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame> { new FarmerSprite.AnimationFrame(17, 200), new FarmerSprite.AnimationFrame(16, 200), new FarmerSprite.AnimationFrame(0, 200) }); Sprite.loop = false; break; case 1: { List <FarmerSprite.AnimationFrame> pant = new List <FarmerSprite.AnimationFrame> { new FarmerSprite.AnimationFrame(18, 200, false, false, pantSound, false), new FarmerSprite.AnimationFrame(19, 200) }; int pants = Game1.random.Next(7, 20); for (int i = 0; i < pants; i++) { pant.Add(new FarmerSprite.AnimationFrame(18, 200, false, false, pantSound, false)); pant.Add(new FarmerSprite.AnimationFrame(19, 200)); } Sprite.setCurrentAnimation(pant); break; } case 2: case 3: Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame> { new FarmerSprite.AnimationFrame(27, (Game1.random.NextDouble() < 0.3) ? 500 : Game1.random.Next(2000, 15000)), new FarmerSprite.AnimationFrame(18, 1, false, false, base.hold, false) }); Sprite.loop = false; break; } } break; case 50: if (commandBehavior == "speak") { if (Utility.isOnScreen(getTileLocationPoint(), 640, base.currentLocation)) { Game1.playSound("dog_bark"); shake(500); } Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame> { new FarmerSprite.AnimationFrame(26, 500, false, facingDirection == 3, null, false), new FarmerSprite.AnimationFrame(23, 1, false, facingDirection == 3, base.hold, false), }); } else if (withinPlayerThreshold(2)) { if (!wagging) { wag(base.FacingDirection == 3); } } // Sit else if (Sprite.currentFrame != 23 && Sprite.CurrentAnimation == null) { Sprite.currentFrame = 23; } else if (Sprite.currentFrame == 23 && Game1.random.NextDouble() < 0.01) { bool localFlip = base.FacingDirection == 3; switch (Game1.random.Next(7)) { // Pant case 0: base.CurrentBehavior = 0; Halt(); faceDirection((!localFlip) ? 1 : 3); Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame> { new FarmerSprite.AnimationFrame(23, 100, false, localFlip, null, false), new FarmerSprite.AnimationFrame(22, 100, false, localFlip, null, false), new FarmerSprite.AnimationFrame(21, 100, false, localFlip, null, false), new FarmerSprite.AnimationFrame(20, 100, false, localFlip, base.hold, false) }); Sprite.loop = false; break; // Bark case 1: if (Utility.isOnScreen(getTileLocationPoint(), 640, base.currentLocation)) { Game1.playSound("dog_bark"); shake(500); } Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame> { new FarmerSprite.AnimationFrame(26, 500, false, localFlip, null, false), new FarmerSprite.AnimationFrame(23, 1, false, localFlip, base.hold, false) }); break; case 2: wag(localFlip); break; case 3: case 4: Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame> { new FarmerSprite.AnimationFrame(23, Game1.random.Next(2000, 6000), false, localFlip, null, false), new FarmerSprite.AnimationFrame(23, 1, false, localFlip, base.hold, false) }); break; default: { Sprite.loop = false; List <FarmerSprite.AnimationFrame> panting = new List <FarmerSprite.AnimationFrame> { new FarmerSprite.AnimationFrame(24, 200, false, localFlip, pantSound, false), new FarmerSprite.AnimationFrame(25, 200, false, localFlip, null, false) }; int pantings = Game1.random.Next(5, 15); for (int j = 0; j < pantings; j++) { panting.Add(new FarmerSprite.AnimationFrame(24, 200, false, localFlip, pantSound, false)); panting.Add(new FarmerSprite.AnimationFrame(25, 200, false, localFlip, null, false)); } Sprite.setCurrentAnimation(panting); break; } } } break; case 0: if (Sprite.CurrentAnimation == null && Game1.random.NextDouble() < 0.01) { switch (Game1.random.Next(7 + ((base.currentLocation is Farm) ? 1 : 0))) { case 0: case 1: case 2: case 3: base.CurrentBehavior = 0; break; case 4: case 5: switch (base.FacingDirection) { case 2: Halt(); faceDirection(2); Sprite.loop = false; base.CurrentBehavior = 2; break; case 0: case 1: case 3: Halt(); if (base.FacingDirection == 0) { base.FacingDirection = ((!(Game1.random.NextDouble() < 0.5)) ? 1 : 3); } faceDirection(base.FacingDirection); Sprite.loop = false; base.CurrentBehavior = 50; break; } break; case 6: case 7: base.CurrentBehavior = 51; break; } } break; } if (Sprite.CurrentAnimation != null) { if (commandBehaviorTimer == 0) { resetCurrentBehavior(); commandBehaviorTimer = -1; base.CurrentBehavior = ModUtil.PickRandom(new int[] { 0, 50 }); } commandBehavior = null; Sprite.loop = false; } else { wagging = false; } if (Game1.IsMasterGame && Sprite.CurrentAnimation == null) { MovePosition(time, Game1.viewport, location); } } } }