diff --git a/src/engine/db/handlers/dbMobHandler.java b/src/engine/db/handlers/dbMobHandler.java index e3d64b0a..f4c5b854 100644 --- a/src/engine/db/handlers/dbMobHandler.java +++ b/src/engine/db/handlers/dbMobHandler.java @@ -12,7 +12,6 @@ package engine.db.handlers; import engine.gameManager.DbManager; import engine.objects.Mob; import engine.objects.Zone; -import engine.server.MBServerStatics; import org.joda.time.DateTime; import org.pmw.tinylog.Logger; @@ -122,10 +121,9 @@ public class dbMobHandler extends dbHandlerBase { if (toCreate == null) return; - if (toCreate != null) { - toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES); + if (toCreate != null) toCreate.setDeathTime(System.currentTimeMillis()); - } + } } catch (SQLException e) { diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index a54ea968..64df857c 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -50,15 +50,18 @@ public class MobAI { } if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter && canCast(mob)) { + if (mob.isPlayerGuard() == false && MobCast(mob)) { mob.updateLocation(); return; } + if (mob.isPlayerGuard() == true && GuardCast(mob)) { mob.updateLocation(); return; } } + if (!CombatUtilities.inRangeToAttack(mob, target)) return; @@ -258,7 +261,9 @@ public class MobAI { //guard captains inherit barracks patrol points dynamically if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) { + Building barracks = mob.building; + if (barracks != null && barracks.patrolPoints != null && !barracks.getPatrolPoints().isEmpty()) { mob.patrolPoints = barracks.patrolPoints; } else { @@ -275,8 +280,8 @@ public class MobAI { MovementUtilities.aiMove(mob, mob.destination, true); - if (mob.BehaviourType.equals(Enum.MobBehaviourType.GuardCaptain)) { - for (Entry minion : mob.siegeMinionMap.entrySet()) { + if (mob.BehaviourType.equals(Enum.MobBehaviourType.GuardCaptain)) + for (Entry minion : mob.siegeMinionMap.entrySet()) //make sure mob is out of combat stance @@ -288,8 +293,6 @@ public class MobAI { MovementUtilities.aiMove(minion.getKey(), formationPatrolPoint, true); } } - } - } } catch (Exception e) { Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackTarget" + " " + e.getMessage()); } @@ -306,11 +309,14 @@ public class MobAI { return false; if(mob.isPlayerGuard == true){ + int contractID; + if(mob.BehaviourType.equals(Enum.MobBehaviourType.GuardMinion)) contractID = mob.npcOwner.contract.getContractID(); else contractID = mob.contract.getContractID(); + if(Enum.MinionType.ContractToMinionMap.get(contractID).isMage() == false) return false; } @@ -384,24 +390,20 @@ public class MobAI { //check for hit-roll - if (mobPower.requiresHitRoll) { - + if (mobPower.requiresHitRoll) if (CombatUtilities.triggerDefense(mob, mob.getCombatTarget())) return false; - } // Cast the spell if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) { - PerformActionMsg msg; if (!mobPower.isHarmful() || mobPower.targetSelf) { PowersManager.useMobPower(mob, mob, mobPower, powerRank); msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, mob); - } - else { + } else { PowersManager.useMobPower(mob, target, mobPower, powerRank); msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target); } @@ -410,6 +412,7 @@ public class MobAI { PowersManager.finishUseMobPower(msg, mob, 0, 0); long randomCooldown = (long)((ThreadLocalRandom.current().nextInt(10,15) * 1000) * MobAIThread.AI_CAST_FREQUENCY); + mob.nextCastTime = System.currentTimeMillis() + randomCooldown; return true; } @@ -642,10 +645,12 @@ public class MobAI { mob.setCombatTarget(null); return; } + if (mob.BehaviourType.ordinal() != Enum.MobBehaviourType.Pet1.ordinal()) CheckToSendMobHome(mob); if (mob.getCombatTarget() != null) { + if (mob.getCombatTarget().isAlive() == false) { mob.setCombatTarget(null); return; @@ -753,7 +758,7 @@ public class MobAI { for (AbstractWorldObject awoMob : awoList) { - //dont scan self. + // exclude self. if (aiAgent.equals(awoMob)) continue; @@ -867,7 +872,7 @@ public class MobAI { } } } else if (System.currentTimeMillis() > (aiAgent.deathTime + (aiAgent.spawnTime * 1000))) { - //aiAgent.respawn(); + if (Zone.respawnQue.contains(aiAgent) == false) { Zone.respawnQue.add(aiAgent); } @@ -957,6 +962,7 @@ public class MobAI { float rangeSquared = mob.getRange() * mob.getRange(); float distanceSquared = mob.getLoc().distanceSquared2D(mob.getCombatTarget().getLoc()); + if(mob.isMoving() == true && distanceSquared < rangeSquared - 50) { mob.destination = mob.getLoc(); MovementUtilities.moveToLocation(mob, mob.destination, 0); @@ -1002,12 +1008,14 @@ public class MobAI { Mob aggroMob = (Mob) awoMob; - //dont attack other guards + //don't attack other guards if (aggroMob.isGuard()) continue; + if(aggroMob.BehaviourType.equals(Enum.MobBehaviourType.Pet1)) continue; + if (mob.getLoc().distanceSquared2D(aggroMob.getLoc()) > sqr(50)) continue; @@ -1048,9 +1056,9 @@ public class MobAI { try { if (!mob.npcOwner.isAlive()) { - if(mob.getCombatTarget() == null) { + if (mob.getCombatTarget() == null) { CheckForPlayerGuardAggro(mob); - }else { + } else { AbstractWorldObject newTarget = ChangeTargetFromHateValue(mob); @@ -1095,10 +1103,10 @@ public class MobAI { private static void PetLogic(Mob mob) { try { - if (mob.getOwner() == null && mob.isNecroPet() == false && mob.isSiege() == false) { + + if (mob.getOwner() == null && mob.isNecroPet() == false && mob.isSiege() == false) if (ZoneManager.getSeaFloor().zoneMobSet.contains(mob)) mob.killCharacter("no owner"); - } if (MovementUtilities.canMove(mob) && mob.BehaviourType.canRoam) CheckMobMovement(mob); @@ -1110,17 +1118,16 @@ public class MobAI { if (mob.getTimestamps().containsKey("HEALTHRECOVERED") == false) mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis()); - if (mob.isSit() && mob.getTimeStamp("HEALTHRECOVERED") < System.currentTimeMillis() + 3000) { + if (mob.isSit() && mob.getTimeStamp("HEALTHRECOVERED") < System.currentTimeMillis() + 3000) if (mob.getHealth() < mob.getHealthMax()) { + float recoveredHealth = mob.getHealthMax() * ((1 + mob.getBonuses().getFloatPercentAll(Enum.ModType.HealthRecoverRate, Enum.SourceType.None)) * 0.01f); mob.setHealth(mob.getHealth() + recoveredHealth); mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis()); - if (mob.getHealth() > mob.getHealthMax()) { + if (mob.getHealth() > mob.getHealthMax()) mob.setHealth(mob.getHealthMax()); - } } - } } catch (Exception e) { Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: PetLogic" + " " + e.getMessage()); } diff --git a/src/engine/mobileAI/Threads/MobRespawnThread.java b/src/engine/mobileAI/Threads/MobRespawnThread.java index eee68bb3..24e2f281 100644 --- a/src/engine/mobileAI/Threads/MobRespawnThread.java +++ b/src/engine/mobileAI/Threads/MobRespawnThread.java @@ -25,9 +25,6 @@ import org.pmw.tinylog.Logger; public class MobRespawnThread implements Runnable { - // Instance variables - - // Thread constructor public MobRespawnThread() { Logger.info(" MobRespawnThread thread has started!"); diff --git a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java index 22a60adf..8c425c04 100644 --- a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java +++ b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java @@ -14,7 +14,6 @@ import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.*; import engine.objects.*; -import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; import java.util.ArrayList; @@ -69,7 +68,6 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { npc.getSiegeMinionMap().remove(toRemove); - //toRemove.disableIntelligence(); WorldGrid.RemoveWorldObject(toRemove); if (toRemove.getParentZone() != null) @@ -199,9 +197,9 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { if (npc == null) return true; - Building b = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID()); + Building building = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID()); - if (b == null) + if (building == null) return true; //clear minion @@ -211,6 +209,7 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { if (minionMsg.getType() == 2) { Mob toRemove = Mob.getFromCache(minionMsg.getUUID()); + if (!npc.getSiegeMinionMap().containsKey(toRemove)) return true; @@ -219,7 +218,6 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { npc.getSiegeMinionMap().remove(toRemove); - //toRemove.disableIntelligence(); WorldGrid.RemoveWorldObject(toRemove); if (toRemove.getParentZone() != null) @@ -236,21 +234,18 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); } - // we Found the move to remove, lets break the for loop so it doesnt look for more. - - ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, b); + ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, building); mca1.actionType = 3; - mca1.setTargetType(b.getObjectType().ordinal()); - mca1.setTargetID(b.getObjectUUID()); + mca1.setTargetType(building.getObjectType().ordinal()); + mca1.setTargetID(building.getObjectUUID()); mca1.setTargetType3(npc.getObjectType().ordinal()); mca1.setTargetID3(npc.getObjectUUID()); - mca1.setAssetName1(b.getName()); + mca1.setAssetName1(building.getName()); mca1.setUnknown54(1); Dispatch dispatch = Dispatch.borrow(player, mca1); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - ; ManageNPCMsg mnm = new ManageNPCMsg(npc); dispatch = Dispatch.borrow(player, mnm); @@ -302,14 +297,14 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { if (!DbManager.MobQueries.ADD_TO_GUARDS(npc.getObjectUUID(), mobBase, pirateName, npc.getSiegeMinionMap().size() + 1)) return true; - Mob toCreate = Mob.createGuardMob(npc, npc.getGuild(), zone, b.getLoc(), npc.getLevel(), pirateName); + Mob toCreate = Mob.createGuardMob(npc, npc.getGuild(), zone, building.getLoc(), npc.getLevel(), pirateName); if (toCreate == null) return true; // toCreate.despawn(); + if (toCreate != null) { - toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES); toCreate.setDeathTime(System.currentTimeMillis()); toCreate.parentZone.zoneMobSet.add(toCreate); } diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index b5183c00..f6b17f21 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -95,7 +95,6 @@ public class Mob extends AbstractIntelligenceAgent { private AbstractWorldObject fearedObject = null; private int buildingID; private boolean isSiege = false; - private long timeToSpawnSiege; private long lastAttackTime = 0; private int lastMobPowerToken = 0; private HashMap equip = null; @@ -103,6 +102,7 @@ public class Mob extends AbstractIntelligenceAgent { private DateTime upgradeDateTime = null; private boolean lootSync = false; + /** * No Id Constructor */ @@ -1309,10 +1309,9 @@ public class Mob extends AbstractIntelligenceAgent { this.hasLoot = false; this.playerAgroMap.clear(); - this.timeToSpawnSiege = System.currentTimeMillis() + 60 * 15 * 1000; - if (this.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) { + if (this.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) this.spawnTime = (int) (-2.500 * ((Mob) this.npcOwner).building.getRank() + 22.5) * 60; - } + if (this.isPet()) { PlayerCharacter petOwner = this.getOwner(); @@ -1333,10 +1332,8 @@ public class Mob extends AbstractIntelligenceAgent { this.hasLoot = false; //if (this.parentZone != null) - //this.parentZone.zoneMobSet.remove(this); - if(ZoneManager.getSeaFloor().zoneMobSet.contains(this)) { - ZoneManager.getSeaFloor().zoneMobSet.remove(this); - } + //this.parentZone.zoneMobSet.remove(this); + ZoneManager.getSeaFloor().zoneMobSet.remove(this); try { this.clearEffects(); } catch (Exception e) { @@ -1382,9 +1379,8 @@ public class Mob extends AbstractIntelligenceAgent { } public void respawn() { - //Commenting out Mob ID rotation. + this.despawned = false; - //this.playerAgroMap.clear(); this.setCombatTarget(null); this.setHealth(this.healthMax); this.stamina.set(this.staminaMax); @@ -1397,17 +1393,22 @@ public class Mob extends AbstractIntelligenceAgent { this.lastBindLoc = this.bindLoc; this.setLoc(this.lastBindLoc); this.stopMovement(this.lastBindLoc); + NPCManager.applyRuneSetEffects(this); + this.recalculateStats(); this.setHealth(this.healthMax); - if (this.building == null && this.npcOwner != null && ((Mob) this.npcOwner).BehaviourType.ordinal() == MobBehaviourType.GuardCaptain.ordinal()) { + + if (this.building == null && this.npcOwner != null && ((Mob) this.npcOwner).BehaviourType.ordinal() == MobBehaviourType.GuardCaptain.ordinal()) this.building = ((Mob) this.npcOwner).building; - } else if (this.building != null) { + else if (this.building != null) this.region = BuildingManager.GetRegion(this.building, bindLoc.x, bindLoc.y, bindLoc.z); - } + //MovementManager.translocate(this, this.bindLoc, this.region); + if (!this.isSiege && !this.isPlayerGuard && contract == null) loadInventory(); + this.updateLocation(); } @@ -1488,7 +1489,7 @@ public class Mob extends AbstractIntelligenceAgent { float s; h = this.mobBase.getHealthMax(); - if(this.isPet()){ + if (this.isPet()) { h = this.level * 0.5f * 120; } m = this.statSpiCurrent; @@ -2059,10 +2060,6 @@ public class Mob extends AbstractIntelligenceAgent { this.isSiege = isSiege; } - public void setTimeToSpawnSiege(long timeToSpawnSiege) { - this.timeToSpawnSiege = timeToSpawnSiege; - } - public void setNpcOwner(AbstractCharacter npcOwner) { this.npcOwner = npcOwner; }