From 7079bb6a63f696df267d9c6637d5f6ed791bf677 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Fri, 1 Sep 2023 21:39:34 -0500 Subject: [PATCH] resist loading refactored as static method to NPCManager --- src/engine/gameManager/NPCManager.java | 53 ++++++++++++++++++++ src/engine/objects/AbstractCharacter.java | 2 +- src/engine/objects/Mob.java | 60 ++--------------------- 3 files changed, 58 insertions(+), 57 deletions(-) diff --git a/src/engine/gameManager/NPCManager.java b/src/engine/gameManager/NPCManager.java index e38b8a69..65719d21 100644 --- a/src/engine/gameManager/NPCManager.java +++ b/src/engine/gameManager/NPCManager.java @@ -346,4 +346,57 @@ public enum NPCManager { } } } + + public static void applyMobbaseEffects(Mob mob) { + EffectsBase effectsBase; + for (MobBaseEffects mbe : mob.mobBase.effectsList) { + + effectsBase = PowersManager.getEffectByToken(mbe.getToken()); + + if (effectsBase == null) { + Logger.info("Mob: " + mob.getObjectUUID() + " EffectsBase Null for Token " + mbe.getToken()); + continue; + } + + //check to upgrade effects if needed. + if (mob.effects.containsKey(Integer.toString(effectsBase.getUUID()))) { + + if (mbe.getReqLvl() > (int) mob.level) + continue; + + Effect eff = mob.effects.get(Integer.toString(effectsBase.getUUID())); + + if (eff == null) + continue; + + //Current effect is a higher rank, dont apply. + if (eff.getTrains() > mbe.getRank()) + continue; + + //new effect is of a higher rank. remove old effect and apply new one. + eff.cancelJob(); + mob.addEffectNoTimer(Integer.toString(effectsBase.getUUID()), effectsBase, mbe.getRank(), true); + } else { + + if (mbe.getReqLvl() > (int) mob.level) + continue; + + mob.addEffectNoTimer(Integer.toString(effectsBase.getUUID()), effectsBase, mbe.getRank(), true); + } + + } + } + + public static void applyEquipmentResists(Mob mob){ + if(mob.equip != null){ + for(MobEquipment equipped : mob.equip.values()){ + ItemBase itemBase = equipped.getItemBase(); + if(itemBase.isHeavyArmor() || itemBase.isLightArmor() || itemBase.isMediumArmor()){ + mob.resists.setResist(Enum.DamageType.Crush, mob.resists.getResist(Enum.DamageType.Crush,0) + itemBase.getCrushResist()); + mob.resists.setResist(Enum.DamageType.Slash, mob.resists.getResist(Enum.DamageType.Slash,0) + itemBase.getCrushResist()); + mob.resists.setResist(Enum.DamageType.Pierce, mob.resists.getResist(Enum.DamageType.Pierce,0) + itemBase.getCrushResist()); + } + } + } + } } diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 3d788dbe..84c5b784 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -88,7 +88,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { protected AtomicFloat mana = new AtomicFloat(); protected float manaMax; // Health/Mana/Stamina protected AtomicBoolean isAlive = new AtomicBoolean(true); - protected Resists resists = new Resists("Genric"); + public Resists resists = new Resists("Genric"); protected ConcurrentHashMap timers; protected ConcurrentHashMap timestamps; protected int atrHandOne; diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index e189e5b6..31ca46ce 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.EffectsBase; import engine.server.MBServerStatics; import org.joda.time.DateTime; import org.pmw.tinylog.Logger; @@ -70,7 +69,7 @@ public class Mob extends AbstractIntelligenceAgent { private int currentID; private long lastAttackTime = 0; private int lastMobPowerToken = 0; - private HashMap equip = null; + public HashMap equip = null; private DeferredPowerJob weaponPower; private DateTime upgradeDateTime = null; private boolean lootSync = false; @@ -974,7 +973,7 @@ public class Mob extends AbstractIntelligenceAgent { this.setLoc(this.lastBindLoc); this.stopMovement(this.lastBindLoc); - this.applyMobbaseEffects(); + NPCManager.applyMobbaseEffects(this); this.recalculateStats(); this.setHealth(this.healthMax); @@ -1663,8 +1662,8 @@ public class Mob extends AbstractIntelligenceAgent { if (this.getMobBase().enemy.size() > 0) this.enemy.addAll(this.getMobBase().enemy); } - this.applyMobbaseEffects(); - this.applyEquipmentResists(); + NPCManager.applyMobbaseEffects(this); + NPCManager.applyEquipmentResists(this); this.recalculateStats(); this.setHealth(this.healthMax); @@ -1683,18 +1682,6 @@ public class Mob extends AbstractIntelligenceAgent { } - public void applyEquipmentResists(){ - if(this.equip != null){ - for(MobEquipment equipped : this.equip.values()){ - ItemBase itemBase = equipped.getItemBase(); - if(itemBase.isHeavyArmor() || itemBase.isLightArmor() || itemBase.isMediumArmor()){ - this.resists.setResist(DamageType.Crush, this.resists.getResist(DamageType.Crush,0) + itemBase.getCrushResist()); - this.resists.setResist(DamageType.Slash, this.resists.getResist(DamageType.Slash,0) + itemBase.getCrushResist()); - this.resists.setResist(DamageType.Pierce, this.resists.getResist(DamageType.Pierce,0) + itemBase.getCrushResist()); - } - } - } - } @Override protected ConcurrentHashMap initializePowers() { return new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); @@ -1875,43 +1862,4 @@ public class Mob extends AbstractIntelligenceAgent { lock.writeLock().unlock(); } } - public void applyMobbaseEffects(){ - EffectsBase effectsBase; - for (MobBaseEffects mbe : this.mobBase.effectsList) { - - effectsBase = PowersManager.getEffectByToken(mbe.getToken()); - - if (effectsBase == null) { - Logger.info("Mob: " + this.getObjectUUID() + " EffectsBase Null for Token " + mbe.getToken()); - continue; - } - - //check to upgrade effects if needed. - if (this.effects.containsKey(Integer.toString(effectsBase.getUUID()))) { - - if (mbe.getReqLvl() > (int) this.level) - continue; - - Effect eff = this.effects.get(Integer.toString(effectsBase.getUUID())); - - if (eff == null) - continue; - - //Current effect is a higher rank, dont apply. - if (eff.getTrains() > mbe.getRank()) - continue; - - //new effect is of a higher rank. remove old effect and apply new one. - eff.cancelJob(); - this.addEffectNoTimer(Integer.toString(effectsBase.getUUID()), effectsBase, mbe.getRank(), true); - } else { - - if (mbe.getReqLvl() > (int) this.level) - continue; - - this.addEffectNoTimer(Integer.toString(effectsBase.getUUID()), effectsBase, mbe.getRank(), true); - } - - } - } }