forked from MagicBane/Server
i hope this works
This commit is contained in:
+106
-24
@@ -11,14 +11,15 @@ package engine.mobileAI;
|
||||
import engine.Enum;
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.*;
|
||||
import engine.math.Vector3f;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.mobileAI.Threads.MobAIThread;
|
||||
import engine.mobileAI.Threads.Respawner;
|
||||
import engine.mobileAI.utilities.CombatUtilities;
|
||||
import engine.mobileAI.utilities.MovementUtilities;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.msg.MoveToPointMsg;
|
||||
import engine.net.client.msg.PerformActionMsg;
|
||||
import engine.net.client.msg.PowerProjectileMsg;
|
||||
import engine.objects.*;
|
||||
@@ -103,7 +104,7 @@ public class MobAI {
|
||||
if (mob.behaviourType.callsForHelp)
|
||||
MobCallForHelp(mob);
|
||||
|
||||
if (MovementUtilities.inRangeDropAggro(mob, target)) {
|
||||
if (inRangeDropAggro(mob, target)) {
|
||||
mob.setCombatTarget(null);
|
||||
return;
|
||||
}
|
||||
@@ -287,10 +288,10 @@ public class MobAI {
|
||||
|
||||
if (mob.agentType.equals(Enum.AIAgentType.GUARDMINION)) {
|
||||
Mob captain = (Mob) mob.guardCaptain;
|
||||
mob.setDestination(captain.destination.add(Formation.getOffset(2, mob.guardCaptain.minions.indexOf(mob.getObjectUUID()) + 3)));
|
||||
mob.destination = captain.destination.add(Formation.getOffset(2, mob.guardCaptain.minions.indexOf(mob.getObjectUUID()) + 3));
|
||||
mob.lastPatrolPointIndex = captain.lastPatrolPointIndex;
|
||||
} else {
|
||||
mob.setDestination(mob.patrolPoints.get(mob.lastPatrolPointIndex));
|
||||
NavigationManager.pathfind(mob, mob.patrolPoints.get(mob.lastPatrolPointIndex));
|
||||
mob.lastPatrolPointIndex += 1;
|
||||
}
|
||||
|
||||
@@ -303,7 +304,7 @@ public class MobAI {
|
||||
MobAI.Patrol(minion);
|
||||
}
|
||||
|
||||
MovementUtilities.aiMove(mob, mob.destination, true);
|
||||
aiMove(mob, true,0);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackTarget" + " " + e.getMessage());
|
||||
@@ -689,7 +690,7 @@ public class MobAI {
|
||||
if (aiAgent.enemy.size() > 0 && aiAgent.enemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType()) == false)
|
||||
continue;
|
||||
|
||||
if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) {
|
||||
if (inRangeToAggro(aiAgent, loadedPlayer)) {
|
||||
aiAgent.setCombatTarget(loadedPlayer);
|
||||
return;
|
||||
}
|
||||
@@ -722,7 +723,7 @@ public class MobAI {
|
||||
|
||||
try {
|
||||
|
||||
if (!MovementUtilities.canMove(mob))
|
||||
if (!canMove(mob))
|
||||
return;
|
||||
|
||||
mob.updateLocation();
|
||||
@@ -748,8 +749,8 @@ public class MobAI {
|
||||
if (CombatUtilities.inRange2D(mob, mob.guardCaptain, 6))
|
||||
return;
|
||||
|
||||
mob.setDestination(mob.guardCaptain.getLoc());
|
||||
MovementUtilities.moveToLocation(mob, mob.destination, 5, false);
|
||||
NavigationManager.pathfind(mob, mob.guardCaptain.getLoc());
|
||||
aiMove(mob, false,5);
|
||||
} else
|
||||
chaseTarget(mob);
|
||||
break;
|
||||
@@ -834,7 +835,7 @@ public class MobAI {
|
||||
if (mob.getCombatTarget() == null)
|
||||
return;
|
||||
|
||||
if (mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget()) &&
|
||||
if (mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget()) &&
|
||||
mob.agentType.equals(Enum.AIAgentType.PET) == false) {
|
||||
|
||||
mob.setCombatTarget(null);
|
||||
@@ -877,7 +878,7 @@ public class MobAI {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (MovementUtilities.inRangeOfBindLocation(mob) == false) {
|
||||
} else if (inRangeOfBindLocation(mob) == false) {
|
||||
|
||||
PowersBase recall = PowersManager.getPowerByToken(-1994153779);
|
||||
PowersManager.useMobPower(mob, mob, recall, 40);
|
||||
@@ -904,8 +905,8 @@ public class MobAI {
|
||||
|
||||
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) {
|
||||
if (mob.getRange() > 15) {
|
||||
mob.setDestination(mob.getCombatTarget().getLoc());
|
||||
MovementUtilities.moveToLocation(mob, mob.destination, 0, false);
|
||||
NavigationManager.pathfind(mob, mob.getCombatTarget().getLoc());
|
||||
aiMove(mob, false,0);
|
||||
} else {
|
||||
|
||||
//check if building
|
||||
@@ -913,12 +914,12 @@ public class MobAI {
|
||||
switch (mob.getCombatTarget().getObjectType()) {
|
||||
case PlayerCharacter:
|
||||
case Mob:
|
||||
mob.setDestination(MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget()));
|
||||
MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange() + 1, false);
|
||||
mob.destination = GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget());
|
||||
aiMove(mob, false,mob.getRange() + 1);
|
||||
break;
|
||||
case Building:
|
||||
mob.setDestination(mob.getCombatTarget().getLoc());
|
||||
MovementUtilities.moveToLocation(mob, mob.getCombatTarget().getLoc(), 0, false);
|
||||
mob.destination = mob.getCombatTarget().getLoc();
|
||||
aiMove(mob, false,0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1000,7 +1001,7 @@ public class MobAI {
|
||||
if (ZoneManager.seaFloor.zoneMobSet.contains(mob))
|
||||
mob.killCharacter("no owner");
|
||||
|
||||
if (MovementUtilities.canMove(mob) && mob.behaviourType.canRoam)
|
||||
if (canMove(mob) && mob.behaviourType.canRoam)
|
||||
CheckMobMovement(mob);
|
||||
|
||||
CheckForAttack(mob);
|
||||
@@ -1130,7 +1131,7 @@ public class MobAI {
|
||||
if (GuardCanAggro(mob, loadedPlayer) == false)
|
||||
continue;
|
||||
|
||||
if (MovementUtilities.inRangeToAggro(mob, loadedPlayer) && mob.getCombatTarget() == null) {
|
||||
if (inRangeToAggro(mob, loadedPlayer) && mob.getCombatTarget() == null) {
|
||||
mob.setCombatTarget(loadedPlayer);
|
||||
return;
|
||||
}
|
||||
@@ -1240,9 +1241,9 @@ public class MobAI {
|
||||
float xPoint = ThreadLocalRandom.current().nextInt(400) - 200;
|
||||
float zPoint = ThreadLocalRandom.current().nextInt(400) - 200;
|
||||
Vector3fImmutable TreePos = mob.getGuild().getOwnedCity().getLoc();
|
||||
mob.setDestination(new Vector3fImmutable(TreePos.x + xPoint, TreePos.y, TreePos.z + zPoint));
|
||||
NavigationManager.pathfind(mob, new Vector3fImmutable(TreePos.x + xPoint, TreePos.y, TreePos.z + zPoint));
|
||||
|
||||
MovementUtilities.aiMove(mob, mob.destination, true);
|
||||
aiMove(mob, true,0);
|
||||
|
||||
if (mob.agentType.equals(Enum.AIAgentType.GUARDCAPTAIN)) {
|
||||
for (Integer minionUUID : mob.minions) {
|
||||
@@ -1252,11 +1253,12 @@ public class MobAI {
|
||||
//make sure mob is out of combat stance
|
||||
|
||||
if (minion.despawned == false) {
|
||||
if (MovementUtilities.canMove(minion)) {
|
||||
if (canMove(minion)) {
|
||||
Vector3f minionOffset = Formation.getOffset(2, mob.minions.indexOf(minionUUID) + 3);
|
||||
minion.updateLocation();
|
||||
Vector3fImmutable formationPatrolPoint = new Vector3fImmutable(mob.destination.x + minionOffset.x, mob.destination.y, mob.destination.z + minionOffset.z);
|
||||
MovementUtilities.aiMove(minion, formationPatrolPoint, true);
|
||||
minion.destination = formationPatrolPoint;
|
||||
aiMove(minion, true,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1284,7 +1286,7 @@ public class MobAI {
|
||||
if (potentialTarget.equals(mob.getCombatTarget()))
|
||||
continue;
|
||||
|
||||
if (potentialTarget != null && mob.playerAgroMap.get(potentialTarget.getObjectUUID()).floatValue() > CurrentHateValue && MovementUtilities.inRangeToAggro(mob, potentialTarget)) {
|
||||
if (potentialTarget != null && mob.playerAgroMap.get(potentialTarget.getObjectUUID()).floatValue() > CurrentHateValue && inRangeToAggro(mob, potentialTarget)) {
|
||||
CurrentHateValue = mob.playerAgroMap.get(potentialTarget.getObjectUUID()).floatValue();
|
||||
mostHatedTarget = potentialTarget;
|
||||
}
|
||||
@@ -1296,4 +1298,84 @@ public class MobAI {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean inRangeDropAggro(Mob agent, AbstractCharacter target) {
|
||||
float rangeSquared = MobAIThread.AI_BASE_AGGRO_RANGE * MobAIThread.AI_BASE_AGGRO_RANGE;
|
||||
if(agent.isPlayerGuard())
|
||||
rangeSquared = 62500;
|
||||
if(agent.isSiege())
|
||||
rangeSquared = agent.getRange() * agent.getRange();
|
||||
|
||||
return agent.loc.distanceSquared(target.loc) > rangeSquared;
|
||||
|
||||
}
|
||||
|
||||
public static boolean inRangeToAggro(Mob agent, PlayerCharacter target) {
|
||||
return MobAIThread.AI_BASE_AGGRO_RANGE * MobAIThread.AI_BASE_AGGRO_RANGE > agent.loc.distanceSquared(target.loc) ;
|
||||
}
|
||||
|
||||
public static boolean inRangeOfBindLocation(Mob agent) {
|
||||
if(agent.isPlayerGuard() && agent.guardedCity.isLocationOnCityZone(agent.loc))
|
||||
return true;
|
||||
float bindRangeSquared = (agent.parentZone.getBounds().getHalfExtents().x * agent.parentZone.getBounds().getHalfExtents().x) + (MobAIThread.AI_DROP_AGGRO_RANGE * MobAIThread.AI_DROP_AGGRO_RANGE);
|
||||
return agent.loc.distanceSquared(agent.bindLoc) < bindRangeSquared;
|
||||
}
|
||||
|
||||
public static boolean canMove(Mob agent) {
|
||||
if (!agent.behaviourType.canRoam)
|
||||
return false;
|
||||
|
||||
return (agent.isAlive() && !agent.getBonuses().getBool(Enum.ModType.Stunned, Enum.SourceType.None) && !agent.getBonuses().getBool(Enum.ModType.CannotMove, Enum.SourceType.None));
|
||||
}
|
||||
|
||||
public static Vector3fImmutable GetDestinationToCharacter(Mob aiAgent, AbstractCharacter character) {
|
||||
|
||||
if (!character.isMoving())
|
||||
return character.getLoc();
|
||||
|
||||
|
||||
float agentDistanceEndLoc = aiAgent.getLoc().distanceSquared2D(character.getEndLoc());
|
||||
float characterDistanceEndLoc = character.getLoc().distanceSquared2D(character.getEndLoc());
|
||||
|
||||
if (agentDistanceEndLoc > characterDistanceEndLoc)
|
||||
return character.getEndLoc();
|
||||
|
||||
return character.getLoc();
|
||||
}
|
||||
|
||||
public static void aiMove(Mob mob, boolean isWalking, float offset) {
|
||||
|
||||
//update our walk/run state.
|
||||
if (isWalking && !mob.isWalk()) {
|
||||
mob.setWalkMode(true);
|
||||
MovementManager.sendRWSSMsg(mob);
|
||||
} else if (!isWalking && mob.isWalk()) {
|
||||
mob.setWalkMode(false);
|
||||
MovementManager.sendRWSSMsg(mob);
|
||||
}
|
||||
if(offset > 0){
|
||||
Vector3fImmutable newLoc = Vector3fImmutable.getRandomPointInCircle(mob.destination, offset);
|
||||
mob.destination = newLoc;
|
||||
}
|
||||
|
||||
|
||||
MoveToPointMsg msg = new MoveToPointMsg();
|
||||
|
||||
msg.setSourceType(Enum.GameObjectType.Mob.ordinal());
|
||||
msg.setSourceID(mob.getObjectUUID());
|
||||
msg.setStartCoord(mob.loc);
|
||||
msg.setEndCoord(mob.destination);
|
||||
msg.setInBuildingFloor(-1);
|
||||
msg.setInBuilding(-1);
|
||||
msg.setStartLocType(0);
|
||||
msg.setInBuildingUUID(0);
|
||||
|
||||
|
||||
try {
|
||||
MovementManager.movement(msg, mob);
|
||||
} catch (MsgSendException e) {
|
||||
// TODO Figure out how we want to handle the msg send exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user