From 70a0ed135bf7d76cfc8b198bb1f9bb36e8c3d754 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 2 Sep 2023 12:47:04 -0400 Subject: [PATCH] Refactored mob powers to rune powers. Now uses rune_id to call into system which is derived in the getter to support minions. --- src/engine/db/handlers/dbPowerHandler.java | 20 ++++++------- src/engine/devcmd/cmds/aiInfoCmd.java | 6 ++-- src/engine/gameManager/PowersManager.java | 30 ++++---------------- src/engine/mobileAI/MobAI.java | 33 +++++++++------------- src/engine/objects/Mob.java | 3 ++ src/engine/powers/MobPowerEntry.java | 17 ----------- src/engine/powers/RunePowerEntry.java | 21 ++++++++++++++ src/engine/server/world/WorldServer.java | 2 +- 8 files changed, 58 insertions(+), 74 deletions(-) delete mode 100644 src/engine/powers/MobPowerEntry.java create mode 100644 src/engine/powers/RunePowerEntry.java diff --git a/src/engine/db/handlers/dbPowerHandler.java b/src/engine/db/handlers/dbPowerHandler.java index 664da1de..ef7ff5da 100644 --- a/src/engine/db/handlers/dbPowerHandler.java +++ b/src/engine/db/handlers/dbPowerHandler.java @@ -15,7 +15,7 @@ import engine.gameManager.PowersManager; import engine.objects.Mob; import engine.objects.PreparedStatementShared; import engine.powers.EffectsBase; -import engine.powers.MobPowerEntry; +import engine.powers.RunePowerEntry; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -86,16 +86,16 @@ public class dbPowerHandler extends dbHandlerBase { } } - public static HashMap> LOAD_MOB_POWERS() { + public static HashMap> LOAD_MOB_POWERS() { - HashMap> mobPowers = new HashMap<>(); - MobPowerEntry mobPowerEntry; + HashMap> mobPowers = new HashMap<>(); + RunePowerEntry runePowerEntry; int mobbaseID; int recordsRead = 0; try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_mobbase_powers ORDER BY `id` ASC;")) { + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_powers")) { ResultSet rs = preparedStatement.executeQuery(); @@ -104,15 +104,15 @@ public class dbPowerHandler extends dbHandlerBase { recordsRead++; mobbaseID = rs.getInt("mobbaseUUID"); - mobPowerEntry = new MobPowerEntry(rs); + runePowerEntry = new RunePowerEntry(rs); if (mobPowers.get(mobbaseID) == null) { - ArrayList powerList = new ArrayList<>(); - powerList.add(mobPowerEntry); + ArrayList powerList = new ArrayList<>(); + powerList.add(runePowerEntry); mobPowers.put(mobbaseID, powerList); } else { - ArrayList powerList = mobPowers.get(mobbaseID); - powerList.add(mobPowerEntry); + ArrayList powerList = mobPowers.get(mobbaseID); + powerList.add(runePowerEntry); mobPowers.put(mobbaseID, powerList); } } diff --git a/src/engine/devcmd/cmds/aiInfoCmd.java b/src/engine/devcmd/cmds/aiInfoCmd.java index b37728d1..c728d595 100644 --- a/src/engine/devcmd/cmds/aiInfoCmd.java +++ b/src/engine/devcmd/cmds/aiInfoCmd.java @@ -15,7 +15,7 @@ import engine.gameManager.PowersManager; import engine.objects.AbstractGameObject; import engine.objects.Mob; import engine.objects.PlayerCharacter; -import engine.powers.MobPowerEntry; +import engine.powers.RunePowerEntry; import java.util.Map; @@ -91,8 +91,8 @@ public class aiInfoCmd extends AbstractDevCmd { output += "Powers:" + newline; - for (MobPowerEntry mobPowerEntry : PowersManager.getPowersForMobile(mob)) - output += PowersManager.getPowerByToken(mobPowerEntry.token).getName() + newline; + for (RunePowerEntry runePowerEntry : PowersManager.getPowersForRune(mob.getMobBaseID())) + output += PowersManager.getPowerByToken(runePowerEntry.token).getName() + newline; throwbackInfo(playerCharacter, output); } diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index 7377d70d..2691631d 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -53,13 +53,9 @@ public enum PowersManager { public static HashMap powerActionsByID = new HashMap<>(); public static HashMap ActionTokenByIDString = new HashMap<>(); public static HashMap AnimationOverrides = new HashMap<>(); - public static HashMap> _allMobPowers; + public static HashMap> _allRunePowers; private static JobScheduler js; - private PowersManager() { - - } - public static void initPowersManager(boolean fullPowersLoad) { if (fullPowersLoad) @@ -103,28 +99,14 @@ public enum PowersManager { } } - public static ArrayList getPowersForMobile(Mob mobile) { - - ArrayList mobPowers = new ArrayList<>(); - ArrayList powerEntries; + public static ArrayList getPowersForRune(int rune_id) { - if (mobile.agentType.equals(AIAgentType.GUARDMINION)) - powerEntries = PowersManager._allMobPowers.get(mobile.guardCaptain.contractUUID); - else - powerEntries = PowersManager._allMobPowers.get(mobile.contractUUID); - - if (powerEntries != null) - mobPowers.addAll(powerEntries); - - if (mobile.agentType.equals(AIAgentType.GUARDMINION)) - powerEntries = PowersManager._allMobPowers.get(((Mob) mobile.guardCaptain).loadID); - else - powerEntries = PowersManager._allMobPowers.get(mobile.loadID); + ArrayList powerEntries = PowersManager._allRunePowers.get(rune_id); - if (powerEntries != null) - mobPowers.addAll(powerEntries); + if (powerEntries == null) + powerEntries = new ArrayList<>(); - return mobPowers; + return powerEntries; } // This pre-loads all powers and effects diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index ea5e7e5f..43a8b600 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -22,8 +22,8 @@ import engine.net.client.msg.PerformActionMsg; import engine.net.client.msg.PowerProjectileMsg; import engine.objects.*; import engine.powers.ActionsBase; -import engine.powers.MobPowerEntry; import engine.powers.PowersBase; +import engine.powers.RunePowerEntry; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -323,7 +323,7 @@ public class MobAI { return false; } - if (PowersManager.getPowersForMobile(mob).isEmpty()) + if (PowersManager.getPowersForRune(mob.getMobBaseID()).isEmpty()) return false; if (!mob.canSee((PlayerCharacter) mob.getCombatTarget())) { @@ -348,8 +348,8 @@ public class MobAI { // and casts it on the current target (or itself). Validation // (including empty lists) is done previously within canCast(); - ArrayList powerEntries; - ArrayList purgeEntries; + ArrayList powerEntries; + ArrayList purgeEntries; AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget(); if (mob.behaviourType.callsForHelp) @@ -357,22 +357,22 @@ public class MobAI { // Generate a list of tokens from the mob powers for this mobile. - powerEntries = new ArrayList<>(PowersManager.getPowersForMobile(mob)); + powerEntries = new ArrayList<>(PowersManager.getPowersForRune(mob.getMobBaseID())); purgeEntries = new ArrayList<>(); // If player has this effect on them currently then remove // this token from our list. - for (MobPowerEntry mobPowerEntry : powerEntries) { + for (RunePowerEntry runePowerEntry : powerEntries) { - PowersBase powerBase = PowersManager.getPowerByToken(mobPowerEntry.token); + PowersBase powerBase = PowersManager.getPowerByToken(runePowerEntry.token); for (ActionsBase actionBase : powerBase.getActions()) { String stackType = actionBase.stackType; if (target.getEffects() != null && target.getEffects().containsKey(stackType)) - purgeEntries.add(mobPowerEntry); + purgeEntries.add(runePowerEntry); } } @@ -431,37 +431,32 @@ public class MobAI { // and casts it on the current target (or itself). Validation // (including empty lists) is done previously within canCast(); - ArrayList powerEntries; - ArrayList purgeEntries; + ArrayList powerEntries; + ArrayList purgeEntries; AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget(); if (mob.behaviourType.callsForHelp) MobCallForHelp(mob); - // Generate a list of tokens from the mob powers for this mobile. - - powerEntries = PowersManager.getPowersForMobile(mob); - purgeEntries = new ArrayList<>(); - // If player has this effect on them currently then remove // this token from our list. - powerEntries = new ArrayList<>(PowersManager.getPowersForMobile(mob)); + powerEntries = new ArrayList<>(PowersManager.getPowersForRune(mob.getMobBaseID())); purgeEntries = new ArrayList<>(); // If player has this effect on them currently then remove // this token from our list. - for (MobPowerEntry mobPowerEntry : powerEntries) { + for (RunePowerEntry runePowerEntry : powerEntries) { - PowersBase powerBase = PowersManager.getPowerByToken(mobPowerEntry.token); + PowersBase powerBase = PowersManager.getPowerByToken(runePowerEntry.token); for (ActionsBase actionBase : powerBase.getActions()) { String stackType = actionBase.stackType; if (target.getEffects() != null && target.getEffects().containsKey(stackType)) - purgeEntries.add(mobPowerEntry); + purgeEntries.add(runePowerEntry); } } diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 31ca46ce..b25910e4 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -669,6 +669,9 @@ public class Mob extends AbstractIntelligenceAgent { public int getMobBaseID() { + if (this.agentType.equals(AIAgentType.GUARDMINION)) + return this.guardCaptain.contract.getMobbaseID(); + if (this.mobBase != null) return this.mobBase.getObjectUUID(); diff --git a/src/engine/powers/MobPowerEntry.java b/src/engine/powers/MobPowerEntry.java deleted file mode 100644 index 1aee9848..00000000 --- a/src/engine/powers/MobPowerEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package engine.powers; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class MobPowerEntry { - - public int token; - public int rank; - - - public MobPowerEntry(ResultSet rs) throws SQLException { - this.token = rs.getInt("token"); - this.rank = rs.getInt("rank"); - } - -} diff --git a/src/engine/powers/RunePowerEntry.java b/src/engine/powers/RunePowerEntry.java new file mode 100644 index 00000000..ad0b099c --- /dev/null +++ b/src/engine/powers/RunePowerEntry.java @@ -0,0 +1,21 @@ +package engine.powers; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class RunePowerEntry { + + public String name; + public int token; + public String power_type; + public int rank; + + + public RunePowerEntry(ResultSet rs) throws SQLException { + this.name = rs.getString("name"); + this.token = rs.getInt("token"); + this.power_type = rs.getString("power_type"); + this.rank = rs.getInt("rank"); + } + +} diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index d5ef3301..68428980 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -352,7 +352,7 @@ public class WorldServer { DbManager.MobBaseQueries.GET_ALL_MOBBASES(); Logger.info("Loading Mob Powers"); - PowersManager._allMobPowers = dbPowerHandler.LOAD_MOB_POWERS(); + PowersManager._allRunePowers = dbPowerHandler.LOAD_MOB_POWERS(); Logger.info("Loading item enchants"); DbManager.LootQueries.LOAD_ENCHANT_VALUES();