diff --git a/src/engine/devcmd/cmds/aiInfoCmd.java b/src/engine/devcmd/cmds/aiInfoCmd.java index 4a524c34..594a8204 100644 --- a/src/engine/devcmd/cmds/aiInfoCmd.java +++ b/src/engine/devcmd/cmds/aiInfoCmd.java @@ -15,6 +15,7 @@ import engine.gameManager.PowersManager; import engine.objects.AbstractGameObject; import engine.objects.Mob; import engine.objects.PlayerCharacter; +import engine.powers.MobPowerEntry; import java.util.Map; @@ -90,8 +91,8 @@ public class aiInfoCmd extends AbstractDevCmd { output += "Powers:" + newline; - for (int token : mob.mobPowers.keySet()) - output += PowersManager.getPowerByToken(token).getName() + newline; + for (MobPowerEntry mobPowerEntry : PowersManager._allMobPowers.get(mob.contractUUID)) + output += PowersManager.getPowerByToken(mobPowerEntry.token).getName() + newline; throwbackInfo(playerCharacter, output); } diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index b66f1dd0..bc0e15b2 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -53,7 +53,7 @@ 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> _allMobPowers; private static JobScheduler js; private PowersManager() { @@ -103,6 +103,24 @@ public enum PowersManager { } } + public static ArrayList getPowersForMobile(Mob mobile) { + + ArrayList mobPowers = new ArrayList<>(); + ArrayList powerEntries; + + powerEntries = PowersManager._allMobPowers.get(mobile.loadID); + + if (powerEntries != null) + mobPowers.addAll(powerEntries); + + powerEntries = PowersManager._allMobPowers.get(mobile.contractUUID); + + if (powerEntries != null) + mobPowers.addAll(powerEntries); + + return mobPowers; + } + // This pre-loads all powers and effects public static void InitializePowers() { diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index e0530f40..2ca8d4d5 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -22,6 +22,7 @@ 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.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -321,7 +322,7 @@ public class MobAI { return false; } - if (mob.mobPowers.isEmpty()) + if (PowersManager.getPowersForMobile(mob).isEmpty()) return false; if (!mob.canSee((PlayerCharacter) mob.getCombatTarget())) { @@ -346,8 +347,8 @@ public class MobAI { // and casts it on the current target (or itself). Validation // (including empty lists) is done previously within canCast(); - ArrayList powerTokens; - ArrayList purgeTokens; + ArrayList powerEntries; + ArrayList purgeEntries; AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget(); if (mob.behaviourType.callsForHelp) @@ -355,36 +356,36 @@ public class MobAI { // Generate a list of tokens from the mob powers for this mobile. - powerTokens = new ArrayList<>(mob.mobPowers.keySet()); - purgeTokens = new ArrayList<>(); + powerEntries = new ArrayList<>(PowersManager.getPowersForMobile(mob)); + purgeEntries = new ArrayList<>(); // If player has this effect on them currently then remove // this token from our list. - for (int powerToken : powerTokens) { + for (MobPowerEntry mobPowerEntry : powerEntries) { - PowersBase powerBase = PowersManager.getPowerByToken(powerToken); + PowersBase powerBase = PowersManager.getPowerByToken(mobPowerEntry.token); for (ActionsBase actionBase : powerBase.getActions()) { String stackType = actionBase.stackType; if (target.getEffects() != null && target.getEffects().containsKey(stackType)) - purgeTokens.add(powerToken); + purgeEntries.add(mobPowerEntry); } } - powerTokens.removeAll(purgeTokens); + powerEntries.removeAll(purgeEntries); // Sanity check - if (powerTokens.isEmpty()) + if (powerEntries.isEmpty()) return false; // Pick random spell from our list of powers - int powerToken = powerTokens.get(ThreadLocalRandom.current().nextInt(powerTokens.size())); - int powerRank = mob.mobPowers.get(powerToken); + int powerToken = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())).token; + int powerRank = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())).rank; PowersBase mobPower = PowersManager.getPowerByToken(powerToken); @@ -429,8 +430,8 @@ public class MobAI { // and casts it on the current target (or itself). Validation // (including empty lists) is done previously within canCast(); - ArrayList powerTokens; - ArrayList purgeTokens; + ArrayList powerEntries; + ArrayList purgeEntries; AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget(); if (mob.behaviourType.callsForHelp) @@ -438,30 +439,36 @@ public class MobAI { // Generate a list of tokens from the mob powers for this mobile. - powerTokens = new ArrayList<>(mob.mobPowers.keySet()); - purgeTokens = new ArrayList<>(); + powerEntries = PowersManager.getPowersForMobile(mob); + purgeEntries = new ArrayList<>(); // If player has this effect on them currently then remove // this token from our list. - for (int powerToken : powerTokens) { + powerEntries = new ArrayList<>(PowersManager.getPowersForMobile(mob)); + purgeEntries = new ArrayList<>(); - PowersBase powerBase = PowersManager.getPowerByToken(powerToken); + // If player has this effect on them currently then remove + // this token from our list. + + for (MobPowerEntry mobPowerEntry : powerEntries) { + + PowersBase powerBase = PowersManager.getPowerByToken(mobPowerEntry.token); for (ActionsBase actionBase : powerBase.getActions()) { String stackType = actionBase.stackType; if (target.getEffects() != null && target.getEffects().containsKey(stackType)) - purgeTokens.add(powerToken); + purgeEntries.add(mobPowerEntry); } } - powerTokens.removeAll(purgeTokens); + powerEntries.removeAll(purgeEntries); // Sanity check - if (powerTokens.isEmpty()) + if (powerEntries.isEmpty()) return false; int powerToken = 0; @@ -470,11 +477,11 @@ public class MobAI { if (nukeRoll < 55) { //use direct damage spell - powerToken = powerTokens.get(powerTokens.size() - 1); + powerToken = powerEntries.get(powerEntries.size() - 1).token; } else { //use random spell - powerToken = powerTokens.get(ThreadLocalRandom.current().nextInt(powerTokens.size())); + powerToken = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())).token; } int powerRank = 1; diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index b2f26e91..7525efa8 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -25,7 +25,6 @@ import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.msg.PetMsg; import engine.net.client.msg.PlaceAssetMsg; -import engine.powers.MobPowerEntry; import engine.server.MBServerStatics; import org.joda.time.DateTime; import org.pmw.tinylog.Logger; @@ -34,7 +33,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.EnumSet; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -52,7 +50,6 @@ public class Mob extends AbstractIntelligenceAgent { public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock(); public boolean despawned = false; public Vector3fImmutable destination = Vector3fImmutable.ZERO; - public LinkedHashMap mobPowers = new LinkedHashMap<>(); public MobBase mobBase; public int spawnTime; public Zone parentZone; @@ -1655,18 +1652,6 @@ public class Mob extends AbstractIntelligenceAgent { else this.equip = new HashMap<>(); - // Powers from mobbase - - if (PowersManager.AllMobPowers.containsKey(this.getMobBaseID())) - for (MobPowerEntry mobPowerEntry : PowersManager.AllMobPowers.get(this.getMobBaseID())) - mobPowers.put(mobPowerEntry.token, mobPowerEntry.rank); - - // Powers from contract - - if (this.contract != null && PowersManager.AllMobPowers.containsKey(this.contract.getContractID())) - for (MobPowerEntry mobPowerEntry : PowersManager.AllMobPowers.get(this.contract.getContractID())) - mobPowers.put(mobPowerEntry.token, mobPowerEntry.rank); - if (this.equip == null) { Logger.error("Null equipset returned for uuid " + currentID); this.equip = new HashMap<>(0); diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index d662eaa5..d5ef3301 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._allMobPowers = dbPowerHandler.LOAD_MOB_POWERS(); Logger.info("Loading item enchants"); DbManager.LootQueries.LOAD_ENCHANT_VALUES();