From 38e5081b0e39a2a60de47f785ec08ab62394dfeb Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 22 Apr 2023 17:16:34 -0500 Subject: [PATCH] moved createSiegeMob and createGuardMob to the Mob class --- src/engine/ai/MobileFSM.java | 4 - src/engine/db/handlers/dbMobHandler.java | 2 +- src/engine/devcmd/cmds/InfoCmd.java | 2 +- src/engine/gameManager/NPCManager.java | 129 ----------- .../handlers/MinionTrainingMsgHandler.java | 4 +- src/engine/objects/Mob.java | 200 +++++++++++++++++- src/engine/objects/NPC.java | 46 ---- 7 files changed, 195 insertions(+), 192 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 23bce07b..dae40c36 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -554,10 +554,6 @@ public class MobileFSM { public static void GuardMinionLogic(Mob mob){ if(mob.despawned){ if(System.currentTimeMillis() > mob.deathTime + (mob.spawnTime * 1000)){ - if(mob.getEquipmentSetID() != ((Mob)mob.npcOwner).getEquipmentSetID()){ - mob.equipmentSetID = ((Mob)mob.npcOwner).getEquipmentSetID(); - mob.runAfterLoad(); - } mob.respawn(); } return; diff --git a/src/engine/db/handlers/dbMobHandler.java b/src/engine/db/handlers/dbMobHandler.java index dfc85902..8a73b01e 100644 --- a/src/engine/db/handlers/dbMobHandler.java +++ b/src/engine/db/handlers/dbMobHandler.java @@ -114,7 +114,7 @@ public class dbMobHandler extends dbHandlerBase { while (rs.next()) { int mobBaseID = rs.getInt("mobBaseID"); String name = rs.getString("name"); - Mob toCreate = NPCManager.createGuardMob(captain, captain.getGuild(), captain.getParentZone(), captain.building.getLoc(), captain.getLevel(),name); + Mob toCreate = Mob.createGuardMob(captain, captain.getGuild(), captain.getParentZone(), captain.building.getLoc(), captain.getLevel(),name); if (toCreate == null) return; diff --git a/src/engine/devcmd/cmds/InfoCmd.java b/src/engine/devcmd/cmds/InfoCmd.java index c36158a9..1fbaffa8 100644 --- a/src/engine/devcmd/cmds/InfoCmd.java +++ b/src/engine/devcmd/cmds/InfoCmd.java @@ -463,7 +463,7 @@ public class InfoCmd extends AbstractDevCmd { output += newline; output += "Speed : " + targetMob.getSpeed(); output += newline; - output += "EquipSet: " + targetMob.getEquipmentSetID(); + output += "EquipSet: " + targetMob.equipmentSetID; output += newline; output += "Parent Zone LoadNum : " + targetMob.getParentZone().getLoadNum(); output += newline; diff --git a/src/engine/gameManager/NPCManager.java b/src/engine/gameManager/NPCManager.java index caf2b9e3..1ba7ca68 100644 --- a/src/engine/gameManager/NPCManager.java +++ b/src/engine/gameManager/NPCManager.java @@ -200,136 +200,7 @@ public enum NPCManager { playerCharacter.necroPets.clear(); } - public static synchronized Mob createGuardMob(Mob guardCaptain, Guild guild, Zone parent, Vector3fImmutable loc, short level, String pirateName) { - MobBase minionMobBase; - Mob mob; - int maxSlots = 1; - - switch (guardCaptain.getRank()) { - case 1: - case 2: - maxSlots = 1; - break; - case 3: - maxSlots = 2; - break; - case 4: - case 5: - maxSlots = 3; - break; - case 6: - maxSlots = 4; - break; - case 7: - maxSlots = 5; - break; - default: - maxSlots = 1; - - } - - if (guardCaptain.siegeMinionMap.size() == maxSlots) - return null; - - minionMobBase = guardCaptain.mobBase; - - if (minionMobBase == null) - return null; - - mob = new Mob(minionMobBase, guild, parent, level, new Vector3fImmutable(1, 1, 1), 0, true); - - mob.despawned = true; - - mob.setLevel(level); - //grab equipment and name from minionbase. - if (guardCaptain.contract != null) { - Enum.MinionType minionType = Enum.MinionType.ContractToMinionMap.get(guardCaptain.contract.getContractID()); - if (minionType != null) { - mob.equipmentSetID = minionType.getEquipSetID(); - String rank = ""; - - if (guardCaptain.getRank() < 3) - rank = MBServerStatics.JUNIOR; - else if (guardCaptain.getRank() < 6) - rank = ""; - else if (guardCaptain.getRank() == 6) - rank = MBServerStatics.VETERAN; - else - rank = MBServerStatics.ELITE; - - if (rank.isEmpty()) - mob.nameOverride = pirateName + " " + minionType.getRace() + " " + minionType.getName(); - else - mob.nameOverride = pirateName + " " + minionType.getRace() + " " + rank + " " + minionType.getName(); - } - } - - if (parent != null) - mob.setRelPos(parent, loc.x - parent.absX, loc.y - parent.absY, loc.z - parent.absZ); - - mob.setObjectTypeMask(MBServerStatics.MASK_MOB | mob.getTypeMasks()); - - // mob.setMob(); - mob.isPlayerGuard = true; - mob.setParentZone(parent); - DbManager.addToCache(mob); - mob.runAfterLoad(); - - - RuneBase guardRune = RuneBase.getRuneBase(252621); - - for (MobBaseEffects mbe : guardRune.getEffectsList()) { - - EffectsBase eb = PowersManager.getEffectByToken(mbe.getToken()); - - if (eb == null) { - Logger.info("EffectsBase Null for Token " + mbe.getToken()); - continue; - } - - //check to upgrade effects if needed. - if (mob.effects.containsKey(Integer.toString(eb.getUUID()))) { - if (mbe.getReqLvl() > (int) mob.level) { - continue; - } - - Effect eff = mob.effects.get(Integer.toString(eb.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(eb.getUUID()), eb, mbe.getRank(), true); - } else { - - if (mbe.getReqLvl() > (int) mob.level) - continue; - - mob.addEffectNoTimer(Integer.toString(eb.getUUID()), eb, mbe.getRank(), true); - } - } - - int slot = 0; - slot += guardCaptain.siegeMinionMap.size() + 1; - - guardCaptain.siegeMinionMap.put(mob, slot); - mob.setInBuildingLoc(guardCaptain.building, guardCaptain); - //mob.setBindLoc(loc.add(mob.inBuildingLoc)); - mob.setLoc(guardCaptain.building.getLoc()); - mob.setLastRegion(AbstractWorldObject.GetRegionByWorldObject(mob)); - mob.setBindLoc(guardCaptain.building.getStuckLocation()); - mob.deathTime = System.currentTimeMillis(); - mob.spawnTime = 900; - mob.npcOwner = guardCaptain; - mob.BehaviourType = Enum.MobBehaviourType.GuardMinion; - return mob; - } public static void removeSiegeMinions(Mob mobile) { diff --git a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java index 291af9b1..31966887 100644 --- a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java +++ b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java @@ -148,7 +148,7 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { if (mobBase == 0) return true; - Mob toCreate = npc.createSiegeMob(mobBase, npc.getGuild(), zone, b.getLoc(), (short) 1); + Mob toCreate = Mob.createSiegeMob(npc,mobBase, npc.getGuild(), zone, b.getLoc(), (short) 1); if (toCreate == null) return true; @@ -280,7 +280,7 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { if (!DbManager.MobQueries.ADD_TO_GUARDS(npc.getObjectUUID(), mobBase, pirateName, npc.getSiegeMinionMap().size() + 1)) return true; - Mob toCreate = NPCManager.createGuardMob(npc, npc.getGuild(), zone, b.getLoc(), npc.getLevel(),pirateName); + Mob toCreate = Mob.createGuardMob(npc, npc.getGuild(), zone, b.getLoc(), npc.getLevel(),pirateName); if (toCreate == null) return true; diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 10b388a5..d026adc1 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -29,6 +29,7 @@ import engine.net.client.msg.ErrorPopupMsg; import engine.net.client.msg.ManageCityAssetsMsg; 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; @@ -719,7 +720,9 @@ public class Mob extends AbstractIntelligenceAgent { if (!isPet && this.contract == null) this.level = (short) this.mobBase.getLevel(); else this.level = 1; } - + if (this.building != null && this.contract != null) { + slotMobInBuilding(); // picks first available free slot + } //set bonuses this.bonuses = new PlayerBonuses(this); @@ -1913,10 +1916,6 @@ public class Mob extends AbstractIntelligenceAgent { return lastRegion; } - public void setLastRegion(Regions lastRegion) { - this.lastRegion = lastRegion; - } - public boolean isLootSync() { return lootSync; } @@ -1929,10 +1928,6 @@ public class Mob extends AbstractIntelligenceAgent { return equip; } - public int getEquipmentSetID() { - return equipmentSetID; - } - public String getNameOverride() { return nameOverride; } @@ -2092,4 +2087,191 @@ public class Mob extends AbstractIntelligenceAgent { } } } + private void slotMobInBuilding() { + int maxSlots = 10; + + for (int slot = 1; slot < maxSlots + 1; slot++) + if (!this.building.getHirelings().containsValue(slot)) { + this.building.getHirelings().put(this, slot); + break; + } + } + public static synchronized Mob createGuardMob(Mob guardCaptain, Guild guild, Zone parent, Vector3fImmutable loc, short level, String pirateName) { + + MobBase minionMobBase; + Mob mob; + int maxSlots = 1; + + switch (guardCaptain.getRank()) { + case 1: + case 2: + maxSlots = 1; + break; + case 3: + maxSlots = 2; + break; + case 4: + case 5: + maxSlots = 3; + break; + case 6: + maxSlots = 4; + break; + case 7: + maxSlots = 5; + break; + default: + maxSlots = 1; + + } + + if (guardCaptain.siegeMinionMap.size() == maxSlots) + return null; + + minionMobBase = guardCaptain.mobBase; + + if (minionMobBase == null) + return null; + + mob = new Mob(minionMobBase, guild, parent, level, new Vector3fImmutable(1, 1, 1), 0, true); + mob.setLevel(level); + if(guardCaptain.equipmentSetID != 0) + mob.equipmentSetID = guardCaptain.equipmentSetID; + + mob.runAfterLoad(); + mob.despawned = true; + //grab equipment and name from minionbase. + if (guardCaptain.contract != null) { + Enum.MinionType minionType = Enum.MinionType.ContractToMinionMap.get(guardCaptain.contract.getContractID()); + if (minionType != null) { + String rank = ""; + + if (guardCaptain.getRank() < 3) + rank = MBServerStatics.JUNIOR; + else if (guardCaptain.getRank() < 6) + rank = ""; + else if (guardCaptain.getRank() == 6) + rank = MBServerStatics.VETERAN; + else + rank = MBServerStatics.ELITE; + + if (rank.isEmpty()) + mob.nameOverride = pirateName + " " + minionType.getRace() + " " + minionType.getName(); + else + mob.nameOverride = pirateName + " " + minionType.getRace() + " " + rank + " " + minionType.getName(); + } + } + + if (parent != null) + mob.setRelPos(parent, loc.x - parent.absX, loc.y - parent.absY, loc.z - parent.absZ); + + mob.setObjectTypeMask(MBServerStatics.MASK_MOB | mob.getTypeMasks()); + + // mob.setMob(); + mob.isPlayerGuard = true; + mob.setParentZone(parent); + DbManager.addToCache(mob); + + + + RuneBase guardRune = RuneBase.getRuneBase(252621); + + for (MobBaseEffects mbe : guardRune.getEffectsList()) { + + EffectsBase eb = PowersManager.getEffectByToken(mbe.getToken()); + + if (eb == null) { + Logger.info("EffectsBase Null for Token " + mbe.getToken()); + continue; + } + + //check to upgrade effects if needed. + if (mob.effects.containsKey(Integer.toString(eb.getUUID()))) { + if (mbe.getReqLvl() > (int) mob.level) { + continue; + } + + Effect eff = mob.effects.get(Integer.toString(eb.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(eb.getUUID()), eb, mbe.getRank(), true); + } else { + + if (mbe.getReqLvl() > (int) mob.level) + continue; + + mob.addEffectNoTimer(Integer.toString(eb.getUUID()), eb, mbe.getRank(), true); + } + } + + int slot = 0; + slot += guardCaptain.siegeMinionMap.size() + 1; + + guardCaptain.siegeMinionMap.put(mob, slot); + mob.setInBuildingLoc(guardCaptain.building, guardCaptain); + Vector3fImmutable buildingWorldLoc = ZoneManager.convertLocalToWorld(guardCaptain.building, mob.inBuildingLoc); + mob.setBindLoc(buildingWorldLoc); + mob.setLoc(buildingWorldLoc); + mob.deathTime = System.currentTimeMillis(); + mob.spawnTime = 900; + mob.npcOwner = guardCaptain; + mob.BehaviourType = Enum.MobBehaviourType.GuardMinion; + + return mob; + } + public static synchronized Mob createSiegeMob(NPC owner, int loadID, Guild guild, Zone parent, Vector3fImmutable loc, short level) { + + MobBase minionMobBase; + Mob mob; + + if (owner.getSiegeMinionMap().size() == 3) + return null; + + minionMobBase = MobBase.getMobBase(loadID); + + if (minionMobBase == null) + return null; + + mob = new Mob(minionMobBase, guild, parent, level,new Vector3fImmutable(1,1,1), 0,false); + mob.runAfterLoad(); + mob.despawned = true; + DbManager.addToCache(mob); + + if (parent != null) + mob.setRelPos(parent, loc.x - parent.absX, loc.y - parent.absY, loc.z - parent.absZ); + + mob.setObjectTypeMask(MBServerStatics.MASK_MOB | mob.getTypeMasks()); + + //mob.setMob(); + mob.setSiege(true); + mob.setParentZone(parent); + + int slot = 0; + + if (!owner.getSiegeMinionMap().containsValue(1)) + slot = 1; + else if (!owner.getSiegeMinionMap().containsValue(2)) + slot = 2; + + owner.getSiegeMinionMap().put(mob, slot); + mob.setInBuildingLoc(owner.building, owner); + + Vector3fImmutable buildingWorldLoc = ZoneManager.convertLocalToWorld(owner.building, mob.inBuildingLoc); + mob.setBindLoc(buildingWorldLoc); + mob.setLoc(buildingWorldLoc); + + mob.setSpawnTime(10); + mob.setNpcOwner(owner); + mob.BehaviourType = MobBehaviourType.Pet1; + mob.BehaviourType.canRoam = false; + return mob; + } } diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index f667178b..18d6f503 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -1435,53 +1435,7 @@ public class NPC extends AbstractCharacter { } - public synchronized Mob createSiegeMob(int loadID, Guild guild, Zone parent, Vector3fImmutable loc, short level) { - MobBase minionMobBase; - Mob mob; - - if (siegeMinionMap.size() == 3) - return null; - - minionMobBase = MobBase.getMobBase(loadID); - - if (minionMobBase == null) - return null; - - mob = new Mob(minionMobBase, guild, parent, level,new Vector3fImmutable(1,1,1), 0,false); - mob.runAfterLoad(); - mob.despawned = true; - DbManager.addToCache(mob); - - if (parent != null) - mob.setRelPos(parent, loc.x - parent.absX, loc.y - parent.absY, loc.z - parent.absZ); - - mob.setObjectTypeMask(MBServerStatics.MASK_MOB | mob.getTypeMasks()); - - //mob.setMob(); - mob.setSiege(true); - mob.setParentZone(parent); - - int slot = 0; - - if (!siegeMinionMap.containsValue(1)) - slot = 1; - else if (!siegeMinionMap.containsValue(2)) - slot = 2; - - siegeMinionMap.put(mob, slot); - mob.setInBuildingLoc(this.building, this); - - Vector3fImmutable buildingWorldLoc = ZoneManager.convertLocalToWorld(this.building, mob.inBuildingLoc); - mob.setBindLoc(buildingWorldLoc); - mob.setLoc(buildingWorldLoc); - - mob.setSpawnTime(10); - mob.setNpcOwner(this); - mob.BehaviourType = MobBehaviourType.Pet1; - mob.BehaviourType.canRoam = false; - return mob; - } public int getUpgradeCost() {