10 changed files with 387 additions and 21 deletions
			
			
		| @ -0,0 +1,10 @@ | |||||||
|  | package engine.mobileAI.BehaviourFiles; | ||||||
|  | 
 | ||||||
|  | import engine.objects.Mob; | ||||||
|  | 
 | ||||||
|  | public class PlayerGuard { | ||||||
|  | 
 | ||||||
|  |     public static void process(Mob guard){ | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,88 @@ | |||||||
|  | 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.AbstractWorldObject; | ||||||
|  | import engine.objects.ItemBase; | ||||||
|  | import engine.objects.Mob; | ||||||
|  | import engine.objects.PlayerCharacter; | ||||||
|  | import engine.powers.PowersBase; | ||||||
|  | import engine.server.MBServerStatics; | ||||||
|  | 
 | ||||||
|  | import java.util.Map; | ||||||
|  | 
 | ||||||
|  | public class PlayerPet { | ||||||
|  | 
 | ||||||
|  |     public static void process(Mob pet){ | ||||||
|  |         if(pet.getOwner() == null){ | ||||||
|  |             pet.despawn(); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if(!pet.playerAgroMap.contains(pet.getOwner().getObjectUUID())){ | ||||||
|  |             pet.teleport(pet.getOwner().loc); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         switch(enumMobState.getState(pet)){ | ||||||
|  |             case dead: | ||||||
|  |                 pet.despawn(); | ||||||
|  |                 return; | ||||||
|  |             case patrolling: | ||||||
|  |                 if(pet.loc.distanceSquared(pet.getOwner().loc) > 25){ | ||||||
|  |                     MovementUtilities.aiMove(pet,pet.getOwner().loc,false); | ||||||
|  |                 } else if (pet.isMoving()) { | ||||||
|  |                     pet.stopMovement(pet.getMovementLoc()); | ||||||
|  |                 } | ||||||
|  |                 return; | ||||||
|  |             case attacking: | ||||||
|  |                 attack(pet); | ||||||
|  |                 return; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static void attack(Mob mob){ | ||||||
|  | 
 | ||||||
|  |         if (mob.combatTarget == null || !mob.combatTarget.isAlive()) { | ||||||
|  |             mob.setCombatTarget(null); | ||||||
|  |             aggro(mob); | ||||||
|  |             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); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     public static void aggro(Mob mob){ | ||||||
|  | 
 | ||||||
|  |             for(AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(mob.loc,30, MBServerStatics.MASK_PET)) { | ||||||
|  |                 Mob potentialTarget = (Mob) awo; | ||||||
|  |                 if (!potentialTarget.isAlive()) | ||||||
|  |                     continue; | ||||||
|  |                 if (MovementUtilities.inRangeToAggro(mob, potentialTarget)) { | ||||||
|  |                     mob.setCombatTarget(potentialTarget); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,47 @@ | |||||||
|  | package engine.mobileAI.BehaviourFiles; | ||||||
|  | 
 | ||||||
|  | import engine.Enum; | ||||||
|  | import engine.mobileAI.utilities.CombatUtilities; | ||||||
|  | import engine.objects.Mob; | ||||||
|  | 
 | ||||||
|  | public class SiegeMob { | ||||||
|  |     public static void process(Mob treb){ | ||||||
|  |         if(!treb.isAlive()){ | ||||||
|  |             if(!treb.despawned){ | ||||||
|  |                 treb.despawn(); | ||||||
|  |                 treb.deathTime = System.currentTimeMillis(); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             if(treb.deathTime == 0) { | ||||||
|  |                 treb.deathTime = System.currentTimeMillis(); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |             if(treb.deathTime + 900000L > System.currentTimeMillis()) { | ||||||
|  |                 treb.respawn(); | ||||||
|  |                 treb.setCombatTarget(null); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         if(treb.combatTarget == null) | ||||||
|  |             return; | ||||||
|  | 
 | ||||||
|  |         if(!treb.combatTarget.getObjectType().equals(Enum.GameObjectType.Building)) { | ||||||
|  |             treb.setCombatTarget(null); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if(!treb.combatTarget.isAlive()) { | ||||||
|  |             treb.setCombatTarget(null); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if(!CombatUtilities.inRangeToAttack(treb,treb.combatTarget)) | ||||||
|  |             treb.setCombatTarget(null); | ||||||
|  | 
 | ||||||
|  |         if (System.currentTimeMillis() > treb.getNextAttackTime()) { | ||||||
|  |             CombatUtilities.combatCycle(treb, treb.combatTarget, true, null); | ||||||
|  |             treb.setNextAttackTime(System.currentTimeMillis() + 11000L); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,161 @@ | |||||||
|  | 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); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,32 @@ | |||||||
|  | package engine.mobileAI; | ||||||
|  | 
 | ||||||
|  | import engine.mobileAI.BehaviourFiles.PlayerGuard; | ||||||
|  | import engine.mobileAI.BehaviourFiles.PlayerPet; | ||||||
|  | import engine.mobileAI.BehaviourFiles.SiegeMob; | ||||||
|  | import engine.mobileAI.BehaviourFiles.StandardMob; | ||||||
|  | import engine.objects.Mob; | ||||||
|  | 
 | ||||||
|  | public class EasyAI { | ||||||
|  | 
 | ||||||
|  |     public static void aiRun(Mob mob) { | ||||||
|  |         if (mob == null) | ||||||
|  |             return; | ||||||
|  | 
 | ||||||
|  |         if (mob.isPlayerGuard) { | ||||||
|  |             PlayerGuard.process(mob); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if(mob.isSiege()){ | ||||||
|  |             SiegeMob.process(mob); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (mob.isPet()) { | ||||||
|  |             PlayerPet.process(mob); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         StandardMob.process(mob); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,27 @@ | |||||||
|  | package engine.mobileAI; | ||||||
|  | 
 | ||||||
|  | import engine.objects.Mob; | ||||||
|  | 
 | ||||||
|  | public enum enumMobState { | ||||||
|  |         idle, | ||||||
|  |         attacking, | ||||||
|  |         patrolling, | ||||||
|  |         dead; | ||||||
|  | 
 | ||||||
|  |     public static enumMobState getState(Mob mob){ | ||||||
|  |         if(mob.playerAgroMap.isEmpty()) | ||||||
|  |             return enumMobState.idle; | ||||||
|  | 
 | ||||||
|  |         if(!mob.isAlive()) | ||||||
|  |             return enumMobState.dead; | ||||||
|  | 
 | ||||||
|  |         if(mob.combatTarget != null) | ||||||
|  |             return enumMobState.attacking; | ||||||
|  | 
 | ||||||
|  |         return enumMobState.patrolling; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static boolean Agressive(Mob mob){ | ||||||
|  |         return mob.BehaviourType.name().contains("Aggro"); | ||||||
|  |     } | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in new issue