Example #1
0
        public override void update(GameTime time, GameLocation location)
        {
            if (isPetted)
            {
                this.currentLocation.characters.Remove(this);
                return;
            }
            if (!isScared)
            {
                CheckScared();
            }
            if (isScared)
            {
                if (this.currentLocation.farmers.Count == 0)
                {
                    this.currentLocation.characters.Remove(this);
                    return;
                }

                this.farmerPassesThrough = true;

                Flee(time);

                if (this.FacingDirection != this.fleeFacingDirection.Value)
                {
                    this.Sprite.StopAnimation();
                    this.faceDirection(this.fleeFacingDirection.Value);
                }

                if (this.Sprite.CurrentAnimation == null)
                {
                    AnimatedSprite.endOfAnimationBehavior frameBehavior = (AnimatedSprite.endOfAnimationBehavior)(x =>
                    {
                        string stepAudio = "thudStep";

                        string str = this.currentLocation.doesTileHaveProperty((int)this.getTileLocation().X, (int)this.getTileLocation().Y, "Type", "Back");
                        if (str == "Wood")
                        {
                            stepAudio = "woodyStep";
                        }
                        else if (str == "Stone")
                        {
                            stepAudio = "stoneStep";
                        }

                        this.currentLocation.localSoundAt(stepAudio, this.getTileLocation());
                    });

                    if (this.FacingDirection == 1)
                    {
                        this.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(8, 70),
                            new FarmerSprite.AnimationFrame(9, 70, false, false, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(10, 70, false, false, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(11, 70, false, false, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(12, 70),
                            new FarmerSprite.AnimationFrame(13, 70)
                        });
                    }
                    else if (this.FacingDirection == 3)
                    {
                        this.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(8, 70, false, true, null, false),
                            new FarmerSprite.AnimationFrame(9, 70, false, true, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(10, 70, false, true, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(11, 70, false, true, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(12, 70, false, true, null, false),
                            new FarmerSprite.AnimationFrame(13, 70, false, true, null, false)
                        });
                    }
                    else if (this.FacingDirection == 0)
                    {
                        this.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(15, 70),
                            new FarmerSprite.AnimationFrame(16, 70, false, false, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(17, 70, false, false, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(18, 70, false, false, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(19, 70),
                            new FarmerSprite.AnimationFrame(20, 70)
                        });
                    }
                    else if (this.FacingDirection == 2)
                    {
                        this.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(1, 70),
                            new FarmerSprite.AnimationFrame(2, 70, false, false, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(3, 70, false, false, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(4, 70, false, false, frameBehavior, false),
                            new FarmerSprite.AnimationFrame(5, 70),
                            new FarmerSprite.AnimationFrame(6, 70)
                        });
                    }
                }

                if (this.FacingDirection == 3)
                {
                    this.drawOffset.Set(Vector2.Zero);
                }
                else
                {
                    this.drawOffset.Set(new Vector2(-16f, 0.0f));
                }

                this.flip = this.FacingDirection == 3;

                if (!this.currentLocation.isTileOnMap(this.getTileLocation()))
                {
                    this.currentLocation.characters.Remove(this);
                    this.currentLocation.playSoundAt(Sounds.LEAFRUSTLE, this.getTileLocation());
                    return;
                }

                BaseUpdate(time, location);
            }
            else
            {
                base.update(time, location);
            }
        }
Example #2
0
            private List <FarmerSprite.AnimationFrame> CreateAnimationFrames(int[] frameIndexes, AnimatedSprite.endOfAnimationBehavior frameBehavior = null)
            {
                var frames = new List <FarmerSprite.AnimationFrame>();

                for (int i = 0; i < frameIndexes.Length; ++i)
                {
                    if (i == frameIndexes.Length - 1)
                    {
                        frames.Add(new FarmerSprite.AnimationFrame(frameIndexes[i], 100, false, false, frameBehavior));
                    }
                    else
                    {
                        frames.Add(new FarmerSprite.AnimationFrame(frameIndexes[i], 100));
                    }
                }

                return(frames);
            }
        private static bool Move(Horse horse, GameTime time)
        {
            if (!_isWandering && Game1.random.NextDouble() < _config.GetWanderFrequency())
            {
                _moveDirection = (Direction)Game1.random.Next(0, 4);
                _ticksToMove   = Game1.random.Next(_config.GetWanderRange().Item1, _config.GetWanderRange().Item2);

                if (!_hasMovedToday)
                {
                    _moveDirection = Direction.Down;
                    _ticksToMove   = 60;
                    _hasMovedToday = true;
                }

                horse.faceDirection((int)_moveDirection);

                AnimatedSprite.endOfAnimationBehavior frameBehavior = x =>
                {
                    switch (horse.currentLocation.doesTileHaveProperty((int)horse.getTileLocation().X,
                                                                       (int)horse.getTileLocation().Y, "Type", "Back"))
                    {
                    case "Stone":
                        horse.currentLocation.localSoundAt("stoneStep", horse.getTileLocation());
                        break;

                    case "Wood":
                        horse.currentLocation.localSoundAt("woodyStep", horse.getTileLocation());
                        break;

                    default:
                        horse.currentLocation.localSoundAt("thudStep", horse.getTileLocation());
                        break;
                    }
                };

                if (horse.FacingDirection == 1)
                {
                    horse.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                    {
                        new FarmerSprite.AnimationFrame(8, 70),
                        new FarmerSprite.AnimationFrame(9, 70, false, false, frameBehavior),
                        new FarmerSprite.AnimationFrame(10, 70, false, false, frameBehavior),
                        new FarmerSprite.AnimationFrame(11, 70, false, false, frameBehavior),
                        new FarmerSprite.AnimationFrame(12, 70),
                        new FarmerSprite.AnimationFrame(13, 70)
                    });
                }
                else if (horse.FacingDirection == 3)
                {
                    horse.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                    {
                        new FarmerSprite.AnimationFrame(8, 70, false, true),
                        new FarmerSprite.AnimationFrame(9, 70, false, true, frameBehavior),
                        new FarmerSprite.AnimationFrame(10, 70, false, true, frameBehavior),
                        new FarmerSprite.AnimationFrame(11, 70, false, true, frameBehavior),
                        new FarmerSprite.AnimationFrame(12, 70, false, true),
                        new FarmerSprite.AnimationFrame(13, 70, false, true)
                    });
                }
                else if (horse.FacingDirection == 0)
                {
                    horse.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                    {
                        new FarmerSprite.AnimationFrame(15, 70),
                        new FarmerSprite.AnimationFrame(16, 70, false, false, frameBehavior),
                        new FarmerSprite.AnimationFrame(17, 70, false, false, frameBehavior),
                        new FarmerSprite.AnimationFrame(18, 70, false, false, frameBehavior),
                        new FarmerSprite.AnimationFrame(19, 70),
                        new FarmerSprite.AnimationFrame(20, 70)
                    });
                }
                else if (horse.FacingDirection == 2)
                {
                    horse.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                    {
                        new FarmerSprite.AnimationFrame(1, 70),
                        new FarmerSprite.AnimationFrame(2, 70, false, false, frameBehavior),
                        new FarmerSprite.AnimationFrame(3, 70, false, false, frameBehavior),
                        new FarmerSprite.AnimationFrame(4, 70, false, false, frameBehavior),
                        new FarmerSprite.AnimationFrame(5, 70),
                        new FarmerSprite.AnimationFrame(6, 70)
                    });
                }

                VerboseLog($"Moving {horse.getName()} {_moveDirection} for {_ticksToMove}");
                _isWandering = true;
            }

            if (_isWandering && _ticksToMove >= 0)
            {
                if (horse.currentLocation.isCollidingPosition(
                        horse.nextPosition(horse.getDirection()),
                        Game1.viewport,
                        false,
                        0,
                        false,
                        horse
                        ))
                {
                    VerboseLog("Bonk! Stopping wandering.");
                    _isWandering = false;
                    horse.Sprite.StopAnimation();
                    horse.faceDirection((int)_moveDirection);
                    horse.Halt();
                    _ticksToMove = 0;
                    return(true);
                }

                switch (_moveDirection)
                {
                case Direction.Up:
                    horse.SetMovingOnlyUp();
                    break;

                case Direction.Right:
                    horse.SetMovingOnlyRight();
                    break;

                case Direction.Down:
                    horse.SetMovingOnlyDown();
                    break;

                case Direction.Left:
                    horse.SetMovingOnlyLeft();
                    break;
                }

                // Are we walking off the map?
                var nextPos = horse.nextPositionPoint();
                var mapSize = horse.currentLocation.map.DisplaySize;

                if (nextPos.X <= 0 || nextPos.X >= mapSize.Width || nextPos.Y <= 0 || nextPos.Y >= mapSize.Height)
                {
                    VerboseLog("Edge Bonk! Stopped wandering.");
                    _isWandering = false;
                    horse.Sprite.StopAnimation();
                    horse.faceDirection((int)_moveDirection);
                    horse.Halt();
                    _ticksToMove = 0;
                    return(true);
                }

                horse.speed       = 1;
                horse.Sprite.loop = true;
                horse.Sprite.animateOnce(time);
                horse.tryToMoveInDirection(horse.getDirection(), false, 0, false);

                _ticksToMove--;

                if (_ticksToMove == 0)
                {
                    _isWandering = false;
                    horse.Sprite.StopAnimation();
                    horse.Halt();

                    return(true);
                }

                return(false);
            }

            return(true);
        }
