diff --git a/src/engine/db/handlers/dbResistHandler.java b/src/engine/db/handlers/dbResistHandler.java index 7557ba37..40f63e75 100644 --- a/src/engine/db/handlers/dbResistHandler.java +++ b/src/engine/db/handlers/dbResistHandler.java @@ -23,7 +23,25 @@ public class dbResistHandler extends dbHandlerBase { public dbResistHandler() { } + public void LOAD_RESISTS_FOR_MOBS() { + Resists resists = null; + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mob_resists`;")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while(rs.next()){ + resists = new Resists(rs); + if(!Resists.mobResists.containsKey(rs.getInt("ID"))) + Resists.mobResists.put(rs.getInt("ID"),resists); + } + + } catch (SQLException e) { + Logger.error(e); + } + } public Resists GET_RESISTS_FOR_MOB(int resistID) { Resists resists = null; diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 8c2dc2c4..fedd978e 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -685,6 +685,9 @@ public abstract class AbstractCharacter extends AbstractWorldObject { } public final void setResists(final Resists value) { + if(this.getObjectType().equals(GameObjectType.Mob)) + return; + this.resists = value; } diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index a5b28aaf..ff11af12 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -38,6 +38,7 @@ import java.util.LinkedHashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantReadWriteLock; +import static engine.gameManager.NPCManager._runeSetMap; import static engine.net.client.msg.ErrorPopupMsg.sendErrorPopup; public class Mob extends AbstractIntelligenceAgent { @@ -161,14 +162,62 @@ public class Mob extends AbstractIntelligenceAgent { this.agentType = AIAgentType.MOBILE; - this.setResists(Resists.getResists(rs.getInt("mob_spawnType"))); + //this.setResists(Resists.getResists(rs.getInt("mob_spawnType"))); + setResistsForMob(this); } catch (Exception e) { Logger.error(e + " " + this.dbID); } } + public static void setResistsForMob(Mob mob){ + mob.resists = new Resists("Generic"); + Zone MacroParent = null; + for(Zone zone : ZoneManager.getAllZonesIn(mob.loc)){ + if(zone.isMacroZone() == false) + continue; + switch(zone.getName()){ + //ice generics + case "Ymur's Crown": + case "Kralgaar Holm": + case "Ecklund Wilds": + case "Aurrochs Skrae": + mob.resists = Resists.getResists(28); + break; + //Desert Generics + case "Leth'khalivar Desert": + case "Kharsoom": + case "Vale of Nar Addad": + case "The Blood Sands": + mob.resists = Resists.getResists(2); + break; + //Swamp Generics + case "Thollok Marsh": + case "The Black Bog": + case "Sevaath Mere": + mob.resists = Resists.getResists(10); + break; + //Oblivion Generics + case "Plain of Ashes": + case "Bone Marches": + case "The Doomplain": + case "Greensward Pyre": + mob.resists = Resists.getResists(4); + break; + //Maelstrom Generics + case "Pandemonium": + case "Western Battleground": + mob.resists = Resists.getResists(32); + break; + } + if(mob.getNameOverride().length() > 1){ + mob.resists = Resists.getResists(3); + } + + } + } + public static void serializeMobForClientMsgOtherPlayer(Mob mob, ByteBufferWriter writer) throws SerializationException { Mob.serializeForClientMsgOtherPlayer(mob, writer); } diff --git a/src/engine/objects/Resists.java b/src/engine/objects/Resists.java index fa0188ea..c2970d6b 100644 --- a/src/engine/objects/Resists.java +++ b/src/engine/objects/Resists.java @@ -27,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap; public class Resists { - private static ConcurrentHashMap mobResists = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + public static ConcurrentHashMap mobResists = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); private ConcurrentHashMap resists = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); private ConcurrentHashMap immuneTo = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); private DamageType protection; diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index b7282b94..2386efd5 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -375,6 +375,10 @@ public class WorldServer { BaseClass.LoadAllBaseClasses(); Race.loadAllRaces(); RuneBaseEffect.LoadRuneBaseEffects(); + + Logger.info("Loading MobBases."); + DbManager.ResistQueries.LOAD_RESISTS_FOR_MOBS(); + Logger.info("Loading MobBases."); DbManager.MobBaseQueries.GET_ALL_MOBBASES();