Browse Source

hamlet guard aggro

combat-2
FatBoy-DOTC 6 months ago
parent
commit
3f3fb53675
  1. 122
      src/engine/mobileAI/MobAI.java

122
src/engine/mobileAI/MobAI.java

@ -30,6 +30,7 @@ import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -214,6 +215,7 @@ public class MobAI {
} }
} }
assert mob.patrolPoints != null;
if (mob.lastPatrolPointIndex > mob.patrolPoints.size() - 1) if (mob.lastPatrolPointIndex > mob.patrolPoints.size() - 1)
mob.lastPatrolPointIndex = 0; mob.lastPatrolPointIndex = 0;
@ -233,6 +235,7 @@ public class MobAI {
if (mob.agentType.equals(mbEnums.AIAgentType.GUARDCAPTAIN)) if (mob.agentType.equals(mbEnums.AIAgentType.GUARDCAPTAIN))
for (Integer minionUUID : mob.minions) { for (Integer minionUUID : mob.minions) {
Mob minion = Mob.getMob(minionUUID); Mob minion = Mob.getMob(minionUUID);
assert minion != null;
if (minion.isAlive() && minion.combatTarget == null) if (minion.isAlive() && minion.combatTarget == null)
MobAI.patrol(minion); MobAI.patrol(minion);
} }
@ -654,49 +657,44 @@ public class MobAI {
mob.updateLocation(); mob.updateLocation();
switch (mob.behaviourType) { if (mob.behaviourType == mbEnums.MobBehaviourType.Pet1) {
if (mob.guardCaptain == null)
return;
case Pet1: //mob no longer has its owner loaded, translate pet to owner
if (mob.guardCaptain == null) if (!mob.playerAgroMap.containsKey(mob.guardCaptain.getObjectUUID())) {
return; MovementManager.translocate(mob, mob.guardCaptain.getLoc());
return;
}
if (mob.getCombatTarget() == null) {
//mob no longer has its owner loaded, translate pet to owner //move back to owner
if (!mob.playerAgroMap.containsKey(mob.guardCaptain.getObjectUUID())) { if (mob.getRange() * mob.getRange() >= mob.loc.distanceSquared(mob.guardCaptain.loc))
MovementManager.translocate(mob, mob.guardCaptain.getLoc());
return; return;
}
if (mob.getCombatTarget() == null) { mob.destination = mob.guardCaptain.getLoc();
MovementUtilities.moveToLocation(mob, mob.destination, 5, false);
} else
chaseTarget(mob);
} else {
if (mob.getCombatTarget() == null) {
//move back to owner if (!mob.isMoving()) {
if (mob.getRange() * mob.getRange() >= mob.loc.distanceSquared(mob.guardCaptain.loc)) // Minions only patrol on their own if captain is dead.
return;
mob.destination = mob.guardCaptain.getLoc(); if (!mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION))
MovementUtilities.moveToLocation(mob, mob.destination, 5, false); patrol(mob);
else if (!mob.guardCaptain.isAlive())
patrol(mob);
} else } else
chaseTarget(mob); mob.stopPatrolTime = System.currentTimeMillis();
break; } else {
default: chaseTarget(mob);
if (mob.getCombatTarget() == null) { }
if (!mob.isMoving()) {
// Minions only patrol on their own if captain is dead.
if (!mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION))
patrol(mob);
else if (!mob.guardCaptain.isAlive())
patrol(mob);
} else
mob.stopPatrolTime = System.currentTimeMillis();
} else {
chaseTarget(mob);
}
break;
} }
} catch (Exception e) { } catch (Exception e) {
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: CheckMobMovement" + " " + e.getMessage()); Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: CheckMobMovement" + " " + e.getMessage());
@ -795,6 +793,7 @@ public class MobAI {
Mob minion = Mob.getMob(minionUUID); Mob minion = Mob.getMob(minionUUID);
PowersManager.useMobPower(minion, minion, recall, 40); PowersManager.useMobPower(minion, minion, recall, 40);
assert minion != null;
minion.setCombatTarget(null); minion.setCombatTarget(null);
} }
} }
@ -949,19 +948,57 @@ public class MobAI {
private static void hamletGuardLogic(Mob mob) { private static void hamletGuardLogic(Mob mob) {
try { try {
//safehold guard
if (mob.getCombatTarget() == null) if (ConfigManager.MB_RULESET.getValue().equals("LORE")) {
safeGuardAggro(mob); if (mob.getCombatTarget() == null)
else if (!mob.getCombatTarget().isAlive()) hamletGuardAggro(mob);
safeGuardAggro(mob); else if (!mob.getCombatTarget().isAlive())
hamletGuardAggro(mob);
} else {
//safehold guard
if (mob.getCombatTarget() == null)
safeGuardAggro(mob);
else if (!mob.getCombatTarget().isAlive())
safeGuardAggro(mob);
}
checkForAttack(mob); checkForAttack(mob);
} catch (Exception e) { } catch (Exception e) {
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: HamletGuardLogic" + " " + e.getMessage()); Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: HamletGuardLogic" + " " + e.getMessage());
} }
} }
private static void hamletGuardAggro(Mob mob) {
ConcurrentHashMap<Integer, Float> loadedPlayers = mob.playerAgroMap;
for (Entry<Integer, Float> playerEntry : loadedPlayers.entrySet()) {
int playerID = playerEntry.getKey();
PlayerCharacter loadedPlayer = PlayerCharacter.getPlayerCharacter(playerID);
if (loadedPlayer == null)
continue;
if (!loadedPlayer.isAlive())
continue;
//Can't see target, skip aggro.
if (!mob.canSee(loadedPlayer))
continue;
// No aggro for this player
if (!guardCanAggro(mob, loadedPlayer))
continue;
if (MovementUtilities.inRangeToAggro(mob, loadedPlayer) && mob.getCombatTarget() == null) {
mob.setCombatTarget(loadedPlayer);
return;
}
}
}
private static void defaultLogic(Mob mob) { private static void defaultLogic(Mob mob) {
try { try {
@ -1085,7 +1122,7 @@ public class MobAI {
return false; return false;
} }
if (mob.guardedCity.cityOutlaws.contains(target.getObjectUUID())) if (mob.guardedCity != null && 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()))
@ -1093,8 +1130,8 @@ public class MobAI {
//first check condemn list for aggro allowed (allies button is checked) //first check condemn list for aggro allowed (allies button is checked)
if (ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().reverseKOS) { if (Objects.requireNonNull(ZoneManager.getCityAtLocation(mob.getLoc())).getTOL().reverseKOS) {
for (Entry<Integer, Condemned> entry : ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().getCondemned().entrySet()) { for (Entry<Integer, Condemned> entry : Objects.requireNonNull(ZoneManager.getCityAtLocation(mob.getLoc())).getTOL().getCondemned().entrySet()) {
//target is listed individually //target is listed individually
@ -1116,7 +1153,7 @@ public class MobAI {
//allies button is not checked //allies button is not checked
for (Entry<Integer, Condemned> entry : ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().getCondemned().entrySet()) { for (Entry<Integer, Condemned> entry : Objects.requireNonNull(ZoneManager.getCityAtLocation(mob.getLoc())).getTOL().getCondemned().entrySet()) {
//target is listed individually //target is listed individually
@ -1175,6 +1212,7 @@ public class MobAI {
//make sure mob is out of combat stance //make sure mob is out of combat stance
assert minion != null;
if (!minion.despawned) { 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);

Loading…
Cancel
Save