Example #4
0
        public override void update(GameTime time, GameLocation location)
        {
            base.currentLocation = location;
            mutex.Update(location);
            squeezingThroughGate  = false;
            faceTowardFarmer      = false;
            faceTowardFarmerTimer = -1;
            Sprite.loop           = rider != null && !rider.hidden;
            if (rider != null && (bool)rider.hidden)
            {
                return;
            }
            if (rider != null && rider.isAnimatingMount)
            {
                rider.showNotCarrying();
            }
            if ((bool)mounting)
            {
                if (rider == null || !rider.IsLocalPlayer)
                {
                    return;
                }
                if (rider.mount != null)
                {
                    mounting.Value         = false;
                    rider.isAnimatingMount = false;
                    rider = null;
                    Halt();
                    farmerPassesThrough = false;
                    return;
                }
                if (rider.Position.X < (float)(GetBoundingBox().X + 16 - 4))
                {
                    rider.position.X += 4f;
                }
                else if (rider.Position.X > (float)(GetBoundingBox().X + 16 + 4))
                {
                    rider.position.X -= 4f;
                }
                if (rider.getStandingY() < GetBoundingBox().Y - 4)
                {
                    rider.position.Y += 4f;
                }
                else if (rider.getStandingY() > GetBoundingBox().Y + 4)
                {
                    rider.position.Y -= 4f;
                }
                if (rider.yJumpOffset >= -8 && rider.yJumpVelocity <= 0f)
                {
                    Halt();
                    Sprite.loop = true;
                    base.currentLocation.characters.Remove(this);
                    rider.mount            = this;
                    rider.freezePause      = -1;
                    mounting.Value         = false;
                    rider.isAnimatingMount = false;
                    rider.canMove          = true;
                    if (FacingDirection == 1)
                    {
                        rider.xOffset += 8f;
                    }
                }
            }
            else if ((bool)dismounting)
            {
                if (rider == null || !rider.IsLocalPlayer)
                {
                    Halt();
                    return;
                }
                if (rider.isAnimatingMount)
                {
                    rider.faceDirection(FacingDirection);
                }
                Vector2 targetPosition = new Vector2(dismountTile.X * 64f + 32f - (float)(rider.GetBoundingBox().Width / 2), dismountTile.Y * 64f + 4f);
                if (Math.Abs(rider.Position.X - targetPosition.X) > 4f)
                {
                    if (rider.Position.X < targetPosition.X)
                    {
                        rider.position.X += Math.Min(4f, targetPosition.X - rider.Position.X);
                    }
                    else if (rider.Position.X > targetPosition.X)
                    {
                        rider.position.X += Math.Max(-4f, targetPosition.X - rider.Position.X);
                    }
                }
                if (Math.Abs(rider.Position.Y - targetPosition.Y) > 4f)
                {
                    if (rider.Position.Y < targetPosition.Y)
                    {
                        rider.position.Y += Math.Min(4f, targetPosition.Y - rider.Position.Y);
                    }
                    else if (rider.Position.Y > targetPosition.Y)
                    {
                        rider.position.Y += Math.Max(-4f, targetPosition.Y - rider.Position.Y);
                    }
                }
                if (rider.yJumpOffset >= 0 && rider.yJumpVelocity <= 0f)
                {
                    rider.position.Y += 8f;
                    rider.position.X  = targetPosition.X;
                    int tries = 0;
                    while (rider.currentLocation.isCollidingPosition(rider.GetBoundingBox(), Game1.viewport, isFarmer: true, 0, glider: false, rider) && tries < 6)
                    {
                        tries++;
                        rider.position.Y -= 4f;
                    }
                    if (tries == 6)
                    {
                        rider.Position         = base.Position;
                        dismounting.Value      = false;
                        rider.isAnimatingMount = false;
                        rider.freezePause      = -1;
                        rider.canMove          = true;
                        return;
                    }
                    dismount();
                }
            }
            else if (rider == null && FacingDirection != 2 && Sprite.CurrentAnimation == null && Game1.random.NextDouble() < 0.002)
            {
                Sprite.loop = false;
                switch (FacingDirection)
                {
                case 0:
                    Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                    {
                        new FarmerSprite.AnimationFrame(25, Game1.random.Next(250, 750)),
                        new FarmerSprite.AnimationFrame(14, 10)
                    });
                    break;

                case 1:
                    Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                    {
                        new FarmerSprite.AnimationFrame(21, 100),
                        new FarmerSprite.AnimationFrame(22, 100),
                        new FarmerSprite.AnimationFrame(23, 400),
                        new FarmerSprite.AnimationFrame(24, 400),
                        new FarmerSprite.AnimationFrame(23, 400),
                        new FarmerSprite.AnimationFrame(24, 400),
                        new FarmerSprite.AnimationFrame(23, 400),
                        new FarmerSprite.AnimationFrame(24, 400),
                        new FarmerSprite.AnimationFrame(23, 400),
                        new FarmerSprite.AnimationFrame(22, 100),
                        new FarmerSprite.AnimationFrame(21, 100)
                    });
                    break;

                case 3:
                    Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                    {
                        new FarmerSprite.AnimationFrame(21, 100, secondaryArm: false, flip: true),
                        new FarmerSprite.AnimationFrame(22, 100, secondaryArm: false, flip: true),
                        new FarmerSprite.AnimationFrame(23, 100, secondaryArm: false, flip: true),
                        new FarmerSprite.AnimationFrame(24, 400, secondaryArm: false, flip: true),
                        new FarmerSprite.AnimationFrame(23, 400, secondaryArm: false, flip: true),
                        new FarmerSprite.AnimationFrame(24, 400, secondaryArm: false, flip: true),
                        new FarmerSprite.AnimationFrame(23, 400, secondaryArm: false, flip: true),
                        new FarmerSprite.AnimationFrame(24, 400, secondaryArm: false, flip: true),
                        new FarmerSprite.AnimationFrame(23, 400, secondaryArm: false, flip: true),
                        new FarmerSprite.AnimationFrame(22, 100, secondaryArm: false, flip: true),
                        new FarmerSprite.AnimationFrame(21, 100, secondaryArm: false, flip: true)
                    });
                    break;
                }
            }
            else if (rider != null)
            {
                if (FacingDirection != rider.FacingDirection || ridingAnimationDirection != FacingDirection)
                {
                    Sprite.StopAnimation();
                    faceDirection(rider.FacingDirection);
                }
                bool num = (rider.movementDirections.Any() && rider.CanMove) || rider.position.Field.IsInterpolating();
                SyncPositionToRider();
                if (num && Sprite.CurrentAnimation == null)
                {
                    AnimatedSprite.endOfAnimationBehavior mountFootstep = delegate
                    {
                        if (rider != null)
                        {
                            string a = rider.currentLocation.doesTileHaveProperty((int)rider.getTileLocation().X, (int)rider.getTileLocation().Y, "Type", "Back");
                            if (!(a == "Stone"))
                            {
                                if (a == "Wood")
                                {
                                    if (rider.ShouldHandleAnimationSound())
                                    {
                                        rider.currentLocation.localSoundAt("woodyStep", getTileLocation());
                                    }
                                    if (rider == Game1.player)
                                    {
                                        Rumble.rumble(0.1f, 50f);
                                    }
                                }
                                else
                                {
                                    if (rider.ShouldHandleAnimationSound())
                                    {
                                        rider.currentLocation.localSoundAt("thudStep", getTileLocation());
                                    }
                                    if (rider == Game1.player)
                                    {
                                        Rumble.rumble(0.3f, 50f);
                                    }
                                }
                            }
                            else
                            {
                                if (rider.ShouldHandleAnimationSound())
                                {
                                    rider.currentLocation.localSoundAt("stoneStep", getTileLocation());
                                }
                                if (rider == Game1.player)
                                {
                                    Rumble.rumble(0.1f, 50f);
                                }
                            }
                        }
                    };
                    if (FacingDirection == 1)
                    {
                        Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                        {
                            new FarmerSprite.AnimationFrame(8, 70),
                            new FarmerSprite.AnimationFrame(9, 70, secondaryArm: false, flip: false, mountFootstep),
                            new FarmerSprite.AnimationFrame(10, 70, secondaryArm: false, flip: false, mountFootstep),
                            new FarmerSprite.AnimationFrame(11, 70, secondaryArm: false, flip: false, mountFootstep),
                            new FarmerSprite.AnimationFrame(12, 70),
                            new FarmerSprite.AnimationFrame(13, 70)
                        });
                    }
                    else if (FacingDirection == 3)
                    {
                        Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                        {
                            new FarmerSprite.AnimationFrame(8, 70, secondaryArm: false, flip: true),
                            new FarmerSprite.AnimationFrame(9, 70, secondaryArm: false, flip: true, mountFootstep),
                            new FarmerSprite.AnimationFrame(10, 70, secondaryArm: false, flip: true, mountFootstep),
                            new FarmerSprite.AnimationFrame(11, 70, secondaryArm: false, flip: true, mountFootstep),
                            new FarmerSprite.AnimationFrame(12, 70, secondaryArm: false, flip: true),
                            new FarmerSprite.AnimationFrame(13, 70, secondaryArm: false, flip: true)
                        });
                    }
                    else if (FacingDirection == 0)
                    {
                        Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                        {
                            new FarmerSprite.AnimationFrame(15, 70),
                            new FarmerSprite.AnimationFrame(16, 70, secondaryArm: false, flip: false, mountFootstep),
                            new FarmerSprite.AnimationFrame(17, 70, secondaryArm: false, flip: false, mountFootstep),
                            new FarmerSprite.AnimationFrame(18, 70, secondaryArm: false, flip: false, mountFootstep),
                            new FarmerSprite.AnimationFrame(19, 70),
                            new FarmerSprite.AnimationFrame(20, 70)
                        });
                    }
                    else if (FacingDirection == 2)
                    {
                        Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                        {
                            new FarmerSprite.AnimationFrame(1, 70),
                            new FarmerSprite.AnimationFrame(2, 70, secondaryArm: false, flip: false, mountFootstep),
                            new FarmerSprite.AnimationFrame(3, 70, secondaryArm: false, flip: false, mountFootstep),
                            new FarmerSprite.AnimationFrame(4, 70, secondaryArm: false, flip: false, mountFootstep),
                            new FarmerSprite.AnimationFrame(5, 70),
                            new FarmerSprite.AnimationFrame(6, 70)
                        });
                    }
                    ridingAnimationDirection = FacingDirection;
                }
                if (!num)
                {
                    Sprite.StopAnimation();
                    faceDirection(rider.FacingDirection);
                }
            }
            if (FacingDirection == 3)
            {
                drawOffset.Set(Vector2.Zero);
            }
            else
            {
                drawOffset.Set(new Vector2(-16f, 0f));
            }
            flip = FacingDirection == 3;
            base.update(time, location);
        }