From fda3386e7b9d498201069cc0324b19730da89c47 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 3 Aug 2023 09:43:30 -0400 Subject: [PATCH] Multiple inner classes extracted from LootManager. --- .../db/handlers/dbLootTableHandler.java | 12 +- src/engine/gameManager/LootManager.java | 129 +----------------- src/engine/loot/GenTable.java | 18 +++ src/engine/loot/GenTableRow.java | 20 +++ src/engine/loot/ItemTable.java | 21 +++ src/engine/loot/ItemTableRow.java | 20 +++ src/engine/loot/ModTable.java | 21 +++ src/engine/loot/ModTableRow.java | 18 +++ src/engine/loot/ModTypeTable.java | 18 +++ src/engine/loot/ModTypeTableRow.java | 16 +++ 10 files changed, 161 insertions(+), 132 deletions(-) create mode 100644 src/engine/loot/GenTable.java create mode 100644 src/engine/loot/GenTableRow.java create mode 100644 src/engine/loot/ItemTable.java create mode 100644 src/engine/loot/ItemTableRow.java create mode 100644 src/engine/loot/ModTable.java create mode 100644 src/engine/loot/ModTableRow.java create mode 100644 src/engine/loot/ModTypeTable.java create mode 100644 src/engine/loot/ModTypeTableRow.java diff --git a/src/engine/db/handlers/dbLootTableHandler.java b/src/engine/db/handlers/dbLootTableHandler.java index 6d39f970..ec9ba9df 100644 --- a/src/engine/db/handlers/dbLootTableHandler.java +++ b/src/engine/db/handlers/dbLootTableHandler.java @@ -11,6 +11,10 @@ package engine.db.handlers; import engine.gameManager.DbManager; import engine.gameManager.LootManager; +import engine.loot.GenTableRow; +import engine.loot.ItemTableRow; +import engine.loot.ModTableRow; +import engine.loot.ModTypeTableRow; import engine.objects.Item; import engine.objects.LootTable; import org.pmw.tinylog.Logger; @@ -140,7 +144,7 @@ public class dbLootTableHandler extends dbHandlerBase { ResultSet rs = preparedStatement.executeQuery(); while (rs.next()) { - LootManager.GenTableRow row = new LootManager.GenTableRow(rs); + GenTableRow row = new GenTableRow(rs); LootManager.AddGenTableRow(rs.getInt("groupID"), row); } @@ -162,7 +166,7 @@ public class dbLootTableHandler extends dbHandlerBase { while (rs.next()) { recordsRead++; - LootManager.ItemTableRow row = new LootManager.ItemTableRow(rs); + ItemTableRow row = new ItemTableRow(rs); LootManager.AddItemTableRow(rs.getInt("lootTable"), row); } @@ -183,7 +187,7 @@ public class dbLootTableHandler extends dbHandlerBase { while (rs.next()) { recordsRead++; - LootManager.ModTypeTableRow mttr = new LootManager.ModTypeTableRow(rs); + ModTypeTableRow mttr = new ModTypeTableRow(rs); LootManager.AddModTypeTableRow(rs.getInt("modGroup"), mttr); } @@ -203,7 +207,7 @@ public class dbLootTableHandler extends dbHandlerBase { while (rs.next()) { recordsRead++; - LootManager.ModTableRow mtr = new LootManager.ModTableRow(rs); + ModTableRow mtr = new ModTableRow(rs); LootManager.AddModTableRow(rs.getInt("modTable"), mtr); } diff --git a/src/engine/gameManager/LootManager.java b/src/engine/gameManager/LootManager.java index 1f02dd1a..dff01fdd 100644 --- a/src/engine/gameManager/LootManager.java +++ b/src/engine/gameManager/LootManager.java @@ -9,13 +9,12 @@ package engine.gameManager; import engine.Enum; +import engine.loot.*; import engine.net.DispatchMessage; import engine.net.client.msg.chat.ChatSystemMsg; import engine.objects.*; import org.pmw.tinylog.Logger; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.Random; @@ -396,130 +395,4 @@ public enum LootManager { } } - public static class GenTable { - public ArrayList rows = new ArrayList(); - - public GenTableRow getRowForRange(int roll) { - - GenTableRow outRow = null; - - for (GenTableRow iteration : this.rows) - if (roll >= iteration.minRoll && roll <= iteration.maxRoll) - outRow = iteration; - - return outRow; - } - } - - public static class ItemTable { - public ArrayList rows = new ArrayList(); - - public ItemTableRow getRowForRange(int roll) { - - if (roll > 320) - roll = 320; - - ItemTableRow outRow = null; - - for (ItemTableRow iteration : this.rows) - if (roll >= iteration.minRoll && roll <= iteration.maxRoll) - outRow = iteration; - - return outRow; - } - } - - public static class ModTypeTable { - public ArrayList rows = new ArrayList(); - - public ModTypeTableRow getRowForRange(int roll) { - - ModTypeTableRow outRow = null; - - for (ModTypeTableRow iteration : this.rows) - if (roll >= iteration.minRoll && roll <= iteration.maxRoll) - return iteration; - - return outRow; - } - } - - public static class ModTable { - public ArrayList rows = new ArrayList(); - - public ModTableRow getRowForRange(int roll) { - - if (roll > 320) - roll = 320; - - ModTableRow outRow = null; - - for (ModTableRow iteration : this.rows) - if (roll >= iteration.minRoll && roll <= iteration.maxRoll) - outRow = iteration; - - return outRow; - } - } - - public static class GenTableRow { - public int minRoll; - public int maxRoll; - public int itemTableID; - public int pModTable; - public int sModTable; - - public GenTableRow(ResultSet rs) throws SQLException { - this.minRoll = rs.getInt("minRoll"); - this.maxRoll = rs.getInt("maxRoll"); - this.itemTableID = rs.getInt("lootTableID"); - this.pModTable = rs.getInt("pModTableID"); - this.sModTable = rs.getInt("sModTableID"); - } - } - - public static class ItemTableRow { - public int minRoll; - public int maxRoll; - public int cacheID; - public int minSpawn; - public int maxSpawn; - - public ItemTableRow(ResultSet rs) throws SQLException { - this.minRoll = rs.getInt("minRoll"); - this.maxRoll = rs.getInt("maxRoll"); - this.cacheID = rs.getInt("itemBaseUUID"); - this.minSpawn = rs.getInt("minSpawn"); - this.maxSpawn = rs.getInt("maxSpawn"); - - } - } - - public static class ModTypeTableRow { - public int minRoll; - public int maxRoll; - public int modTableID; - - public ModTypeTableRow(ResultSet rs) throws SQLException { - this.minRoll = rs.getInt("minRoll"); - this.maxRoll = rs.getInt("maxRoll"); - this.modTableID = rs.getInt("subTableID"); - - } - } - - public static class ModTableRow { - public int minRoll; - public int maxRoll; - public String action; - public int level; - - public ModTableRow(ResultSet rs) throws SQLException { - this.minRoll = rs.getInt("minRoll"); - this.maxRoll = rs.getInt("maxRoll"); - this.action = rs.getString("action"); - this.level = rs.getInt("level"); - - } - } } \ No newline at end of file diff --git a/src/engine/loot/GenTable.java b/src/engine/loot/GenTable.java new file mode 100644 index 00000000..5b5dd997 --- /dev/null +++ b/src/engine/loot/GenTable.java @@ -0,0 +1,18 @@ +package engine.loot; + +import java.util.ArrayList; + +public class GenTable { + public ArrayList rows = new ArrayList(); + + public GenTableRow getRowForRange(int roll) { + + GenTableRow outRow = null; + + for (GenTableRow iteration : this.rows) + if (roll >= iteration.minRoll && roll <= iteration.maxRoll) + outRow = iteration; + + return outRow; + } +} diff --git a/src/engine/loot/GenTableRow.java b/src/engine/loot/GenTableRow.java new file mode 100644 index 00000000..e72a4cf3 --- /dev/null +++ b/src/engine/loot/GenTableRow.java @@ -0,0 +1,20 @@ +package engine.loot; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class GenTableRow { + public int minRoll; + public int maxRoll; + public int itemTableID; + public int pModTable; + public int sModTable; + + public GenTableRow(ResultSet rs) throws SQLException { + this.minRoll = rs.getInt("minRoll"); + this.maxRoll = rs.getInt("maxRoll"); + this.itemTableID = rs.getInt("lootTableID"); + this.pModTable = rs.getInt("pModTableID"); + this.sModTable = rs.getInt("sModTableID"); + } +} diff --git a/src/engine/loot/ItemTable.java b/src/engine/loot/ItemTable.java new file mode 100644 index 00000000..e2afc1b4 --- /dev/null +++ b/src/engine/loot/ItemTable.java @@ -0,0 +1,21 @@ +package engine.loot; + +import java.util.ArrayList; + +public class ItemTable { + public ArrayList rows = new ArrayList<>(); + + public ItemTableRow getRowForRange(int roll) { + + if (roll > 320) + roll = 320; + + ItemTableRow outRow = null; + + for (ItemTableRow iteration : this.rows) + if (roll >= iteration.minRoll && roll <= iteration.maxRoll) + outRow = iteration; + + return outRow; + } +} diff --git a/src/engine/loot/ItemTableRow.java b/src/engine/loot/ItemTableRow.java new file mode 100644 index 00000000..00a20b8a --- /dev/null +++ b/src/engine/loot/ItemTableRow.java @@ -0,0 +1,20 @@ +package engine.loot; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class ItemTableRow { + public int minRoll; + public int maxRoll; + public int cacheID; + public int minSpawn; + public int maxSpawn; + + public ItemTableRow(ResultSet rs) throws SQLException { + this.minRoll = rs.getInt("minRoll"); + this.maxRoll = rs.getInt("maxRoll"); + this.cacheID = rs.getInt("itemBaseUUID"); + this.minSpawn = rs.getInt("minSpawn"); + this.maxSpawn = rs.getInt("maxSpawn"); + } +} diff --git a/src/engine/loot/ModTable.java b/src/engine/loot/ModTable.java new file mode 100644 index 00000000..06908938 --- /dev/null +++ b/src/engine/loot/ModTable.java @@ -0,0 +1,21 @@ +package engine.loot; + +import java.util.ArrayList; + +public class ModTable { + public ArrayList rows = new ArrayList(); + + public ModTableRow getRowForRange(int roll) { + + if (roll > 320) + roll = 320; + + ModTableRow outRow = null; + + for (ModTableRow iteration : this.rows) + if (roll >= iteration.minRoll && roll <= iteration.maxRoll) + outRow = iteration; + + return outRow; + } +} diff --git a/src/engine/loot/ModTableRow.java b/src/engine/loot/ModTableRow.java new file mode 100644 index 00000000..94665cf6 --- /dev/null +++ b/src/engine/loot/ModTableRow.java @@ -0,0 +1,18 @@ +package engine.loot; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class ModTableRow { + public int minRoll; + public int maxRoll; + public String action; + public int level; + + public ModTableRow(ResultSet rs) throws SQLException { + this.minRoll = rs.getInt("minRoll"); + this.maxRoll = rs.getInt("maxRoll"); + this.action = rs.getString("action"); + this.level = rs.getInt("level"); + } +} diff --git a/src/engine/loot/ModTypeTable.java b/src/engine/loot/ModTypeTable.java new file mode 100644 index 00000000..b444a73b --- /dev/null +++ b/src/engine/loot/ModTypeTable.java @@ -0,0 +1,18 @@ +package engine.loot; + +import java.util.ArrayList; + +public class ModTypeTable { + public ArrayList rows = new ArrayList<>(); + + public ModTypeTableRow getRowForRange(int roll) { + + ModTypeTableRow outRow = null; + + for (ModTypeTableRow iteration : this.rows) + if (roll >= iteration.minRoll && roll <= iteration.maxRoll) + return iteration; + + return outRow; + } +} diff --git a/src/engine/loot/ModTypeTableRow.java b/src/engine/loot/ModTypeTableRow.java new file mode 100644 index 00000000..13b8cef9 --- /dev/null +++ b/src/engine/loot/ModTypeTableRow.java @@ -0,0 +1,16 @@ +package engine.loot; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class ModTypeTableRow { + public int minRoll; + public int maxRoll; + public int modTableID; + + public ModTypeTableRow(ResultSet rs) throws SQLException { + this.minRoll = rs.getInt("minRoll"); + this.maxRoll = rs.getInt("maxRoll"); + this.modTableID = rs.getInt("subTableID"); + } +}