Browse Source

Caching of drop rates within LootManager

master
MagicBot 1 year ago
parent
commit
95a9e45391
  1. 1
      src/engine/gameManager/ConfigManager.java
  2. 360
      src/engine/gameManager/LootManager.java
  3. 59
      src/engine/objects/Experience.java
  4. 5
      src/engine/objects/LootTable.java
  5. 2
      src/engine/server/world/WorldServer.java

1
src/engine/gameManager/ConfigManager.java

@ -109,7 +109,6 @@ public enum ConfigManager {
// Called at bootstrap: ensures that all config values are loaded. // Called at bootstrap: ensures that all config values are loaded.
public static boolean init() { public static boolean init() {
Logger.info("Loading config from environment..."); Logger.info("Loading config from environment...");

360
src/engine/gameManager/LootManager.java

@ -24,7 +24,9 @@ import java.util.concurrent.ThreadLocalRandom;
/** /**
* Class contains static methods for data from Magicbane's loot tables * Class contains static methods for data from Magicbane's loot tables
*/ */
public class LootManager { public enum LootManager {
LOOTMANAGER;
//new tables //new tables
private static final HashMap<Integer, GenTable> generalItemTables = new HashMap<>(); private static final HashMap<Integer, GenTable> generalItemTables = new HashMap<>();
@ -32,37 +34,63 @@ public class LootManager {
private static final HashMap<Integer, ModTypeTable> modTypeTables = new HashMap<>(); private static final HashMap<Integer, ModTypeTable> modTypeTables = new HashMap<>();
private static final HashMap<Integer, ModTable> modTables = new HashMap<>(); private static final HashMap<Integer, ModTable> modTables = new HashMap<>();
private LootManager() { // Drop Rates
}
public static float NORMAL_DROP_RATE;
public static float NORMAL_EXP_RATE;
public static float NORMAL_GOLD_RATE;
public static float HOTZONE_DROP_RATE;
public static float HOTZONE_EXP_RATE;
public static float HOTZONE_GOLD_RATE;
// Bootstrap routine to initialize the Loot Manager
public static void init() {
// Bootstrap routine to load loot data from database
public static void loadLootData() {
DbManager.LootQueries.LOAD_ALL_LOOTGROUPS(); DbManager.LootQueries.LOAD_ALL_LOOTGROUPS();
DbManager.LootQueries.LOAD_ALL_LOOTTABLES(); DbManager.LootQueries.LOAD_ALL_LOOTTABLES();
DbManager.LootQueries.LOAD_ALL_MODGROUPS(); DbManager.LootQueries.LOAD_ALL_MODGROUPS();
DbManager.LootQueries.LOAD_ALL_MODTABLES(); DbManager.LootQueries.LOAD_ALL_MODTABLES();
NORMAL_DROP_RATE = Float.parseFloat(ConfigManager.MB_NORMAL_DROP_RATE.getValue());
NORMAL_EXP_RATE = Float.parseFloat(ConfigManager.MB_NORMAL_EXP_RATE.getValue());
NORMAL_GOLD_RATE = Float.parseFloat(ConfigManager.MB_NORMAL_GOLD_RATE.getValue());
HOTZONE_DROP_RATE = Float.parseFloat(ConfigManager.MB_HOTZONE_DROP_RATE.getValue());
HOTZONE_EXP_RATE = Float.parseFloat(ConfigManager.MB_HOTZONE_EXP_RATE.getValue());
HOTZONE_GOLD_RATE = Float.parseFloat(ConfigManager.MB_HOTZONE_GOLD_RATE.getValue());
} }
public static void GenerateMobLoot(Mob mob, boolean fromDeath) { public static void GenerateMobLoot(Mob mob, boolean fromDeath) {
//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
float multiplier = Float.parseFloat(ConfigManager.MB_NORMAL_DROP_RATE.getValue());
if (inHotzone) { float multiplier = NORMAL_DROP_RATE;
//if mob is inside hotzone, use the hotzone multiplier from the config instead
multiplier = Float.parseFloat(ConfigManager.MB_HOTZONE_DROP_RATE.getValue()); //if mob is inside hotzone, use the hotzone multiplier from the config instead
}
if (inHotzone)
multiplier = HOTZONE_DROP_RATE;
//iterate the booty sets //iterate the booty sets
if (mob.getMobBase().bootySet != 0 && NPCManager._bootySetMap.containsKey(mob.getMobBase().bootySet) == true) {
RunBootySet(NPCManager._bootySetMap.get(mob.getMobBase().bootySet), mob, multiplier, inHotzone, fromDeath); if (mob.getMobBase().bootySet != 0 && NPCManager._bootySetMap.containsKey(mob.getMobBase().bootySet) == true)
} RunBootySet(NPCManager._bootySetMap.get(mob.getMobBase().bootySet), mob, multiplier, inHotzone, fromDeath);
if (mob.bootySet != 0 && NPCManager._bootySetMap.containsKey(mob.bootySet) == true) {
if (mob.bootySet != 0 && NPCManager._bootySetMap.containsKey(mob.bootySet) == true)
RunBootySet(NPCManager._bootySetMap.get(mob.bootySet), mob, multiplier, inHotzone, fromDeath); RunBootySet(NPCManager._bootySetMap.get(mob.bootySet), mob, multiplier, inHotzone, fromDeath);
}
//lastly, check mobs inventory for godly or disc runes to send a server announcement //lastly, check mobs inventory for godly or disc runes to send a server announcement
if (!fromDeath) { if (!fromDeath) {
for (Item it : mob.getInventory()) { for (Item it : mob.getInventory()) {
ItemBase ib = it.getItemBase(); ItemBase ib = it.getItemBase();
if (ib.isDiscRune() || ib.getName().toLowerCase().contains("of the gods")) { if (ib.isDiscRune() || ib.getName().toLowerCase().contains("of the gods")) {
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mob.getName() + " in " + mob.getParentZone().getName() + " has found the " + ib.getName() + ". Are you tough enough to take it?"); ChatSystemMsg chatMsg = new ChatSystemMsg(null, mob.getName() + " in " + mob.getParentZone().getName() + " has found the " + ib.getName() + ". Are you tough enough to take it?");
chatMsg.setMessageType(10); chatMsg.setMessageType(10);
@ -73,21 +101,23 @@ public class LootManager {
} }
} }
} }
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) {
if (fromDeath)
DropEquipment(mob, multiplier); DropEquipment(mob, multiplier);
} else { else {
for (BootySetEntry bse : entries) { for (BootySetEntry bse : entries) {
switch (bse.bootyType) { switch (bse.bootyType) {
case "GOLD": case "GOLD":
GenerateGoldDrop(mob, bse, inHotzone); GenerateGoldDrop(mob, bse, inHotzone);
break; break;
case "LOOT": case "LOOT":
GenerateLootDrop(mob, bse.lootTable, bse.dropChance, multiplier);//generate normal loot drop GenerateLootDrop(mob, bse.lootTable, bse.dropChance, multiplier); //generate normal loot drop
if (inHotzone) {
if (inHotzone)
if (generalItemTables.containsKey(bse.lootTable + 1)) if (generalItemTables.containsKey(bse.lootTable + 1))
GenerateLootDrop(mob, bse.lootTable + 1, bse.dropChance, multiplier);//generate loot drop from hotzone table GenerateLootDrop(mob, bse.lootTable + 1, bse.dropChance, multiplier); //generate loot drop from hotzone table
}
break; break;
case "ITEM": case "ITEM":
GenerateItemLootDrop(mob, bse, multiplier); GenerateItemLootDrop(mob, bse, multiplier);
@ -96,60 +126,79 @@ 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) {
return null; if (genTableID == 0 || mob == null || generalItemTables.containsKey(genTableID) == false)
} return null;
MobLoot outItem;
int genRoll; MobLoot outItem;
genRoll = new Random().nextInt(99) + 1; int genRoll;
GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(genRoll);
if (selectedRow == null) { genRoll = new Random().nextInt(99) + 1;
return null; GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(genRoll);
}
int itemTableId = selectedRow.itemTableID; if (selectedRow == null)
//gets the 1-320 roll for this mob return null;
int itemTableId = selectedRow.itemTableID;
//gets the 1-320 roll for this mob
int roll2 = TableRoll(mob.level); int roll2 = TableRoll(mob.level);
ItemTableRow tableRow = itemTables.get(itemTableId).getRowForRange(roll2);
if (tableRow == null) { ItemTableRow tableRow = itemTables.get(itemTableId).getRowForRange(roll2);
return null;
} if (tableRow == null)
int itemUUID = tableRow.cacheID; return null;
if (itemUUID == 0) {
return null; int itemUUID = tableRow.cacheID;
}
if (ItemBase.getItemBase(itemUUID).getType().ordinal() == Enum.ItemType.RESOURCE.ordinal()) { if (itemUUID == 0)
int amount = ThreadLocalRandom.current().nextInt(tableRow.maxSpawn - tableRow.minSpawn) + tableRow.minSpawn; return null;
return new MobLoot(mob, ItemBase.getItemBase(itemUUID), amount, false);
} if (ItemBase.getItemBase(itemUUID).getType().ordinal() == Enum.ItemType.RESOURCE.ordinal()) {
outItem = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false); int amount = ThreadLocalRandom.current().nextInt(tableRow.maxSpawn - tableRow.minSpawn) + tableRow.minSpawn;
Enum.ItemType outType = outItem.getItemBase().getType(); return new MobLoot(mob, ItemBase.getItemBase(itemUUID), amount, false);
if (outType.ordinal() == Enum.ItemType.WEAPON.ordinal() || outType.ordinal() == Enum.ItemType.ARMOR.ordinal() || outType.ordinal() == Enum.ItemType.JEWELRY.ordinal()) { }
if (outItem.getItemBase().isGlass() == false) {
try { outItem = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false);
outItem = GeneratePrefix(mob, outItem, genTableID, genRoll); Enum.ItemType outType = outItem.getItemBase().getType();
} catch(Exception e){
Logger.error("Failed to GeneratePrefix for item: " + outItem.getName()); if (outType.ordinal() == Enum.ItemType.WEAPON.ordinal() || outType.ordinal() == Enum.ItemType.ARMOR.ordinal() || outType.ordinal() == Enum.ItemType.JEWELRY.ordinal()) {
} if (outItem.getItemBase().isGlass() == false) {
try{ try {
outItem = GenerateSuffix(mob,outItem,genTableID,genRoll); outItem = GeneratePrefix(mob, outItem, genTableID, genRoll);
} catch(Exception e){ } catch (Exception e) {
Logger.error("Failed to GenerateSuffix for item: " + outItem.getName()); Logger.error("Failed to GeneratePrefix for item: " + outItem.getName());
} }
try {
outItem = GenerateSuffix(mob, outItem, genTableID, genRoll);
} catch (Exception e) {
Logger.error("Failed to GenerateSuffix for item: " + outItem.getName());
} }
} }
return outItem; }
return outItem;
} }
private static MobLoot GeneratePrefix(Mob mob, MobLoot inItem, int genTableID, int genRoll){
int prefixChanceRoll = ThreadLocalRandom.current().nextInt(99)+1; private static MobLoot GeneratePrefix(Mob mob, MobLoot inItem, int genTableID, int genRoll) {
int prefixChanceRoll = ThreadLocalRandom.current().nextInt(99) + 1;
double prefixChance = 2.057 * mob.level - 28.67; double prefixChance = 2.057 * mob.level - 28.67;
if (prefixChanceRoll < prefixChance) { if (prefixChanceRoll < prefixChance) {
GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(genRoll); GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(genRoll);
ModTypeTable prefixTable = modTypeTables.get(selectedRow.pModTable); ModTypeTable prefixTable = modTypeTables.get(selectedRow.pModTable);
int prefixroll = ThreadLocalRandom.current().nextInt(99)+1;
int prefixroll = ThreadLocalRandom.current().nextInt(99) + 1;
if (modTables.get(prefixTable.getRowForRange(prefixroll).modTableID) != null) { if (modTables.get(prefixTable.getRowForRange(prefixroll).modTableID) != null) {
ModTable prefixModTable = modTables.get(prefixTable.getRowForRange(prefixroll).modTableID); ModTable prefixModTable = modTables.get(prefixTable.getRowForRange(prefixroll).modTableID);
ModTableRow prefixMod = prefixModTable.getRowForRange(TableRoll(mob.level)); ModTableRow prefixMod = prefixModTable.getRowForRange(TableRoll(mob.level));
if (prefixMod != null && prefixMod.action.length() > 0) { if (prefixMod != null && prefixMod.action.length() > 0) {
inItem.setPrefix(prefixMod.action); inItem.setPrefix(prefixMod.action);
inItem.addPermanentEnchantment(prefixMod.action, 0, prefixMod.level, true); inItem.addPermanentEnchantment(prefixMod.action, 0, prefixMod.level, true);
@ -158,16 +207,23 @@ public class LootManager {
} }
return inItem; return inItem;
} }
private static MobLoot GenerateSuffix(Mob mob, MobLoot inItem, int genTableID, int genRoll){
int suffixChanceRoll = ThreadLocalRandom.current().nextInt(99)+1; private static MobLoot GenerateSuffix(Mob mob, MobLoot inItem, int genTableID, int genRoll) {
int suffixChanceRoll = ThreadLocalRandom.current().nextInt(99) + 1;
double suffixChance = 2.057 * mob.level - 28.67; double suffixChance = 2.057 * mob.level - 28.67;
if (suffixChanceRoll < suffixChance) { if (suffixChanceRoll < suffixChance) {
GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(genRoll); GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(genRoll);
int suffixroll = ThreadLocalRandom.current().nextInt(99)+1; int suffixroll = ThreadLocalRandom.current().nextInt(99) + 1;
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) {
inItem.setSuffix(suffixMod.action); inItem.setSuffix(suffixMod.action);
inItem.addPermanentEnchantment(suffixMod.action, 0, suffixMod.level, false); inItem.addPermanentEnchantment(suffixMod.action, 0, suffixMod.level, false);
@ -176,94 +232,116 @@ public class LootManager {
} }
return inItem; return inItem;
} }
private static int TableRoll(int mobLevel){
if(mobLevel > 65){ private static int TableRoll(int mobLevel) {
if (mobLevel > 65)
mobLevel = 65; mobLevel = 65;
}
int max = (int)(4.882 * mobLevel + 127.0); int max = (int) (4.882 * mobLevel + 127.0);
if(max > 321){
max = 321; if (max > 319)
} max = 319;
int min = (int)(4.469 * mobLevel - 3.469);
//if(isHotzone == true){ int min = (int) (4.469 * mobLevel - 3.469);
// min += mobLevel; int roll = ThreadLocalRandom.current().nextInt(max - min) + min;
// if(min > 220){
// min = 220;
// }
//}
int roll = ThreadLocalRandom.current().nextInt(max-min) + min;
return roll; return roll;
} }
public static void GenerateGoldDrop(Mob mob, BootySetEntry bse, Boolean inHotzone){
public static void GenerateGoldDrop(Mob mob, BootySetEntry bse, Boolean inHotzone) {
int chanceRoll = ThreadLocalRandom.current().nextInt(99) + 1; int chanceRoll = ThreadLocalRandom.current().nextInt(99) + 1;
if (chanceRoll > bse.dropChance) {
//early exit, failed to hit minimum chance roll OR booty was generated from mob's death //early exit, failed to hit minimum chance roll OR booty was generated from mob's death
if (chanceRoll > bse.dropChance)
return; return;
}
//determine and add gold to mob inventory //determine and add gold to mob inventory
int high = bse.highGold; int high = bse.highGold;
int low = bse.lowGold; int low = bse.lowGold;
int gold = ThreadLocalRandom.current().nextInt(high - low) + low; int gold = ThreadLocalRandom.current().nextInt(high - low) + low;
if(inHotzone == true){
gold = (int)(gold * Float.parseFloat(ConfigManager.MB_HOTZONE_GOLD_RATE.getValue())); if (inHotzone == true)
} else{ gold = (int) (gold * HOTZONE_GOLD_RATE);
gold = (int)(gold * Float.parseFloat(ConfigManager.MB_NORMAL_GOLD_RATE.getValue())); else
} gold = (int) (NORMAL_GOLD_RATE);
if (gold > 0) { if (gold > 0) {
MobLoot goldAmount = new MobLoot(mob, gold); MobLoot goldAmount = new MobLoot(mob, gold);
mob.getCharItemManager().addItemToInventory(goldAmount); mob.getCharItemManager().addItemToInventory(goldAmount);
} }
} }
public static void GenerateLootDrop(Mob mob, int tableID, float dropChance,float multiplier){
try{ public static void GenerateLootDrop(Mob mob, int tableID, float dropChance, float multiplier) {
int chanceRoll = ThreadLocalRandom.current().nextInt(99) + 1;
if (chanceRoll > dropChance * multiplier) { try {
int chanceRoll = ThreadLocalRandom.current().nextInt(99) + 1;
//early exit, failed to hit minimum chance roll //early exit, failed to hit minimum chance roll
return;
} if (chanceRoll > dropChance * multiplier)
MobLoot toAdd = getGenTableItem(tableID, mob); return;
if (toAdd != null) {
if(toAdd.getPrefix() == null && toAdd.getSuffix() == null){ MobLoot toAdd = getGenTableItem(tableID, mob);
toAdd.setIsID(true);
if (toAdd != null) {
if (toAdd.getPrefix() == null && toAdd.getSuffix() == null)
toAdd.setIsID(true);
mob.getCharItemManager().addItemToInventory(toAdd);
} }
mob.getCharItemManager().addItemToInventory(toAdd); } catch (Exception e) {
}
}
catch(Exception e){
//TODO chase down loot generation error, affects roughly 2% of drops //TODO chase down loot generation error, affects roughly 2% of drops
int i = 0; int i = 0;
} }
} }
public static void DropEquipment(Mob mob, float multiplier){
public static void DropEquipment(Mob mob, float multiplier) {
//do equipment here //do equipment here
if (mob.getEquip() != null) { if (mob.getEquip() != null) {
for (MobEquipment me : mob.getEquip().values()) { for (MobEquipment me : mob.getEquip().values()) {
if (me.getDropChance() == 0) if (me.getDropChance() == 0)
continue; continue;
float equipmentRoll = ThreadLocalRandom.current().nextInt(101); float equipmentRoll = ThreadLocalRandom.current().nextInt(101);
float dropChance = me.getDropChance() * 100; float dropChance = me.getDropChance() * 100;
if (equipmentRoll <= (dropChance * multiplier)) { if (equipmentRoll <= (dropChance * multiplier)) {
MobLoot ml = new MobLoot(mob, me.getItemBase(), false); MobLoot ml = new MobLoot(mob, me.getItemBase(), false);
if (ml.getPrefix().isEmpty() == true && ml.getSuffix().isEmpty() == true) {
if (ml.getPrefix().isEmpty() == true && ml.getSuffix().isEmpty() == true)
ml.setIsID(true); ml.setIsID(true);
}
mob.getCharItemManager().addItemToInventory(ml); mob.getCharItemManager().addItemToInventory(ml);
} }
} }
} }
return;
} }
public static void GenerateItemLootDrop(Mob mob, BootySetEntry bse, float multiplier){
public static void GenerateItemLootDrop(Mob mob, BootySetEntry bse, float multiplier) {
int chanceRoll = ThreadLocalRandom.current().nextInt(99) + 1; int chanceRoll = ThreadLocalRandom.current().nextInt(99) + 1;
if (chanceRoll > bse.dropChance * multiplier) {
//early exit, failed to hit minimum chance roll //early exit, failed to hit minimum chance roll
if (chanceRoll > bse.dropChance * multiplier)
return; return;
}
MobLoot disc = new MobLoot(mob, ItemBase.getItemBase(bse.itemBase), true); MobLoot disc = new MobLoot(mob, ItemBase.getItemBase(bse.itemBase), true);
if (disc != null) if (disc != null)
mob.getCharItemManager().addItemToInventory(disc); mob.getCharItemManager().addItemToInventory(disc);
} }
public static void AddGenTableRow(int tableID, GenTableRow row) { public static void AddGenTableRow(int tableID, GenTableRow row) {
if (!generalItemTables.containsKey(tableID)) { if (!generalItemTables.containsKey(tableID)) {
//create the new table //create the new table
GenTable gt = new GenTable(); GenTable gt = new GenTable();
@ -275,7 +353,9 @@ public class LootManager {
toAdd.rows.add(row); toAdd.rows.add(row);
} }
} }
public static void AddItemTableRow(int tableID, ItemTableRow row) { public static void AddItemTableRow(int tableID, ItemTableRow row) {
if (!itemTables.containsKey(tableID)) { if (!itemTables.containsKey(tableID)) {
//create the new table //create the new table
ItemTable it = new ItemTable(); ItemTable it = new ItemTable();
@ -287,7 +367,9 @@ public class LootManager {
toAdd.rows.add(row); toAdd.rows.add(row);
} }
} }
public static void AddModTypeTableRow(int tableID, ModTypeTableRow row) { public static void AddModTypeTableRow(int tableID, ModTypeTableRow row) {
if (!modTypeTables.containsKey(tableID)) { if (!modTypeTables.containsKey(tableID)) {
//create the new table //create the new table
ModTypeTable mtt = new ModTypeTable(); ModTypeTable mtt = new ModTypeTable();
@ -299,7 +381,9 @@ public class LootManager {
toAdd.rows.add(row); toAdd.rows.add(row);
} }
} }
public static void AddModTableRow(int tableID, ModTableRow row) { public static void AddModTableRow(int tableID, ModTableRow row) {
if (!modTables.containsKey(tableID)) { if (!modTables.containsKey(tableID)) {
//create the new table //create the new table
ModTable mt = new ModTable(); ModTable mt = new ModTable();
@ -311,64 +395,73 @@ public class LootManager {
toAdd.rows.add(row); toAdd.rows.add(row);
} }
} }
public static class GenTable { public static class GenTable {
public ArrayList<GenTableRow> rows = new ArrayList<GenTableRow>(); public ArrayList<GenTableRow> rows = new ArrayList<GenTableRow>();
public GenTableRow getRowForRange(int roll) { public GenTableRow getRowForRange(int roll) {
GenTableRow outRow = null; GenTableRow outRow = null;
for (GenTableRow iteration : this.rows) {
if (roll >= iteration.minRoll && roll <= iteration.maxRoll) { for (GenTableRow iteration : this.rows)
if (roll >= iteration.minRoll && roll <= iteration.maxRoll)
outRow = iteration; outRow = iteration;
}
}
return outRow; return outRow;
} }
} }
public static class ItemTable { public static class ItemTable {
public ArrayList<ItemTableRow> rows = new ArrayList<ItemTableRow>(); public ArrayList<ItemTableRow> rows = new ArrayList<ItemTableRow>();
public ItemTableRow getRowForRange(int roll) { public ItemTableRow getRowForRange(int roll) {
if (roll > 320) {
if (roll > 320)
roll = 320; roll = 320;
}
ItemTableRow outRow = null; ItemTableRow outRow = null;
for (ItemTableRow iteration : this.rows) {
if (roll >= iteration.minRoll && roll <= iteration.maxRoll) { for (ItemTableRow iteration : this.rows)
if (roll >= iteration.minRoll && roll <= iteration.maxRoll)
outRow = iteration; outRow = iteration;
}
}
return outRow; return outRow;
} }
} }
public static class ModTypeTable { public static class ModTypeTable {
public ArrayList<ModTypeTableRow> rows = new ArrayList<ModTypeTableRow>(); public ArrayList<ModTypeTableRow> rows = new ArrayList<ModTypeTableRow>();
public ModTypeTableRow getRowForRange(int roll) { public ModTypeTableRow getRowForRange(int roll) {
ModTypeTableRow outRow = null; ModTypeTableRow outRow = null;
for (ModTypeTableRow iteration : this.rows) {
if (roll >= iteration.minRoll && roll <= iteration.maxRoll) { for (ModTypeTableRow iteration : this.rows)
if (roll >= iteration.minRoll && roll <= iteration.maxRoll)
return iteration; return iteration;
}
}
return outRow; return outRow;
} }
} }
public static class ModTable { public static class ModTable {
public ArrayList<ModTableRow> rows = new ArrayList<ModTableRow>(); public ArrayList<ModTableRow> rows = new ArrayList<ModTableRow>();
public ModTableRow getRowForRange(int roll) { public ModTableRow getRowForRange(int roll) {
if (roll > 320) {
if (roll > 320)
roll = 320; roll = 320;
}
ModTableRow outRow = null; ModTableRow outRow = null;
for (ModTableRow iteration : this.rows) {
if (roll >= iteration.minRoll && roll <= iteration.maxRoll) { for (ModTableRow iteration : this.rows)
if (roll >= iteration.minRoll && roll <= iteration.maxRoll)
outRow = iteration; outRow = iteration;
}
}
return outRow; return outRow;
} }
} }
public static class GenTableRow { public static class GenTableRow {
public int minRoll; public int minRoll;
public int maxRoll; public int maxRoll;
@ -384,6 +477,7 @@ public class LootManager {
this.sModTable = rs.getInt("sModTableID"); this.sModTable = rs.getInt("sModTableID");
} }
} }
public static class ItemTableRow { public static class ItemTableRow {
public int minRoll; public int minRoll;
public int maxRoll; public int maxRoll;
@ -400,6 +494,7 @@ public class LootManager {
} }
} }
public static class ModTypeTableRow { public static class ModTypeTableRow {
public int minRoll; public int minRoll;
public int maxRoll; public int maxRoll;
@ -412,6 +507,7 @@ public class LootManager {
} }
} }
public static class ModTableRow { public static class ModTableRow {
public int minRoll; public int minRoll;
public int maxRoll; public int maxRoll;

59
src/engine/objects/Experience.java

@ -10,7 +10,6 @@
package engine.objects; package engine.objects;
import engine.Enum.TargetColor; import engine.Enum.TargetColor;
import engine.gameManager.ConfigManager;
import engine.gameManager.ZoneManager; import engine.gameManager.ZoneManager;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
@ -18,6 +17,8 @@ import engine.server.MBServerStatics;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.TreeMap; import java.util.TreeMap;
import static engine.gameManager.LootManager.LOOTMANAGER;
public class Experience { public class Experience {
private static final TreeMap<Integer, Integer> ExpToLevel; private static final TreeMap<Integer, Integer> ExpToLevel;
@ -238,44 +239,44 @@ public class Experience {
// called to determine current level based on xp // called to determine current level based on xp
public static int getLevel(int experience) { public static int getLevel(int experience) {
int expKey = ExpToLevel.floorKey(experience); int expKey = ExpToLevel.floorKey(experience);
int level = ExpToLevel.get(expKey); int level = ExpToLevel.get(expKey);
if (level > MBServerStatics.LEVELCAP) {
if (level > MBServerStatics.LEVELCAP)
level = MBServerStatics.LEVELCAP; level = MBServerStatics.LEVELCAP;
}
return level; return level;
} }
// Get the base xp for a level // Get the base xp for a level
public static int getBaseExperience(int level) { public static int getBaseExperience(int level) {
if (level < LevelToExp.length) {
if (level < LevelToExp.length)
return LevelToExp[level]; return LevelToExp[level];
}
int fLevel = level - 1; int fLevel = level - 1;
int baseXP = fLevel * fLevel * fLevel; int baseXP = fLevel * fLevel * fLevel;
return (int) ((fLevel < 40) ? (baseXP * 150) return (int) ((fLevel < 40) ? (baseXP * 150)
: (baseXP * (150 + (7.6799998 * (level - 40))))); : (baseXP * (150 + (7.6799998 * (level - 40)))));
} }
// Get XP needed for the next level
public static int getExpForNextLevel(int experience, int currentLevel) {
return (getBaseExperience(currentLevel + 1) - experience);
}
// Max XP granted for killing a blue, yellow or orange mob // Max XP granted for killing a blue, yellow or orange mob
public static float maxXPPerKill(int level) { public static float maxXPPerKill(int level) {
if (level < 1) if (level < 1)
level = 1; level = 1;
if (level > 75) if (level > 75)
level = 75; level = 75;
return MaxExpPerLevel[level]; return MaxExpPerLevel[level];
// return (LevelToExp[level + 1] - LevelToExp[level])/(11 + level/2);
// return ((((level * level)-level)*50)+16);
} }
// Returns a penalty modifier depending on mob color // Returns a penalty modifier depending on mob color
public static double getConMod(AbstractCharacter pc, AbstractCharacter mob) { public static double getConMod(AbstractCharacter pc, AbstractCharacter mob) {
switch (TargetColor.getCon(pc, mob)) { switch (TargetColor.getCon(pc, mob)) {
case Red: case Red:
return 1.25; return 1.25;
@ -299,16 +300,16 @@ public class Experience {
int highestLevel) { int highestLevel) {
double penalty = 0.0; double penalty = 0.0;
int adjustedGroupSize = 0;
int totalLevels = 0;
int level = currPlayer.getLevel(); int level = currPlayer.getLevel();
// Group Size Penalty // Group Size Penalty
if (players.size() > 2) if (players.size() > 2)
penalty = (players.size() - 2) * 1.5; penalty = (players.size() - 2) * 1.5;
// Calculate Penalty For Highest level -> Current Player difference, != // Calculate Penalty For Highest level -> Current Player difference, !=
// check to prevent divide by zero error // check to prevent divide by zero error
if (highestLevel != level) if (highestLevel != level)
penalty += ((highestLevel - level) * .5); penalty += ((highestLevel - level) * .5);
@ -318,6 +319,7 @@ public class Experience {
// penalty += ((avgLevels - level) * .5); // penalty += ((avgLevels - level) * .5);
// Extra noob penalty // Extra noob penalty
if ((highestLevel - level) > 25) if ((highestLevel - level) > 25)
penalty += (highestLevel - level - 25); penalty += (highestLevel - level - 25);
@ -325,7 +327,9 @@ public class Experience {
} }
public static void doExperience(PlayerCharacter killer, AbstractCharacter mob, Group g) { public static void doExperience(PlayerCharacter killer, AbstractCharacter mob, Group g) {
// Check for some failure conditions // Check for some failure conditions
if (killer == null || mob == null) if (killer == null || mob == null)
return; return;
@ -341,10 +345,13 @@ public class Experience {
// Check if leader is within range of kill and then get leadership // Check if leader is within range of kill and then get leadership
// skill // skill
Vector3fImmutable killLoc = mob.getLoc(); Vector3fImmutable killLoc = mob.getLoc();
if (killLoc.distanceSquared2D(g.getGroupLead().getLoc()) < (MBServerStatics.EXP_RANGE * MBServerStatics.EXP_RANGE)) { if (killLoc.distanceSquared2D(g.getGroupLead().getLoc()) < (MBServerStatics.EXP_RANGE * MBServerStatics.EXP_RANGE)) {
CharacterSkill leaderskill = g.getGroupLead().skills CharacterSkill leaderskill = g.getGroupLead().skills
.get("Leadership"); .get("Leadership");
if (leaderskill != null) if (leaderskill != null)
leadership = leaderskill.getNumTrains(); leadership = leaderskill.getNumTrains();
if (leadership > 90) if (leadership > 90)
@ -352,13 +359,18 @@ public class Experience {
} }
// Check every group member for distance to see if they get xp // Check every group member for distance to see if they get xp
for (PlayerCharacter pc : g.getMembers()) { for (PlayerCharacter pc : g.getMembers()) {
if (pc.isAlive()) { // Skip if the player is dead. if (pc.isAlive()) { // Skip if the player is dead.
// Check within range // Check within range
if (killLoc.distanceSquared2D(pc.getLoc()) < (MBServerStatics.EXP_RANGE * MBServerStatics.EXP_RANGE)) { if (killLoc.distanceSquared2D(pc.getLoc()) < (MBServerStatics.EXP_RANGE * MBServerStatics.EXP_RANGE)) {
giveEXPTo.add(pc); giveEXPTo.add(pc);
// Track highest level character // Track highest level character
if (pc.getLevel() > highestLevel) if (pc.getLevel() > highestLevel)
highestLevel = pc.getLevel(); highestLevel = pc.getLevel();
} }
@ -366,34 +378,41 @@ public class Experience {
} }
// Process every player in the group getting XP // Process every player in the group getting XP
for (PlayerCharacter playerCharacter : giveEXPTo) { for (PlayerCharacter playerCharacter : giveEXPTo) {
if (playerCharacter.getLevel() >= MBServerStatics.LEVELCAP) if (playerCharacter.getLevel() >= MBServerStatics.LEVELCAP)
continue; continue;
// Sets Max XP with server exp mod taken into account. // Sets Max XP with server exp mod taken into account.
grantedExperience = (double) Float.parseFloat(ConfigManager.MB_NORMAL_EXP_RATE.getValue()) * maxXPPerKill(playerCharacter.getLevel());
grantedExperience = (double) LOOTMANAGER.NORMAL_EXP_RATE * maxXPPerKill(playerCharacter.getLevel());
// Adjust XP for Mob Level // Adjust XP for Mob Level
grantedExperience *= getConMod(playerCharacter, mob); grantedExperience *= getConMod(playerCharacter, mob);
// Process XP for this member // Process XP for this member
penalty = getGroupMemberPenalty(leadership, playerCharacter, giveEXPTo, penalty = getGroupMemberPenalty(leadership, playerCharacter, giveEXPTo,
highestLevel); highestLevel);
// Leadership Penalty Reduction // Leadership Penalty Reduction
if (leadership > 0) if (leadership > 0)
penalty -= ((leadership) * 0.01) * penalty; penalty -= ((leadership) * 0.01) * penalty;
// Modify for hotzone // Modify for hotzone
if (grantedExperience != 0) if (grantedExperience != 0)
if (ZoneManager.inHotZone(mob.getLoc())) if (ZoneManager.inHotZone(mob.getLoc()))
grantedExperience *= Float.parseFloat(ConfigManager.MB_HOTZONE_EXP_RATE.getValue()); grantedExperience *= LOOTMANAGER.HOTZONE_EXP_RATE;
// Check for 0 XP due to white mob, otherwise subtract penalty // Check for 0 XP due to white mob, otherwise subtract penalty
// xp // xp
if (grantedExperience == 0) {
if (grantedExperience == 0)
grantedExperience = 1; grantedExperience = 1;
} else { else {
grantedExperience -= (penalty * 0.01) * grantedExperience; grantedExperience -= (penalty * 0.01) * grantedExperience;
// Errant Penalty Calculation // Errant Penalty Calculation
@ -416,12 +435,12 @@ public class Experience {
return; return;
// Get XP and adjust for Mob Level with world xp modifier taken into account // Get XP and adjust for Mob Level with world xp modifier taken into account
grantedExperience = (double) Float.parseFloat(ConfigManager.MB_NORMAL_EXP_RATE.getValue()) * maxXPPerKill(killer.getLevel()); grantedExperience = (double) LOOTMANAGER.NORMAL_EXP_RATE * maxXPPerKill(killer.getLevel());
grantedExperience *= getConMod(killer, mob); grantedExperience *= getConMod(killer, mob);
// Modify for hotzone // Modify for hotzone
if (ZoneManager.inHotZone(mob.getLoc())) if (ZoneManager.inHotZone(mob.getLoc()))
grantedExperience *= Float.parseFloat(ConfigManager.MB_HOTZONE_EXP_RATE.getValue()); grantedExperience *= LOOTMANAGER.HOTZONE_EXP_RATE;
// Errant penalty // Errant penalty
if (grantedExperience != 1) if (grantedExperience != 1)

5
src/engine/objects/LootTable.java

@ -12,7 +12,6 @@ package engine.objects;
import engine.Enum.ItemContainerType; import engine.Enum.ItemContainerType;
import engine.Enum.ItemType; import engine.Enum.ItemType;
import engine.Enum.OwnerType; import engine.Enum.OwnerType;
import engine.gameManager.ConfigManager;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.gameManager.NPCManager; import engine.gameManager.NPCManager;
import engine.gameManager.ZoneManager; import engine.gameManager.ZoneManager;
@ -25,6 +24,8 @@ import java.util.Random;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import static engine.gameManager.LootManager.LOOTMANAGER;
public class LootTable { public class LootTable {
private static final ConcurrentHashMap<Integer, LootTable> lootGroups = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); private static final ConcurrentHashMap<Integer, LootTable> lootGroups = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
@ -165,7 +166,7 @@ public class LootTable {
float chance = mlb.getChance() * .01f; float chance = mlb.getChance() * .01f;
chance *= Float.parseFloat(ConfigManager.MB_NORMAL_DROP_RATE.getValue()); chance *= LOOTMANAGER.NORMAL_DROP_RATE;
calculatedLootTable = mlb.getLootTableID(); calculatedLootTable = mlb.getLootTableID();

2
src/engine/server/world/WorldServer.java

@ -338,7 +338,7 @@ public class WorldServer {
// Load new loot system // Load new loot system
Logger.info("Loading New Loot Tables"); Logger.info("Loading New Loot Tables");
LootManager.loadLootData(); LootManager.init();
//load old loot system (still needed for rolling for now) //load old loot system (still needed for rolling for now)
LootTable.populateLootTables(); LootTable.populateLootTables();

Loading…
Cancel
Save