context: using System;
  using Microsoft.Xna.Framework;
  using System.Linq;
  using CheezeMod;
  using Terraria;
  using Terraria.ID;
  using Terraria.ModLoader;
  
  namespace CheezeMod.NPCs
  {
      public class CheezeGlobalNPC : GlobalNPC
      {
          public override bool InstancePerEntity // To Allow Non-Instanced and Non-Static Variables
          {
              get
              {
                  return true;
              }
          }
  
          public bool radiation = false;
          public bool extremeRadiation = false;
          public bool downfall = false;
          public bool angelsBane = false;
          public bool sellFlare = false;
  
  
          // ====== // Custom Functions \\ ====== \\
          #region CustomFunctions
          private static int FlyffMax()
          {
              if (Main.expertMode) return 4 + Main.rand.Next(4);
              else return 3 + Main.rand.Next(2);
          }
          private static bool FlyffChance(int drawTimes)
          {
              if(Main.expertMode) return Main.rand.Next(8) + drawTimes <= 2;
              else return Main.rand.Next(5) + drawTimes <= 1;
          }
  
          #endregion
  
          // ====== // Override Functions \\ ====== \\
          #region MonsterEffects
  
          public override void SetupShop(int type, Chest shop, ref int nextSlot)
          {
              if (type == NPCID.Merchant && CheezePlayer.sellFlare)
              {
                  shop.item[nextSlot].SetDefaults(ItemID.Flare);
                  nextSlot++;
                  shop.item[nextSlot].SetDefaults(ItemID.BlueFlare);
                  nextSlot++;
              }
              if(type == NPCID.ArmsDealer)
              {
                  shop.item[nextSlot].SetDefaults(mod.ItemType("Rocket0"));
                  nextSlot++;
              }
              base.SetupShop(type, shop, ref nextSlot);
          }
          public override void ResetEffects(NPC npc)
          {
              this.radiation = false;
              this.extremeRadiation = false;
              this.downfall = false;
              this.angelsBane = false;
              this.sellFlare = false;
          }
  
          public override void DrawEffects(NPC npc, ref Color drawColor)
          {
              if (downfall == true)
              {
                  if (npc.boss == false && npc.noTileCollide == false)
                  {
                      npc.noGravity = false;
                      npc.velocity.Y += 2;
                      npc.velocity.Y *= 0.85f;
                      drawColor.R /= 2;
                      drawColor.G /= 2;
                  }
              }
              if (angelsBane == true)
              {
                  if (npc.life > 1000)
                  {
                      if (Main.rand.Next(3) == 0)
                      {
                          Dust.NewDust(npc.position, npc.width, npc.height, mod.DustType("WhiteLightCircle"), npc.velocity.X * 0.3f, npc.velocity.Y * 0.3f);
                          drawColor.B /= 2;
                      }
                  }
                  if (Main.rand.Next(3) == 0)
                  {
                      Dust.NewDust(npc.position, npc.width, npc.height, mod.DustType("YellowLight"), npc.velocity.X * 0.3f, npc.velocity.Y * 0.3f);
                      drawColor.B /= 2;
                  }
              }
  
              if (radiation)
              {
                  //if (Main.rand.Next(3) == 0)
                  // {
                  //    Dust.NewDust(player.position, player.width, player.height, DustID.AncientLight, player.velocity.X * 0.3f, player.velocity.Y * 0.3f);
                  // }
                  drawColor.G *= 2;
                  drawColor.B /= 2;
                  Dust.NewDust(npc.position, npc.width, npc.height, mod.DustType("Radiation"), npc.velocity.X * 0.3f, npc.velocity.Y * 0.3f);
              }
              if (extremeRadiation)
              {
                  drawColor.R /= 2;
                  drawColor.G *= 3;
                  drawColor.B /= 2;
                  Dust.NewDust(npc.position, npc.width, npc.height, mod.DustType("ExtremeRadiation"), npc.velocity.X * 0.3f, npc.velocity.Y * 0.3f);
              }
          }
          public override void UpdateLifeRegen(NPC npc, ref int damage)
          {
              if (angelsBane == true)
              {
                  if (npc.life > 1000)
                  {
                      npc.lifeRegen -= 100;
                      damage = 10 + Main.rand.Next(10);
                      npc.lifeRegenExpectedLossPerSecond = 100;
                  }
                  else
                  {
                      npc.lifeRegen -= 50;
                      damage = 5+Main.rand.Next(5);
                      npc.lifeRegenExpectedLossPerSecond = 50;
                  }
  
              }
              if(radiation)
              {
                  npc.lifeRegen -= 30;
                  if (damage < 3)
                  {
                      damage = 3;
                  }
                  npc.defense -= 5;
                  npc.lifeRegenExpectedLossPerSecond = 30;
              }
              if (extremeRadiation)
              {
                  npc.lifeRegen -= 120;
                  if(damage<12)
                  {
                      damage = 12;
                  }
                  npc.defense -= 10;
                  npc.lifeRegenExpectedLossPerSecond = 120;
              }
          }
          #endregion
          #region MonsterLoot
          // == Monster Drops == \\
          public override void NPCLoot(NPC npc)
          {
              // Biomes //
              #region Biomes
              // Granite
  
              if (npc.type == NPCID.GraniteGolem || npc.type == 483) // 483 is the ID of Granite Elemental.
              { // Granite
  
                  for (int i = 0; i <= 5; i++) // 6 times.
                  {
                      if (Main.rand.Next(5) == 0) // 20% chance .
                      {
                          Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("GraniteShard"), 1);
                      }
                  }
              }
  
              // Ice
  
              if (npc.type == NPCID.UndeadViking)
              {
                  if (Main.rand.NextFloat(1f) > 0.95f)
                  {
                      Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("VikingHammerHead"), 1);
                  }
                  if (Main.rand.NextFloat(1f) > 0.95f)
                  {
                      Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("VikingAxeHead"), 1);
                  }
              }
              // Marble
  
              if (npc.type == NPCID.Medusa || npc.type == NPCID.GreekSkeleton)
              {
                  for (int i = 0; i <= 5; i++) // 6 times.
                  {
                      if (Main.rand.Next(5) == 0) // 25% chance.
                      {
                          Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("RelicFragment"), 1);
                      }
                  }
              }
  
              //Meteor
  
              if (npc.type == NPCID.MeteorHead)
              {
                  if (Main.rand.Next(5) == 0) // 20% chance.
                  {
                      Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("MeteoriteBolt"), Main.rand.Next(3) + 1);
                  }
              }
  
              //Underworld
  
              if (npc.type == 39) // Bone Serpent
              {
                  if (Main.rand.Next(100) == 0) // 1% chance.
                  {
                      Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 220, 1);
                  }
  
gt:                 if (Main.rand.Next(100) == 0) // 1% chance.