forked from MagicBane/Server
Refactor to install new loot tables.
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
package engine.db.handlers;
|
package engine.db.handlers;
|
||||||
|
|
||||||
import engine.gameManager.DbManager;
|
import engine.gameManager.DbManager;
|
||||||
import engine.gameManager.LootManager;
|
|
||||||
import engine.loot.*;
|
import engine.loot.*;
|
||||||
import engine.objects.Item;
|
import engine.objects.Item;
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
@@ -238,86 +237,4 @@ public class dbLootHandler extends dbHandlerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LOAD_ALL_GENTABLES() {
|
|
||||||
|
|
||||||
int recordsRead = 0;
|
|
||||||
|
|
||||||
try (Connection connection = DbManager.getConnection();
|
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_gentables")) {
|
|
||||||
|
|
||||||
ResultSet rs = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
GenTableRow row = new GenTableRow(rs);
|
|
||||||
LootManager.AddGenTableRow(rs.getInt("gentable"), row);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Logger.error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.info("read: " + recordsRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LOAD_ALL_ITEMTABLES() {
|
|
||||||
|
|
||||||
int recordsRead = 0;
|
|
||||||
|
|
||||||
try (Connection connection = DbManager.getConnection();
|
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_itemtables")) {
|
|
||||||
|
|
||||||
ResultSet rs = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
recordsRead++;
|
|
||||||
ItemTableRow row = new ItemTableRow(rs);
|
|
||||||
LootManager.AddItemTableRow(rs.getInt("itemTable"), row);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Logger.error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.info("read: " + recordsRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LOAD_ALL_MODTYPES() {
|
|
||||||
int recordsRead = 0;
|
|
||||||
|
|
||||||
try (Connection connection = DbManager.getConnection();
|
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_modtypetables")) {
|
|
||||||
|
|
||||||
ResultSet rs = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
recordsRead++;
|
|
||||||
ModTypeTableRow mttr = new ModTypeTableRow(rs);
|
|
||||||
LootManager.AddModTypeTableRow(rs.getInt("modType"), mttr);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Logger.error(e);
|
|
||||||
}
|
|
||||||
Logger.info("read: " + recordsRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LOAD_ALL_MODTABLES() {
|
|
||||||
int recordsRead = 0;
|
|
||||||
|
|
||||||
try (Connection connection = DbManager.getConnection();
|
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_modtables")) {
|
|
||||||
|
|
||||||
ResultSet rs = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
recordsRead++;
|
|
||||||
ModTableRow mtr = new ModTableRow(rs);
|
|
||||||
LootManager.AddModTableRow(rs.getInt("modTable"), mtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Logger.error(e);
|
|
||||||
}
|
|
||||||
Logger.info("read: " + recordsRead);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public class SimulateBootyCmd extends AbstractDevCmd {
|
|||||||
else
|
else
|
||||||
output += "NORMAL TABLE [" + entry.bootyType + "] " + entry.genTable + ": " + entry.dropChance * dropRate + newline;
|
output += "NORMAL TABLE [" + entry.bootyType + "] " + entry.genTable + ": " + entry.dropChance * dropRate + newline;
|
||||||
|
|
||||||
if (hotZoneRan == false && ZoneManager.inHotZone(mob.getLoc()) && LootManager.generalItemTables.containsKey(entry.genTable + 1)) {
|
if (hotZoneRan == false && ZoneManager.inHotZone(mob.getLoc()) && LootManager._genTables.containsKey(entry.genTable + 1)) {
|
||||||
output += "HOTZONE TABLE [" + entry.bootyType + "] " + (entry.genTable + 1) + ": " + entry.dropChance * dropRate + newline;
|
output += "HOTZONE TABLE [" + entry.bootyType + "] " + (entry.genTable + 1) + ": " + entry.dropChance * dropRate + newline;
|
||||||
hotZoneRan = true;
|
hotZoneRan = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,12 +34,6 @@ public enum LootManager {
|
|||||||
public static HashMap<Integer, ArrayList<ModTableEntry>> _modTables = new HashMap<>();
|
public static HashMap<Integer, ArrayList<ModTableEntry>> _modTables = new HashMap<>();
|
||||||
public static HashMap<Integer, ArrayList<ModTypeTableEntry>> _modTypeTables = new HashMap<>();
|
public static HashMap<Integer, ArrayList<ModTypeTableEntry>> _modTypeTables = new HashMap<>();
|
||||||
|
|
||||||
//new tables
|
|
||||||
public static final HashMap<Integer, GenTable> generalItemTables = null;
|
|
||||||
public static final HashMap<Integer, ItemTable> itemTables = null;
|
|
||||||
public static final HashMap<Integer, ModTypeTable> modTypeTables = null;
|
|
||||||
public static final HashMap<Integer, ModTable> modTables = null;
|
|
||||||
|
|
||||||
// Drop Rates
|
// Drop Rates
|
||||||
|
|
||||||
public static float NORMAL_DROP_RATE;
|
public static float NORMAL_DROP_RATE;
|
||||||
@@ -60,12 +54,6 @@ public enum LootManager {
|
|||||||
_modTables = DbManager.LootQueries.LOAD_MOD_TABLES();
|
_modTables = DbManager.LootQueries.LOAD_MOD_TABLES();
|
||||||
_modTypeTables = DbManager.LootQueries.LOAD_MOD_TYPE_TABLES();
|
_modTypeTables = DbManager.LootQueries.LOAD_MOD_TYPE_TABLES();
|
||||||
|
|
||||||
|
|
||||||
DbManager.LootQueries.LOAD_ALL_GENTABLES();
|
|
||||||
DbManager.LootQueries.LOAD_ALL_ITEMTABLES();
|
|
||||||
DbManager.LootQueries.LOAD_ALL_MODTYPES();
|
|
||||||
DbManager.LootQueries.LOAD_ALL_MODTABLES();
|
|
||||||
|
|
||||||
// Cache drop rate values from Config manager.
|
// Cache drop rate values from Config manager.
|
||||||
|
|
||||||
NORMAL_DROP_RATE = Float.parseFloat(ConfigManager.MB_NORMAL_DROP_RATE.getValue());
|
NORMAL_DROP_RATE = Float.parseFloat(ConfigManager.MB_NORMAL_DROP_RATE.getValue());
|
||||||
@@ -139,7 +127,7 @@ public enum LootManager {
|
|||||||
// Only one bite at the hotzone apple per bootyset.
|
// Only one bite at the hotzone apple per bootyset.
|
||||||
|
|
||||||
if (inHotzone == true && hotzoneWasRan == false)
|
if (inHotzone == true && hotzoneWasRan == false)
|
||||||
if (generalItemTables.containsKey(bse.genTable + 1) && ThreadLocalRandom.current().nextInt(1, 100 + 1) < (bse.dropChance * dropRate)) {
|
if (_genTables.containsKey(bse.genTable + 1) && ThreadLocalRandom.current().nextInt(1, 100 + 1) < (bse.dropChance * dropRate)) {
|
||||||
GenerateLootDrop(mob, bse.genTable + 1, true); //generate loot drop from hotzone table
|
GenerateLootDrop(mob, bse.genTable + 1, true); //generate loot drop from hotzone table
|
||||||
hotzoneWasRan = true;
|
hotzoneWasRan = true;
|
||||||
}
|
}
|
||||||
@@ -154,28 +142,28 @@ public enum LootManager {
|
|||||||
|
|
||||||
public static MobLoot getGenTableItem(int genTableID, Mob mob, Boolean inHotzone) {
|
public static MobLoot getGenTableItem(int genTableID, Mob mob, Boolean inHotzone) {
|
||||||
|
|
||||||
if (mob == null || generalItemTables.containsKey(genTableID) == false)
|
if (mob == null || _genTables.containsKey(genTableID) == false)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
MobLoot outItem;
|
MobLoot outItem;
|
||||||
|
|
||||||
int genRoll = new Random().nextInt(99) + 1;
|
int genRoll = new Random().nextInt(99) + 1;
|
||||||
|
|
||||||
GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(genRoll);
|
GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll);
|
||||||
|
|
||||||
if (selectedRow == null)
|
if (selectedRow == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
int itemTableId = selectedRow.itemTableID;
|
int itemTableId = selectedRow.itemTableID;
|
||||||
|
|
||||||
if (itemTables.containsKey(itemTableId) == false)
|
if (_itemTables.containsKey(itemTableId) == false)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
//gets the 1-320 roll for this mob
|
//gets the 1-320 roll for this mob
|
||||||
|
|
||||||
int itemTableRoll = TableRoll(mob.level, inHotzone);
|
int itemTableRoll = TableRoll(mob.level, inHotzone);
|
||||||
|
|
||||||
ItemTableRow tableRow = itemTables.get(itemTableId).getRowForRange(itemTableRoll);
|
ItemTableEntry tableRow = ItemTableEntry.rollTable(itemTableId, itemTableRoll);
|
||||||
|
|
||||||
if (tableRow == null)
|
if (tableRow == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -221,69 +209,55 @@ public enum LootManager {
|
|||||||
|
|
||||||
private static MobLoot GeneratePrefix(Mob mob, MobLoot inItem, int genTableID, int genRoll, Boolean inHotzone) {
|
private static MobLoot GeneratePrefix(Mob mob, MobLoot inItem, int genTableID, int genRoll, Boolean inHotzone) {
|
||||||
|
|
||||||
GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(genRoll);
|
GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll);
|
||||||
|
|
||||||
if (selectedRow == null)
|
if (selectedRow == null)
|
||||||
return inItem;
|
return inItem;
|
||||||
|
|
||||||
ModTypeTable prefixTable = modTypeTables.get(selectedRow.pModTable);
|
int prefixroll = ThreadLocalRandom.current().nextInt(1, 100 + 1);
|
||||||
|
|
||||||
|
ModTypeTableEntry prefixTable = ModTypeTableEntry.rollTable(selectedRow.pModTable, prefixroll);
|
||||||
|
|
||||||
if (prefixTable == null)
|
if (prefixTable == null)
|
||||||
return inItem;
|
return inItem;
|
||||||
|
|
||||||
int prefixroll = ThreadLocalRandom.current().nextInt(1, 100 + 1);
|
ModTableEntry prefixMod = ModTableEntry.rollTable(prefixTable.modTableID, TableRoll(mob.level, inHotzone));
|
||||||
|
|
||||||
if (modTables.get(prefixTable.getRowForRange(prefixroll).modTableID) != null) {
|
if (prefixMod == null)
|
||||||
ModTable prefixModTable = modTables.get(prefixTable.getRowForRange(prefixroll).modTableID);
|
return inItem;
|
||||||
|
|
||||||
if (prefixModTable == null)
|
if (prefixMod.action.length() > 0) {
|
||||||
return inItem;
|
inItem.setPrefix(prefixMod.action);
|
||||||
|
inItem.addPermanentEnchantment(prefixMod.action, 0, prefixMod.level, true);
|
||||||
ModTableRow prefixMod = prefixModTable.getRowForRange(TableRoll(mob.level, inHotzone));
|
|
||||||
|
|
||||||
if (prefixMod == null)
|
|
||||||
return inItem;
|
|
||||||
|
|
||||||
if (prefixMod != null && prefixMod.action.length() > 0) {
|
|
||||||
inItem.setPrefix(prefixMod.action);
|
|
||||||
inItem.addPermanentEnchantment(prefixMod.action, 0, prefixMod.level, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
return inItem;
|
return inItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MobLoot GenerateSuffix(Mob mob, MobLoot inItem, int genTableID, int genRoll, Boolean inHotzone) {
|
private static MobLoot GenerateSuffix(Mob mob, MobLoot inItem, int genTableID, int genRoll, Boolean inHotzone) {
|
||||||
|
|
||||||
GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(genRoll);
|
GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll);
|
||||||
|
|
||||||
if (selectedRow == null)
|
if (selectedRow == null)
|
||||||
return inItem;
|
return inItem;
|
||||||
|
|
||||||
int suffixroll = ThreadLocalRandom.current().nextInt(1, 100 + 1);
|
int suffixRoll = ThreadLocalRandom.current().nextInt(1, 100 + 1);
|
||||||
|
|
||||||
ModTypeTable suffixTable = modTypeTables.get(selectedRow.sModTable);
|
ModTypeTableEntry suffixTable = ModTypeTableEntry.rollTable(selectedRow.sModTable, suffixRoll);
|
||||||
|
|
||||||
if (suffixTable == null)
|
if (suffixTable == null)
|
||||||
return inItem;
|
return inItem;
|
||||||
|
|
||||||
if (modTables.get(suffixTable.getRowForRange(suffixroll).modTableID) != null) {
|
ModTableEntry suffixMod = ModTableEntry.rollTable(suffixTable.modTableID, TableRoll(mob.level, inHotzone));
|
||||||
|
|
||||||
ModTable suffixModTable = modTables.get(suffixTable.getRowForRange(suffixroll).modTableID);
|
if (suffixMod == null)
|
||||||
|
return inItem;
|
||||||
|
|
||||||
if (suffixModTable == null)
|
if (suffixMod.action.length() > 0) {
|
||||||
return inItem;
|
inItem.setPrefix(suffixMod.action);
|
||||||
|
inItem.addPermanentEnchantment(suffixMod.action, 0, suffixMod.level, true);
|
||||||
ModTableRow suffixMod = suffixModTable.getRowForRange(TableRoll(mob.level, inHotzone));
|
|
||||||
|
|
||||||
if (suffixMod == null)
|
|
||||||
return inItem;
|
|
||||||
|
|
||||||
if (suffixMod != null && suffixMod.action.length() > 0) {
|
|
||||||
inItem.setSuffix(suffixMod.action);
|
|
||||||
inItem.addPermanentEnchantment(suffixMod.action, 0, suffixMod.level, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return inItem;
|
return inItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,60 +367,4 @@ public enum LootManager {
|
|||||||
mob.getCharItemManager().addItemToInventory(lootItem);
|
mob.getCharItemManager().addItemToInventory(lootItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddGenTableRow(int tableID, GenTableRow row) {
|
}
|
||||||
|
|
||||||
if (!generalItemTables.containsKey(tableID)) {
|
|
||||||
//create the new table
|
|
||||||
GenTable gt = new GenTable();
|
|
||||||
gt.rows.add(row);
|
|
||||||
generalItemTables.put(tableID, gt);
|
|
||||||
} else {
|
|
||||||
//add row to existing table
|
|
||||||
GenTable toAdd = generalItemTables.get(tableID);
|
|
||||||
toAdd.rows.add(row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddItemTableRow(int tableID, ItemTableRow row) {
|
|
||||||
|
|
||||||
if (!itemTables.containsKey(tableID)) {
|
|
||||||
//create the new table
|
|
||||||
ItemTable it = new ItemTable();
|
|
||||||
it.rows.add(row);
|
|
||||||
itemTables.put(tableID, it);
|
|
||||||
} else {
|
|
||||||
//add row to existing table
|
|
||||||
ItemTable toAdd = itemTables.get(tableID);
|
|
||||||
toAdd.rows.add(row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddModTypeTableRow(int tableID, ModTypeTableRow row) {
|
|
||||||
|
|
||||||
if (!modTypeTables.containsKey(tableID)) {
|
|
||||||
//create the new table
|
|
||||||
ModTypeTable mtt = new ModTypeTable();
|
|
||||||
mtt.rows.add(row);
|
|
||||||
modTypeTables.put(tableID, mtt);
|
|
||||||
} else {
|
|
||||||
//add row to existing table
|
|
||||||
ModTypeTable toAdd = modTypeTables.get(tableID);
|
|
||||||
toAdd.rows.add(row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddModTableRow(int tableID, ModTableRow row) {
|
|
||||||
|
|
||||||
if (!modTables.containsKey(tableID)) {
|
|
||||||
//create the new table
|
|
||||||
ModTable mt = new ModTable();
|
|
||||||
mt.rows.add(row);
|
|
||||||
modTables.put(tableID, mt);
|
|
||||||
} else {
|
|
||||||
//add row to existing table
|
|
||||||
ModTable toAdd = modTables.get(tableID);
|
|
||||||
toAdd.rows.add(row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user