Files
BattleBane/src/engine/ai/MobileFSM.java
T

997 lines
44 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.ai;
2023-07-15 09:23:48 -04:00
2023-04-17 07:20:39 -04:00
import engine.Enum;
2022-04-30 09:41:17 -04:00
import engine.Enum.DispatchChannel;
import engine.InterestManagement.WorldGrid;
2022-04-30 09:41:17 -04:00
import engine.ai.utilities.CombatUtilities;
import engine.ai.utilities.MovementUtilities;
import engine.gameManager.*;
2023-04-17 20:51:34 -05:00
import engine.math.Vector3f;
import engine.math.Vector3fImmutable;
2022-04-30 09:41:17 -04:00
import engine.net.DispatchMessage;
import engine.net.client.msg.PerformActionMsg;
import engine.net.client.msg.PowerProjectileMsg;
import engine.net.client.msg.UpdateStateMsg;
import engine.objects.*;
import engine.powers.ActionsBase;
2022-04-30 09:41:17 -04:00
import engine.powers.PowersBase;
import engine.server.MBServerStatics;
2023-08-01 18:52:44 -05:00
import org.pmw.tinylog.Logger;
import java.util.ArrayList;
import java.util.HashSet;
2022-04-30 09:41:17 -04:00
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
2023-07-15 09:23:48 -04:00
2022-04-30 09:41:17 -04:00
import static engine.math.FastMath.sqr;
2023-07-15 09:23:48 -04:00
2022-04-30 09:41:17 -04:00
public class MobileFSM {
2023-07-27 21:22:20 -05:00
2023-04-20 21:23:42 -05:00
private static void AttackTarget(Mob mob, AbstractWorldObject target) {
2023-08-01 18:52:44 -05:00
try {
if (mob == null)
return;
if (target == null || !target.isAlive()) {
mob.setCombatTarget(null);
2023-06-25 13:36:24 -05:00
return;
}
2023-08-01 18:52:44 -05:00
if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter && canCast(mob)) {
if (MobCast(mob)) {
mob.updateLocation();
return;
}
}
if (!CombatUtilities.inRangeToAttack(mob, target))
return;
switch (target.getObjectType()) {
case PlayerCharacter:
PlayerCharacter targetPlayer = (PlayerCharacter) target;
AttackPlayer(mob, targetPlayer);
break;
case Building:
Building targetBuilding = (Building) target;
AttackBuilding(mob, targetBuilding);
break;
case Mob:
Mob targetMob = (Mob) target;
AttackMob(mob, targetMob);
break;
}
mob.updateLocation();
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackTarget" + " " + e.getMessage());
2023-06-25 13:36:24 -05:00
}
2022-04-30 09:41:17 -04:00
}
2023-07-15 09:23:48 -04:00
2023-04-23 20:38:28 -05:00
public static void AttackPlayer(Mob mob, PlayerCharacter target) {
2023-08-01 18:52:44 -05:00
try{
2023-07-15 09:23:48 -04:00
if (!mob.canSee(target)) {
2023-04-20 21:23:42 -05:00
mob.setCombatTarget(null);
2022-04-30 09:41:17 -04:00
return;
}
2023-04-23 20:38:28 -05:00
if (mob.BehaviourType.callsForHelp)
2023-04-20 21:23:42 -05:00
MobCallForHelp(mob);
if (!MovementUtilities.inRangeDropAggro(mob, target)) {
mob.setCombatTarget(null);
2022-04-30 09:41:17 -04:00
return;
}
2023-04-20 21:23:42 -05:00
if (CombatUtilities.inRange2D(mob, target, mob.getRange())) {
//no weapons, default mob attack speed 3 seconds.
if (System.currentTimeMillis() < mob.getLastAttackTime())
return;
// ranged mobs cant attack while running. skip until they finally stop.
if (mob.isMoving() && mob.getRange() > 20)
2022-04-30 09:41:17 -04:00
return;
// add timer for last attack.
2023-04-20 21:23:42 -05:00
ItemBase mainHand = mob.getWeaponItemBase(true);
ItemBase offHand = mob.getWeaponItemBase(false);
2022-04-30 09:41:17 -04:00
if (mainHand == null && offHand == null) {
2023-04-20 21:23:42 -05:00
CombatUtilities.combatCycle(mob, target, true, null);
2022-04-30 09:41:17 -04:00
int delay = 3000;
2023-04-20 21:23:42 -05:00
if (mob.isSiege())
2022-04-30 09:41:17 -04:00
delay = 11000;
2023-04-20 21:23:42 -05:00
mob.setLastAttackTime(System.currentTimeMillis() + delay);
} else if (mob.getWeaponItemBase(true) != null) {
int delay = 3000;
if (mob.isSiege())
delay = 11000;
CombatUtilities.combatCycle(mob, target, true, mob.getWeaponItemBase(true));
mob.setLastAttackTime(System.currentTimeMillis() + delay);
} else if (mob.getWeaponItemBase(false) != null) {
int attackDelay = 3000;
if (mob.isSiege())
attackDelay = 11000;
CombatUtilities.combatCycle(mob, target, false, mob.getWeaponItemBase(false));
mob.setLastAttackTime(System.currentTimeMillis() + attackDelay);
}
2022-04-30 09:41:17 -04:00
}
2023-07-18 20:01:58 -05:00
if(target.getPet() != null){
if(target.getPet().getCombatTarget() == null && target.getPet().assist() == true){
target.getPet().setCombatTarget(mob);
}
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackPlayer" + " " + e.getMessage());
}
}
2023-07-15 09:23:48 -04:00
2023-04-23 20:38:28 -05:00
public static void AttackBuilding(Mob mob, Building target) {
2023-08-01 18:52:44 -05:00
try{
2023-04-20 21:23:42 -05:00
if (target.getRank() == -1 || !target.isVulnerable() || BuildingManager.getBuildingFromCache(target.getObjectUUID()) == null) {
mob.setCombatTarget(null);
2022-04-30 09:41:17 -04:00
return;
}
2023-04-20 21:23:42 -05:00
City playercity = ZoneManager.getCityAtLocation(mob.getLoc());
2023-04-23 20:38:28 -05:00
if (playercity != null)
for (Mob guard : playercity.getParent().zoneMobSet)
if (guard.BehaviourType != null && guard.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal())
if (guard.getCombatTarget() == null && !guard.getGuild().equals(mob.getGuild()))
guard.setCombatTarget(mob);
2023-04-20 21:23:42 -05:00
if (mob.isSiege())
MovementManager.sendRWSSMsg(mob);
ItemBase mainHand = mob.getWeaponItemBase(true);
ItemBase offHand = mob.getWeaponItemBase(false);
if (mainHand == null && offHand == null) {
CombatUtilities.combatCycle(mob, target, true, null);
int delay = 3000;
if (mob.isSiege())
delay = 15000;
mob.setLastAttackTime(System.currentTimeMillis() + delay);
2023-04-23 20:38:28 -05:00
} else if (mob.getWeaponItemBase(true) != null) {
2023-04-20 21:23:42 -05:00
int attackDelay = 3000;
if (mob.isSiege())
attackDelay = 15000;
CombatUtilities.combatCycle(mob, target, true, mob.getWeaponItemBase(true));
mob.setLastAttackTime(System.currentTimeMillis() + attackDelay);
} else if (mob.getWeaponItemBase(false) != null) {
int attackDelay = 3000;
if (mob.isSiege())
attackDelay = 15000;
CombatUtilities.combatCycle(mob, target, false, mob.getWeaponItemBase(false));
mob.setLastAttackTime(System.currentTimeMillis() + attackDelay);
}
if (mob.isSiege()) {
PowerProjectileMsg ppm = new PowerProjectileMsg(mob, target);
ppm.setRange(50);
DispatchMessage.dispatchMsgToInterestArea(mob, ppm, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackBuilding" + " " + e.getMessage());
}
2023-04-20 21:23:42 -05:00
}
2023-07-15 09:23:48 -04:00
2023-04-23 20:38:28 -05:00
public static void AttackMob(Mob mob, Mob target) {
2023-08-01 18:52:44 -05:00
try{
2023-04-20 21:23:42 -05:00
if (mob.getRange() >= 30 && mob.isMoving())
return;
//no weapons, default mob attack speed 3 seconds.
ItemBase mainHand = mob.getWeaponItemBase(true);
ItemBase offHand = mob.getWeaponItemBase(false);
if (mainHand == null && offHand == null) {
CombatUtilities.combatCycle(mob, target, true, null);
int delay = 3000;
if (mob.isSiege())
delay = 11000;
mob.setLastAttackTime(System.currentTimeMillis() + delay);
2023-04-23 20:38:28 -05:00
} else if (mob.getWeaponItemBase(true) != null) {
2023-04-20 21:23:42 -05:00
int attackDelay = 3000;
if (mob.isSiege())
attackDelay = 11000;
CombatUtilities.combatCycle(mob, target, true, mob.getWeaponItemBase(true));
mob.setLastAttackTime(System.currentTimeMillis() + attackDelay);
} else if (mob.getWeaponItemBase(false) != null) {
int attackDelay = 3000;
if (mob.isSiege())
attackDelay = 11000;
CombatUtilities.combatCycle(mob, target, false, mob.getWeaponItemBase(false));
mob.setLastAttackTime(System.currentTimeMillis() + attackDelay);
2023-07-18 19:51:00 -05:00
if(target.combatTarget == null){
target.combatTarget = mob;
}
2023-04-20 21:23:42 -05:00
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackMob" + " " + e.getMessage());
}
}
2023-07-15 09:23:48 -04:00
2023-04-20 21:23:42 -05:00
private static void Patrol(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-04-17 20:51:34 -05:00
//make sure mob is out of combat stance
if (mob.isCombat() && mob.getCombatTarget() == null) {
mob.setCombat(false);
UpdateStateMsg rwss = new UpdateStateMsg();
rwss.setPlayer(mob);
DispatchMessage.sendToAllInRange(mob, rwss);
}
2023-07-15 09:23:48 -04:00
int patrolDelay = ThreadLocalRandom.current().nextInt((int) (MobileFSMManager.AI_PATROL_DIVISOR * 0.5f), MobileFSMManager.AI_PATROL_DIVISOR) + MobileFSMManager.AI_PATROL_DIVISOR;
2023-05-28 11:25:12 -05:00
if (mob.stopPatrolTime + (patrolDelay * 1000) > System.currentTimeMillis())
2023-04-16 12:48:23 -05:00
//early exit while waiting to patrol again
return;
//guard captains inherit barracks patrol points dynamically
2023-05-03 21:19:49 -05:00
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) {
2023-04-16 12:48:23 -05:00
Building barracks = mob.building;
2023-05-03 20:38:42 -05:00
if (barracks != null && barracks.patrolPoints != null && !barracks.getPatrolPoints().isEmpty()) {
2023-04-16 12:48:23 -05:00
mob.patrolPoints = barracks.patrolPoints;
2023-07-15 09:23:48 -04:00
} else {
2023-05-03 21:19:49 -05:00
randomGuardPatrolPoint(mob);
return;
2023-04-17 20:51:34 -05:00
}
2023-04-16 12:48:23 -05:00
}
2023-07-15 09:23:48 -04:00
if (mob.lastPatrolPointIndex > mob.patrolPoints.size() - 1) {
mob.lastPatrolPointIndex = 0;
}
2023-05-06 12:14:28 -05:00
mob.destination = mob.patrolPoints.get(mob.lastPatrolPointIndex);
mob.lastPatrolPointIndex += 1;
2023-05-03 21:19:49 -05:00
MovementUtilities.aiMove(mob, mob.destination, true);
2023-07-15 09:23:48 -04:00
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) {
2023-05-06 13:03:00 -05:00
for (Entry<Mob, Integer> minion : mob.siegeMinionMap.entrySet()) {
//make sure mob is out of combat stance
if (minion.getKey().despawned == false) {
if (minion.getKey().isCombat() && minion.getKey().getCombatTarget() == null) {
minion.getKey().setCombat(false);
UpdateStateMsg rwss = new UpdateStateMsg();
rwss.setPlayer(minion.getKey());
DispatchMessage.sendToAllInRange(minion.getKey(), rwss);
}
if (MovementUtilities.canMove(minion.getKey())) {
Vector3f minionOffset = Formation.getOffset(2, minion.getValue() + 3);
minion.getKey().updateLocation();
Vector3fImmutable formationPatrolPoint = new Vector3fImmutable(mob.destination.x + minionOffset.x, mob.destination.y, mob.destination.z + minionOffset.z);
MovementUtilities.aiMove(minion.getKey(), formationPatrolPoint, true);
}
}
}
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackTarget" + " " + e.getMessage());
}
2023-04-16 12:48:23 -05:00
}
2023-07-15 09:23:48 -04:00
2023-02-04 21:26:04 -06:00
public static boolean canCast(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
// Performs validation to determine if a
// mobile in the proper state to cast.
if (mob == null)
2023-02-02 19:44:23 -06:00
return false;
if (mob.mobPowers.isEmpty())
2023-02-04 21:26:04 -06:00
return false;
2023-07-15 09:23:48 -04:00
if (!mob.canSee((PlayerCharacter) mob.getCombatTarget())) {
2023-06-25 19:30:28 -05:00
mob.setCombatTarget(null);
return false;
}
int castRoll = ThreadLocalRandom.current().nextInt(101);
if(castRoll <= MobileFSMManager.AI_POWER_DIVISOR){
return false;
}
if (mob.nextCastTime == 0)
2023-02-04 21:26:04 -06:00
mob.nextCastTime = System.currentTimeMillis();
return mob.nextCastTime <= System.currentTimeMillis();
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: canCast" + " " + e.getMessage());
}
return false;
2023-02-02 19:44:23 -06:00
}
2023-07-15 09:23:48 -04:00
2023-02-04 21:26:04 -06:00
public static boolean MobCast(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
// Method picks a random spell from a mobile's list of powers
2023-03-15 11:51:28 -04:00
// and casts it on the current target (or itself). Validation
// (including empty lists) is done previously within canCast();
ArrayList<Integer> powerTokens;
2023-03-15 09:39:17 -04:00
ArrayList<Integer> purgeTokens;
2023-02-04 21:26:04 -06:00
PlayerCharacter target = (PlayerCharacter) mob.getCombatTarget();
if (mob.BehaviourType.callsForHelp)
MobCallForHelp(mob);
// Generate a list of tokens from the mob powers for this mobile.
powerTokens = new ArrayList<>(mob.mobPowers.keySet());
2023-03-15 09:39:17 -04:00
purgeTokens = new ArrayList<>();
2023-03-15 11:47:27 -04:00
// If player has this effect on them currently then remove
// this token from our list.
for (int powerToken : powerTokens) {
PowersBase powerBase = PowersManager.getPowerByToken(powerToken);
for (ActionsBase actionBase : powerBase.getActions()) {
2023-03-15 11:47:27 -04:00
String stackType = actionBase.stackType;
if (target.getEffects() != null && target.getEffects().containsKey(stackType))
2023-03-15 09:39:17 -04:00
purgeTokens.add(powerToken);
}
}
2023-03-15 09:39:17 -04:00
powerTokens.removeAll(purgeTokens);
2023-03-15 10:11:01 -04:00
// Sanity check
if (powerTokens.isEmpty())
return false;
// Pick random spell from our list of powers
int powerToken = powerTokens.get(ThreadLocalRandom.current().nextInt(powerTokens.size()));
int powerRank = mob.mobPowers.get(powerToken);
PowersBase mobPower = PowersManager.getPowerByToken(powerToken);
//check for hit-roll
2023-07-15 09:23:48 -04:00
if (mobPower.requiresHitRoll) {
if (CombatUtilities.triggerDefense(mob, mob.getCombatTarget())) {
return false;
}
if (CombatUtilities.triggerDodge(mob, mob.getCombatTarget())) {
return false;
}
if (CombatUtilities.triggerBlock(mob, mob.getCombatTarget())) {
return false;
}
if (CombatUtilities.triggerParry(mob, mob.getCombatTarget())) {
return false;
}
}
// Cast the spell
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) {
PowersManager.useMobPower(mob, (AbstractCharacter) mob.getCombatTarget(), mobPower, powerRank);
PerformActionMsg msg;
2023-04-23 20:38:28 -05:00
if (!mobPower.isHarmful() || mobPower.targetSelf)
msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, mob);
else
msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target);
msg.setUnknown04(2);
PowersManager.finishUseMobPower(msg, mob, 0, 0);
2023-03-15 11:47:27 -04:00
// Default minimum seconds between cast = 10
float randomCooldown = (ThreadLocalRandom.current().nextInt(150) + 100) * 0.01f;
mob.nextCastTime = System.currentTimeMillis() + (long)((mobPower.getCooldown() + (MobileFSMManager.AI_POWER_DIVISOR * 1000)) * randomCooldown);
return true;
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: MobCast" + " " + e.getMessage());
}
return false;
}
2023-07-15 09:23:48 -04:00
2023-02-04 21:26:04 -06:00
public static void MobCallForHelp(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
boolean callGotResponse = false;
if (mob.nextCallForHelp == 0) {
mob.nextCallForHelp = System.currentTimeMillis();
}
2023-04-23 20:38:28 -05:00
if (mob.nextCallForHelp < System.currentTimeMillis())
2023-02-04 21:26:04 -06:00
return;
//mob sends call for help message
ChatManager.chatSayInfo(null, mob.getName() + " calls for help!");
2023-02-02 19:44:23 -06:00
Zone mobCamp = mob.getParentZone();
for (Mob helper : mobCamp.zoneMobSet) {
if (helper.BehaviourType.respondsToCallForHelp && helper.BehaviourType.BehaviourHelperType.equals(mob.BehaviourType)) {
helper.setCombatTarget(mob.getCombatTarget());
callGotResponse = true;
2023-02-02 19:44:23 -06:00
}
}
2023-04-23 20:38:28 -05:00
if (callGotResponse)
//wait 60 seconds to call for help again
mob.nextCallForHelp = System.currentTimeMillis() + 60000;
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: MobCallForHelp" + " " + e.getMessage());
}
2023-02-02 19:44:23 -06:00
}
2023-07-15 09:23:48 -04:00
public static void DetermineAction(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-07-27 20:03:14 -05:00
//always check the respawn que, respawn 1 mob max per second to not flood the client
2023-07-27 21:22:20 -05:00
2023-04-23 20:38:28 -05:00
if (mob == null)
return;
2023-04-23 20:38:28 -05:00
if (mob.despawned && mob.getMobBase().getLoadID() == 13171) {
2023-04-22 21:55:06 -05:00
//trebuchet spawn handler
CheckForRespawn(mob);
return;
}
2023-04-23 20:38:28 -05:00
if (mob.despawned && mob.isPlayerGuard) {
2023-04-22 21:55:06 -05:00
//override for guards
2023-07-15 09:23:48 -04:00
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) {
if (mob.npcOwner.isAlive() == false || ((Mob) mob.npcOwner).despawned == true) {
//minions don't respawn while guard captain is dead
2023-07-15 09:23:48 -04:00
if (mob.isAlive() == false) {
2023-05-07 11:53:00 -05:00
mob.deathTime = System.currentTimeMillis();
return;
2023-05-07 11:53:00 -05:00
}
}
}
2023-04-22 21:55:06 -05:00
CheckForRespawn(mob);
//check to send mob home for player guards to prevent exploit of dragging guards away and then teleporting
2023-07-15 18:38:46 -05:00
if(mob.BehaviourType.ordinal() != Enum.MobBehaviourType.Pet1.ordinal()){
CheckToSendMobHome(mob);
}
2023-04-22 21:55:06 -05:00
return;
}
2023-04-23 20:38:28 -05:00
if (!mob.isAlive()) {
2023-04-20 21:23:42 -05:00
//no need to continue if mob is dead, check for respawn and move on
CheckForRespawn(mob);
2023-04-18 20:52:33 -05:00
return;
}
2023-07-27 22:10:47 -05:00
if (mob.playerAgroMap.isEmpty() && mob.isPlayerGuard == false && mob.BehaviourType.ordinal() != Enum.MobBehaviourType.Pet1.ordinal()) {
2023-04-20 21:23:42 -05:00
//no players loaded, no need to proceed
2023-07-27 22:10:47 -05:00
mob.setCombatTarget(null);
2023-04-17 20:51:34 -05:00
return;
2023-07-27 22:10:47 -05:00
}
2023-04-30 14:55:12 -05:00
if (mob.isCombat() && mob.getCombatTarget() == null) {
mob.setCombat(false);
UpdateStateMsg rwss = new UpdateStateMsg();
rwss.setPlayer(mob);
DispatchMessage.sendToAllInRange(mob, rwss);
}
2023-07-15 15:27:22 -05:00
if(mob.BehaviourType.ordinal() != Enum.MobBehaviourType.Pet1.ordinal()) {
CheckToSendMobHome(mob);
}
2023-07-27 21:18:52 -05:00
if (mob.combatTarget != null) {
if(mob.getCombatTarget().isAlive() == false){
mob.setCombatTarget(null);
return;
}
if(mob.getCombatTarget().getObjectTypeMask() == MBServerStatics.MASK_PLAYER){
if(mob.playerAgroMap.containsKey(mob.getCombatTarget().getObjectUUID()) == false){
mob.setCombatTarget(null);
return;
}
if(mob.canSee((PlayerCharacter)mob.getCombatTarget()) == false) {
mob.setCombatTarget(null);
return;
}
}
2023-05-28 12:07:00 -05:00
}
2023-07-27 22:10:47 -05:00
//if(mob.getTimestamps().containsKey("LOCATIONSYNC") == false){
// mob.getTimestamps().put("LOCATIONSYNC",System.currentTimeMillis());
//}
2023-04-23 20:38:28 -05:00
switch (mob.BehaviourType) {
2023-04-20 21:23:42 -05:00
case GuardCaptain:
GuardCaptainLogic(mob);
break;
case GuardMinion:
GuardMinionLogic(mob);
break;
case GuardWallArcher:
GuardWallArcherLogic(mob);
break;
case Pet1:
PetLogic(mob);
break;
2023-04-21 10:02:09 -05:00
case HamletGuard:
HamletGuardLogic(mob);
break;
2023-04-20 21:23:42 -05:00
default:
DefaultLogic(mob);
break;
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: DetermineAction" + " " + e.getMessage());
}
}
2023-07-15 09:23:48 -04:00
private static void CheckForAggro(Mob aiAgent) {
2023-08-01 18:52:44 -05:00
try{
//looks for and sets mobs combatTarget
2023-04-23 20:38:28 -05:00
if (!aiAgent.isAlive())
return;
ConcurrentHashMap<Integer, Boolean> loadedPlayers = aiAgent.playerAgroMap;
for (Entry playerEntry : loadedPlayers.entrySet()) {
int playerID = (int) playerEntry.getKey();
PlayerCharacter loadedPlayer = PlayerCharacter.getFromCache(playerID);
//Player is null, let's remove them from the list.
if (loadedPlayer == null) {
loadedPlayers.remove(playerID);
continue;
}
//Player is Dead, Mob no longer needs to attempt to aggro. Remove them from aggro map.
if (!loadedPlayer.isAlive()) {
loadedPlayers.remove(playerID);
continue;
}
//Can't see target, skip aggro.
2023-04-23 20:38:28 -05:00
if (!aiAgent.canSee(loadedPlayer))
continue;
// No aggro for this race type
if (aiAgent.notEnemy.size() > 0 && aiAgent.notEnemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType()) == true)
2023-05-09 21:11:51 -05:00
continue;
//mob has enemies and this player race is not it
if(aiAgent.enemy.size() > 0 && aiAgent.enemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType()) == false){
continue;
}
if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) {
2023-04-14 20:50:47 -05:00
aiAgent.setCombatTarget(loadedPlayer);
return;
}
}
2023-07-18 20:01:58 -05:00
if(aiAgent.combatTarget == null) {
//look for pets to aggro if no players found to aggro
HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(aiAgent, MobileFSMManager.AI_BASE_AGGRO_RANGE, MBServerStatics.MASK_PET);
for (AbstractWorldObject awoMob : awoList) {
//dont scan self.
if (aiAgent.equals(awoMob))
continue;
Mob aggroMob = (Mob) awoMob;
2023-07-18 19:51:00 -05:00
aiAgent.setCombatTarget(aggroMob);
return;
2023-07-18 20:01:58 -05:00
}
2023-07-18 19:51:00 -05:00
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(aiAgent.getObjectUUID() + " " + aiAgent.getName() + " Failed At: CheckForAggro" + " " + e.getMessage());
}
}
2023-07-15 09:23:48 -04:00
private static void CheckMobMovement(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-04-23 20:38:28 -05:00
if (!MovementUtilities.canMove(mob))
2023-04-17 20:51:34 -05:00
return;
2023-07-25 21:27:54 -05:00
mob.updateLocation();
2023-07-15 09:23:48 -04:00
switch (mob.BehaviourType) {
2023-05-06 12:14:28 -05:00
case Pet1:
2023-07-15 18:38:46 -05:00
if(mob.getOwner() == null){
return;
}
2023-05-06 12:14:28 -05:00
if (!mob.playerAgroMap.containsKey(mob.getOwner().getObjectUUID())) {
//mob no longer has its owner loaded, translocate pet to owner
MovementManager.translocate(mob, mob.getOwner().getLoc(), null);
return;
}
if (mob.getCombatTarget() == null) {
//move back to owner
if (CombatUtilities.inRange2D(mob, mob.getOwner(), 6))
2023-04-30 16:54:39 -05:00
return;
2023-05-06 12:14:28 -05:00
mob.destination = mob.getOwner().getLoc();
MovementUtilities.moveToLocation(mob, mob.destination, 5);
} else
chaseTarget(mob);
break;
case GuardMinion:
2023-07-15 09:23:48 -04:00
if (!mob.npcOwner.isAlive() || ((Mob) mob.npcOwner).despawned)
2023-05-06 12:14:28 -05:00
randomGuardPatrolPoint(mob);
2023-07-15 09:23:48 -04:00
else {
if (mob.getCombatTarget() != null) {
2023-05-06 15:53:35 -05:00
chaseTarget(mob);
}
}
2023-05-06 12:14:28 -05:00
break;
default:
if (mob.getCombatTarget() == null) {
2023-07-15 09:23:48 -04:00
if (!mob.isMoving()) {
2023-05-06 12:14:28 -05:00
Patrol(mob);
2023-07-15 09:23:48 -04:00
} else {
2023-05-28 11:19:32 -05:00
mob.stopPatrolTime = System.currentTimeMillis();
2023-04-30 16:54:39 -05:00
}
2023-07-15 09:23:48 -04:00
} else {
2023-05-06 12:14:28 -05:00
chaseTarget(mob);
2023-04-30 16:54:39 -05:00
}
2023-05-06 12:14:28 -05:00
break;
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: CheckMobMovement" + " " + e.getMessage());
}
}
2023-07-15 09:23:48 -04:00
private static void CheckForRespawn(Mob aiAgent) {
2023-08-01 18:52:44 -05:00
try{
2023-04-20 21:23:42 -05:00
if (aiAgent.deathTime == 0) {
aiAgent.setDeathTime(System.currentTimeMillis());
2023-04-21 12:56:09 -05:00
return;
2023-04-20 21:23:42 -05:00
}
//handles checking for respawn of dead mobs even when no players have mob loaded
//Despawn Timer with Loot currently in inventory.
2023-04-23 20:38:28 -05:00
if (!aiAgent.despawned) {
2023-04-21 15:17:37 -05:00
if (aiAgent.getCharItemManager().getInventoryCount() > 0) {
if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER_WITH_LOOT) {
aiAgent.despawn();
2023-04-21 15:17:37 -05:00
aiAgent.deathTime = System.currentTimeMillis();
2023-07-25 21:35:09 -05:00
return;
}
2023-04-21 15:17:37 -05:00
//No items in inventory.
} else {
2023-04-21 15:17:37 -05:00
//Mob's Loot has been looted.
if (aiAgent.isHasLoot()) {
if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER_ONCE_LOOTED) {
aiAgent.despawn();
aiAgent.deathTime = System.currentTimeMillis();
2023-07-25 21:35:09 -05:00
return;
2023-04-21 15:17:37 -05:00
}
//Mob never had Loot.
} else {
if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER) {
aiAgent.despawn();
aiAgent.deathTime = System.currentTimeMillis();
2023-07-25 21:35:09 -05:00
return;
2023-04-21 15:17:37 -05:00
}
}
}
2023-07-15 13:27:35 -05:00
} else if (System.currentTimeMillis() > (aiAgent.deathTime + (aiAgent.spawnTime * 1000))) {
2023-07-27 20:03:14 -05:00
//aiAgent.respawn();
2023-08-01 19:50:52 -05:00
if(aiAgent.getParentZone().respawnQue.contains(aiAgent) == false) {
aiAgent.getParentZone().respawnQue.add(aiAgent);
}
2023-04-20 21:23:42 -05:00
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(aiAgent.getObjectUUID() + " " + aiAgent.getName() + " Failed At: CheckForRespawn" + " " + e.getMessage());
}
}
2023-07-15 09:23:48 -04:00
public static void CheckForAttack(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
//checks if mob can attack based on attack timer and range
2023-04-23 20:38:28 -05:00
if (mob.isAlive() == false)
2023-04-20 21:23:42 -05:00
return;
2023-07-15 09:23:48 -04:00
if (mob.getCombatTarget() == null) {
2023-06-25 19:44:27 -05:00
return;
}
2023-07-22 18:58:55 -05:00
if (mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget()) == false && mob.BehaviourType.ordinal() != Enum.MobBehaviourType.Pet1.ordinal()) {
2023-04-22 21:55:06 -05:00
mob.setCombatTarget(null);
if (mob.isCombat()) {
mob.setCombat(false);
UpdateStateMsg rwss = new UpdateStateMsg();
rwss.setPlayer(mob);
DispatchMessage.sendToAllInRange(mob, rwss);
}
return;
}
if (!mob.isCombat()) {
mob.setCombat(true);
UpdateStateMsg rwss = new UpdateStateMsg();
rwss.setPlayer(mob);
DispatchMessage.sendToAllInRange(mob, rwss);
}
2023-04-23 20:38:28 -05:00
if (System.currentTimeMillis() > mob.getLastAttackTime())
2023-04-20 21:23:42 -05:00
AttackTarget(mob, mob.getCombatTarget());
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: CheckForAttack" + " " + e.getMessage());
}
}
2023-07-15 09:23:48 -04:00
private static void CheckToSendMobHome(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-07-15 09:23:48 -04:00
if (mob.BehaviourType.isAgressive) {
if (mob.isPlayerGuard()) {
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) {
CheckForPlayerGuardAggro(mob);
}
} else {
CheckForAggro(mob);
}
2023-05-28 11:03:29 -05:00
}
2023-07-15 09:23:48 -04:00
if (mob.getCombatTarget() != null && CombatUtilities.inRange2D(mob, mob.getCombatTarget(), MobileFSMManager.AI_BASE_AGGRO_RANGE * 0.5f)) {
2023-05-28 10:21:56 -05:00
return;
}
2023-05-06 15:53:35 -05:00
if (mob.isPlayerGuard() && !mob.despawned) {
2023-04-18 20:47:49 -05:00
City current = ZoneManager.getCityAtLocation(mob.getLoc());
if (current == null || current.equals(mob.getGuild().getOwnedCity()) == false) {
2023-04-17 21:31:56 -05:00
PowersBase recall = PowersManager.getPowerByToken(-1994153779);
PowersManager.useMobPower(mob, mob, recall, 40);
mob.setCombatTarget(null);
2023-07-15 09:23:48 -04:00
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal() && mob.isAlive()) {
2023-05-03 20:38:42 -05:00
//guard captain pulls his minions home with him
for (Entry<Mob, Integer> minion : mob.siegeMinionMap.entrySet()) {
PowersManager.useMobPower(minion.getKey(), minion.getKey(), recall, 40);
minion.getKey().setCombatTarget(null);
}
}
2023-04-18 20:47:49 -05:00
}
2023-07-15 09:23:48 -04:00
} else if (MovementUtilities.inRangeOfBindLocation(mob) == false) {
PowersBase recall = PowersManager.getPowerByToken(-1994153779);
PowersManager.useMobPower(mob, mob, recall, 40);
mob.setCombatTarget(null);
2023-05-28 10:11:20 -05:00
for (Entry playerEntry : mob.playerAgroMap.entrySet()) {
2023-07-15 09:23:48 -04:00
PlayerCharacter.getFromCache((int) playerEntry.getKey()).setHateValue(0);
2023-05-28 10:11:20 -05:00
}
2023-03-14 13:32:41 -05:00
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: CheckToSendMobHome" + " " + e.getMessage());
}
}
2023-07-15 09:23:48 -04:00
2023-04-16 13:30:46 -05:00
private static void chaseTarget(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-04-16 13:30:46 -05:00
mob.updateMovementState();
2023-07-25 21:27:54 -05:00
mob.updateLocation();
2023-04-16 13:30:46 -05:00
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) {
if (mob.getRange() > 15) {
mob.destination = mob.getCombatTarget().getLoc();
MovementUtilities.moveToLocation(mob, mob.destination, 0);
} else {
2023-07-15 22:34:09 -05:00
//check if building
switch (mob.getCombatTarget().getObjectType()) {
case PlayerCharacter:
case Mob:
mob.destination = MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget());
MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange());
break;
case Building:
mob.destination = mob.getCombatTarget().getLoc();
MovementUtilities.moveToLocation(mob,mob.getCombatTarget().getLoc(),0);
break;
}
2023-04-16 13:30:46 -05:00
}
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: chaseTarget" + " " + e.getMessage());
}
2023-04-16 13:30:46 -05:00
}
2023-07-15 09:23:48 -04:00
private static void SafeGuardAggro(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(mob, 100, MBServerStatics.MASK_MOB);
for (AbstractWorldObject awoMob : awoList) {
//dont scan self.
2023-07-25 21:42:50 -05:00
if (mob.equals(awoMob) || mob.isGuard() == true)
continue;
Mob aggroMob = (Mob) awoMob;
//dont attack other guards
if (aggroMob.isGuard())
continue;
if (mob.getLoc().distanceSquared2D(aggroMob.getLoc()) > sqr(50))
continue;
mob.setCombatTarget(aggroMob);
2023-04-16 18:58:55 -05:00
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: SafeGuardAggro" + " " + e.getMessage());
}
2023-04-16 18:58:55 -05:00
}
2023-07-15 09:23:48 -04:00
2023-04-23 20:38:28 -05:00
public static void GuardCaptainLogic(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-04-23 20:38:28 -05:00
if (mob.getCombatTarget() == null)
2023-04-20 21:23:42 -05:00
CheckForPlayerGuardAggro(mob);
2023-04-16 21:48:21 -05:00
CheckMobMovement(mob);
2023-06-25 19:44:27 -05:00
CheckForAttack(mob);
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: GuardCaptainLogic" + " " + e.getMessage());
}
2023-04-16 21:48:21 -05:00
}
2023-07-15 09:23:48 -04:00
2023-04-23 20:38:28 -05:00
public static void GuardMinionLogic(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-04-23 20:38:28 -05:00
if (!mob.npcOwner.isAlive() && mob.getCombatTarget() == null) {
2023-04-18 20:52:33 -05:00
CheckForPlayerGuardAggro(mob);
}
2023-07-15 09:23:48 -04:00
if (mob.npcOwner.getCombatTarget() != null)
2023-05-06 14:52:10 -05:00
mob.setCombatTarget(mob.npcOwner.getCombatTarget());
2023-07-15 09:23:48 -04:00
else
2023-05-07 08:35:11 -05:00
mob.setCombatTarget(null);
2023-04-18 20:52:33 -05:00
CheckMobMovement(mob);
2023-06-25 19:44:27 -05:00
CheckForAttack(mob);
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: GuardMinionLogic" + " " + e.getMessage());
}
2023-04-18 20:52:33 -05:00
}
2023-07-15 09:23:48 -04:00
2023-04-23 20:38:28 -05:00
public static void GuardWallArcherLogic(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-04-23 20:38:28 -05:00
if (mob.getCombatTarget() == null)
2023-04-18 20:52:33 -05:00
CheckForPlayerGuardAggro(mob);
2023-04-23 20:38:28 -05:00
else
2023-04-18 20:52:33 -05:00
CheckForAttack(mob);
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: GuardWallArcherLogic" + " " + e.getMessage());
}
2023-04-18 20:52:33 -05:00
}
2023-07-15 09:23:48 -04:00
2023-04-23 20:38:28 -05:00
private static void PetLogic(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-07-15 18:38:46 -05:00
if(mob.getOwner() == null && mob.isNecroPet() == false && mob.isSiege() == false){
if(ZoneManager.getSeaFloor().zoneMobSet.contains(mob)){
mob.killCharacter("no owner");
}
}
2023-04-23 20:38:28 -05:00
if (MovementUtilities.canMove(mob) && mob.BehaviourType.canRoam)
2023-04-20 21:23:42 -05:00
CheckMobMovement(mob);
2023-07-15 09:23:48 -04:00
CheckForAttack(mob);
//recover health
if(mob.getTimestamps().containsKey("HEALTHRECOVERED") == false){
mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis());
}
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());
2023-07-18 19:51:00 -05:00
if(mob.getHealth() > mob.getHealthMax()){
mob.setHealth(mob.getHealthMax());
}
}
2023-08-01 18:52:44 -05:00
}} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: PetLogic" + " " + e.getMessage());
}
2023-04-20 21:23:42 -05:00
}
2023-07-15 09:23:48 -04:00
2023-04-23 20:38:28 -05:00
private static void HamletGuardLogic(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-04-21 10:02:09 -05:00
if (mob.getCombatTarget() == null) {
//safehold guard
SafeGuardAggro(mob);
2023-07-15 09:23:48 -04:00
} else {
if (mob.combatTarget.isAlive() == false) {
2023-05-28 11:02:37 -05:00
SafeGuardAggro(mob);
}
2023-04-21 10:02:09 -05:00
}
2023-07-15 09:23:48 -04:00
CheckForAttack(mob);
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: HamletGuardLogic" + " " + e.getMessage());
}
2023-04-21 10:02:09 -05:00
}
2023-07-15 09:23:48 -04:00
2023-04-23 20:38:28 -05:00
private static void DefaultLogic(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-04-20 21:23:42 -05:00
//check for players that can be aggroed if mob is agressive and has no target
2023-07-27 21:18:52 -05:00
if(mob.getCombatTarget() != null && mob.playerAgroMap.containsKey(mob.getCombatTarget().getObjectUUID()) == false){
mob.setCombatTarget(null);
}
2023-05-07 11:53:00 -05:00
if (mob.BehaviourType.isAgressive) {
AbstractWorldObject newTarget = ChangeTargetFromHateValue(mob);
if (newTarget != null) {
mob.setCombatTarget(newTarget);
} else {
if (mob.getCombatTarget() == null) {
if (mob.BehaviourType == Enum.MobBehaviourType.HamletGuard)
//safehold guard
SafeGuardAggro(mob);
else
//normal aggro
CheckForAggro(mob);
}
}
2023-04-20 21:23:42 -05:00
}
//check if mob can move for patrol or moving to target
2023-04-23 20:38:28 -05:00
if (mob.BehaviourType.canRoam)
2023-04-20 21:23:42 -05:00
CheckMobMovement(mob);
//check if mob can attack if it isn't wimpy
if (!mob.BehaviourType.isWimpy && mob.combatTarget != null)
2023-04-20 21:23:42 -05:00
CheckForAttack(mob);
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: DefaultLogic" + " " + e.getMessage());
}
2023-04-20 21:23:42 -05:00
}
2023-07-15 09:23:48 -04:00
2023-04-16 21:48:21 -05:00
public static void CheckForPlayerGuardAggro(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-04-16 21:48:21 -05:00
//looks for and sets mobs combatTarget
2023-04-23 20:38:28 -05:00
if (!mob.isAlive())
2023-04-16 21:48:21 -05:00
return;
ConcurrentHashMap<Integer, Boolean> loadedPlayers = mob.playerAgroMap;
for (Entry playerEntry : loadedPlayers.entrySet()) {
int playerID = (int) playerEntry.getKey();
PlayerCharacter loadedPlayer = PlayerCharacter.getFromCache(playerID);
//Player is null, let's remove them from the list.
if (loadedPlayer == null) {
loadedPlayers.remove(playerID);
continue;
}
//Player is Dead, Mob no longer needs to attempt to aggro. Remove them from aggro map.
if (!loadedPlayer.isAlive()) {
loadedPlayers.remove(playerID);
continue;
}
//Can't see target, skip aggro.
2023-04-23 20:38:28 -05:00
if (!mob.canSee(loadedPlayer))
2023-04-16 21:48:21 -05:00
continue;
// No aggro for this player
2023-04-23 20:38:28 -05:00
if (GuardCanAggro(mob, loadedPlayer) == false)
2023-04-16 21:48:21 -05:00
continue;
if (MovementUtilities.inRangeToAggro(mob, loadedPlayer)) {
mob.setCombatTarget(loadedPlayer);
return;
}
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: CheckForPlayerGuardAggro" + e.getMessage());
}
2023-04-16 21:48:21 -05:00
}
2023-07-15 09:23:48 -04:00
2023-05-07 08:35:11 -05:00
public static Boolean GuardCanAggro(Mob mob, PlayerCharacter target) {
2023-08-01 18:52:44 -05:00
try{
2023-05-06 14:52:10 -05:00
if (mob.getGuild().getNation().equals(target.getGuild().getNation()))
return false;
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) {
2023-07-15 09:23:48 -04:00
if (((Mob) mob.npcOwner).building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true) {
return true;
}
2023-07-15 09:23:48 -04:00
} else if (mob.building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true) {
2023-05-07 11:53:00 -05:00
return true;
}
2023-05-06 14:52:10 -05:00
//first check condemn list for aggro allowed (allies button is checked)
if (ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().reverseKOS) {
for (Entry<Integer, Condemned> entry : ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().getCondemned().entrySet()) {
if (entry.getValue().getPlayerUID() == target.getObjectUUID() && entry.getValue().isActive())
//target is listed individually
return false;
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild())
//target's guild is listed
return false;
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild().getNation())
//target's nation is listed
return false;
}
return true;
2023-07-15 09:23:48 -04:00
} else {
2023-05-06 14:52:10 -05:00
//allies button is not checked
2023-04-17 20:51:34 -05:00
for (Entry<Integer, Condemned> entry : ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().getCondemned().entrySet()) {
2023-04-23 20:38:28 -05:00
if (entry.getValue().getPlayerUID() == target.getObjectUUID() && entry.getValue().isActive())
2023-04-16 21:48:21 -05:00
//target is listed individually
return true;
2023-04-23 20:38:28 -05:00
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild())
2023-04-16 21:48:21 -05:00
//target's guild is listed
return true;
2023-04-23 20:38:28 -05:00
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild().getNation())
2023-04-16 21:48:21 -05:00
//target's nation is listed
return true;
}
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: GuardCanAggro" + " " + e.getMessage());
}
2023-04-16 21:48:21 -05:00
return false;
}
2023-07-15 09:23:48 -04:00
public static void randomGuardPatrolPoint(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-05-06 14:52:10 -05:00
if (mob.isMoving() == true) {
//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
mob.stopPatrolTime = System.currentTimeMillis();
return;
}
//wait between 10 and 15 seconds after reaching patrol point before moving
int patrolDelay = ThreadLocalRandom.current().nextInt(10000) + 5000;
if (mob.stopPatrolTime + patrolDelay > System.currentTimeMillis())
//early exit while waiting to patrol again
return;
2023-05-03 20:38:42 -05:00
float xPoint = ThreadLocalRandom.current().nextInt(400) - 200;
float zPoint = ThreadLocalRandom.current().nextInt(400) - 200;
Vector3fImmutable TreePos = mob.getGuild().getOwnedCity().getLoc();
2023-07-15 09:23:48 -04:00
mob.destination = new Vector3fImmutable(TreePos.x + xPoint, TreePos.y, TreePos.z + zPoint);
2023-05-03 21:19:49 -05:00
MovementUtilities.aiMove(mob, mob.destination, true);
2023-07-15 09:23:48 -04:00
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) {
2023-05-03 21:19:49 -05:00
for (Entry<Mob, Integer> minion : mob.siegeMinionMap.entrySet()) {
//make sure mob is out of combat stance
2023-05-03 21:20:30 -05:00
if (minion.getKey().despawned == false) {
if (minion.getKey().isCombat() && minion.getKey().getCombatTarget() == null) {
minion.getKey().setCombat(false);
UpdateStateMsg rwss = new UpdateStateMsg();
rwss.setPlayer(minion.getKey());
DispatchMessage.sendToAllInRange(minion.getKey(), rwss);
}
if (MovementUtilities.canMove(minion.getKey())) {
Vector3f minionOffset = Formation.getOffset(2, minion.getValue() + 3);
minion.getKey().updateLocation();
Vector3fImmutable formationPatrolPoint = new Vector3fImmutable(mob.destination.x + minionOffset.x, mob.destination.y, mob.destination.z + minionOffset.z);
MovementUtilities.aiMove(minion.getKey(), formationPatrolPoint, true);
}
2023-05-03 21:19:49 -05:00
}
}
}
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: randomGuardPatrolPoints" + " " + e.getMessage());
}
}
2023-07-15 09:23:48 -04:00
public static AbstractWorldObject ChangeTargetFromHateValue(Mob mob) {
2023-08-01 18:52:44 -05:00
try{
2023-05-07 11:53:00 -05:00
float CurrentHateValue = 0;
2023-07-15 09:23:48 -04:00
if (mob.getCombatTarget() != null && mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) {
CurrentHateValue = ((PlayerCharacter) mob.getCombatTarget()).getHateValue();
2023-05-07 12:15:38 -05:00
}
2023-05-07 11:53:00 -05:00
AbstractWorldObject mostHatedTarget = null;
for (Entry playerEntry : mob.playerAgroMap.entrySet()) {
2023-07-15 09:23:48 -04:00
PlayerCharacter potentialTarget = PlayerCharacter.getFromCache((int) playerEntry.getKey());
if (potentialTarget.equals(mob.getCombatTarget())) {
2023-05-07 12:15:38 -05:00
continue;
}
2023-07-15 09:23:48 -04:00
if (potentialTarget != null && potentialTarget.getHateValue() > CurrentHateValue && MovementUtilities.inRangeToAggro(mob, potentialTarget)) {
2023-05-07 12:06:54 -05:00
CurrentHateValue = potentialTarget.getHateValue();
mostHatedTarget = potentialTarget;
2023-05-07 11:53:00 -05:00
}
}
return mostHatedTarget;
2023-08-01 18:52:44 -05:00
} catch(Exception e){
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: ChangeTargetFromMostHated" + " " + e.getMessage());
}
return null;
2023-05-07 11:53:00 -05:00
}
}