diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 667db7b0..6332f406 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -315,6 +315,9 @@ public class MobileFSM { 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 + if(mob.isAlive() == false){ + mob.deathTime = System.currentTimeMillis(); + } return; } } @@ -582,13 +585,20 @@ public class MobileFSM { } private static void DefaultLogic(Mob mob) { //check for players that can be aggroed if mob is agressive and has no target - if (mob.BehaviourType.isAgressive && mob.getCombatTarget() == null) { - if (mob.BehaviourType == Enum.MobBehaviourType.HamletGuard) - //safehold guard - SafeGuardAggro(mob); - else - //normal aggro - CheckForAggro(mob); + 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); + } + } } //check if mob can move for patrol or moving to target if (mob.BehaviourType.canRoam) @@ -630,6 +640,9 @@ public class MobileFSM { public static Boolean GuardCanAggro(Mob mob, PlayerCharacter target) { if (mob.getGuild().getNation().equals(target.getGuild().getNation())) return false; + if(mob.building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true){ + return true; + } //first check condemn list for aggro allowed (allies button is checked) if (ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().reverseKOS) { for (Entry entry : ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().getCondemned().entrySet()) { @@ -697,4 +710,15 @@ public class MobileFSM { } } } + public static AbstractWorldObject ChangeTargetFromHateValue(Mob mob){ + float CurrentHateValue = 0; + AbstractWorldObject mostHatedTarget = null; + for (Entry playerEntry : mob.playerAgroMap.entrySet()) { + if(((AbstractCharacter)playerEntry.getKey()).getHateValue() > CurrentHateValue){ + CurrentHateValue = ((AbstractCharacter)playerEntry.getKey()).getHateValue(); + mostHatedTarget = PlayerCharacter.getFromCache((int)playerEntry.getKey()); + } + } + return mostHatedTarget; + } } \ No newline at end of file diff --git a/src/engine/gameManager/CombatManager.java b/src/engine/gameManager/CombatManager.java index 88fdc5df..fae77eb0 100644 --- a/src/engine/gameManager/CombatManager.java +++ b/src/engine/gameManager/CombatManager.java @@ -100,13 +100,13 @@ public enum CombatManager { } - public static void AttackTarget(PlayerCharacter pc, AbstractWorldObject target) { + public static void AttackTarget(PlayerCharacter playerCharacter, AbstractWorldObject target) { boolean swingOffhand = false; //check my weapon can I do an offhand attack - Item weaponOff = pc.getCharItemManager().getEquipped().get(MBServerStatics.SLOT_OFFHAND); - Item weaponMain = pc.getCharItemManager().getEquipped().get(MBServerStatics.SLOT_MAINHAND); + Item weaponOff = playerCharacter.getCharItemManager().getEquipped().get(MBServerStatics.SLOT_OFFHAND); + Item weaponMain = playerCharacter.getCharItemManager().getEquipped().get(MBServerStatics.SLOT_MAINHAND); // if you carry something in the offhand thats a weapon you get to swing it if (weaponOff != null) { @@ -120,10 +120,10 @@ public enum CombatManager { } //we always swing our mainhand if we are not on timer - JobContainer main = pc.getTimers().get("Attack" + MBServerStatics.SLOT_MAINHAND); + JobContainer main = playerCharacter.getTimers().get("Attack" + MBServerStatics.SLOT_MAINHAND); if (main == null) { // no timers on the mainhand, lets submit a job to swing - CombatManager.createTimer(pc, MBServerStatics.SLOT_MAINHAND, 1, true); // attack in 0.1 of a second + CombatManager.createTimer(playerCharacter, MBServerStatics.SLOT_MAINHAND, 1, true); // attack in 0.1 of a second } if (swingOffhand) { @@ -131,19 +131,14 @@ public enum CombatManager { only swing offhand if we have a weapon in it or are unarmed in both hands and no timers running */ - JobContainer off = pc.getTimers().get("Attack" + MBServerStatics.SLOT_OFFHAND); + JobContainer off = playerCharacter.getTimers().get("Attack" + MBServerStatics.SLOT_OFFHAND); if (off == null) { - CombatManager.createTimer(pc, MBServerStatics.SLOT_OFFHAND, 1, true); // attack in 0.1 of a second + CombatManager.createTimer(playerCharacter, MBServerStatics.SLOT_OFFHAND, 1, true); // attack in 0.1 of a second } } - City playerCity = ZoneManager.getCityAtLocation(pc.getLoc()); - if( playerCity != null) - for(Building barracks : playerCity.cityBarracks) - for(Map.Entry entry : barracks.getHirelings().entrySet()) - if(entry.getKey().getCombatTarget() == null){ - if(MobileFSM.GuardCanAggro((Mob) entry.getKey(),pc)) - entry.getKey().setCombatTarget(pc); - } + City playerCity = ZoneManager.getCityAtLocation(playerCharacter.getLoc()); + if( playerCity != null && playerCity.getGuild().getNation().equals(playerCharacter.getGuild().getNation()) == false && playerCity.cityOutlaws.contains(playerCharacter.getObjectUUID()) == false) + playerCity.cityOutlaws.add(playerCharacter.getObjectUUID()); } public static void setAttackTarget(PetAttackMsg msg, ClientConnection origin) throws MsgSendException { diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index dba734b8..9a2ea52a 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -92,6 +92,7 @@ public class City extends AbstractWorldObject { public volatile boolean protectionEnforced = true; private String hash; public ArrayListcityBarracks; + public ArrayList cityOutlaws; /** * ResultSet Constructor @@ -1080,7 +1081,8 @@ public class City extends AbstractWorldObject { // so store it in a temporary collection toRemove.add(playerUUID); - + if(cityOutlaws.contains(playerUUID)) + cityOutlaws.remove(playerUUID); // ***For debugging // Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size()); }