Browse Source

catch code for loot crash

master
FatBoy-DOTC 1 year ago
parent
commit
4932ee36ea
  1. 175
      src/engine/loot/LootManager.java

175
src/engine/loot/LootManager.java

@ -16,6 +16,7 @@ import engine.gameManager.ZoneManager;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.msg.chat.ChatSystemMsg; import engine.net.client.msg.chat.ChatSystemMsg;
import engine.objects.*; import engine.objects.*;
import org.pmw.tinylog.Logger;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -47,7 +48,6 @@ public class LootManager {
} }
public static void GenerateMobLoot(Mob mob, boolean fromDeath) { public static void GenerateMobLoot(Mob mob, boolean fromDeath) {
try{
//determine if mob is in hotzone //determine if mob is in hotzone
boolean inHotzone = ZoneManager.inHotZone(mob.getLoc()); boolean inHotzone = ZoneManager.inHotZone(mob.getLoc());
//get multiplier form config manager //get multiplier form config manager
@ -76,107 +76,115 @@ public class LootManager {
} }
} }
} catch(Exception e){
//TODO catch whatever went wrong
}
} }
private static void RunBootySet(ArrayList<BootySetEntry> entries, Mob mob, float multiplier, boolean inHotzone, boolean fromDeath) { private static void RunBootySet(ArrayList<BootySetEntry> entries, Mob mob, float multiplier, boolean inHotzone, boolean fromDeath) {
if (fromDeath) { int roll; // table roll
//do equipment here BootySetEntry entry = null;
if (mob.getEquip() != null) { int setCount = 0;
for (MobEquipment me : mob.getEquip().values()) { try {
if (me.getDropChance() == 0) if (fromDeath) {
continue; //do equipment here
float equipmentRoll = ThreadLocalRandom.current().nextInt(101); if (mob.getEquip() != null) {
float dropChance = me.getDropChance() * 100; for (MobEquipment me : mob.getEquip().values()) {
if (equipmentRoll <= (dropChance * multiplier)) { if (me.getDropChance() == 0)
MobLoot ml = new MobLoot(mob, me.getItemBase(), false); continue;
if(ml.getPrefix().isEmpty() == true && ml.getSuffix().isEmpty() == true){ float equipmentRoll = ThreadLocalRandom.current().nextInt(101);
ml.setIsID(true); float dropChance = me.getDropChance() * 100;
if (equipmentRoll <= (dropChance * multiplier)) {
MobLoot ml = new MobLoot(mob, me.getItemBase(), false);
if (ml.getPrefix().isEmpty() == true && ml.getSuffix().isEmpty() == true) {
ml.setIsID(true);
}
mob.getCharItemManager().addItemToInventory(ml);
} }
mob.getCharItemManager().addItemToInventory(ml);
} }
} }
return;
} }
return; for (BootySetEntry bse : entries) {
} entry = bse;
for (BootySetEntry bse : entries) { float dropChance = bse.dropChance * multiplier;
int roll; switch (bse.bootyType) {
float dropChance = bse.dropChance * multiplier; case "GOLD":
switch (bse.bootyType) { roll = ThreadLocalRandom.current().nextInt(101);
case "GOLD": if (roll > dropChance) {
roll = ThreadLocalRandom.current().nextInt(101); //early exit, failed to hit minimum chance roll OR booty was generated from mob's death
if (roll > dropChance) { break;
//early exit, failed to hit minimum chance roll OR booty was generated from mob's death }
break; //determine and add gold to mob inventory
} int gold = new Random().nextInt(bse.highGold - bse.lowGold) + bse.lowGold;
//determine and add gold to mob inventory if (gold > 0) {
int gold = new Random().nextInt(bse.highGold - bse.lowGold) + bse.lowGold; MobLoot goldAmount = new MobLoot(mob, (int) (gold * multiplier));
if (gold > 0) { mob.getCharItemManager().addItemToInventory(goldAmount);
MobLoot goldAmount = new MobLoot(mob, (int) (gold * multiplier)); }
mob.getCharItemManager().addItemToInventory(goldAmount);
}
break;
case "LOOT":
roll = ThreadLocalRandom.current().nextInt(101);
if (roll > dropChance) {
//early exit, failed to hit minimum chance roll
break; break;
} case "LOOT":
//iterate the booty tables and add items to mob inventory roll = ThreadLocalRandom.current().nextInt(101);
MobLoot toAdd = getGenTableItem(bse.lootTable, mob); if (roll > dropChance) {
if (toAdd != null) { //early exit, failed to hit minimum chance roll
if(toAdd.getPrefix() != null && toAdd.getPrefix().isEmpty() == true && toAdd.getSuffix()!= null && toAdd.getSuffix().isEmpty() == true){ break;
toAdd.setIsID(true);
} }
mob.getCharItemManager().addItemToInventory(toAdd); //iterate the booty tables and add items to mob inventory
} MobLoot toAdd = getGenTableItem(bse.lootTable, mob);
if (inHotzone) { if (toAdd != null) {
if (generalItemTables.containsKey(bse.lootTable + 1)) { if (toAdd.getPrefix() != null && toAdd.getPrefix().isEmpty() == true && toAdd.getSuffix() != null && toAdd.getSuffix().isEmpty() == true) {
int lootTableID = bse.lootTable + 1; toAdd.setIsID(true);
MobLoot toAddHZ = getGenTableItem(lootTableID, mob); }
if (toAddHZ != null) mob.getCharItemManager().addItemToInventory(toAdd);
if(toAdd.getPrefix() != null && toAdd.getPrefix().isEmpty() == true && toAdd.getSuffix()!= null && toAdd.getSuffix().isEmpty() == true){ }
toAdd.setIsID(true); if (inHotzone) {
} if (generalItemTables.containsKey(bse.lootTable + 1)) {
int lootTableID = bse.lootTable + 1;
MobLoot toAddHZ = getGenTableItem(lootTableID, mob);
if (toAddHZ != null)
if (toAdd.getPrefix() != null && toAdd.getPrefix().isEmpty() == true && toAdd.getSuffix() != null && toAdd.getSuffix().isEmpty() == true) {
toAdd.setIsID(true);
}
mob.getCharItemManager().addItemToInventory(toAddHZ); mob.getCharItemManager().addItemToInventory(toAddHZ);
}
} }
} break;
break; case "ITEM":
case "ITEM": MobLoot disc = new MobLoot(mob, ItemBase.getItemBase(bse.itemBase), true);
MobLoot disc = new MobLoot(mob, ItemBase.getItemBase(bse.itemBase), true); if (disc != null && !fromDeath)
if (disc != null && !fromDeath) mob.getCharItemManager().addItemToInventory(disc);
mob.getCharItemManager().addItemToInventory(disc);
break; break;
}
}
if (inHotzone) {
//hotzone glass roll, 1% chance to roll on glass table
if (ThreadLocalRandom.current().nextInt(101) > 99) {
int roll2 = TableRoll(mob.level);
if (itemTables.get(126).getRowForRange(roll2) == null) {
return;
}
ItemTableRow tableRow = itemTables.get(126).getRowForRange(roll2);
if(tableRow == null){
return;
} }
int itemUUID = tableRow.cacheID; }
if (itemUUID == 0) { if (inHotzone) {
return; //hotzone glass roll, 1% chance to roll on glass table
if (ThreadLocalRandom.current().nextInt(101) > 99) {
int roll2 = TableRoll(mob.level);
if (itemTables.get(126).getRowForRange(roll2) == null) {
return;
}
ItemTableRow tableRow = itemTables.get(126).getRowForRange(roll2);
if (tableRow == null) {
return;
}
int itemUUID = tableRow.cacheID;
if (itemUUID == 0) {
return;
}
MobLoot toAddHZ = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false);
if (toAddHZ != null)
mob.getCharItemManager().addItemToInventory(toAddHZ);
} }
MobLoot toAddHZ = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false);
if (toAddHZ != null)
mob.getCharItemManager().addItemToInventory(toAddHZ);
} }
setCount++;
}catch(Exception e){
//catch crash bug
int tableID = entry.lootTable;
String bootyType = entry.bootyType;
int itemBase = entry.itemBase;
Logger.error("FAILED LOOT ROLL: TableID: " + tableID + "bootyType: " + bootyType + " itemUUID: " + itemBase);
} }
} }
public static MobLoot getGenTableItem(int genTableID, Mob mob) { public static MobLoot getGenTableItem(int genTableID, Mob mob) {
try {
if (genTableID == 0 || mob == null || generalItemTables.containsKey(genTableID) == false) { if (genTableID == 0 || mob == null || generalItemTables.containsKey(genTableID) == false) {
return null; return null;
} }
@ -237,9 +245,6 @@ public class LootManager {
} }
} }
return outItem; return outItem;
}catch(Exception e){
return null;
}
} }
private static int TableRoll(int mobLevel){ private static int TableRoll(int mobLevel){
int max = (int)(4.882 * mobLevel + 121.0); int max = (int)(4.882 * mobLevel + 121.0);

Loading…
Cancel
Save