Browse Source

Comment updated.

combat-2
MagicBot 6 months ago
parent
commit
5de932b095
  1. 87
      src/engine/mobileAI/MobAI.java

87
src/engine/mobileAI/MobAI.java

@ -43,6 +43,7 @@ public class MobAI {
// Controls all mob actions from regular mobs to pets and guards. // Controls all mob actions from regular mobs to pets and guards.
// Initiates in the "DetermineAction" method and branches from there // Initiates in the "DetermineAction" method and branches from there
// //
// CombatManager.class implements shared combat routines for all avatars.
private static void attackTarget(Mob mob, AbstractWorldObject target) { private static void attackTarget(Mob mob, AbstractWorldObject target) {
@ -56,8 +57,7 @@ public class MobAI {
return; return;
} }
if (target.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && if (target.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && !mob.canSee((AbstractCharacter) target)) {
!mob.canSee((AbstractCharacter) target)) {
mob.setCombatTarget(null); mob.setCombatTarget(null);
return; return;
} }
@ -125,7 +125,7 @@ public class MobAI {
} }
if (target.getPet() != null) if (target.getPet() != null)
if (target.getPet().getCombatTarget() == null && target.getPet().assist == true) if (target.getPet().getCombatTarget() == null && target.getPet().assist)
target.getPet().setCombatTarget(mob); target.getPet().setCombatTarget(mob);
} catch (Exception e) { } catch (Exception e) {
@ -177,7 +177,6 @@ public class MobAI {
//no weapons, default mob attack speed 3 seconds. //no weapons, default mob attack speed 3 seconds.
CombatManager.combatCycle(mob, target); CombatManager.combatCycle(mob, target);
} catch (Exception e) { } catch (Exception e) {
@ -194,10 +193,9 @@ public class MobAI {
// early exit while waiting to patrol again. // early exit while waiting to patrol again.
// Minions are force marched if captain is alive // Minions are force marched if captain is alive
boolean forced = mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION) && boolean forced = mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION) && mob.guardCaptain.isAlive();
mob.guardCaptain.isAlive();
if (mob.stopPatrolTime + (patrolDelay * 1000) > System.currentTimeMillis()) if (mob.stopPatrolTime + (patrolDelay * 1000L) > System.currentTimeMillis())
if (!forced) if (!forced)
return; return;
@ -258,7 +256,7 @@ public class MobAI {
if (mob == null) if (mob == null)
return false; return false;
if (mob.isPlayerGuard() == true) { if (mob.isPlayerGuard()) {
if (mob.agentType.equals(mbEnums.AIAgentType.GUARDWALLARCHER)) if (mob.agentType.equals(mbEnums.AIAgentType.GUARDWALLARCHER))
return false; //wall archers don't cast return false; //wall archers don't cast
@ -269,14 +267,13 @@ public class MobAI {
// exception allowing werewolf and werebear guard captains to cast // exception allowing werewolf and werebear guard captains to cast
if (mbEnums.MinionType.ContractToMinionMap.get(contractID).isMage() == false && contractID != 980103 && contractID != 980104) if (!mbEnums.MinionType.ContractToMinionMap.get(contractID).isMage() && contractID != 980103 && contractID != 980104)
return false; return false;
} }
// Mobile has no powers defined in mobbase or contract.. // Mobile has no powers defined in mobbase or contract..
if (PowersManager.getPowersForRune(mob.getMobBaseID()).isEmpty() && if (PowersManager.getPowersForRune(mob.getMobBaseID()).isEmpty() && PowersManager.getPowersForRune(contractID).isEmpty())
PowersManager.getPowersForRune(contractID).isEmpty())
return false; return false;
if (mob.nextCastTime == 0) if (mob.nextCastTime == 0)
@ -376,7 +373,7 @@ public class MobAI {
msg.setUnknown04(2); msg.setUnknown04(2);
PowersManager.finishUseMobPower(msg, mob, 0, 0); PowersManager.finishUseMobPower(msg, mob, 0, 0);
long randomCooldown = (long) ((ThreadLocalRandom.current().nextInt(10, 15) * 1000) * MobAIThread.AI_CAST_FREQUENCY); long randomCooldown = (long) ((ThreadLocalRandom.current().nextInt(10, 15) * 1000L) * MobAIThread.AI_CAST_FREQUENCY);
mob.nextCastTime = System.currentTimeMillis() + randomCooldown; mob.nextCastTime = System.currentTimeMillis() + randomCooldown;
return true; return true;
@ -460,7 +457,7 @@ public class MobAI {
if (mob == null) if (mob == null)
return; return;
if (mob.getTimestamps().containsKey("lastExecution") == false) if (!mob.getTimestamps().containsKey("lastExecution"))
mob.getTimestamps().put("lastExecution", System.currentTimeMillis()); mob.getTimestamps().put("lastExecution", System.currentTimeMillis());
if (System.currentTimeMillis() < mob.getTimeStamp("lastExecution")) if (System.currentTimeMillis() < mob.getTimeStamp("lastExecution"))
@ -480,11 +477,11 @@ public class MobAI {
if (mob.despawned && mob.isPlayerGuard()) { if (mob.despawned && mob.isPlayerGuard()) {
if (mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION)) { if (mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION)) {
if (mob.guardCaptain.isAlive() == false || ((Mob) mob.guardCaptain).despawned == true) { if (!mob.guardCaptain.isAlive() || ((Mob) mob.guardCaptain).despawned) {
//minions don't respawn while guard captain is dead //minions don't respawn while guard captain is dead
if (mob.isAlive() == false) { if (!mob.isAlive()) {
mob.deathTime = System.currentTimeMillis(); mob.deathTime = System.currentTimeMillis();
return; return;
} }
@ -525,12 +522,12 @@ public class MobAI {
} }
if (mob.agentType.equals(mbEnums.AIAgentType.PET) == false) if (!mob.agentType.equals(mbEnums.AIAgentType.PET))
checkToSendMobHome(mob); checkToSendMobHome(mob);
if (mob.getCombatTarget() != null) { if (mob.getCombatTarget() != null) {
if (mob.getCombatTarget().isAlive() == false) { if (!mob.getCombatTarget().isAlive()) {
mob.setCombatTarget(null); mob.setCombatTarget(null);
return; return;
} }
@ -539,12 +536,12 @@ public class MobAI {
PlayerCharacter target = (PlayerCharacter) mob.getCombatTarget(); PlayerCharacter target = (PlayerCharacter) mob.getCombatTarget();
if (mob.playerAgroMap.containsKey(target.getObjectUUID()) == false) { if (!mob.playerAgroMap.containsKey(target.getObjectUUID())) {
mob.setCombatTarget(null); mob.setCombatTarget(null);
return; return;
} }
if (mob.canSee((PlayerCharacter) mob.getCombatTarget()) == false) { if (!mob.canSee((PlayerCharacter) mob.getCombatTarget())) {
mob.setCombatTarget(null); mob.setCombatTarget(null);
return; return;
} }
@ -611,12 +608,12 @@ public class MobAI {
// No aggro for this race type // No aggro for this race type
if (aiAgent.notEnemy.size() > 0 && aiAgent.notEnemy.contains(loadedPlayer.race.getRaceType().getMonsterType()) == true) if (aiAgent.notEnemy.size() > 0 && aiAgent.notEnemy.contains(loadedPlayer.race.getRaceType().getMonsterType()))
continue; continue;
//mob has enemies and this player race is not it //mob has enemies and this player race is not it
if (aiAgent.enemy.size() > 0 && aiAgent.enemy.contains(loadedPlayer.race.getRaceType().getMonsterType()) == false) if (aiAgent.enemy.size() > 0 && !aiAgent.enemy.contains(loadedPlayer.race.getRaceType().getMonsterType()))
continue; continue;
if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) { if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) {
@ -690,9 +687,9 @@ public class MobAI {
// Minions only patrol on their own if captain is dead. // Minions only patrol on their own if captain is dead.
if (mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION) == false) if (!mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION))
patrol(mob); patrol(mob);
else if (mob.guardCaptain.isAlive() == false) else if (!mob.guardCaptain.isAlive())
patrol(mob); patrol(mob);
} else } else
mob.stopPatrolTime = System.currentTimeMillis(); mob.stopPatrolTime = System.currentTimeMillis();
@ -724,7 +721,6 @@ public class MobAI {
if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER_WITH_LOOT) { if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER_WITH_LOOT) {
aiAgent.despawn(); aiAgent.despawn();
aiAgent.deathTime = System.currentTimeMillis(); aiAgent.deathTime = System.currentTimeMillis();
return;
} }
//No items in inventory. //No items in inventory.
} else { } else {
@ -733,14 +729,12 @@ public class MobAI {
if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER_ONCE_LOOTED) { if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER_ONCE_LOOTED) {
aiAgent.despawn(); aiAgent.despawn();
aiAgent.deathTime = System.currentTimeMillis(); aiAgent.deathTime = System.currentTimeMillis();
return;
} }
//Mob never had Loot. //Mob never had Loot.
} else { } else {
if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER) { if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER) {
aiAgent.despawn(); aiAgent.despawn();
aiAgent.deathTime = System.currentTimeMillis(); aiAgent.deathTime = System.currentTimeMillis();
return;
} }
} }
} }
@ -758,14 +752,13 @@ public class MobAI {
//checks if mob can attack based on attack timer and range //checks if mob can attack based on attack timer and range
if (mob.isAlive() == false) if (!mob.isAlive())
return; return;
if (mob.getCombatTarget() == null) if (mob.getCombatTarget() == null)
return; return;
if (mob.getCombatTarget().getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget()) == false && if (mob.getCombatTarget().getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && !MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget()) && !mob.agentType.equals(mbEnums.AIAgentType.PET)) {
mob.agentType.equals(mbEnums.AIAgentType.PET) == false) {
mob.setCombatTarget(null); mob.setCombatTarget(null);
return; return;
@ -788,7 +781,7 @@ public class MobAI {
City current = ZoneManager.getCityAtLocation(mob.getLoc()); City current = ZoneManager.getCityAtLocation(mob.getLoc());
if (current == null || current.equals(mob.getGuild().getOwnedCity()) == false) { if (current == null || !current.equals(mob.getGuild().getOwnedCity())) {
PowersBase recall = PowersManager.getPowerByToken(-1994153779); PowersBase recall = PowersManager.getPowerByToken(-1994153779);
PowersManager.useMobPower(mob, mob, recall, 40); PowersManager.useMobPower(mob, mob, recall, 40);
@ -806,7 +799,7 @@ public class MobAI {
} }
} }
} }
} else if (MovementUtilities.inRangeOfBindLocation(mob) == false) { } else if (!MovementUtilities.inRangeOfBindLocation(mob)) {
PowersBase recall = PowersManager.getPowerByToken(-1994153779); PowersBase recall = PowersManager.getPowerByToken(-1994153779);
PowersManager.useMobPower(mob, mob, recall, 40); PowersManager.useMobPower(mob, mob, recall, 40);
@ -824,7 +817,7 @@ public class MobAI {
try { try {
if (mob.getTimestamps().containsKey("lastChase") == false) if (!mob.getTimestamps().containsKey("lastChase"))
mob.getTimestamps().put("lastChase", System.currentTimeMillis()); mob.getTimestamps().put("lastChase", System.currentTimeMillis());
else if (System.currentTimeMillis() < mob.getTimestamps().get("lastChase").longValue() + (750 + ThreadLocalRandom.current().nextInt(0, 500))) else if (System.currentTimeMillis() < mob.getTimestamps().get("lastChase").longValue() + (750 + ThreadLocalRandom.current().nextInt(0, 500)))
return; return;
@ -874,7 +867,7 @@ public class MobAI {
Mob aggroMob = (Mob) awoMob; Mob aggroMob = (Mob) awoMob;
//don't attack other guards //don't attack other guards
if (aggroMob.isGuard() == true) if (aggroMob.isGuard())
continue; continue;
//don't attack pets //don't attack pets
@ -925,7 +918,7 @@ public class MobAI {
try { try {
if (mob.guardCaptain == null && mob.isNecroPet() == false && mob.isSiege() == false) if (mob.guardCaptain == null && !mob.isNecroPet() && !mob.isSiege())
if (ZoneManager.seaFloor.zoneMobSet.contains(mob)) if (ZoneManager.seaFloor.zoneMobSet.contains(mob))
mob.killCharacter("no owner"); mob.killCharacter("no owner");
@ -936,7 +929,7 @@ public class MobAI {
//recover health //recover health
if (mob.getTimestamps().containsKey("HEALTHRECOVERED") == false) if (!mob.getTimestamps().containsKey("HEALTHRECOVERED"))
mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis()); mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis());
if (mob.isSit() && mob.getTimeStamp("HEALTHRECOVERED") < System.currentTimeMillis() + 3000) if (mob.isSit() && mob.getTimeStamp("HEALTHRECOVERED") < System.currentTimeMillis() + 3000)
@ -961,7 +954,7 @@ public class MobAI {
if (mob.getCombatTarget() == null) if (mob.getCombatTarget() == null)
safeGuardAggro(mob); safeGuardAggro(mob);
else if (mob.getCombatTarget().isAlive() == false) else if (!mob.getCombatTarget().isAlive())
safeGuardAggro(mob); safeGuardAggro(mob);
checkForAttack(mob); checkForAttack(mob);
@ -976,7 +969,7 @@ public class MobAI {
//check for players that can be aggroed if mob is agressive and has no target //check for players that can be aggroed if mob is agressive and has no target
if (mob.getCombatTarget() != null && mob.playerAgroMap.containsKey(mob.getCombatTarget().getObjectUUID()) == false) if (mob.getCombatTarget() != null && !mob.playerAgroMap.containsKey(mob.getCombatTarget().getObjectUUID()))
mob.setCombatTarget(null); mob.setCombatTarget(null);
if (mob.behaviourType.isAgressive) { if (mob.behaviourType.isAgressive) {
@ -1021,9 +1014,7 @@ public class MobAI {
// Defer to captain if possible for current target // Defer to captain if possible for current target
if (mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION) && if (mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION) && mob.guardCaptain.isAlive() && mob.guardCaptain.combatTarget != null) {
mob.guardCaptain.isAlive()
&& mob.guardCaptain.combatTarget != null) {
mob.setCombatTarget(mob.guardCaptain.combatTarget); mob.setCombatTarget(mob.guardCaptain.combatTarget);
return; return;
} }
@ -1056,7 +1047,7 @@ public class MobAI {
// No aggro for this player // No aggro for this player
if (guardCanAggro(mob, loadedPlayer) == false) if (!guardCanAggro(mob, loadedPlayer))
continue; continue;
if (MovementUtilities.inRangeToAggro(mob, loadedPlayer) && mob.getCombatTarget() == null) { if (MovementUtilities.inRangeToAggro(mob, loadedPlayer) && mob.getCombatTarget() == null) {
@ -1090,12 +1081,12 @@ public class MobAI {
try { try {
if (ConfigManager.MB_RULESET.getValue().equals("LORE") && target.guild.equals(Guild.getErrantGuild()) == false) { if (ConfigManager.MB_RULESET.getValue().equals("LORE") && !target.guild.equals(Guild.getErrantGuild())) {
if(mob.guild.charter.equals(target.guild.charter) == true) if (mob.guild.charter.equals(target.guild.charter))
return false; return false;
} }
if (mob.guardedCity.cityOutlaws.contains(target.getObjectUUID()) == true) if (mob.guardedCity.cityOutlaws.contains(target.getObjectUUID()))
return true; return true;
if (mob.getGuild().getNation().equals(target.getGuild().getNation())) if (mob.getGuild().getNation().equals(target.getGuild().getNation()))
@ -1157,7 +1148,7 @@ public class MobAI {
//early exit for a mob who is already moving to a patrol point //early exit for a mob who is already moving to a patrol point
//while mob moving, update lastPatrolTime so that when they stop moving the 10 second timer can begin //while mob moving, update lastPatrolTime so that when they stop moving the 10 second timer can begin
if (mob.isMoving() == true) { if (mob.isMoving()) {
mob.stopPatrolTime = System.currentTimeMillis(); mob.stopPatrolTime = System.currentTimeMillis();
return; return;
} }
@ -1185,7 +1176,7 @@ public class MobAI {
//make sure mob is out of combat stance //make sure mob is out of combat stance
if (minion.despawned == false) { if (!minion.despawned) {
if (MovementUtilities.canMove(minion)) { if (MovementUtilities.canMove(minion)) {
Vector3f minionOffset = mbEnums.FormationType.getOffset(2, mob.minions.indexOf(minionUUID) + 3); Vector3f minionOffset = mbEnums.FormationType.getOffset(2, mob.minions.indexOf(minionUUID) + 3);
minion.updateLocation(); minion.updateLocation();
@ -1218,8 +1209,8 @@ public class MobAI {
if (potentialTarget.equals(mob.getCombatTarget())) if (potentialTarget.equals(mob.getCombatTarget()))
continue; continue;
if (ConfigManager.MB_RULESET.getValue().equals("LORE") && potentialTarget.guild.equals(Guild.getErrantGuild()) == false) { if (ConfigManager.MB_RULESET.getValue().equals("LORE") && !potentialTarget.guild.equals(Guild.getErrantGuild())) {
if(mob.guild.charter.equals(potentialTarget.guild.charter) == true) if (mob.guild.charter.equals(potentialTarget.guild.charter))
continue; continue;
} }

Loading…
Cancel
Save