Пример #1
0
        /// <summary>Summon an unused tractor to a player's current position, if any are available. If the player is a farmhand in multiplayer, only tractors in synced locations can be found by this method.</summary>
        /// <param name="player">The target player.</param>
        /// <returns>Returns whether a tractor was successfully summoned.</returns>
        private bool SummonLocalTractorTo(Farmer player)
        {
            // get player info
            if (player == null)
            {
                return(false);
            }
            GameLocation location = player.currentLocation;
            Vector2      tile     = player.getTileLocation();

            // find nearest horse in player's current location (if available)
            Horse horse = this
                          .GetTractorsIn(location, includeMounted: false)
                          .OrderBy(match => Utility.distance(tile.X, tile.Y, match.getTileX(), match.getTileY()))
                          .FirstOrDefault();

            // else get horse from any location
            if (horse == null)
            {
                horse = this
                        .GetLocations()
                        .SelectMany(loc => this.GetTractorsIn(loc, includeMounted: false))
                        .FirstOrDefault();
            }

            // warp to player
            if (horse != null)
            {
                TractorManager.SetLocation(horse, location, tile);
                return(true);
            }
            return(false);
        }
Пример #2
0
        /// <summary>Spawn a new tractor.</summary>
        /// <param name="location">The location in which to spawn a tractor.</param>
        /// <param name="tileX">The tile X position at which to spawn it.</param>
        /// <param name="tileY">The tile Y position at which to spawn it.</param>
        private TractorManager SpawnTractor(BuildableGameLocation location, int tileX, int tileY)
        {
            TractorManager tractor = new TractorManager(tileX, tileY, this.Config, this.Attachments, this.GetTexture("tractor"), this.Helper.Translation, this.Helper.Reflection);

            tractor.SetLocation(location, new Vector2(tileX, tileY));
            tractor.SetPixelPosition(new Vector2(tractor.Current.Position.X + 20, tractor.Current.Position.Y));
            return(tractor);
        }
Пример #3
0
        /// <summary>Summon an unused tractor to a player's current position, if any are available. If the player is a farmhand in multiplayer, only tractors in synced locations can be found by this method.</summary>
        /// <param name="player">The target player.</param>
        /// <returns>Returns whether a tractor was successfully summoned.</returns>
        private bool SummonLocalTractorTo(Farmer player)
        {
            // get player info
            if (player == null)
            {
                return(false);
            }
            GameLocation location = player.currentLocation;
            Vector2      tile     = player.getTileLocation();

            // find nearest tractor in player's current location (if available), else any location
            Horse tractor = this
                            .GetTractorsIn(location, includeMounted: false)
                            .OrderBy(match => Utility.distance(tile.X, tile.Y, match.getTileX(), match.getTileY()))
                            .FirstOrDefault();

            if (tractor == null)
            {
                tractor = this
                          .GetLocations()
                          .SelectMany(loc => this.GetTractorsIn(loc, includeMounted: false))
                          .FirstOrDefault();
            }

            // create a tractor if needed
            if (tractor == null && this.Config.CanSummonWithoutGarage && Context.IsMainPlayer)
            {
                Guid id = Guid.NewGuid();
                tractor = new Horse(id, 0, 0)
                {
                    Name = TractorManager.GetTractorName(id)
                };
                this.ApplyTextures(tractor);
            }

            // warp to player
            if (tractor != null)
            {
                TractorManager.SetLocation(tractor, location, tile);
                return(true);
            }
            return(false);
        }
Пример #4
0
        /// <summary>The event called after the location list changes.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnLocationListChanged(object sender, LocationListChangedEventArgs e)
        {
            if (!this.IsEnabled)
            {
                return;
            }

            // rescue lost tractors
            if (Context.IsMainPlayer)
            {
                foreach (GameLocation location in e.Removed)
                {
                    foreach (Horse tractor in this.GetTractorsIn(location).ToArray())
                    {
                        TractorManager.SetLocation(tractor, Game1.getFarm(), tractor.DefaultPosition);
                    }
                }
            }
        }
Пример #5
0
        /****
        ** Helper methods
        ****/
        /// <summary>Summon an unused tractor to the player's current position, if any are available.</summary>
        private void SummonTractor()
        {
            // find nearest horse in player's current location (if available)
            Horse horse = this
                          .GetTractorsIn(Game1.currentLocation, includeMounted: false)
                          .OrderBy(match => Utility.distance(Game1.player.getTileX(), Game1.player.getTileY(), match.getTileX(), match.getTileY()))
                          .FirstOrDefault();

            // else get horse from any location
            if (horse == null)
            {
                horse = this
                        .GetLocations()
                        .SelectMany(location => this.GetTractorsIn(location, includeMounted: false))
                        .FirstOrDefault();
            }

            // warp to player
            if (horse != null)
            {
                TractorManager.SetLocation(horse, Game1.currentLocation, Game1.player.getTileLocation());
            }
        }