forked from MagicBane/Server
90 lines
3.3 KiB
Java
90 lines
3.3 KiB
Java
|
|
package engine.mobileAI.behaviours;
|
||
|
|
|
||
|
|
import engine.Enum;
|
||
|
|
import engine.gameManager.BuildingManager;
|
||
|
|
import engine.gameManager.CombatManager;
|
||
|
|
import engine.gameManager.MovementManager;
|
||
|
|
import engine.gameManager.ZoneManager;
|
||
|
|
import engine.mobileAI.utilities.CombatUtilities;
|
||
|
|
import engine.objects.Building;
|
||
|
|
import engine.objects.City;
|
||
|
|
import engine.objects.Mob;
|
||
|
|
import engine.server.MBServerStatics;
|
||
|
|
import org.pmw.tinylog.Logger;
|
||
|
|
|
||
|
|
public class SiegeEngineAI {
|
||
|
|
|
||
|
|
public static void run(Mob engine) {
|
||
|
|
|
||
|
|
//1. check to respawn if engine is dead or initially spawning
|
||
|
|
if (!engine.isAlive() || engine.despawned) {
|
||
|
|
if (System.currentTimeMillis() - engine.deathTime > MBServerStatics.FIFTEEN_MINUTES) {
|
||
|
|
engine.respawn();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//2. early exit if owner is null, siege engines cannot act with player intervention
|
||
|
|
if (engine.getOwner() == null)
|
||
|
|
return;
|
||
|
|
|
||
|
|
//3. early exit if target is null, siege engines have no purpose without a target
|
||
|
|
if (engine.combatTarget == null)
|
||
|
|
return;
|
||
|
|
|
||
|
|
//4. early exit if target is not a building, siege engines can only attack buildings
|
||
|
|
if (!engine.combatTarget.getObjectType().equals(Enum.GameObjectType.Building)) {
|
||
|
|
engine.setCombatTarget(null);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
//5. early exit if target is out of range, engines don't move and neither do buildings, avoid infinite loop
|
||
|
|
if(CombatManager.NotInRange(engine,engine.combatTarget,engine.getRange())) {
|
||
|
|
engine.setCombatTarget(null);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
//6. attack target, sanity checks passed, attack target
|
||
|
|
AttackBuilding(engine,(Building) engine.combatTarget);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void AttackBuilding(Mob engine, Building target) {
|
||
|
|
|
||
|
|
try {
|
||
|
|
|
||
|
|
if (engine == null || target == null)
|
||
|
|
return;
|
||
|
|
|
||
|
|
if (target.getRank() == -1 || !target.isVulnerable() || BuildingManager.getBuildingFromCache(target.getObjectUUID()) == null) {
|
||
|
|
engine.setCombatTarget(null);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
City playercity = ZoneManager.getCityAtLocation(engine.getLoc());
|
||
|
|
|
||
|
|
if (playercity != null)
|
||
|
|
for (Mob guard : playercity.getParent().zoneMobSet)
|
||
|
|
if (guard.BehaviourType != null && guard.BehaviourType.equals(Enum.MobBehaviourType.GuardCaptain))
|
||
|
|
if (guard.getCombatTarget() == null && guard.getGuild() != null && engine.getGuild() != null && !guard.getGuild().equals(engine.getGuild()))
|
||
|
|
guard.setCombatTarget(engine);
|
||
|
|
|
||
|
|
|
||
|
|
MovementManager.sendRWSSMsg(engine);
|
||
|
|
|
||
|
|
CombatUtilities.combatCycle(engine, target, true, null);
|
||
|
|
int delay = 15000;
|
||
|
|
engine.setLastAttackTime(System.currentTimeMillis() + delay);
|
||
|
|
|
||
|
|
|
||
|
|
//if (mob.isSiege()) {
|
||
|
|
// PowerProjectileMsg ppm = new PowerProjectileMsg(mob, target);
|
||
|
|
// ppm.setRange(50);
|
||
|
|
// DispatchMessage.dispatchMsgToInterestArea(mob, ppm, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);
|
||
|
|
//}
|
||
|
|
|
||
|
|
} catch (Exception e) {
|
||
|
|
Logger.info(engine.getObjectUUID() + " " + engine.getName() + " Failed At: AttackBuilding" + " " + e.getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|