/// <summary>The event called after the list of NPCs in a location changes.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void OnNpcListChanged(object sender, NpcListChangedEventArgs e) { if (!this.IsEnabled) { return; } // workaround for mines not spawning a ladder on monster levels if (e.Location is MineShaft mine && e.IsCurrentLocation) { if (mine.mustKillAllMonstersToAdvance() && mine.characters.All(p => p is Horse)) { IReflectedField <bool> hasLadder = this.Helper.Reflection.GetField <bool>(mine, "ladderHasSpawned"); if (!hasLadder.GetValue()) { mine.createLadderAt(mine.mineEntrancePosition(Game1.player)); hasLadder.SetValue(true); } } } // workaround for instantly-built tractors spawning a horse if (Context.IsMainPlayer && e.Location is BuildableGameLocation buildableLocation) { Horse[] horses = e.Added.OfType <Horse>().ToArray(); if (horses.Any()) { HashSet <Guid> tractorIDs = new HashSet <Guid>(this.GetGaragesIn(buildableLocation).Select(p => p.HorseId)); foreach (Horse horse in horses) { if (tractorIDs.Contains(horse.HorseId) && !TractorManager.IsTractor(horse)) { horse.Name = TractorManager.GetTractorName(horse.HorseId); } } } } }
/// <summary>The event called after the list of NPCs in a location changes.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void OnNpcListChanged(object sender, NpcListChangedEventArgs e) { if (!this.IsEnabled) { return; } // workaround for instantly-built tractors spawning a horse if (Context.IsMainPlayer && e.Location is BuildableGameLocation buildableLocation) { Horse[] horses = e.Added.OfType <Horse>().ToArray(); if (horses.Any()) { HashSet <Guid> tractorIDs = new HashSet <Guid>(this.GetGaragesIn(buildableLocation).Select(p => p.HorseId)); foreach (Horse horse in horses) { if (tractorIDs.Contains(horse.HorseId) && !TractorManager.IsTractor(horse)) { horse.Name = TractorManager.GetTractorName(horse.HorseId); } } } } }
/// <summary>Get whether a horse is a tractor.</summary> /// <param name="horse">The horse to check.</param> private bool IsTractor(Horse horse) { return(TractorManager.IsTractor(horse)); }