Advertisement
minervamaga

Untitled

Sep 20th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.03 KB | None | 0 0
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. using StardewModdingAPI;
  4. using StardewModdingAPI.Events;
  5. using StardewModdingAPI.Utilities;
  6. using StardewValley;
  7. using StardewValley.Monsters;
  8. using System.Linq;
  9.  
  10. namespace NoMineFlyersRedux
  11. {
  12.     /// <summary>The mod entry point.</summary>
  13.     public class ModEntry : Mod
  14.     {
  15.         /*********
  16.         ** Public methods
  17.         *********/
  18.         /// <summary>The mod entry point, called after the mod is first loaded.</summary>
  19.         /// <param name="helper">Provides simplified APIs for writing mods.</param>
  20.         public override void Entry(IModHelper helper)
  21.         {
  22.             //Checks list of locations when moving between them.  Gives that event a nickname for later
  23.             helper.Events.World.LocationListChanged += this.OnLocationChanged;
  24.             //Checks list of NPCs when updated.  Gives that event a nickname too
  25.             helper.Events.World.NpcListChanged += this.OnNpcListChanged;
  26.         }
  27.  
  28.  
  29.         /*********
  30.         ** Private methods
  31.         *********/
  32.         /// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
  33.         /// <param name="sender">The event sender.</param>
  34.         /// <param name="e">The event data.</param>
  35.         private void RemoveIfApplicable(GameLocation location, Monster monster)
  36.             //We're gonna kill the bugs
  37.             //looks at the location in GameLocations and the monster in Monsters
  38.         {
  39.             if (monster is Bug)
  40.                 //If our monster is the Bug type
  41.             location.characters.Remove(monster);
  42.                 //Kill it!
  43.         }
  44.  
  45.         private void OnLocationChanged(object sender, LocationListChangedEventArgs e)
  46.         {
  47.             // ignore if player hasn't loaded a save yet
  48.             if (!Context.IsWorldReady)
  49.                 return;
  50.            
  51.             //Checks each game location as it's added to the list
  52.             foreach (GameLocation location in e.Added)
  53.                 //Then checks each monter in the list and adds them to a read-only list; prevents crashes when removing characters
  54.                 foreach (Monster monster in location.characters.OfType<Monster>().ToArray())
  55.                 {
  56.                     //executes the RemoveIfApplicable to the specified location and monster
  57.                     this.RemoveIfApplicable(location, monster);
  58.                 }
  59.  
  60.             // Log to console when it does the thing
  61.             //this.Monitor.Log($"Flyers removed!", LogLevel.Trace);
  62.             this.Monitor.Log($"Flyers removed!");
  63.         }
  64.  
  65.         private void OnNpcListChanged(object sender, NpcListChangedEventArgs e)
  66.             //Here's where we check the NPC list and use the SMAPI event
  67.         {
  68.             foreach (Monster monster in e.Added)
  69.                 //Every monster in the Monster group that is added gets checked
  70.                 this.RemoveIfApplicable(e.Location, monster);
  71.                 //Do the thing if it matches our specified monster
  72.         }
  73.  
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement