package engine.mobileAI.BehaviourFiles; import engine.InterestManagement.WorldGrid; import engine.gameManager.PowersManager; import engine.mobileAI.enumMobState; import engine.mobileAI.utilities.CombatUtilities; import engine.mobileAI.utilities.MovementUtilities; import engine.objects.*; import engine.powers.PowersBase; import engine.server.MBServerStatics; import java.util.Map; public class StandardMob { public static void process(Mob mob){ switch(enumMobState.getState(mob)){ case idle: return; case dead: respawn(mob); return; case patrolling: if(mob.combatTarget == null) aggro(mob); if(mob.combatTarget == null) patrol(mob); return; case attacking: attack(mob); return; } } public static void respawn(Mob mob){ if (mob.deathTime == 0) { mob.setDeathTime(System.currentTimeMillis()); return; } if (!mob.despawned) { if (mob.getCharItemManager() != null && mob.getCharItemManager().getInventoryCount() > 0) { if (System.currentTimeMillis() > mob.deathTime + MBServerStatics.DESPAWN_TIMER_WITH_LOOT) { mob.despawn(); mob.deathTime = System.currentTimeMillis(); return; } //No items in inventory. } else if (mob.isHasLoot()) { if (System.currentTimeMillis() > mob.deathTime + MBServerStatics.DESPAWN_TIMER_ONCE_LOOTED) { mob.despawn(); mob.deathTime = System.currentTimeMillis(); return; } //Mob never had Loot. } else { if (System.currentTimeMillis() > mob.deathTime + MBServerStatics.DESPAWN_TIMER) { mob.despawn(); mob.deathTime = System.currentTimeMillis(); return; } } } if(Mob.discDroppers.contains(mob)) return; if (System.currentTimeMillis() > (mob.deathTime + (mob.spawnTime * 1000L))) { if (!Zone.respawnQue.contains(mob)) { Zone.respawnQue.add(mob); } } } public static void aggro(Mob mob){ if(enumMobState.Agressive(mob)){ for(int id : mob.playerAgroMap.keySet()){ PlayerCharacter potentialTarget = PlayerCharacter.getFromCache(id); if(!potentialTarget.isAlive() || mob.canSee(potentialTarget)) continue; if (MovementUtilities.inRangeToAggro(mob, potentialTarget)) { mob.setCombatTarget(potentialTarget); return; } } for(AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(mob.loc,60, MBServerStatics.MASK_PET)){ Mob potentialTarget = (Mob)awo; if(!potentialTarget.isAlive()) continue; if (MovementUtilities.inRangeToAggro(mob, potentialTarget)) { mob.setCombatTarget(potentialTarget); return; } } } } public static void patrol(Mob mob){ if (!MovementUtilities.canMove(mob)) return; if (mob.stopPatrolTime + 5000L > System.currentTimeMillis()) return; if(mob.isMoving()) return; if (mob.lastPatrolPointIndex > mob.patrolPoints.size() - 1) mob.lastPatrolPointIndex = 0; mob.destination = mob.patrolPoints.get(mob.lastPatrolPointIndex); mob.lastPatrolPointIndex += 1; MovementUtilities.aiMove(mob, mob.destination, true); } public static void attack(Mob mob){ if (!MovementUtilities.inRangeOfBindLocation(mob)) { PowersBase recall = PowersManager.getPowerByToken(-1994153779); PowersManager.useMobPower(mob, mob, recall, 40); mob.setCombatTarget(null); for (Map.Entry playerEntry : mob.playerAgroMap.entrySet()) PlayerCharacter.getFromCache((int) playerEntry.getKey()).setHateValue(0); mob.setCombatTarget(null); return; } if (mob.combatTarget == null || !mob.combatTarget.isAlive()) { mob.setCombatTarget(null); return; } if(MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget())){ mob.setCombatTarget(null); MovementUtilities.aiMove(mob,mob.bindLoc,true); return; } if(!CombatUtilities.inRangeToAttack(mob,mob.combatTarget)){ if (!MovementUtilities.canMove(mob)) return; MovementUtilities.aiMove(mob,mob.combatTarget.loc,false); return; } mob.stopMovement(mob.getMovementLoc()); ItemBase weapon = mob.getWeaponItemBase(true); boolean mainHand = true; if(weapon == null) { weapon = mob.getWeaponItemBase(false); mainHand = false; } if (System.currentTimeMillis() > mob.getNextAttackTime()) { CombatUtilities.combatCycle(mob, mob.combatTarget, mainHand, weapon); mob.setNextAttackTime(System.currentTimeMillis() + 3000L); } } }