From c8c275bcd55f298ae4a8a517269053c26e0a4c05 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 15 Apr 2023 11:52:19 -0500 Subject: [PATCH] added equip dropping on mobs to LootManager --- src/engine/loot/LootManager.java | 29 +++++++++++++++++++---------- src/engine/objects/Mob.java | 21 +++------------------ 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/engine/loot/LootManager.java b/src/engine/loot/LootManager.java index 2588e0b6..af041eda 100644 --- a/src/engine/loot/LootManager.java +++ b/src/engine/loot/LootManager.java @@ -43,7 +43,7 @@ public class LootManager { DbManager.LootQueries.LOAD_ALL_MODGROUPS(); DbManager.LootQueries.LOAD_ALL_MODTABLES(); } - public static void GenerateMobLoot(Mob mob){ + public static void GenerateMobLoot(Mob mob, boolean fromDeath){ //determine if mob is in hotzone boolean inHotzone = ZoneManager.inHotZone(mob.getLoc()); //get multiplier form config manager @@ -54,10 +54,10 @@ public class LootManager { } //iterate the booty sets if(mob.getMobBase().bootySet != 0 && NPCManager._bootySetMap.containsKey(mob.getMobBase().bootySet)) { - RunBootySet(NPCManager._bootySetMap.get(mob.getMobBase().bootySet), mob, multiplier, inHotzone); + RunBootySet(NPCManager._bootySetMap.get(mob.getMobBase().bootySet), mob, multiplier, inHotzone, fromDeath); } if(mob.bootySet != 0) { - RunBootySet(NPCManager._bootySetMap.get(mob.bootySet), mob, multiplier, inHotzone); + RunBootySet(NPCManager._bootySetMap.get(mob.bootySet), mob, multiplier, inHotzone, fromDeath); } //lastly, check mobs inventory for godly or disc runes to send a server announcement for (Item it : mob.getInventory()) { @@ -70,14 +70,13 @@ public class LootManager { } } } - private static void RunBootySet(ArrayList entries, Mob mob, float multiplier, boolean inHotzone) { + private static void RunBootySet(ArrayList entries, Mob mob, float multiplier, boolean inHotzone, boolean fromDeath) { for (BootySetEntry bse : entries) { - //check if chance roll is good switch (bse.bootyType) { case "GOLD": - if (ThreadLocalRandom.current().nextInt(100) <= (bse.dropChance * multiplier)) { - //early exit, failed to hit minimum chance roll + if (ThreadLocalRandom.current().nextInt(100) <= (bse.dropChance * multiplier) || fromDeath) { + //early exit, failed to hit minimum chance roll OR booty was generated from mob's death break; } //determine and add gold to mob inventory @@ -88,8 +87,8 @@ public class LootManager { } break; case "LOOT": - if (ThreadLocalRandom.current().nextInt(100) <= (bse.dropChance * multiplier)) { - //early exit, failed to hit minimum chance roll + if (ThreadLocalRandom.current().nextInt(100) <= (bse.dropChance * multiplier) || fromDeath) { + //early exit, failed to hit minimum chance roll OR booty was generated from mob's death break; } //iterate the booty tables and add items to mob inventory @@ -107,10 +106,20 @@ public class LootManager { break; case "ITEM": MobLoot disc = new MobLoot(mob, ItemBase.getItemBase(bse.itemBase), true); - if (disc != null) + if (disc != null || fromDeath) mob.getCharItemManager().addItemToInventory(disc); break; + case "EQUIP": + if (ThreadLocalRandom.current().nextInt(100) <= (bse.dropChance * multiplier) || !fromDeath) { + //early exit, failed to hit minimum chance roll OR booty wasn't generated form mob's death + break; + } + MobLoot equipToAdd = new MobLoot(mob, ItemBase.getItemBase(bse.itemBase), true); + if (equipToAdd != null) { + mob.getCharItemManager().addItemToInventory(equipToAdd); + } + break; } } } diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 99aecfc2..6590cdd1 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -1253,23 +1253,8 @@ public class Mob extends AbstractIntelligenceAgent { playerAgroMap.clear(); - if (!this.isPlayerGuard) { - - - if (this.equip != null) { - - for (MobEquipment me : equip.values()) { - if (me.getDropChance() == 0) - continue; - - float chance = ThreadLocalRandom.current().nextFloat(); - - if (chance <= me.getDropChance()) { - MobLoot ml = new MobLoot(this, me.getItemBase(), false); - this.charItemManager.addItemToInventory(ml); - } - } - } + if (!this.isPlayerGuard && this.equip != null) { + LootManager.GenerateMobLoot(this, true); } } @@ -1378,7 +1363,7 @@ public class Mob extends AbstractIntelligenceAgent { if (isPlayerGuard) return; - LootManager.GenerateMobLoot(this); + LootManager.GenerateMobLoot(this, false); } private int getLootTable() {