Guest User

Untitled

a guest
May 27th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 67.04 KB | None | 0 0
  1. using LitJson;
  2. using Microsoft.Xna.Framework;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using Terraria;
  7.  
  8. namespace TAPI
  9. {
  10. public class LootRule
  11. {
  12. private static readonly int
  13. VICINITY_W = Main.maxScreenW,
  14. VICINITY_H = Main.maxScreenH;
  15.  
  16. public static List<Func<NPC, bool>> filters = new List<Func<NPC,bool>>(), bfilters = new List<Func<NPC,bool>>();
  17. public static List<LootRule> globalRules = new List<LootRule>(), bglobalRules = new List<LootRule>();
  18. public static IDictionary<int, List<LootRule>> rulesType = new WrapperDictionary<int, List<LootRule>>(), brulesType = new WrapperDictionary<int, List<LootRule>>();
  19. public static IDictionary<string, List<LootRule>> rulesName = new WrapperDictionary<string, List<LootRule>>(), brulesName = new WrapperDictionary<string, List<LootRule>>();
  20.  
  21. public static IDictionary<string, Func<NPC, bool>> jsonRules = new WrapperDictionary<string, Func<NPC, bool>>();
  22.  
  23. public static bool modifiedLists = false;
  24. public static List<LootRule> modifiedRules = new List<LootRule>();
  25. public static bool settingUp = false;
  26. public static Func<NPC, float> luckHandler = null, bluckHandler = null;
  27.  
  28. public static Func<NPC, bool>
  29. ruleBloodMoon, ruleHardmode, ruleHalloween, ruleChristmas,
  30. rulePumpkinMoon, ruleFrostMoon,
  31. ruleHostile, ruleHasValue,
  32. ruleUnderground,
  33. rulePlayerCorruption, rulePlayerCrimson, rulePlayerEvil, rulePlayerHallow, rulePlayerJungle, rulePlayerSnow, rulePlayerDungeon;
  34.  
  35. public static readonly Func<NPC, float>
  36. LuckHandlerClosestPlayer = npc => npc == null ? 1f : (Main.netMode == 0 ? Main.localPlayer : Main.player[Player.FindClosest(npc.position, npc.width, npc.height)]).lootLuck,
  37. LuckHandlerMaxVicinity = (npc) =>
  38. {
  39. if (npc == null)
  40. return 1f;
  41. List<Player> vicinity = InVicinity(new Rectangle((int)(npc.Center.X - VICINITY_W / 2), (int)(npc.Center.Y - VICINITY_H / 2), VICINITY_W, VICINITY_H));
  42. float maxLuck = 1f;
  43. foreach (Player p in vicinity)
  44. if (p.lootLuck > maxLuck)
  45. maxLuck = p.lootLuck;
  46. return maxLuck;
  47. },
  48. LuckHandlerModVicinity = (npc) =>
  49. {
  50. if (npc == null)
  51. return 1f;
  52. List<Player> vicinity = InVicinity(new Rectangle((int)(npc.Center.X - VICINITY_W / 2), (int)(npc.Center.Y - VICINITY_H / 2), VICINITY_W, VICINITY_H));
  53. float maxLuck = 1f;
  54. foreach (Player p in vicinity)
  55. maxLuck *= p.lootLuck;
  56. return maxLuck;
  57. };
  58.  
  59. private static List<Player> InVicinity(Rectangle rect)
  60. {
  61. List<Player> list = new List<Player>();
  62. Vector2 rcenter = rect.Center();
  63. foreach (Player p in Main.player)
  64. {
  65. if (!p.active) continue;
  66. if (p.ghost) continue;
  67.  
  68. Vector2 pcenter = p.Center;
  69. if (pcenter.X >= rcenter.X)
  70. {
  71. if ((p.position.X + p.width) - (rect.X + rect.Width) <= VICINITY_W)
  72. {
  73. if (pcenter.Y >= rcenter.Y)
  74. {
  75. if ((p.position.Y + p.height) - (rect.Y + rect.Height) <= VICINITY_H)
  76. list.Add(p);
  77. }
  78. else
  79. {
  80. if (rect.Y - p.position.Y <= VICINITY_H)
  81. list.Add(p);
  82. }
  83. }
  84. }
  85. else
  86. {
  87. if (rect.X - p.position.X <= VICINITY_W)
  88. {
  89. if (pcenter.Y >= rcenter.Y)
  90. {
  91. if ((p.position.Y + p.height) - (rect.Y + rect.Height) <= VICINITY_H)
  92. list.Add(p);
  93. }
  94. else
  95. {
  96. if (rect.Y - p.position.Y <= VICINITY_H)
  97. list.Add(p);
  98. }
  99. }
  100. }
  101. }
  102. return list;
  103. }
  104.  
  105. public static Func<NPC, bool> RuleClosestPlayer(Func<NPC, Player, bool> rule)
  106. {
  107. return npc => rule(npc, Main.player[Player.FindClosest(npc.position, npc.width, npc.height)]);
  108. }
  109. public static Func<NPC, bool> RuleOneIn(int max)
  110. {
  111. return npc => Main.rand.OneIn(max);
  112. }
  113. public static Func<NPC, bool> RuleValueLimit(int max)
  114. {
  115. return RuleValueLimit(1, max);
  116. }
  117. public static Func<NPC, bool> RuleValueLimit(int min, int max)
  118. {
  119. return npc => npc.value >= min && npc.value <= max;
  120. }
  121.  
  122. public static void FullBackup()
  123. {
  124. bluckHandler = luckHandler;
  125. bfilters.Clear();
  126. bfilters.AddRange(filters);
  127.  
  128. bglobalRules.Clear();
  129. foreach (LootRule rule in globalRules)
  130. {
  131. rule.Backup();
  132. bglobalRules.Add(rule.copy);
  133. }
  134.  
  135. brulesType.Clear();
  136. foreach (KeyValuePair<int, List<LootRule>> kvp in rulesType)
  137. {
  138. List<LootRule> list = new List<LootRule>();
  139. foreach (LootRule rule in kvp.Value)
  140. {
  141. rule.Backup();
  142. list.Add(rule.copy);
  143. }
  144. brulesType[kvp.Key] = list;
  145. }
  146.  
  147. brulesName.Clear();
  148. foreach (KeyValuePair<string, List<LootRule>> kvp in rulesName)
  149. {
  150. List<LootRule> list = new List<LootRule>();
  151. foreach (LootRule rule in kvp.Value)
  152. {
  153. rule.Backup();
  154. list.Add(rule.copy);
  155. }
  156. brulesName[kvp.Key] = list;
  157. }
  158. }
  159. public static void Restore()
  160. {
  161. luckHandler = bluckHandler;
  162.  
  163. if (modifiedLists)
  164. {
  165. modifiedLists = false;
  166. filters.Clear();
  167. filters.AddRange(bfilters);
  168.  
  169. globalRules.Clear();
  170. foreach (LootRule rule in bglobalRules)
  171. globalRules.Add(rule.copy);
  172.  
  173. rulesType.Clear();
  174. foreach (KeyValuePair<int, List<LootRule>> kvp in brulesType)
  175. {
  176. List<LootRule> list = new List<LootRule>();
  177. foreach (LootRule rule in kvp.Value)
  178. list.Add(rule.copy);
  179. rulesType[kvp.Key] = list;
  180. }
  181.  
  182. rulesName.Clear();
  183. foreach (KeyValuePair<string, List<LootRule>> kvp in brulesName)
  184. {
  185. List<LootRule> list = new List<LootRule>();
  186. foreach (LootRule rule in kvp.Value)
  187. list.Add(rule.copy);
  188. rulesName[kvp.Key] = list;
  189. }
  190. }
  191.  
  192. foreach (LootRule rule in modifiedRules)
  193. rule.copy.CopyInto(rule);
  194. modifiedRules.Clear();
  195. }
  196.  
  197. public static void RunHooks()
  198. {
  199. try
  200. {
  201. foreach (Tuple<string, JsonData> tuple in Mods.lootRules)
  202. {
  203. NPC npc = tuple.Item1 == null ? null : NPCDef.byName[tuple.Item1];
  204. foreach (JsonData j in tuple.Item2)
  205. {
  206. LootRule rule = new LootRule();
  207. rule.ReadFrom(j, npc);
  208. if (npc == null)
  209. globalRules.Add(rule);
  210. else
  211. AddForName(npc.name, rule);
  212. }
  213. }
  214. }
  215. catch (Exception e)
  216. {
  217. ErrorHandling.Handle(e);
  218. }
  219.  
  220. foreach (KeyValuePair<string, NPC> kvp in NPCDef.byName)
  221. {
  222. NPC n = kvp.Value;
  223. if (n.def.modNPCTemplate != null)
  224. n.def.modNPCTemplate.SetupLootRules(n);
  225. }
  226.  
  227. foreach (Mod mod in Mods.mods)
  228. {
  229. if (!mod.Loaded) continue;
  230. foreach (ModNPC modnpc in mod.modBase.modNPCTemplates)
  231. modnpc.SetupLootRules(null);
  232. }
  233. }
  234.  
  235. public static void Setup()
  236. {
  237. Clear();
  238. Fill();
  239. }
  240.  
  241. public static void Clear()
  242. {
  243. filters.Clear(); bfilters.Clear();
  244. globalRules.Clear(); bglobalRules.Clear();
  245. rulesType.Clear(); brulesType.Clear();
  246. rulesName.Clear(); brulesName.Clear();
  247. modifiedLists = false;
  248. modifiedRules.Clear();
  249. jsonRules.Clear();
  250. }
  251.  
  252. public static void Fill()
  253. {
  254. settingUp = true;
  255.  
  256. #region base stuff
  257. jsonRules["BloodMoon"] = ruleBloodMoon = npc => Main.bloodMoon;
  258. jsonRules["Hardmode"] = ruleHardmode = npc => Main.hardMode;
  259. jsonRules["Halloween"] = ruleHalloween = npc => Main.halloween;
  260. jsonRules["Christmas"] = ruleChristmas = npc => Main.xMas;
  261.  
  262. jsonRules["PumpkinMoon"] = rulePumpkinMoon = npc => Main.pumpkinMoon;
  263. jsonRules["FrostMoon"] = ruleFrostMoon = npc => Main.snowMoon;
  264.  
  265. jsonRules["Hostile"] = ruleHostile = npc => npc.lifeMax > 1 && npc.damage > 0 && !npc.friendly;
  266. jsonRules["HasValue"] = ruleHasValue = npc => npc.value > 0;
  267.  
  268. jsonRules["Underground"] = ruleUnderground = npc => npc.position.Y > Main.rockLayer * 16.0;
  269.  
  270. jsonRules["BiomeCorruption"] = rulePlayerCorruption = RuleClosestPlayer((npc, player) => player.zoneEvil);
  271. jsonRules["BiomeCrimson"] = rulePlayerCrimson = RuleClosestPlayer((npc, player) => player.zoneBlood);
  272. jsonRules["BiomeEvil"] = rulePlayerEvil = RuleClosestPlayer((npc, player) => player.zoneEvil || player.zoneBlood);
  273. jsonRules["BiomeHallow"] = rulePlayerHallow = RuleClosestPlayer((npc, player) => player.zoneHoly);
  274. jsonRules["BiomeJungle"] = rulePlayerJungle = RuleClosestPlayer((npc, player) => player.zoneJungle);
  275. jsonRules["BiomeSnow"] = rulePlayerSnow = RuleClosestPlayer((npc, player) => player.zoneSnow);
  276. jsonRules["BiomeDungeon"] = rulePlayerDungeon = RuleClosestPlayer((npc, player) => player.zoneDungeon);
  277.  
  278. Dictionary<string, Func<NPC, bool>> rev = new Dictionary<string,Func<NPC,bool>>();
  279. foreach (KeyValuePair<string, Func<NPC, bool>> kvp in jsonRules)
  280. rev["!" + kvp.Key] = npc => !kvp.Value(npc);
  281. foreach (KeyValuePair<string, Func<NPC, bool>> kvp in rev)
  282. jsonRules[kvp.Key] = kvp.Value;
  283.  
  284. luckHandler = LuckHandlerClosestPlayer;
  285. #endregion
  286.  
  287. #region global rules
  288.  
  289. filters.Add(
  290. npc => npc.name == "Vanilla:Meteor Head" && Main.hardMode
  291. );
  292.  
  293. Add(
  294. new LootRule("Soul of Light/Night").Rules(
  295. npc => npc.name != "Vanilla:Slimer",
  296. ruleHardmode, ruleHostile, ruleHasValue, ruleUnderground
  297. ).LootRules(
  298. new LootRule().Chance(1.0 / 5.0).Rules(
  299. rulePlayerEvil
  300. ).Item("Soul of Night"),
  301. new LootRule().Chance(1.0 / 5.0).Rules(
  302. rulePlayerHallow
  303. ).Item("Soul of Light")
  304. ),
  305.  
  306. new LootRule("Vanilla NPC banners").Chance(1.0 / 200.0).Rules(
  307. npc => Terraria.Item.NPCtoBanner(npc.type) > 0
  308. ).Item(
  309. npc => new Item().SetDefaults(1614 + Terraria.Item.NPCtoBanner(npc.type))
  310. ),
  311.  
  312. new LootRule("Mechanical boss spawners").Rules(
  313. ruleHardmode
  314. ).LootRules(
  315. new LootRule().Chance(1.0 / 2500.0).Rules(
  316. npc => !NPC.downedMechBoss1
  317. ).Item("Mechanical Worm"),
  318. new LootRule().Chance(1.0 / 2500.0).Rules(
  319. npc => !NPC.downedMechBoss2
  320. ).Item("Mechanical Eye"),
  321. new LootRule().Chance(1.0 / 2500.0).Rules(
  322. npc => !NPC.downedMechBoss3
  323. ).Item("Mechanical Skull")
  324. ),
  325.  
  326. new LootRule("Halloween Weak Mob").Chance(1.0 / 2000.0).Rules(
  327. ruleHalloween,
  328. RuleValueLimit(499),
  329. npc => npc.damage < 40 && npc.defense < 20
  330. ).Weighted().LootRules(
  331. new LootRule().Item("Bloody Machete"),
  332. new LootRule().Item("Bladed Glove")
  333. ),
  334.  
  335. new LootRule("Key Molds").Rules(
  336. ruleHardmode,
  337. ruleHasValue
  338. ).LootRules(
  339. new LootRule().Chance(1.0 / 2500.0).Rules(
  340. rulePlayerJungle
  341. ).Item("Jungle Key Mold"),
  342. new LootRule().Chance(1.0 / 2500.0).Rules(
  343. rulePlayerCorruption
  344. ).Item("Corruption Key Mold"),
  345. new LootRule().Chance(1.0 / 2500.0).Rules(
  346. rulePlayerCrimson
  347. ).Item("Crimson Key Mold"),
  348. new LootRule().Chance(1.0 / 2500.0).Rules(
  349. rulePlayerHallow
  350. ).Item("Hallowed Key Mold"),
  351. new LootRule().Chance(1.0 / 2500.0).Rules(
  352. rulePlayerSnow
  353. ).Item("Frozen Key Mold")
  354. ),
  355.  
  356. new LootRule("Living Fire").Chance(1.0 / 50.0).Rules(
  357. ruleHasValue, ruleHardmode,
  358. npc => npc.lifeMax >= 5,
  359. npc => !npc.friendly,
  360. npc => npc.position.Y / 16f > Main.maxTilesY - 200 //TODO: use hellLayer
  361. ).Item("Living Fire Block").Stack(20, 50),
  362.  
  363. new LootRule("Goodie Bags").Chance(1.0 / 80.0).Rules(
  364. npc => npc.name != "Vanilla:Slimer" && npc.name != "Vanilla:Meteor Head",
  365. ruleHalloween, ruleHostile, ruleHasValue
  366. ).Item("Goodie Bag"),
  367.  
  368. new LootRule().Chance(1.0 / 13.0).Rules(
  369. npc => npc.name != "Vanilla:Slimer",
  370. ruleChristmas, ruleHostile, ruleHasValue
  371. ).Item("Present"),
  372.  
  373. new LootRule("Dungeon Spirits").Chance(1.0 / 15.0).Rules(
  374. rulePlayerDungeon, ruleHardmode,
  375. npc => npc.lifeMax > 100,
  376. npc => npc.name != "Vanilla:Dungeon Spirit",
  377. npc => npc.target >= 0,
  378. npc => NPC.downedPlantBoss,
  379. npc => TileDef.wallDungeon[Main.tile[(int)npc.center().X / 16, (int)npc.center().Y / 16].wall]
  380. ).Code(npc => {
  381. NPC.NewNPC((int)npc.center().X, (int)npc.center().Y, "Dungeon Spirit", 0);
  382. }),
  383.  
  384. new LootRule().Chance(1.0 / 1000.0).Rules(
  385. ruleBloodMoon, ruleHardmode
  386. ).Item("KO Cannon"),
  387.  
  388. new LootRule().Chance(1.0 / 100.0).Rules(
  389. ruleHardmode, ruleHasValue,
  390. npc => (double)(npc.position.Y / 16f) < Main.worldSurface + 10.0 && (npc.center().X / 16f < 380f || npc.center().X / 16f > (float)(Main.maxTilesX - 380))
  391. ).Item("Pirate Map"),
  392.  
  393. new LootRule("Hearts and Stars").Rules(
  394. npc => npc.name != "Vanilla:Slimer" && npc.name != "Vanilla:Mother Slime" && npc.name != "Vanilla:Corrupt Slime",
  395. npc => npc.lifeMax > 1 && npc.damage > 0
  396. ).LootRules(
  397. new LootRule().Chance(1.0 / 6.0).Conditional().LootRules(
  398. new LootRule().Chance(1.0 / 2.0).Rules(
  399. RuleClosestPlayer((npc, player) => player.statMana < player.statManaMax2)
  400. ).Item("Star"),
  401. new LootRule().Chance(1.0 / 2.0).Rules(
  402. RuleClosestPlayer((npc, player) => player.statLife < player.statLifeMax2)
  403. ).Item("Heart")
  404. ),
  405. new LootRule().Chance(1.0 / 2.0).Rules(
  406. RuleClosestPlayer((npc, player) => player.statMana < player.statManaMax2)
  407. ).Item("Star")
  408. ),
  409.  
  410. new LootRule("Coins").Code(npc => {
  411. float val = npc.value;
  412. if (npc.midas)
  413. val *= 1.1f + Main.rand.NextFloat() * 0.4f;
  414. val *= 0.8f + Main.rand.NextFloat() * 0.4f;
  415.  
  416. if (Main.rand.OneIn(5))
  417. val *= 1.05f + Main.rand.NextFloat() * 0.05f;
  418. if (Main.rand.OneIn(10))
  419. val *= 1.1f + Main.rand.NextFloat() * 0.1f;
  420. if (Main.rand.OneIn(15))
  421. val *= 1.15f + Main.rand.NextFloat() * 0.15f;
  422. if (Main.rand.OneIn(20))
  423. val *= 1.2f + Main.rand.NextFloat() * 0.2f;
  424.  
  425. int coins = (int)val;
  426. int coinC, coinS, coinG, coinP;
  427. coinC = coins;
  428.  
  429. coinS = coinC / 100;
  430. coinC %= 100;
  431.  
  432. coinG = coinS / 100;
  433. coinS %= 100;
  434.  
  435. coinP = coinG / 100;
  436. coinG %= 100;
  437.  
  438. while (coinP > 0)
  439. {
  440. int drop = coinP;
  441. if (drop > 50 && Main.rand.OneIn(5))
  442. {
  443. drop /= 1 + Main.rand.Next(3);
  444. }
  445. if (Main.rand.OneIn(5))
  446. {
  447. drop /= 1 + Main.rand.Next(3);
  448. }
  449. if (drop < 0)
  450. drop++;
  451. npc.NewItemAt("Vanilla:Platinum Coin", drop);
  452. coinP -= drop;
  453. }
  454. while (coinG > 0)
  455. {
  456. int drop = coinG;
  457. if (drop > 50 && Main.rand.OneIn(5))
  458. {
  459. drop /= 1 + Main.rand.Next(3);
  460. }
  461. if (Main.rand.OneIn(5))
  462. {
  463. drop /= 1 + Main.rand.Next(3);
  464. }
  465. if (drop < 0)
  466. drop++;
  467. npc.NewItemAt("Vanilla:Gold Coin", drop);
  468. coinG -= drop;
  469. }
  470. while (coinS > 0)
  471. {
  472. int drop = coinS;
  473. if (drop > 50 && Main.rand.OneIn(5))
  474. {
  475. drop /= 1 + Main.rand.Next(3);
  476. }
  477. if (Main.rand.OneIn(5))
  478. {
  479. drop /= 1 + Main.rand.Next(3);
  480. }
  481. if (drop < 0)
  482. drop++;
  483. npc.NewItemAt("Vanilla:Silver Coin", drop);
  484. coinS -= drop;
  485. }
  486. while (coinC > 0)
  487. {
  488. int drop = coinC;
  489. if (drop > 50 && Main.rand.OneIn(5))
  490. {
  491. drop /= 1 + Main.rand.Next(3);
  492. }
  493. if (Main.rand.OneIn(5))
  494. {
  495. drop /= 1 + Main.rand.Next(3);
  496. }
  497. if (drop < 0)
  498. drop++;
  499. npc.NewItemAt("Vanilla:Copper Coin", drop);
  500. coinC -= drop;
  501. }
  502. })
  503. );
  504.  
  505. #endregion
  506.  
  507. #region enemy-specific rules
  508.  
  509. #region Surface
  510. #region pre-hardmode
  511. AddFor(new int[] { 1, 16, 138, 141, 147, 184, 187, 204, 302, 333, 334, 335, 336 }, //Slimes
  512. new LootRule().Item("Gel").Stack(1, 2),
  513. new LootRule().Chance(1.0 / 10000.0).Item("Slime Staff")
  514. );
  515.  
  516. AddFor(new int[] { 3, 132, 161, 186, 187, 188, 189, 200, 223, 319, 320, 321, 331, 332 }, //Zombies
  517. new LootRule().Chance(1.0 / 50.0).Item("Shackle"),
  518. new LootRule().Chance(1.0 / 250.0).Item("Zombie Arm")
  519. );
  520.  
  521. AddFor(223, //Zombie 2 (Rain Coat Set)
  522. new LootRule("Rain Coat Set").Chance(1.0 / 10.0).Weighted().LootRules(
  523. new LootRule().Chance(1.0 / 50.0).Item("Rain Hat"),
  524. new LootRule().Chance(1.0 / 50.0).Item("Rain Coat")
  525. )
  526. );
  527.  
  528. AddFor(new int[] { 2, 190, 191, 192, 193, 194, 317, 318 }, //Demon Eyes
  529. new LootRule().Chance(1.0 / 3.0).Item("Lens"),
  530. new LootRule().Chance(1.0 / 100.0).Item("Black Lens")
  531. );
  532.  
  533. AddFor("Pincushion Zombie",
  534. new LootRule().Item("Wooden Arrow").Stack(1, 9)
  535. );
  536.  
  537. AddFor("The Groom",
  538. new LootRule().Item("Top Hat")
  539. );
  540.  
  541. AddFor("Umbrella Slime",
  542. new LootRule().Conditional().LootRules(
  543. new LootRule().Chance(1.0 / 45.0).Item("Umbrella Hat"),
  544. new LootRule().Item("Gel").Stack(2, 5)
  545. )
  546. );
  547.  
  548. AddFor(new Tuple<int, int>(333, 336), //Slimes with a giant bow
  549. new LootRule().Chance(1.0 / 20.0).Item("Giant Bow")
  550. );
  551.  
  552. AddFor(new object[] { new Tuple<int, int>(10, 12), new Tuple<int, int>(95, 97) }, //Giant Worm, Digger
  553. new LootRule().Chance(1.0 / 100.0).Item("Whoopie Cushion")
  554. );
  555.  
  556. AddFor("Meteor Head",
  557. new LootRule().Chance(1.0 / 50.0).Item("Meteorite")
  558. );
  559.  
  560. AddFor("Shark",
  561. new LootRule().Conditional().LootRules(
  562. new LootRule().Chance(1.0 / 50.0).Item("Diving Helmet"),
  563. new LootRule().Item("Shark Fin")
  564. )
  565. );
  566.  
  567. AddFor("Corrupt Bunny",
  568. new LootRule().Chance(1.0 / 75.0).Item("Bunny Hood")
  569. );
  570. #endregion
  571.  
  572. #region hardmode
  573. AddFor("Rainbow Slime",
  574. new LootRule().Item("Gel").Stack(1, 5),
  575. new LootRule().Times(3).Chance(1.0 / 2.0).Item("Gel").Stack(1, 5),
  576. new LootRule().Item("Rainbow Brick").Stack(30, 60)
  577. );
  578.  
  579. AddFor("Angry Nimbus",
  580. new LootRule().Chance(1.0 / 15.0).Item("Nimbus Rod")
  581. );
  582.  
  583. AddFor("Clown",
  584. new LootRule().Chance(1.0 / 30.0).Item("Bananarang").Stack(1, 4),
  585. new LootRule().Code(
  586. npc => DownedBoss(ref NPC.downedClown)
  587. )
  588. );
  589.  
  590. AddFor("Werewolf",
  591. new LootRule().Chance(1.0 / 60.0).Item("Moon Charm")
  592. );
  593. #endregion
  594. #endregion
  595.  
  596. #region Desert
  597. #region pre-hardmode
  598. AddFor("Antlion",
  599. new LootRule().Chance(1.0 / 7.0).Item("Antlion Mandible")
  600. );
  601. #endregion
  602.  
  603. #region hardmode
  604. AddFor("Dark Mummy",
  605. new LootRule().Chance(1.0 / 10.0).Item("Dark Shard")
  606. );
  607.  
  608. AddFor("Light Mummy",
  609. new LootRule().Chance(1.0 / 10.0).Item("Light Shard")
  610. );
  611.  
  612. AddFor(new string[] { "Mummy", "Dark Mummy", "Light Mummy" },
  613. new LootRule().Chance(1.0 / 75.0).Item("Mummy Mask"),
  614. new LootRule().Chance(1.0 / 75.0).Item("Mummy Shirt"),
  615. new LootRule().Chance(1.0 / 75.0).Item("Mummy Pants")
  616. );
  617. #endregion
  618. #endregion
  619.  
  620. #region Snow
  621. #region pre-hardmode
  622. AddFor("Snow Flinx",
  623. new LootRule().Chance(1.0 / 150.0).Item("Snowball Launcher")
  624. );
  625.  
  626. AddFor("Zombie Eskimo",
  627. new LootRule("Eskimo Set").Chance(1.0 / 50.0).Item(
  628. npc => new Item().SetDefaults(803 + Main.rand.Next(3))
  629. )
  630. );
  631.  
  632. AddFor("Undead Viking",
  633. new LootRule().Chance(1.0 / 50.0).Item("Viking Helmet")
  634. );
  635. #endregion
  636.  
  637. #region hardmode
  638. AddFor("Ice Golem",
  639. new LootRule().Chance(1.0 / 3.0).Item("Ice Feather"),
  640. new LootRule().Item("Frost Core")
  641. );
  642.  
  643. AddFor("Armored Viking",
  644. new LootRule().Chance(1.0 / 200.0).Item("Ice Sickle")
  645. );
  646.  
  647. AddFor("Ice Tortoise",
  648. new LootRule().Chance(1.0 / 100.0).Item("Frozen Turtle Shell")
  649. );
  650.  
  651. AddFor(new string[] { "Ice Elemental", "Icy Merman" },
  652. new LootRule().Chance(1.0 / 50.0).Item("Frost Staff")
  653. );
  654. #endregion
  655. #endregion
  656.  
  657. #region Underground
  658. #region pre-hardmode
  659. AddFor("Cave Bat",
  660. new LootRule().Chance(1.0 / 250.0).Item("Chain Knife"),
  661. new LootRule().Chance(1.0 / 200.0).Item("Depth Meter")
  662. );
  663.  
  664. AddFor("Undead Miner",
  665. new LootRule().Chance(1.0 / 75.0).Item("Bone Pickaxe"),
  666. new LootRule().Conditional().LootRules(
  667. new LootRule("Mining Set").Chance(1.0 / 20.0).Weighted().LootRules(
  668. new LootRule().Item("Mining Shirt"),
  669. new LootRule().Item("Mining Pants")
  670. ),
  671. new LootRule().Item("Bomb").Stack(1, 3)
  672. )
  673. );
  674.  
  675. AddFor(new int[] { 21, 201, 202, 203, 322, 323, 324 }, //Skeletons
  676. new LootRule().Conditional().LootRules(
  677. new LootRule().Chance(1.0 / 100.0).Item("Ancient Iron Helmet"),
  678. new LootRule().Chance(1.0 / 200.0).Item("Ancient Gold Helmet"),
  679. new LootRule().Chance(1.0 / 200.0).Item("Bone Sword"),
  680. new LootRule().Chance(1.0 / 500.0).Item("Skull")
  681. )
  682. );
  683.  
  684. AddFor(new string[] { "Blue Jellyfish", "Pink Jellyfish", "Green Jellyfish" },
  685. new LootRule().Chance(1.0 / 100.0).Item("Jellyfish Necklace"),
  686. new LootRule().Item("Glowstick").Stack(1, 4)
  687. );
  688.  
  689. AddFor(new object[] { "Skeleton", "Undead Miner", "Undead Viking", 201, 202, 203, 322, 323, 324 /*Skeleton variations*/ },
  690. new LootRule().Chance(1.0 / 25.0).Item("Hook")
  691. );
  692.  
  693. AddFor("Tim",
  694. new LootRule().Item("Wizard Hat")
  695. );
  696. #endregion
  697.  
  698. #region hardmode
  699. AddFor("Armored Skeleton",
  700. new LootRule().Chance(1.0 / 150.0).Item("Beam Sword")
  701. );
  702.  
  703. AddFor("Skeleton Archer",
  704. new LootRule().Chance(1.0 / 100.0).Item("Magic Quiver"),
  705. new LootRule().Chance(1.0 / 200.0).Item("Marrow")
  706. );
  707.  
  708. AddFor(new string[] { "Black Recluse", "Black Recluse 2" },
  709. new LootRule().Chance(1.0 / 40.0).Item("Poison Staff"),
  710. new LootRule("Spider Fangs").Chance(3.0 / 4.0).Conditional().LootRules(
  711. new LootRule().Chance(1.0 / 3.0).Item("Spider Fang").Stack(1, 3),
  712. new LootRule().Chance(1.0 / 2.0).Item("Spider Fang").Stack(1, 2),
  713. new LootRule().Item("Spider Fang")
  714. )
  715. );
  716.  
  717. AddFor("Mimic",
  718. new LootRule().Rules(
  719. ruleHasValue
  720. ).Conditional().LootRules(
  721. new LootRule("Present Mimic").Rules(
  722. npc => npc.ai[3] == 4f
  723. ).Conditional().LootRules(
  724. new LootRule().Chance(1.0 / 20.0).Item("Toy Sled"),
  725. new LootRule().Weighted().LootRules(
  726. new LootRule().Item("Frostbrand"),
  727. new LootRule().Item("Ice Bow"),
  728. new LootRule().Item("Flower of Frost")
  729. )
  730. ),
  731. new LootRule().Weighted().LootRules(
  732. new LootRule().Item("Dual Hook"),
  733. new LootRule().Item("Magic Dagger"),
  734. new LootRule().Item("Philosopher's Stone"),
  735. new LootRule().Item("Titan Glove"),
  736. new LootRule().Item("Star Cloak"),
  737. new LootRule().Item("Compass"),
  738. new LootRule().Item("Cross Necklace")
  739. )
  740. )
  741. );
  742.  
  743. AddFor("Rune Wizard",
  744. new LootRule().Item("Rune Hat"),
  745. new LootRule().Item("Rune Robe")
  746. );
  747. #endregion
  748. #endregion
  749.  
  750. #region Corruption
  751. #region pre-hardmode
  752. AddFor("Eater of Souls",
  753. new LootRule("Ancient Shadow Set").Chance(1.0 / 175.0).Weighted().LootRules(
  754. new LootRule().Item("Ancient Shadow Helmet"),
  755. new LootRule().Item("Ancient Shadow Scalemail"),
  756. new LootRule().Item("Ancient Shadow Greaves")
  757. )
  758. );
  759.  
  760. AddFor(new string[] { "Eater of Souls", "Corruptor" },
  761. new LootRule().Chance(1.0 / 3.0).Item("Rotten Chunk")
  762. );
  763.  
  764. AddFor(new Tuple<int, int>(7, 9), //Devourer
  765. new LootRule().Chance(1.0 / 3.0).Item("Rotten Chunk").Stack(1, 2),
  766. new LootRule().Item("Worm Tooth").Stack(3, 8)
  767. );
  768. #endregion
  769.  
  770. #region hardmode
  771. AddFor("Corrupt Slime",
  772. new LootRule().Item("Gel").Stack(2, 4)
  773. );
  774.  
  775. AddFor(new string[] { "Seeker Head", "Clinger" },
  776. new LootRule().Item("Cursed Flame").Stack(2, 5)
  777. );
  778. #endregion
  779. #endregion
  780.  
  781. #region Crimson
  782. #region pre-hardmode
  783. AddFor(new string[] { "Face Monster", "Crimera", "Floaty Gross", "Blood Crawler", "Blood Crawler 2" },
  784. new LootRule().Chance(1.0 / 3.0).Item("Vertebrae")
  785. );
  786. #endregion
  787.  
  788. #region hardmode
  789. AddFor("Ichor Sticker",
  790. new LootRule().Item("Ichor").Stack(1, 3)
  791. );
  792.  
  793. AddFor(new string[] { "Herpling", "Crimson Axe", "Floaty Gross", "Crimslime" },
  794. new LootRule().Chance(1.0 / 200.0).Item("Meat Grinder")
  795. );
  796. #endregion
  797. #endregion
  798.  
  799. #region Hallow
  800. AddFor("Chaos Elemental",
  801. new LootRule().Chance(1.0 / 500.0).Item("Rod of Discord")
  802. );
  803.  
  804. AddFor("Pixie",
  805. new LootRule().Item("Pixie Dust").Stack(1, 3)
  806. );
  807.  
  808. AddFor("Unicorn",
  809. new LootRule().Item("Unicorn Horn"),
  810. new LootRule().Chance(1.0 / 100.0).Item("Unicorn on a Stick")
  811. );
  812.  
  813. AddFor("Gastropod",
  814. new LootRule().Item("Gel").Stack(5, 10)
  815. );
  816. #endregion
  817.  
  818. #region Jungle
  819. #region pre-hardmode
  820. AddFor(new object[] { "Hornet", "Man Eater", new Tuple<int, int>(231, 235) /*Hornets*/ },
  821. new LootRule("Ancient Cobalt Set").Chance(1.0 / 100.0).Weighted().LootRules(
  822. new LootRule().Item("Ancient Cobalt Helmet"),
  823. new LootRule().Item("Ancient Cobalt Breastplate"),
  824. new LootRule().Item("Ancient Cobalt Leggings")
  825. )
  826. );
  827.  
  828. AddFor(new object[] { "Hornet", new Tuple<int, int>(231, 235) /*Hornets*/ },
  829. new LootRule().Chance(1.0 / 2.0).Item("Stinger")
  830. );
  831.  
  832. AddFor("Man Eater",
  833. new LootRule().Chance(1.0 / 3.0).Item("Vine")
  834. );
  835.  
  836. AddFor("Spiked Jungle Slime",
  837. new LootRule().Chance(1.0 / 3.0).Item("Stinger")
  838. );
  839.  
  840. AddFor("Piranha",
  841. new LootRule().Conditional().LootRules(
  842. new LootRule().Chance(1.0 / 500.0).Item("Robot Hat"),
  843. new LootRule().Chance(1.0 / 40.0).Item("Hook")
  844. )
  845. );
  846.  
  847. AddFor("Doctor Bones",
  848. new LootRule().Item("Archaeologist's Hat")
  849. );
  850. #endregion
  851.  
  852. #region hardmode
  853. AddFor("Moss Hornet",
  854. new LootRule().Chance(1.0 / 150.0).Item("Tattered Bee Wing")
  855. );
  856.  
  857. AddFor("Moth",
  858. new LootRule().Chance(1.0 / 2.0).Item("Butterfly Dust")
  859. );
  860.  
  861. AddFor("Giant Tortoise",
  862. new LootRule().Chance(1.0 / 17.0).Item("Turtle Shell")
  863. );
  864.  
  865. AddFor("Angler Fish",
  866. new LootRule().Conditional().LootRules(
  867. new LootRule().Chance(1.0 / 500.0).Item("Robot Hat")
  868. )
  869. );
  870.  
  871. AddFor("Angry Trapper",
  872. new LootRule().Chance(1.0 / 200.0).Item("Uzi")
  873. );
  874. #endregion
  875. #endregion
  876.  
  877. #region Dungeon
  878. #region pre-hardmode
  879. AddFor(new int[] { 31, 32, 294, 295, 296 }, //Angry Bones
  880. new LootRule().Chance(1.0 / 450.0).Item("Ancient Necro Helmet"),
  881. new LootRule().Chance(1.0 / 300.0).Item("Clothier Voodoo Doll")
  882. );
  883.  
  884. AddFor("Dungeon Slime",
  885. new LootRule().Item("Golden Key")
  886. );
  887.  
  888. AddFor(new string[] { "Angry Bones", "Dark Caster", "Cursed Skull" },
  889. new LootRule().Conditional().LootRules(
  890. new LootRule().Chance(1.0 / 250.0).Item("Bone Wand"),
  891. new LootRule().Chance(1.0 / 65.0).Item("Golden Key"),
  892. new LootRule().Item("Bone").Stack(1, 3)
  893. )
  894. );
  895. #endregion
  896.  
  897. #region hardmode
  898. AddFor(new Tuple<int, int>(269, 280), //Rusty/Blue/Hell Armored Bones 1-4
  899. new LootRule().Chance(1.0 / 450.0).Item("Bone Feather"),
  900. new LootRule().Conditional().LootRules(
  901. new LootRule().Chance(1.0 / 600.0).Item("Wisp in a Bottle"),
  902. new LootRule().Chance(1.0 / 400.0).Item("Magnet Sphere"),
  903. new LootRule().Chance(1.0 / 300.0).Item("Keybrand")
  904. )
  905. );
  906.  
  907. AddFor(new Tuple<int, int>(281, 282), //Ragged Caster 1-2
  908. new LootRule().Chance(1.0 / 40.0).Item("Spectre Staff")
  909. );
  910.  
  911. AddFor(new Tuple<int, int>(283, 284), //Necromancer 1-2
  912. new LootRule().Chance(1.0 / 40.0).Item("Shadowbeam Staff")
  913. );
  914.  
  915. AddFor(new Tuple<int, int>(285, 286), //Diabolist 1-2
  916. new LootRule().Chance(1.0 / 40.0).Item("Inferno Fork")
  917. );
  918.  
  919. AddFor("Bone Lee",
  920. new LootRule().Chance(1.0 / 7.0).Weighted().LootRules(
  921. new LootRule().Item("Black Belt"),
  922. new LootRule().Item("Tabi")
  923. )
  924. );
  925.  
  926. AddFor("Dungeon Spirit",
  927. new LootRule().Item("Ectoplasm").Stack(1, 2)
  928. );
  929.  
  930. AddFor("Paladin",
  931. new LootRule().Weighted().LootRules(
  932. new LootRule().Weight(1.0 / 35.0).Item("Paladin's Hammer"),
  933. new LootRule().Weight(1.0 / 15.0).Item("Paladin's Shield")
  934. ).EmptyElseLootRule()
  935. );
  936.  
  937. AddFor("Skeleton Sniper",
  938. new LootRule().Weighted().LootRules(
  939. new LootRule().Weight(1.0 / 15.0).Item("Rifle Scope"),
  940. new LootRule().Weight(1.0 / 15.0).Item("Sniper Rifle")
  941. ).EmptyElseLootRule()
  942. );
  943.  
  944. AddFor("Tactical Skeleton",
  945. new LootRule().Weighted().LootRules(
  946. new LootRule().Weight(1.0 / 15.0).Item("SWAT Helmet"),
  947. new LootRule().Weight(1.0 / 15.0).Item("Tactical Shotgun")
  948. ).EmptyElseLootRule()
  949. );
  950.  
  951. AddFor("Skeleton Commando",
  952. new LootRule().Chance(1.0 / 20.0).Item("Rocket Launcher")
  953. );
  954. #endregion
  955. #endregion
  956.  
  957. #region Hell
  958. #region pre-hardmode
  959. AddFor("Fire Imp",
  960. new LootRule().Chance(1.0 / 75.0).Item("Obsidian Rose"),
  961. new LootRule().Chance(1.0 / 300.0).Item("Plumber's Hat")
  962. );
  963.  
  964. AddFor("Hellbat",
  965. new LootRule().Chance(1.0 / 150.0).Item("Magma Stone")
  966. );
  967.  
  968. AddFor("Demon",
  969. new LootRule().Chance(1.0 / 50.0).Item("Demon Scythe")
  970. );
  971.  
  972. AddFor("Voodoo Demon",
  973. new LootRule().Item("Guide Voodoo Doll")
  974. );
  975. #endregion
  976.  
  977. #region hardmode
  978. AddFor("Lava Bat",
  979. new LootRule().Chance(1.0 / 50.0).Item("Magma Stone")
  980. );
  981.  
  982. AddFor("Red Devil",
  983. new LootRule().Chance(1.0 / 75.0).Item("Fire Feather"),
  984. new LootRule().Chance(1.0 / 30.0).Item("Unholy Trident")
  985. );
  986. #endregion
  987. #endregion
  988.  
  989. #region Sky
  990. #region pre-hardmode
  991. AddFor("Harpy",
  992. new LootRule().Chance(1.0 / 200.0).Item("Giant Harpy Feather"),
  993. new LootRule().Chance(1.0 / 2.0).Item("Feather")
  994. );
  995. #endregion
  996.  
  997. #region hardmode
  998. AddFor("Wyvern Head",
  999. new LootRule().Item("Soul of Flight").Stack(5, 10)
  1000. );
  1001. #endregion
  1002. #endregion
  1003.  
  1004. #region Jungle Temple
  1005. AddFor(new string[] { "Lihzahrd", "Lihzahrd 2", "Flying Snake" },
  1006. new LootRule().Chance(1.0 / 3000.0).Item("Lizard Egg"),
  1007. new LootRule().Chance(1.0 / 50.0).Item("Lihzahrd Power Cell")
  1008. );
  1009. #endregion
  1010.  
  1011. #region bosses
  1012. AddFor("Eye of Cthulhu",
  1013. new LootRule().Item("Lesser Healing Potion").Stack(5, 15),
  1014. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1015. new LootRule().Chance(1.0 / 7.0).Item("Eye of Cthulhu Mask"),
  1016. new LootRule().Chance(1.0 / 10.0).Item("Eye of Cthulhu Trophy"),
  1017. new LootRule().Chance(1.0 / 150.0).Item("Binoculars"),
  1018. new LootRule().Rules(
  1019. npc => WorldGen.crimson
  1020. ).LootRules(
  1021. new LootRule().Times(3).Item("Crimtane Ore").Stack(10, 30),
  1022. new LootRule().Item("Crimson Seeds").Stack(1, 3)
  1023. ),
  1024. new LootRule().Rules(
  1025. npc => WorldGen.corruption
  1026. ).LootRules(
  1027. new LootRule().Item("Unholy Arrow").Stack(20, 50),
  1028. new LootRule().Times(3).Item("Demonite Ore").Stack(10, 30),
  1029. new LootRule().Item("Corrupt Seeds").Stack(1, 3)
  1030. ),
  1031. new LootRule().Code(
  1032. npc => DownedBoss(ref NPC.downedBoss1)
  1033. ),
  1034. new LootRule("Message").Code(npc => {
  1035. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1036. })
  1037. );
  1038.  
  1039. AddFor(new Tuple<int, int>(13, 15), //Eater of Worlds
  1040. new LootRule().Chance(1.0 / 2.0).Item("Shadow Scale").Stack(1, 2),
  1041. new LootRule().Chance(1.0 / 2.0).Item("Demonite Ore").Stack(2, 5),
  1042. new LootRule().Rules(
  1043. npc => npc.boss
  1044. ).LootRules(
  1045. new LootRule().Item("Lesser Healing Potion").Stack(5, 15),
  1046. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1047. new LootRule().Chance(1.0 / 30.0).Item("Eater's Bone"),
  1048. new LootRule().Chance(1.0 / 7.0).Item("Eater of Worlds Mask"),
  1049. new LootRule().Chance(1.0 / 10.0).Item("Eater of Worlds Trophy"),
  1050. new LootRule().Code(
  1051. npc => DownedBoss(ref NPC.downedBoss2)
  1052. ),
  1053. new LootRule("Message").Code(npc => {
  1054. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1055. })
  1056. ),
  1057. new LootRule().Chance(1.0 / 4.0).Rules(
  1058. RuleClosestPlayer((npc, player) => player.statLife < player.statLifeMax2)
  1059. ).Item("Heart")
  1060. );
  1061.  
  1062. AddFor("Brain of Cthulhu",
  1063. new LootRule().Item("Lesser Healing Potion").Stack(5, 15),
  1064. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1065. new LootRule().Chance(1.0 / 7.0).Item("Brain of Cthulhu Mask"),
  1066. new LootRule().Chance(1.0 / 10.0).Item("Brain of Cthulhu Trophy"),
  1067. new LootRule().Times(2).Item("Crimtane Ore").Stack(10, 30),
  1068. new LootRule().Code(
  1069. npc => DownedBoss(ref NPC.downedBoss2)
  1070. ),
  1071. new LootRule("Message").Code(npc => {
  1072. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1073. })
  1074. );
  1075.  
  1076. AddFor("Creeper",
  1077. new LootRule().Rules(
  1078. npc => NPC.AnyNPCs(266) //Brain of Cthulhu
  1079. ).LootRules(
  1080. new LootRule().Chance(1.0 / 3.0).Item("Tissue Sample").Stack(2, 5),
  1081. new LootRule().Chance(1.0 / 3.0).Item("Crimtane Ore").Stack(4, 10),
  1082. new LootRule().Chance(1.0 / 2.0).Rules(
  1083. RuleClosestPlayer((npc, player) => player.statLife < player.statLifeMax2)
  1084. ).Item("Heart")
  1085. )
  1086. );
  1087.  
  1088. AddFor("King Slime",
  1089. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1090. new LootRule().Chance(1.0 / 7.0).Item("King Slime Mask"),
  1091. new LootRule().Chance(1.0 / 10.0).Item("King Slime Trophy"),
  1092. new LootRule().Chance(1.0 / 30.0).Item("Slimy Saddle"),
  1093. new LootRule("Ninja Set").Weighted().LootRules(
  1094. new LootRule().Item("Ninja Hood"),
  1095. new LootRule().Item("Ninja Shirt"),
  1096. new LootRule().Item("Ninja Pants")
  1097. ),
  1098. new LootRule().Weighted().LootRules(
  1099. new LootRule().Item("Slime Gun"),
  1100. new LootRule().Item("Slime Hook")
  1101. ),
  1102. new LootRule("Message").Code(npc => {
  1103. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1104. })
  1105. );
  1106.  
  1107. AddFor("Skeletron Head",
  1108. new LootRule().Item("Lesser Healing Potion").Stack(5, 15),
  1109. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1110. new LootRule().Conditional().LootRules(
  1111. new LootRule().Chance(1.0 / 7.0).Item("Skeletron Mask"),
  1112. new LootRule().Chance(1.0 / 7.0).Item("Skeletron Hand"),
  1113. new LootRule().Chance(1.0 / 7.0).Item("Book of Skulls")
  1114. ),
  1115. new LootRule().Chance(1.0 / 10.0).Item("Skeletron Trophy"),
  1116. new LootRule().Code(
  1117. npc => DownedBoss(ref NPC.downedBoss3)
  1118. ),
  1119. new LootRule("Message").Code(npc => {
  1120. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1121. })
  1122. );
  1123.  
  1124. AddFor("Dungeon Guardian",
  1125. new LootRule().Item("Bone Key")
  1126. );
  1127.  
  1128. AddFor("Queen Bee",
  1129. new LootRule().Item("Bottled Honey").Stack(5, 15),
  1130. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1131. new LootRule().Chance(1.0 / 7.0).Item("Queen Bee Mask"),
  1132. new LootRule().Chance(1.0 / 10.0).Item("Queen Bee Trophy"),
  1133. new LootRule().Weighted().LootRules(
  1134. new LootRule().Item("Bee Gun"),
  1135. new LootRule().Item("Bee Keeper"),
  1136. new LootRule().Item("Honey Comb")
  1137. ),
  1138. new LootRule().Chance(1.0 / 20.0).Item("Nectar"),
  1139. new LootRule().Chance(1.0 / 100.0).Item("Honeyed Goggles"),
  1140. new LootRule().Conditional().LootRules(
  1141. new LootRule().Chance(1.0 / 3.0).Item("Hive Wand"),
  1142. new LootRule("Bee Set").Chance(1.0 / 2.0).Weighted().LootRules(
  1143. new LootRule().Item("Bee Hat"),
  1144. new LootRule().Item("Bee Shirt"),
  1145. new LootRule().Item("Bee Pants")
  1146. )
  1147. ),
  1148. new LootRule().Chance(1.0 / 4.0).Item("Beenade").Stack(10, 30),
  1149. new LootRule().Item("Bee Wax").Stack(16, 26),
  1150. new LootRule().Code(
  1151. npc => DownedBoss(ref NPC.downedQueenBee)
  1152. ),
  1153. new LootRule("Message").Code(npc => {
  1154. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1155. })
  1156. );
  1157.  
  1158. AddFor("Wall of Flesh",
  1159. new LootRule().Item("Healing Potion").Stack(5, 15),
  1160. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1161. new LootRule().Chance(1.0 / 7.0).Item("Wall of Flesh Mask"),
  1162. new LootRule().Chance(1.0 / 10.0).Item("Wall of Flesh Trophy"),
  1163. new LootRule().Item("Pwnhammer"),
  1164. new LootRule().Weighted().LootRules(
  1165. new LootRule("Emblem").Weighted().LootRules(
  1166. new LootRule().Item("Sorcerer Emblem"),
  1167. new LootRule().Item("Warrior Emblem"),
  1168. new LootRule().Item("Ranger Emblem")
  1169. ),
  1170. new LootRule().Weighted().LootRules(
  1171. new LootRule().Item("Laser Rifle"),
  1172. new LootRule().Item("Breaker Blade"),
  1173. new LootRule().Item("Clockwork Assault Rifle")
  1174. )
  1175. ),
  1176. new LootRule("Loot Cage").Code(npc => {
  1177. if (Main.netMode != 1)
  1178. {
  1179. int num22 = (int)(npc.position.X + (npc.width / 2)) / 16;
  1180. int num23 = (int)(npc.position.Y + (npc.height / 2)) / 16;
  1181. int num24 = npc.width / 2 / 16 + 1;
  1182. for (int k = num22 - num24; k <= num22 + num24; k++)
  1183. {
  1184. for (int l = num23 - num24; l <= num23 + num24; l++)
  1185. {
  1186. if ((k == num22 - num24 || k == num22 + num24 || l == num23 - num24 || l == num23 + num24) && !Main.tile[k, l].active())
  1187. {
  1188. Main.tile[k, l].type = 140;
  1189. Main.tile[k, l].active(true);
  1190. }
  1191. Main.tile[k, l].lava(false);
  1192. Main.tile[k, l].liquid = 0;
  1193. if (Main.netMode == 2)
  1194. {
  1195. NetMessage.SendTileSquare(-1, k, l, 1);
  1196. }
  1197. else
  1198. {
  1199. WorldGen.SquareTileFrame(k, l, true);
  1200. }
  1201. }
  1202. }
  1203. }
  1204. }),
  1205. new LootRule("Message").Code(npc => {
  1206. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1207. }),
  1208. new LootRule("Hardmode").Rules(
  1209. npc => Main.netMode != 1,
  1210. npc => !Main.hardMode
  1211. ).Code(npc => {
  1212. bool hardMode = Main.hardMode;
  1213. WorldGen.StartHardmode();
  1214. if (NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3 && !hardMode)
  1215. {
  1216. DownedBossMessage(Lang.misc[32], 50, 255, 130);
  1217. }
  1218. })
  1219. );
  1220.  
  1221. AddFor(new Tuple<int, int>(116, 119), //The Hungry (without 1)
  1222. new LootRule().Item("Heart")
  1223. );
  1224.  
  1225. AddFor("The Destroyer",
  1226. new LootRule().Item("Greater Healing Potion").Stack(5, 15),
  1227. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1228. new LootRule().Chance(1.0 / 7.0).Item("Destroyer Mask"),
  1229. new LootRule().Chance(1.0 / 10.0).Item("Destroyer Trophy"),
  1230. new LootRule().Item("Soul of Might").Stack(25, 40),
  1231. new LootRule().Item("Hallowed Bar").Stack(15, 30),
  1232. new LootRule().Code(npc => {
  1233. NPC.downedMechBossAny = true;
  1234. DownedBoss(ref NPC.downedMechBoss1);
  1235. }),
  1236. new LootRule("Message").Code(npc => {
  1237. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1238. }),
  1239. new LootRule("Restless Jungle").Rules(
  1240. npc => NPC.downedMechBoss2 && NPC.downedMechBoss3
  1241. ).Code(npc => {
  1242. DownedBossMessage(Lang.misc[32], 50, 255, 130);
  1243. })
  1244. );
  1245.  
  1246. AddFor("Probe",
  1247. new LootRule().Chance(1.0 / 2.0).Item("Heart")
  1248. );
  1249.  
  1250. AddFor("Skeletron Prime",
  1251. new LootRule().Item("Greater Healing Potion").Stack(5, 15),
  1252. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1253. new LootRule().Chance(1.0 / 7.0).Item("Skeletron Prime Mask"),
  1254. new LootRule().Chance(1.0 / 10.0).Item("Skeletron Prime Trophy"),
  1255. new LootRule().Item("Soul of Fright").Stack(25, 40),
  1256. new LootRule().Item("Hallowed Bar").Stack(15, 30),
  1257. new LootRule().Code(npc => {
  1258. NPC.downedMechBossAny = true;
  1259. DownedBoss(ref NPC.downedMechBoss3);
  1260. }),
  1261. new LootRule("Message").Code(npc => {
  1262. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1263. }),
  1264. new LootRule("Restless Jungle").Rules(
  1265. npc => NPC.downedMechBoss1 && NPC.downedMechBoss2
  1266. ).Code(npc => {
  1267. DownedBossMessage(Lang.misc[32], 50, 255, 130);
  1268. })
  1269. );
  1270.  
  1271. AddFor(new string[] { "Retinazer", "Spazmatism" },
  1272. new LootRule().Conditional().LootRules(
  1273. new LootRule("Last one").Rules(
  1274. npc => !NPC.AnyNPCs(npc.name == "Vanilla:Retinazer" ? "Vanilla:Spazmatism" : "Vanilla:Retinazer")
  1275. ).LootRules(
  1276. new LootRule().Item("Greater Healing Potion").Stack(5, 15),
  1277. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1278. new LootRule().Chance(1.0 / 7.0).Item("Twin Mask"),
  1279. new LootRule().Item("Soul of Sight").Stack(25, 40),
  1280. new LootRule().Item("Hallowed Bar").Stack(15, 30),
  1281. new LootRule().Code(npc => {
  1282. NPC.downedMechBossAny = true;
  1283. DownedBoss(ref NPC.downedMechBoss2);
  1284. }),
  1285. new LootRule("Message").Code(npc => {
  1286. DownedBossMessage("The Twins " + Lang.misc[17]);
  1287. }),
  1288. new LootRule("Restless Jungle").Rules(
  1289. npc => NPC.downedMechBoss1 && NPC.downedMechBoss3
  1290. ).Code(npc => {
  1291. DownedBossMessage(Lang.misc[32], 50, 255, 130);
  1292. })
  1293. ),
  1294. new LootRule("Fix").Code(npc => {
  1295. npc.value = 0;
  1296. npc.boss = false;
  1297. })
  1298. )
  1299. );
  1300.  
  1301. AddFor("Retinazer",
  1302. new LootRule().Chance(1.0 / 10.0).Item("Retinazer Trophy")
  1303. );
  1304.  
  1305. AddFor("Spazmatism",
  1306. new LootRule().Chance(1.0 / 10.0).Item("Spazmatism Trophy")
  1307. );
  1308.  
  1309. AddFor("Plantera",
  1310. new LootRule().Item("Greater Healing Potion").Stack(5, 15),
  1311. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1312. new LootRule().Chance(1.0 / 7.0).Item("Plantera Mask"),
  1313. new LootRule().Chance(1.0 / 10.0).Item("Plantera Trophy"),
  1314. new LootRule().Item("Temple Key"),
  1315. new LootRule().Chance(1.0 / 20.0).Item("Seedling"),
  1316. new LootRule().Chance(1.0 / 200.0).Item("The Axe"),
  1317. new LootRule().Chance(1.0 / 4.0).Item("Pygmy Staff"),
  1318. new LootRule().Conditional().LootRules(
  1319. new LootRule().Rules(
  1320. npc => NPC.downedPlantBoss
  1321. ).Weighted().LootRules(
  1322. new LootRule("Grenade Launcher").LootRules(
  1323. new LootRule().Item("Grenade Launcher"),
  1324. new LootRule().Item("Rocket I").Stack(20, 50)
  1325. ),
  1326. new LootRule().Item("Venus Magnum"),
  1327. new LootRule().Item("Nettle Burst"),
  1328. new LootRule().Item("Leaf Blower"),
  1329. new LootRule().Item("Flower Pow"),
  1330. new LootRule().Item("Wasp Gun")
  1331. ),
  1332. new LootRule("Grenade Launcher").LootRules(
  1333. new LootRule().Item("Grenade Launcher"),
  1334. new LootRule().Item("Rocket I").Stack(20, 50)
  1335. )
  1336. ),
  1337. new LootRule().Code(npc => {
  1338. if (!NPC.downedPlantBoss)
  1339. {
  1340. if (Main.netMode == 0)
  1341. {
  1342. Main.NewText(Lang.misc[33], 50, 255, 130, false);
  1343. }
  1344. else if (Main.netMode == 2)
  1345. {
  1346. NetMessage.SendData(25, -1, -1, Lang.misc[33], 255, 50f, 255f, 130f, 0);
  1347. }
  1348. }
  1349. DownedBoss(ref NPC.downedPlantBoss);
  1350. }),
  1351. new LootRule("Message").Code(npc => {
  1352. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1353. })
  1354. );
  1355.  
  1356. AddFor("Golem",
  1357. new LootRule().Item("Greater Healing Potion").Stack(5, 15),
  1358. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1359. new LootRule().Chance(1.0 / 7.0).Item("Golem Mask"),
  1360. new LootRule().Chance(1.0 / 10.0).Item("Golem Trophy"),
  1361. new LootRule().Weighted().LootRules(
  1362. new LootRule("Stynger").LootRules(
  1363. new LootRule().Item("Stynger"),
  1364. new LootRule().Item("Stynger Bolt").Stack(60, 100)
  1365. ),
  1366. new LootRule().Item("Possessed Hatchet"),
  1367. new LootRule().Item("Sun Stone"),
  1368. new LootRule().Item("Eye of the Golem"),
  1369. new LootRule().Item("Picksaw"),
  1370. new LootRule().Item("Heat Ray"),
  1371. new LootRule().Item("Staff of Earth"),
  1372. new LootRule().Item("Golem Fist")
  1373. ),
  1374. new LootRule().Item("Beetle Husk").Stack(4, 8),
  1375. new LootRule().Code(
  1376. npc => DownedBoss(ref NPC.downedGolemBoss)
  1377. ),
  1378. new LootRule("Message").Code(npc => {
  1379. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1380. })
  1381. );
  1382.  
  1383. AddFor("Duke Fishron",
  1384. new LootRule().Item("Greater Healing Potion").Stack(5, 15),
  1385. new LootRule().Times(npc => 5 + Main.rand.Next(5)).Item("Heart"),
  1386. new LootRule().Chance(1.0 / 7.0).Item("Duke Fishron Mask"),
  1387. new LootRule().Chance(1.0 / 10.0).Item("Duke Fishron Trophy"),
  1388. new LootRule().Chance(1.0 / 15.0).Item("Fishron Wings"),
  1389. new LootRule().Weighted().LootRules(
  1390. new LootRule().Item("Flairon"),
  1391. new LootRule().Item("Tsunami"),
  1392. new LootRule().Item("Razorblade Typhoon"),
  1393. new LootRule().Item("Tempest Staff"),
  1394. new LootRule().Item("Bubble Gun")
  1395. ),
  1396. new LootRule().Code(
  1397. npc => DownedBoss(ref NPC.downedFishron)
  1398. ),
  1399. new LootRule("Message").Code(npc => {
  1400. DownedBossMessage(npc.displayName + " " + Lang.misc[17]);
  1401. })
  1402. );
  1403. #endregion
  1404.  
  1405. #region Goblin Army related
  1406. AddFor("Goblin Scout",
  1407. new LootRule().Item("Tattered Cloth").Stack(1, 2)
  1408. );
  1409.  
  1410. AddFor(new object[] { new Tuple<int, int>(26, 29), 111 }, //all Goblins in the Goblin Army invasion
  1411. new LootRule().Conditional().LootRules(
  1412. new LootRule().Chance(1.0 / 200.0).Item("Harpoon"),
  1413. new LootRule().Chance(1.0 / 2.0).Item("Spiky Ball").Stack(1, 5)
  1414. )
  1415. );
  1416. #endregion
  1417.  
  1418. #region Frost Legion
  1419. AddFor(new string[] { "Snowman Gangsta", "Mister Stabby", "Snow Balla" },
  1420. new LootRule().Item("Snow Block").Stack(5, 10)
  1421. );
  1422. #endregion
  1423.  
  1424. #region Solar Eclipse
  1425. AddFor("Reaper",
  1426. new LootRule().Chance(1.0 / 250.0).Item("Death Sickle")
  1427. );
  1428.  
  1429. AddFor("Eyezor",
  1430. new LootRule().Chance(1.0 / 50.0).Item("Eye Spring")
  1431. );
  1432.  
  1433. AddFor(new string[] { "Frankenstein", "Swamp Thing" },
  1434. new LootRule().Chance(1.0 / 250.0).Item("Broken Hero Sword")
  1435. );
  1436.  
  1437. AddFor(new int[] { 158, 159 }, //Vampire 1-2
  1438. new LootRule().Chance(1.0 / 40.0).Item("Broken Bat Wing"),
  1439. new LootRule().Chance(1.0 / 100.0).Item("Moon Stone")
  1440. );
  1441. #endregion
  1442.  
  1443. #region Pirate Invasion
  1444. AddFor(new Tuple<int, int>(212, 215), //Pirate Deckhand/Corsair/Deadeye/Crossbower
  1445. new LootRule().Chance(1.0 / 8000.0).Item("Coin Gun"),
  1446. new LootRule().Chance(1.0 / 4000.0).Item("Lucky Coin"),
  1447. new LootRule().Chance(1.0 / 2000.0).Item("Discount Card"),
  1448. new LootRule().Chance(1.0 / 2000.0).Item("Pirate Staff"),
  1449. new LootRule().Chance(1.0 / 200.0).Item("Cutlass"),
  1450.  
  1451. new LootRule().Chance(1.0 / 500.0).Item("Sailor Hat"),
  1452. new LootRule().Chance(1.0 / 500.0).Item("Eye Patch"),
  1453. new LootRule().Chance(1.0 / 500.0).Item("Sailor Shirt"),
  1454. new LootRule().Chance(1.0 / 500.0).Item("Sailor Pants"),
  1455.  
  1456. new LootRule().Chance(1.0 / 300.0).Item("Golden Chair"),
  1457. new LootRule().Chance(1.0 / 300.0).Item("Golden Toilet"),
  1458. new LootRule().Chance(1.0 / 300.0).Item("Golden Door"),
  1459. new LootRule().Chance(1.0 / 300.0).Item("Golden Table"),
  1460. new LootRule().Chance(1.0 / 300.0).Item("Golden Bed"),
  1461. new LootRule().Chance(1.0 / 300.0).Item("Golden Piano"),
  1462. new LootRule().Chance(1.0 / 300.0).Item("Golden Dresser"),
  1463. new LootRule().Chance(1.0 / 300.0).Item("Golden Sofa"),
  1464. new LootRule().Chance(1.0 / 300.0).Item("Golden Bathtub"),
  1465. new LootRule().Chance(1.0 / 300.0).Item("Golden Clock"),
  1466. new LootRule().Chance(1.0 / 300.0).Item("Golden Lamp"),
  1467. new LootRule().Chance(1.0 / 300.0).Item("Golden Bookcase"),
  1468. new LootRule().Chance(1.0 / 300.0).Item("Golden Chandelier"),
  1469. new LootRule().Chance(1.0 / 300.0).Item("Golden Candelabra"),
  1470. new LootRule().Chance(1.0 / 300.0).Item("Golden Candle")
  1471. );
  1472.  
  1473. AddFor("Pirate Captain",
  1474. new LootRule().Chance(1.0 / 2000.0).Item("Coin Gun"),
  1475. new LootRule().Chance(1.0 / 1000.0).Item("Lucky Coin"),
  1476. new LootRule().Chance(1.0 / 500.0).Item("Discount Card"),
  1477. new LootRule().Chance(1.0 / 500.0).Item("Pirate Staff"),
  1478. new LootRule().Chance(1.0 / 50.0).Item("Cutlass")
  1479. );
  1480. #endregion
  1481.  
  1482. #region Pumpkin Moon
  1483. AddFor(new Tuple<int, int>(305, 314), //Scarecrow 1-10
  1484. new LootRule("Pumpkin Moon").Chance(
  1485. npc => 1.0 / Math.Max((int)((17 - NPC.waveCount) / 1.25), 1)
  1486. ).Rules(
  1487. rulePumpkinMoon
  1488. ).LootRules(
  1489. new LootRule("Scarecrow Set").Chance(1.0 / 10.0).Item(
  1490. npc => new Item().SetDefaults(1788 + Main.rand.Next(3))
  1491. )
  1492. ),
  1493.  
  1494. new LootRule().Chance(1.0 / 4.0).Item("Heart")
  1495. );
  1496.  
  1497. AddFor("Splinterling",
  1498. new LootRule().Item("Spooky Wood").Stack(1, 4),
  1499. new LootRule().Chance(1.0 / 6.0).Item("Heart")
  1500. );
  1501.  
  1502. AddFor("Hellhound",
  1503. new LootRule().Chance(1.0 / 4.0).Item("Heart")
  1504. );
  1505.  
  1506. AddFor("Poltergeist",
  1507. new LootRule().Chance(1.0 / 4.0).Item("Heart")
  1508. );
  1509.  
  1510. AddFor("Headless Horseman",
  1511. new LootRule("Pumpkin Moon").Chance(
  1512. npc => 1.0 / Math.Max((int)((17 - NPC.waveCount) / 1.25), 1)
  1513. ).Rules(
  1514. rulePumpkinMoon
  1515. ).LootRules(
  1516. new LootRule().Chance(1.0 / 20.0).Item("Jack 'O Lantern Mask")
  1517. ),
  1518.  
  1519. new LootRule().Item("Heart")
  1520. );
  1521.  
  1522. AddFor("Mourning Wood",
  1523. new LootRule("Pumpkin Moon").Rules(
  1524. rulePumpkinMoon
  1525. ).LootRules(
  1526. new LootRule().Rules(
  1527. npc => NPC.waveCount == 15
  1528. ).Item("Mourning Wood Trophy"),
  1529.  
  1530. new LootRule("Wave Chance").Chance(
  1531. npc => 1.0 / Math.Max((int)((17 - NPC.waveCount) / 1.25), 1)
  1532. ).LootRules(
  1533. new LootRule().Weighted().LootRules(
  1534. new LootRule().Item("Spooky Hook"),
  1535. new LootRule().Item("Spooky Twig"),
  1536. new LootRule("Stake Launcher").LootRules(
  1537. new LootRule().Item("Stake Launcher"),
  1538. new LootRule().Item("Stake").Stack(30, 60)
  1539. ),
  1540. new LootRule().Item("Cursed Sapling"),
  1541. new LootRule().Item("Necromantic Scroll")
  1542. )
  1543. )
  1544. ),
  1545.  
  1546. new LootRule().Item("Spooky Wood").Stack(30, 50),
  1547. new LootRule().Times(
  1548. npc => 5 + Main.rand.Next(6)
  1549. ).Item("Heart")
  1550. );
  1551.  
  1552. AddFor("Pumpking",
  1553. new LootRule("Pumpkin Moon").Rules(
  1554. rulePumpkinMoon
  1555. ).LootRules(
  1556. new LootRule().Rules(
  1557. npc => NPC.waveCount == 15
  1558. ).Item("Pumpking Trophy"),
  1559.  
  1560. new LootRule("Wave Chance").Chance(
  1561. npc => 1.0 / Math.Max((int)((17 - NPC.waveCount) / 1.25), 1)
  1562. ).LootRules(
  1563. new LootRule().Weighted().LootRules(
  1564. new LootRule("Candy Corn Rifle").LootRules(
  1565. new LootRule().Item("Candy Corn Rifle"),
  1566. new LootRule().Item("Candy Corn").Stack(50, 100)
  1567. ),
  1568. new LootRule("Jack 'O Lantern Launcher").LootRules(
  1569. new LootRule().Item("Jack 'O Lantern Launcher"),
  1570. new LootRule().Item("Explosive Jack 'O Lantern").Stack(25, 50)
  1571. ),
  1572. new LootRule().Item("Black Fairy Dust"),
  1573. new LootRule().Item("The Horseman's Blade"),
  1574. new LootRule().Item("Bat Scepter"),
  1575. new LootRule().Item("Raven Staff"),
  1576. new LootRule().Item("Spider Egg")
  1577. )
  1578. )
  1579. ),
  1580.  
  1581. new LootRule().Times(
  1582. npc => 5 + Main.rand.Next(6)
  1583. ).Item("Heart")
  1584. );
  1585. #endregion
  1586.  
  1587. #region Frost Moon
  1588. AddFor("Present Mimic",
  1589. new LootRule().Times(
  1590. npc => 5 + Main.rand.Next(6)
  1591. ).Item("Heart"),
  1592. new LootRule().Rules(
  1593. ruleChristmas
  1594. ).Item("Present")
  1595. );
  1596.  
  1597. AddFor(new Tuple<int, int>(338, 340), //Zombie Elf 1-3
  1598. new LootRule().Chance(1.0 / 5.0).Item("Heart"),
  1599. new LootRule("Elf Set").Chance(1.0 / 200.0).Weighted().LootRules(
  1600. new LootRule().Item("Elf Hat"),
  1601. new LootRule().Item("Elf Shirt"),
  1602. new LootRule().Item("Elf Pants")
  1603. )
  1604. );
  1605.  
  1606. AddFor("Gingerbread Man",
  1607. new LootRule().Chance(1.0 / 3.0).Item("Heart")
  1608. );
  1609.  
  1610. AddFor("Everscream",
  1611. new LootRule("Frost Moon").Rules(
  1612. ruleFrostMoon
  1613. ).LootRules(
  1614. new LootRule("Wave Chance").Chance(
  1615. npc => 1.0 / Math.Max((int)((30 - NPC.waveCount) / 2.5), 1)
  1616. ).LootRules(
  1617. new LootRule().Conditional().LootRules(
  1618. new LootRule().Chance(1.0 / 15.0).Item("Festive Wings"),
  1619. new LootRule().Weighted().LootRules(
  1620. new LootRule().Item("Christmas Hook"),
  1621. new LootRule().Item("Christmas Tree Sword"),
  1622. new LootRule().Item("Razorpine")
  1623. )
  1624. ),
  1625. new LootRule().Chance(
  1626. npc => 1.0 / (4 + (NPC.waveCount - 15) / 2)
  1627. ).Rules(
  1628. npc => NPC.waveCount >= 15
  1629. ).Item("Everscream Trophy")
  1630. )
  1631. ),
  1632.  
  1633. new LootRule().Times(
  1634. npc => 5 + Main.rand.Next(6)
  1635. ).Item("Heart")
  1636. );
  1637.  
  1638. AddFor("Ice Queen",
  1639. new LootRule("Frost Moon").Rules(
  1640. ruleFrostMoon
  1641. ).LootRules(
  1642. new LootRule("Wave Chance").Chance(
  1643. npc => 1.0 / Math.Max((int)((30 - NPC.waveCount) / 2.5), 1)
  1644. ).LootRules(
  1645. new LootRule().Conditional().LootRules(
  1646. new LootRule().Chance(1.0 / 30.0).Rules(
  1647. npc => NPC.waveCount >= 15
  1648. ).Item("Reindeer Bells"),
  1649. new LootRule().Chance(1.0 / 15.0).Item("Baby Grinch's Mischief Whistle"),
  1650. new LootRule().Weighted().LootRules(
  1651. new LootRule().Item("Blizzard Staff"),
  1652. new LootRule().Item("Snowman Cannon"),
  1653. new LootRule().Item("North Pole")
  1654. )
  1655. ),
  1656. new LootRule().Chance(
  1657. npc => 1.0 / (4 + (NPC.waveCount - 15) / 2)
  1658. ).Rules(
  1659. npc => NPC.waveCount >= 15
  1660. ).Item("Ice Queen Trophy")
  1661. )
  1662. ),
  1663.  
  1664. new LootRule().Times(
  1665. npc => 5 + Main.rand.Next(6)
  1666. ).Item("Heart")
  1667. );
  1668.  
  1669. AddFor("Santa-NK1",
  1670. new LootRule("Frost Moon").Rules(
  1671. ruleFrostMoon
  1672. ).LootRules(
  1673. new LootRule("Wave Chance").Chance(
  1674. npc => 1.0 / Math.Max((int)((30 - NPC.waveCount) / 2.5), 1)
  1675. ).LootRules(
  1676. new LootRule().Weighted().LootRules(
  1677. new LootRule().Item("Elf Melter"),
  1678. new LootRule().Item("Chain Gun")
  1679. ),
  1680.  
  1681. new LootRule().Chance(
  1682. npc => 1.0 / (4 + (NPC.waveCount - 15) / 2)
  1683. ).Rules(
  1684. npc => NPC.waveCount >= 15
  1685. ).Item("Santa-NK1 Trophy")
  1686. )
  1687. ),
  1688.  
  1689. new LootRule().Times(
  1690. npc => 5 + Main.rand.Next(6)
  1691. ).Item("Heart")
  1692. );
  1693. #endregion
  1694.  
  1695. #region generic
  1696. AddFor(new string[] { "Pixie", "Mummy", "Wraith" },
  1697. new LootRule().Chance(1.0 / 100.0).Item("Fast Clock")
  1698. );
  1699.  
  1700. AddFor(new string[] { "Corrupt Slime", "Dark Mummy" },
  1701. new LootRule().Chance(1.0 / 100.0).Item("Blindfold")
  1702. );
  1703.  
  1704. AddFor(new string[] { "Pixie", "Dark Mummy", "Green Jellyfish" },
  1705. new LootRule().Chance(1.0 / 100.0).Item("Megaphone")
  1706. );
  1707.  
  1708. AddFor(new string[] { "Cursed Hammer", "Enchanted Sword", "Cursed Skull", "Crimson Axe" },
  1709. new LootRule().Chance(1.0 / 100.0).Item("Nazar")
  1710. );
  1711.  
  1712. AddFor(new string[] { "Enchanted Sword", "Floaty Gross" },
  1713. new LootRule().Chance(1.0 / 100.0).Item("Vitamins")
  1714. );
  1715.  
  1716. AddFor(new object[] { "Angler Fish", "Werewolf", new Tuple <int, int>(269,272) },
  1717. new LootRule().Chance(1.0 / 100.0).Item("Adhesive Bandage")
  1718. );
  1719.  
  1720. AddFor(new string[] { "Clown", "Light Mummy", "Giant Bat" },
  1721. new LootRule().Chance(1.0 / 100.0).Item("Trifold Map")
  1722. );
  1723.  
  1724. AddFor(new object[] { "Hornet", "Toxic Sludge", "Moss Hornet", new Tuple<int, int>(231, 235) /*Hornets*/ },
  1725. new LootRule().Chance(1.0 / 100.0).Item("Bezoar")
  1726. );
  1727.  
  1728. AddFor(new object[] { new Tuple<int, int>(273, 276) /*Blue Armored Bones 1-4*/, "Armored Skeleton", "Heavy Skeleton", "Paladin" },
  1729. new LootRule().Chance(1.0 / 100.0).Item("Armor Polish")
  1730. );
  1731.  
  1732. AddFor("Cochineal Beetle",
  1733. new LootRule().Item("Red Husk")
  1734. );
  1735. AddFor("Cyan Beetle",
  1736. new LootRule().Item("Cyan Husk")
  1737. );
  1738. AddFor("Lac Beetle",
  1739. new LootRule().Item("Violet Husk")
  1740. );
  1741. AddFor("Sea Snail",
  1742. new LootRule().Item("Purple Mucos")
  1743. );
  1744. AddFor("Squid",
  1745. new LootRule().Item("Black Ink")
  1746. );
  1747. #endregion
  1748.  
  1749. #endregion
  1750.  
  1751. #region town NPCs
  1752.  
  1753. AddFor("Guide",
  1754. new LootRule().Rules(
  1755. npc => npc.displayName == "Andrew"
  1756. ).Item("Green Cap")
  1757. );
  1758.  
  1759. AddFor("Clothier",
  1760. new LootRule().Item("Red Hat")
  1761. );
  1762.  
  1763. AddFor("Travelling Merchant",
  1764. new LootRule().Item("Peddler's Hat")
  1765. );
  1766.  
  1767. #endregion
  1768. settingUp = false;
  1769. }
  1770.  
  1771. public static void DownedBoss(ref bool b)
  1772. {
  1773. if (!b)
  1774. {
  1775. b = true;
  1776. if (Main.netMode == 2)
  1777. {
  1778. NetMessage.SendData(7, -1, -1, "", 0, 0f, 0f, 0f, 0);
  1779. }
  1780. }
  1781. }
  1782.  
  1783. public static void DownedBossMessage(string message)
  1784. {
  1785. DownedBossMessage(message, 175, 75, 255);
  1786. }
  1787. public static void DownedBossMessage(string message, int r, int g, int b)
  1788. {
  1789. if (Main.netMode == 0)
  1790. {
  1791. Main.NewText(message, (byte)r, (byte)g, (byte)b, false);
  1792. }
  1793. else if (Main.netMode == 2)
  1794. {
  1795. NetMessage.SendData(25, -1, -1, message, 255, r, g, b, 0);
  1796. }
  1797. }
  1798.  
  1799. public static void Add(params LootRule[] rules)
  1800. {
  1801. globalRules.AddRange(rules);
  1802. }
  1803.  
  1804. public static void AddFor(object[] npcs, params LootRule[] rules)
  1805. {
  1806. foreach (object npc in npcs)
  1807. {
  1808. if (npc is string)
  1809. AddFor((string)npc, rules);
  1810. else if (npc is int)
  1811. AddFor((int)npc, rules);
  1812. else if (npc is string[])
  1813. AddFor((string[])npc, rules);
  1814. else if (npc is int[])
  1815. AddFor((int[])npc, rules);
  1816. else if (npc is Tuple<int, int>)
  1817. AddFor((Tuple<int, int>)npc, rules);
  1818. }
  1819. }
  1820.  
  1821. public static void AddFor(string npcName, params LootRule[] rules)
  1822. {
  1823. if (npcName.IndexOf(':') == -1)
  1824. {
  1825. npcName = "Vanilla:" + npcName;
  1826. }
  1827. AddFor(NPCDef.byName[npcName].type, rules);
  1828. }
  1829. public static void AddFor(int[] types, params LootRule[] rules)
  1830. {
  1831. foreach (int type in types)
  1832. {
  1833. AddFor(type, rules);
  1834. }
  1835. }
  1836. public static void AddFor(string[] npcNames, params LootRule[] rules)
  1837. {
  1838. foreach (string npcName in npcNames)
  1839. {
  1840. AddFor(npcName, rules);
  1841. }
  1842. }
  1843. public static void AddForName(string npcName, params LootRule[] rules)
  1844. {
  1845. if (npcName.IndexOf(':') == -1)
  1846. {
  1847. npcName = "Vanilla:" + npcName;
  1848. }
  1849. if (!rulesName.ContainsKey(npcName))
  1850. {
  1851. rulesName[npcName] = new List<LootRule>();
  1852. }
  1853. rulesName[npcName].AddRange(rules);
  1854. }
  1855. public static void AddForName(string[] npcNames, params LootRule[] rules)
  1856. {
  1857. foreach (string npcName in npcNames)
  1858. {
  1859. AddForName(npcName, rules);
  1860. }
  1861. }
  1862. public static void AddFor(int type, params LootRule[] rules)
  1863. {
  1864. if (!rulesType.ContainsKey(type))
  1865. {
  1866. rulesType[type] = new List<LootRule>();
  1867. }
  1868. rulesType[type].AddRange(rules);
  1869. }
  1870. public static void AddFor(Tuple<int, int> range, params LootRule[] rules)
  1871. {
  1872. for (int i = range.Item1; i <= range.Item2; i++)
  1873. {
  1874. AddFor(i, rules);
  1875. }
  1876. }
  1877.  
  1878. public static Tuple<List<Item>, List<Action<NPC>>> GetResults(NPC npc)
  1879. {
  1880. foreach (Func<NPC, bool> filter in filters)
  1881. {
  1882. if (filter(npc))
  1883. {
  1884. return new Tuple<List<Item>, List<Action<NPC>>>(new List<Item>(), new List<Action<NPC>>());
  1885. }
  1886. }
  1887.  
  1888. List<LootRule> rules = new List<LootRule>();
  1889.  
  1890. if (rulesName.ContainsKey(npc.name))
  1891. rules.AddRange(rulesName[npc.name]);
  1892. if (rulesType.ContainsKey(npc.type))
  1893. rules.AddRange(rulesType[npc.type]);
  1894. rules.AddRange(globalRules);
  1895.  
  1896. return GetResultsFor(npc, rules);
  1897. }
  1898. public static Tuple<List<Item>, List<Action<NPC>>> GetResultsFor(NPC npc, List<LootRule> rules)
  1899. {
  1900. List<Item> list = new List<Item>();
  1901. List<Action<NPC>> list2 = new List<Action<NPC>>();
  1902.  
  1903. foreach (LootRule rule in rules)
  1904. {
  1905. Tuple<List<Item>, List<Action<NPC>>> tuple = rule.GetResult(npc);
  1906. list.AddRange(tuple.Item1);
  1907. list2.AddRange(tuple.Item2);
  1908. }
  1909.  
  1910. return new Tuple<List<Item>, List<Action<NPC>>>(list, list2);
  1911. }
  1912.  
  1913. public LootRule parent = null, copy = null;
  1914. public string name = null;
  1915. public List<Func<NPC, bool>> rules = new List<Func<NPC, bool>>();
  1916. public Dynamic<double> weight = 1.0, chance = 1.0;
  1917. public DynamicItem item = new Item();
  1918. public Dynamic<int> minStack = 1, maxStack = 1, times = 1;
  1919. public Action<NPC> code = null;
  1920. public List<LootRule> subrules = new List<LootRule>();
  1921. public bool conditional = false, weighted = false;
  1922. public LootRule elseSubrule = null;
  1923. public bool enabled = true, modified = false;
  1924.  
  1925. public LootRule(string name = null)
  1926. {
  1927. this.name = name;
  1928. }
  1929.  
  1930. public LootRule Rules(params Func<NPC, bool>[] rules)
  1931. {
  1932. this.rules.AddRange(rules);
  1933. return MarkModified();
  1934. }
  1935. public LootRule Weight(double weight = 1)
  1936. {
  1937. this.weight.value = weight;
  1938. return MarkModified();
  1939. }
  1940. public LootRule Weight(Func<NPC, double> f)
  1941. {
  1942. weight.func = f;
  1943. return MarkModified();
  1944. }
  1945. public LootRule Chance(double chance = 1)
  1946. {
  1947. this.chance.value = chance;
  1948. return MarkModified();
  1949. }
  1950. public LootRule Chance(Func<NPC, double> f)
  1951. {
  1952. chance.func = f;
  1953. return MarkModified();
  1954. }
  1955. public LootRule Times(int times = 1)
  1956. {
  1957. this.times.value = times;
  1958. return MarkModified();
  1959. }
  1960. public LootRule Times(Func<NPC, int> f)
  1961. {
  1962. times.func = f;
  1963. return MarkModified();
  1964. }
  1965. public LootRule Item(int type)
  1966. {
  1967. item.value.netDefaults(type);
  1968. if (name == null)
  1969. {
  1970. name = item.value.displayName;
  1971. }
  1972. return MarkModified();
  1973. }
  1974. public LootRule Item(string name)
  1975. {
  1976. if (name.IndexOf(':') == -1)
  1977. {
  1978. name = "Vanilla:" + name;
  1979. }
  1980. item.value.SetDefaults(name);
  1981. if (this.name == null)
  1982. {
  1983. this.name = item.value.displayName;
  1984. }
  1985. return MarkModified();
  1986. }
  1987. public LootRule Stack(int stack = 1)
  1988. {
  1989. return Stack(stack, stack);
  1990. }
  1991. public LootRule Stack(int min, int max)
  1992. {
  1993. minStack.value = min;
  1994. maxStack.value = max;
  1995. return MarkModified();
  1996. }
  1997. public LootRule Stack(Func<NPC, int> stack)
  1998. {
  1999. return Stack(stack, stack);
  2000. }
  2001. public LootRule Stack(Func<NPC, int> min, Func<NPC, int> max)
  2002. {
  2003. minStack.func = min;
  2004. maxStack.func = max;
  2005. return MarkModified();
  2006. }
  2007. public LootRule Item(Func<NPC, Item> f)
  2008. {
  2009. item.func = f;
  2010. return MarkModified();
  2011. }
  2012. public LootRule Code(Action<NPC> code)
  2013. {
  2014. this.code = code;
  2015. if (name == null)
  2016. {
  2017. name = "Code";
  2018. }
  2019. return MarkModified();
  2020. }
  2021. public LootRule Conditional(bool state = true)
  2022. {
  2023. conditional = state;
  2024. weighted = false;
  2025. if (name == null)
  2026. {
  2027. name = "Conditional";
  2028. }
  2029. return MarkModified();
  2030. }
  2031. public LootRule Weighted(bool state = true)
  2032. {
  2033. weighted = state;
  2034. conditional = false;
  2035. if (name == null)
  2036. {
  2037. name = "Weighted";
  2038. }
  2039. return MarkModified();
  2040. }
  2041. public LootRule LootRules(params LootRule[] subrules)
  2042. {
  2043. foreach (LootRule rule in subrules)
  2044. {
  2045. rule.parent = this;
  2046. this.subrules.Add(rule);
  2047. }
  2048. return MarkModified();
  2049. }
  2050. public LootRule EmptyElseLootRule(double totalWeight)
  2051. {
  2052. return EmptyElseLootRule(null, totalWeight);
  2053. }
  2054. public LootRule EmptyElseLootRule(string name = null, double totalWeight = 1)
  2055. {
  2056. return ElseLootRule(new LootRule(), totalWeight);
  2057. }
  2058. public LootRule ElseLootRule(LootRule rule, double totalWeight = 1)
  2059. {
  2060. rule.parent = this;
  2061. elseSubrule = rule.Weight(totalWeight);
  2062. return MarkModified();
  2063. }
  2064. public LootRule Enable()
  2065. {
  2066. enabled = true;
  2067. return MarkModified();
  2068. }
  2069. public LootRule Disable()
  2070. {
  2071. enabled = false;
  2072. return MarkModified();
  2073. }
  2074. public LootRule MarkModified()
  2075. {
  2076. if (settingUp)
  2077. return this;
  2078. if (!modified)
  2079. modifiedRules.Add(this);
  2080. modified = true;
  2081. return this;
  2082. }
  2083.  
  2084. public void Backup()
  2085. {
  2086. CopyInto(copy);
  2087. }
  2088. public void CopyInto(LootRule copy)
  2089. {
  2090. if (copy == null)
  2091. copy = new LootRule();
  2092. if (parent != null)
  2093. copy.parent = parent.copy;
  2094. copy.name = name;
  2095. copy.rules.Clear();
  2096. copy.rules.AddRange(rules);
  2097. weight.CopyInto(copy.weight);
  2098. chance.CopyInto(copy.chance);
  2099. item.CopyInto(copy.item);
  2100. minStack.CopyInto(copy.minStack);
  2101. maxStack.CopyInto(copy.maxStack);
  2102. times.CopyInto(copy.times);
  2103. copy.code = code;
  2104. copy.subrules.Clear();
  2105. foreach (LootRule rule in subrules)
  2106. {
  2107. LootRule copyrule = new LootRule();
  2108. rule.CopyInto(copyrule);
  2109. copy.subrules.Add(copyrule);
  2110. }
  2111. copy.conditional = conditional;
  2112. copy.weighted = weighted;
  2113. copy.elseSubrule = elseSubrule == null ? null : new LootRule();
  2114. if (elseSubrule != null)
  2115. elseSubrule.CopyInto(copy.elseSubrule);
  2116. copy.enabled = enabled;
  2117. copy.copy = this;
  2118. }
  2119.  
  2120. public void ReadFrom(JsonData j, NPC npc)
  2121. {
  2122. if (j.Has("name")) name = (string)j["name"];
  2123. if (j.Has("times")) Times((int)j["times"]);
  2124. if (j.Has("weight")) Weight((double)j["weight"]);
  2125. if (j.Has("chance")) Chance((double)j["chance"]);
  2126. if (j.Has("conditional")) Conditional((bool)j["conditional"]);
  2127. if (j.Has("weighted")) Weighted((bool)j["weighted"]);
  2128. if (j.Has("stack"))
  2129. {
  2130. if (j["stack"].IsInt)
  2131. Stack((int)j["stack"]);
  2132. if (j["stack"].IsArray)
  2133. {
  2134. JsonData jStack = j["stack"];
  2135. Stack((int)jStack[0], (int)jStack[1]);
  2136. }
  2137. else
  2138. throw new ArgumentException("Wrong type of the 'stack' property in LootRule for " + (npc == null ? "global NPC" : ("NPC '" + npc.name + "'")));
  2139. }
  2140. if (j.Has("item"))
  2141. {
  2142. if (j["item"].IsString)
  2143. Item((string)j["item"]);
  2144. else if (j["item"].IsInt)
  2145. Item((int)j["item"]);
  2146. else
  2147. throw new ArgumentException("Wrong type of the 'item' property in LootRule for " + (npc == null ? "global NPC" : ("NPC '" + npc.name + "'")));
  2148. }
  2149.  
  2150. if (j.Has("rules"))
  2151. {
  2152. foreach (JsonData jRule in j["rules"])
  2153. Rules(jsonRules[(string)jRule]);
  2154. }
  2155.  
  2156. if (j.Has("lootRules"))
  2157. {
  2158. foreach (JsonData jLootRule in j["lootRules"])
  2159. {
  2160. LootRule lootRule = new LootRule();
  2161. lootRule.ReadFrom(jLootRule, npc);
  2162. lootRule.parent = this;
  2163. LootRules(lootRule);
  2164. }
  2165. }
  2166.  
  2167. if (j.Has("else"))
  2168. {
  2169. double totalWeight = 1;
  2170. JsonData jElse = j["else"];
  2171. if (jElse.Has("totalWeight")) totalWeight = (double)jElse["totalWeight"];
  2172. LootRule lootRule = new LootRule();
  2173. lootRule.ReadFrom(jElse, npc);
  2174. lootRule.parent = this;
  2175. ElseLootRule(lootRule, totalWeight);
  2176. }
  2177. }
  2178.  
  2179. public int DoesPass(NPC npc)
  2180. {
  2181. if (!enabled)
  2182. return 0;
  2183.  
  2184. int passed = 0;
  2185. int times = this.times.Get(npc);
  2186. for (int i = 0; i < times; i++)
  2187. {
  2188. foreach (Func<NPC, bool> frule in rules)
  2189. {
  2190. if (!frule(npc))
  2191. {
  2192. goto L1;
  2193. }
  2194. }
  2195.  
  2196. double chance = this.chance.Get(npc) * luckHandler(npc);
  2197. if (chance > 0 && (chance >= 1 || Main.rand.NextDouble() < chance))
  2198. {
  2199. passed++;
  2200. }
  2201.  
  2202. L1: {}
  2203. }
  2204. return passed;
  2205. }
  2206.  
  2207. public Tuple<List<Item>, List<Action<NPC>>> GetResult(NPC npc, int passed = -1)
  2208. {
  2209. List<Item> list = new List<Item>();
  2210. List<Action<NPC>> list2 = new List<Action<NPC>>();
  2211.  
  2212. if (passed < 0)
  2213. {
  2214. passed = DoesPass(npc);
  2215. }
  2216. for (int i = 0; i < passed; i++)
  2217. {
  2218. if (subrules.Count == 0)
  2219. {
  2220. Item myItem = GetItem(npc);
  2221. if (myItem != null && !myItem.IsBlank())
  2222. {
  2223. list.Add(myItem);
  2224. }
  2225. if (code != null)
  2226. {
  2227. list2.Add(code);
  2228. }
  2229. }
  2230. else
  2231. {
  2232. if (conditional)
  2233. {
  2234. foreach (LootRule rule in subrules)
  2235. {
  2236. if (rule.DoesPass(npc) != 0)
  2237. {
  2238. Tuple<List<Item>, List<Action<NPC>>> tuple = rule.GetResult(npc, 1);
  2239. list.AddRange(tuple.Item1);
  2240. list2.AddRange(tuple.Item2);
  2241. break;
  2242. }
  2243. }
  2244. }
  2245. else if (weighted)
  2246. {
  2247. double totalWeight = 0;
  2248. WeightedRandom<LootRule> wr = new WeightedRandom<LootRule>(Main.rand);
  2249. foreach (LootRule rule in subrules)
  2250. {
  2251. int passed2 = rule.DoesPass(npc);
  2252. for (int j = 0; j < passed2; j++)
  2253. {
  2254. double weight = rule.weight.Get(npc);
  2255. if (weight > 0)
  2256. {
  2257. wr.Add(rule, weight);
  2258. totalWeight += weight;
  2259. }
  2260. }
  2261. }
  2262.  
  2263. if (elseSubrule != null)
  2264. {
  2265. float luckMult = luckHandler(npc);
  2266. if (luckMult > 0)
  2267. {
  2268. double weight = elseSubrule.weight.Get(npc) / luckMult;
  2269. if (weight > 0)
  2270. {
  2271. wr.Add(elseSubrule, weight - totalWeight);
  2272. totalWeight = weight;
  2273. }
  2274. }
  2275. }
  2276.  
  2277. if (totalWeight != 0)
  2278. {
  2279. LootRule rule = wr.Get();
  2280. Tuple<List<Item>, List<Action<NPC>>> tuple = rule.GetResult(npc, 1);
  2281. list.AddRange(tuple.Item1);
  2282. list2.AddRange(tuple.Item2);
  2283. }
  2284. }
  2285. else
  2286. {
  2287. foreach (LootRule rule in subrules)
  2288. {
  2289. Tuple<List<Item>, List<Action<NPC>>> tuple = rule.GetResult(npc);
  2290. list.AddRange(tuple.Item1);
  2291. list2.AddRange(tuple.Item2);
  2292. }
  2293. }
  2294. }
  2295. }
  2296.  
  2297. return new Tuple<List<Item>, List<Action<NPC>>>(list, list2);
  2298. }
  2299.  
  2300. public Item GetItem(NPC npc)
  2301. {
  2302. Item item = this.item.Get(npc);
  2303. if (item == null || item.IsBlank())
  2304. return null;
  2305.  
  2306. if (this.item.func == null)
  2307. {
  2308. int minStack = this.minStack.Get(npc);
  2309. int maxStack = this.maxStack.Get(npc);
  2310. item.stack = minStack == maxStack ? minStack : (minStack + Main.rand.Next(maxStack - minStack + 1));
  2311. if (Prefix.CanHavePrefix(item))
  2312. item.Prefix(-1);
  2313. }
  2314. return item;
  2315. }
  2316. }
  2317.  
  2318. public class Dynamic<T>
  2319. {
  2320. public T value;
  2321. public Func<NPC, T> func;
  2322.  
  2323. public Dynamic()
  2324. {
  2325. value = default(T);
  2326. func = null;
  2327. }
  2328. public Dynamic(T value)
  2329. {
  2330. this.value = value;
  2331. func = null;
  2332. }
  2333. public Dynamic(Func<NPC, T> func)
  2334. {
  2335. value = default(T);
  2336. this.func = func;
  2337. }
  2338.  
  2339. public T Get(NPC npc)
  2340. {
  2341. if (func != null)
  2342. {
  2343. return func(npc);
  2344. }
  2345. return value;
  2346. }
  2347.  
  2348. public virtual void CopyInto(Dynamic<T> other)
  2349. {
  2350. other.value = value;
  2351. other.func = func;
  2352. }
  2353.  
  2354. public static implicit operator Dynamic<T>(T value)
  2355. {
  2356. return new Dynamic<T>(value);
  2357. }
  2358. public static implicit operator Dynamic<T>(Func<NPC, T> func)
  2359. {
  2360. return new Dynamic<T>(func);
  2361. }
  2362. }
  2363.  
  2364. public class DynamicItem : Dynamic<Item>
  2365. {
  2366. public DynamicItem() : base() { }
  2367. public DynamicItem(Item value) : base(value) { }
  2368. public DynamicItem(Func<NPC, Item> func) : base(func) { }
  2369.  
  2370. public override void CopyInto(Dynamic<Item> other)
  2371. {
  2372. BinBuffer bb = new BinBuffer();
  2373. bb.Write(value);
  2374. bb.Pos = 0;
  2375. other.value = bb.ReadItem();
  2376. other.func = func;
  2377. }
  2378.  
  2379. public static implicit operator DynamicItem(Item value)
  2380. {
  2381. return new DynamicItem(value);
  2382. }
  2383. public static implicit operator DynamicItem(Func<NPC, Item> func)
  2384. {
  2385. return new DynamicItem(func);
  2386. }
  2387. }
  2388. }
Add Comment
Please, Sign In to add comment