示例#1
0
        /// <summary>
        /// Removes your horse from its current location and places it next to the player
        /// </summary>
        private void callHorseOnButtonPress(object sender, EventArgsKeyPressed e)
        {
            // Do nothing
            // If riding horse
            // If player is indoors
            // If horse is already being called
            // If event up
            // If menu up
            // If keypress is not configured key ( defaults to z )
            if (Game1.player.isRidingHorse() || Game1.currentLocation.isOutdoors == false || runningHorse != null || Game1.eventUp || Game1.activeClickableMenu != null || e.KeyPressed.ToString() != ModEntry.modConfig.summonHorseKey)
            {
                return;
            }

            Horse        tempHorse     = null;
            GameLocation horseLocation = null;

            // Find horse
            foreach (var location in Game1.locations)
            {
                foreach (var npc in location.characters)
                {
                    // Only call horse if horse is in a different location
                    if (location == Game1.currentLocation)
                    {
                        //continue;
                    }

                    if (npc is Horse)
                    {
                        if (tempHorse == null)
                        {
                            tempHorse     = ( Horse )npc;
                            horseLocation = location;
                        }
                        else
                        {
                            ModEntry.Log($"There are multiple horses! Calling {tempHorse.name} from {tempHorse.currentLocation.name}");
                        }
                    }
                }
            }

            // No horse found
            if (tempHorse == null)
            {
                return;
            }

            // Do nothing if horse is close to farmer
            if (Utility.distance(tempHorse.position.X, Game1.player.position.X, tempHorse.position.Y, Game1.player.position.Y) < 600)
            {
                ModEntry.Log("Your horse is right next to you... don't be lazy, go walk up to it!");
                return;
            }

            // Change horse location
            if (Game1.currentLocation.characters.Contains(tempHorse) == false && horseLocation.characters.Remove(tempHorse))
            {
                Game1.currentLocation.characters.Add(tempHorse);
                tempHorse.currentLocation = Game1.currentLocation;
            }

            runningHorse = tempHorse;

            // Set horse start position
            int positionXToRunTo = Game1.player.getTileX() * Game1.tileSize;
            int positionYToRunTo = Game1.player.getTileY() * Game1.tileSize;

            positionToRunTo = new Vector2(positionXToRunTo, positionYToRunTo);

            //Game1.currentLocation.tile

            /*
             * int differenceBetweenPlayerAndHorse = ( Game1.player.sprite.spriteWidth - runningHorse.sprite.spriteWidth ) / 2 * Game1.pixelZoom + 6;
             * positionToRunTo = Game1.player.position;
             * positionToRunTo.X += differenceBetweenPlayerAndHorse;
             * runningHorse.position.Y = positionToRunTo.Y;
             * runningHorse.position.X = Game1.viewport.X - runningHorse.sprite.getWidth() * Game1.pixelZoom;
             */

            float boundingBoxOffset = runningHorse.position.X - runningHorse.GetBoundingBox().X;

            runningHorse.position.X = positionToRunTo.X + boundingBoxOffset;
            //runningHorse.position.X = Game1.viewport.X - runningHorse.sprite.getWidth() * Game1.pixelZoom;
            runningHorse.position.Y = positionToRunTo.Y;

            // Set horse moving right
            runningHorse.facingDirection = 1;

            // Set starting variables
            currentRunSpeed      = 30;
            speedToSlowPerRender = 1;
            runningHorse.sprite.currentAnimation = null;
            poofAnimator.position = runningHorse.position;
            poofAnimator.deathAnimation();
            runningHorse = null;
        }