Browse Source

null pointer evasion

master
FatBoy-DOTC 1 year ago
parent
commit
57a38303f8
  1. 114
      src/engine/loot/LootManager.java

114
src/engine/loot/LootManager.java

@ -123,7 +123,7 @@ public class LootManager {
//iterate the booty tables and add items to mob inventory //iterate the booty tables and add items to mob inventory
MobLoot toAdd = getGenTableItem(bse.lootTable, mob); MobLoot toAdd = getGenTableItem(bse.lootTable, mob);
if (toAdd != null) { if (toAdd != null) {
if(toAdd.getPrefix().isEmpty() == true && toAdd.getSuffix().isEmpty() == true){ if(toAdd.getPrefix() != null && toAdd.getPrefix().isEmpty() == true && toAdd.getSuffix()!= null && toAdd.getSuffix().isEmpty() == true){
toAdd.setIsID(true); toAdd.setIsID(true);
} }
mob.getCharItemManager().addItemToInventory(toAdd); mob.getCharItemManager().addItemToInventory(toAdd);
@ -133,7 +133,7 @@ public class LootManager {
int lootTableID = bse.lootTable + 1; int lootTableID = bse.lootTable + 1;
MobLoot toAddHZ = getGenTableItem(lootTableID, mob); MobLoot toAddHZ = getGenTableItem(lootTableID, mob);
if (toAddHZ != null) if (toAddHZ != null)
if(toAdd.getPrefix().isEmpty() == true && toAdd.getSuffix().isEmpty() == true){ if(toAdd.getPrefix() != null && toAdd.getPrefix().isEmpty() == true && toAdd.getSuffix()!= null && toAdd.getSuffix().isEmpty() == true){
toAdd.setIsID(true); toAdd.setIsID(true);
} }
mob.getCharItemManager().addItemToInventory(toAddHZ); mob.getCharItemManager().addItemToInventory(toAddHZ);
@ -169,66 +169,70 @@ public class LootManager {
public static MobLoot getGenTableItem(int genTableID, Mob mob) { public static MobLoot getGenTableItem(int genTableID, Mob mob) {
if (genTableID == 0 || mob == null || generalItemTables.containsKey(genTableID) == false) { try {
return null; if (genTableID == 0 || mob == null || generalItemTables.containsKey(genTableID) == false) {
} return null;
MobLoot outItem; }
int genRoll = new Random().nextInt(101); MobLoot outItem;
GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(genRoll); int genRoll = new Random().nextInt(101);
if (selectedRow == null) { GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(genRoll);
return null; if (selectedRow == null) {
} return null;
int itemTableId = selectedRow.itemTableID; }
//gets the 1-320 roll for this mob int itemTableId = selectedRow.itemTableID;
int roll2 = TableRoll(mob.level); //gets the 1-320 roll for this mob
ItemTableRow tableRow = itemTables.get(itemTableId).getRowForRange(roll2); int roll2 = TableRoll(mob.level);
if (tableRow == null) { ItemTableRow tableRow = itemTables.get(itemTableId).getRowForRange(roll2);
return null; if (tableRow == null) {
} return null;
int itemUUID = tableRow.cacheID; }
if (itemUUID == 0) { int itemUUID = tableRow.cacheID;
return null; if (itemUUID == 0) {
} return null;
if (ItemBase.getItemBase(itemUUID).getType().ordinal() == Enum.ItemType.RESOURCE.ordinal()) { }
int amount = ThreadLocalRandom.current().nextInt(tableRow.maxSpawn - tableRow.minSpawn) + tableRow.minSpawn; if (ItemBase.getItemBase(itemUUID).getType().ordinal() == Enum.ItemType.RESOURCE.ordinal()) {
return new MobLoot(mob, ItemBase.getItemBase(itemUUID), amount, false); int amount = ThreadLocalRandom.current().nextInt(tableRow.maxSpawn - tableRow.minSpawn) + tableRow.minSpawn;
} return new MobLoot(mob, ItemBase.getItemBase(itemUUID), amount, false);
outItem = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false); }
Enum.ItemType outType = outItem.getItemBase().getType(); outItem = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false);
if (outType.ordinal() == Enum.ItemType.WEAPON.ordinal() || outType.ordinal() == Enum.ItemType.ARMOR.ordinal() || outType.ordinal() == Enum.ItemType.JEWELRY.ordinal()) { Enum.ItemType outType = outItem.getItemBase().getType();
if (outItem.getItemBase().isGlass() == false) { if (outType.ordinal() == Enum.ItemType.WEAPON.ordinal() || outType.ordinal() == Enum.ItemType.ARMOR.ordinal() || outType.ordinal() == Enum.ItemType.JEWELRY.ordinal()) {
int prefixChanceRoll = ThreadLocalRandom.current().nextInt(101); if (outItem.getItemBase().isGlass() == false) {
double prefixChance = 2.057 * mob.level - 28.67; int prefixChanceRoll = ThreadLocalRandom.current().nextInt(101);
if(prefixChanceRoll < prefixChance) { double prefixChance = 2.057 * mob.level - 28.67;
ModTypeTable prefixTable = modTypeTables.get(selectedRow.pModTable); if (prefixChanceRoll < prefixChance) {
ModTypeTable prefixTable = modTypeTables.get(selectedRow.pModTable);
int prefixroll = ThreadLocalRandom.current().nextInt(101);
if (modTables.get(prefixTable.getRowForRange(prefixroll).modTableID) != null) { int prefixroll = ThreadLocalRandom.current().nextInt(101);
ModTable prefixModTable = modTables.get(prefixTable.getRowForRange(prefixroll).modTableID); if (modTables.get(prefixTable.getRowForRange(prefixroll).modTableID) != null) {
ModTableRow prefixMod = prefixModTable.getRowForRange(TableRoll(mob.level)); ModTable prefixModTable = modTables.get(prefixTable.getRowForRange(prefixroll).modTableID);
if (prefixMod != null && prefixMod.action.length() > 0) { ModTableRow prefixMod = prefixModTable.getRowForRange(TableRoll(mob.level));
outItem.setPrefix(prefixMod.action); if (prefixMod != null && prefixMod.action.length() > 0) {
outItem.addPermanentEnchantment(prefixMod.action, 0, prefixMod.level, true); outItem.setPrefix(prefixMod.action);
outItem.addPermanentEnchantment(prefixMod.action, 0, prefixMod.level, true);
}
} }
} }
} int suffixChanceRoll = ThreadLocalRandom.current().nextInt(101);
int suffixChanceRoll = ThreadLocalRandom.current().nextInt(101); double suffixChance = 2.057 * mob.level - 28.67;
double suffixChance = 2.057 * mob.level - 28.67; if (suffixChanceRoll < suffixChance) {
if(suffixChanceRoll < suffixChance) { int suffixroll = ThreadLocalRandom.current().nextInt(101);
int suffixroll = ThreadLocalRandom.current().nextInt(101); ModTypeTable suffixTable = modTypeTables.get(selectedRow.sModTable);
ModTypeTable suffixTable = modTypeTables.get(selectedRow.sModTable); if (modTables.get(suffixTable.getRowForRange(suffixroll).modTableID) != null) {
if (modTables.get(suffixTable.getRowForRange(suffixroll).modTableID) != null) { ModTable suffixModTable = modTables.get(suffixTable.getRowForRange(suffixroll).modTableID);
ModTable suffixModTable = modTables.get(suffixTable.getRowForRange(suffixroll).modTableID); ModTableRow suffixMod = suffixModTable.getRowForRange(TableRoll(mob.level));
ModTableRow suffixMod = suffixModTable.getRowForRange(TableRoll(mob.level)); if (suffixMod != null && suffixMod.action.length() > 0) {
if (suffixMod != null && suffixMod.action.length() > 0) { outItem.setSuffix(suffixMod.action);
outItem.setSuffix(suffixMod.action); outItem.addPermanentEnchantment(suffixMod.action, 0, suffixMod.level, false);
outItem.addPermanentEnchantment(suffixMod.action, 0, suffixMod.level, false); }
} }
} }
} }
} }
return outItem;
}catch(Exception e){
return null;
} }
return outItem;
} }
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