forked from MagicBane/Server
mobs use hate value to hot swap targets
This commit is contained in:
@@ -315,6 +315,9 @@ public class MobileFSM {
|
|||||||
if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()){
|
if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()){
|
||||||
if(mob.npcOwner.isAlive() == false || ((Mob)mob.npcOwner).despawned == true){
|
if(mob.npcOwner.isAlive() == false || ((Mob)mob.npcOwner).despawned == true){
|
||||||
//minions don't respawn while guard captain is dead
|
//minions don't respawn while guard captain is dead
|
||||||
|
if(mob.isAlive() == false){
|
||||||
|
mob.deathTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -582,13 +585,20 @@ public class MobileFSM {
|
|||||||
}
|
}
|
||||||
private static void DefaultLogic(Mob mob) {
|
private static void DefaultLogic(Mob mob) {
|
||||||
//check for players that can be aggroed if mob is agressive and has no target
|
//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.isAgressive) {
|
||||||
if (mob.BehaviourType == Enum.MobBehaviourType.HamletGuard)
|
AbstractWorldObject newTarget = ChangeTargetFromHateValue(mob);
|
||||||
//safehold guard
|
if (newTarget != null) {
|
||||||
SafeGuardAggro(mob);
|
mob.setCombatTarget(newTarget);
|
||||||
else
|
} else {
|
||||||
//normal aggro
|
if (mob.getCombatTarget() == null) {
|
||||||
CheckForAggro(mob);
|
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
|
//check if mob can move for patrol or moving to target
|
||||||
if (mob.BehaviourType.canRoam)
|
if (mob.BehaviourType.canRoam)
|
||||||
@@ -630,6 +640,9 @@ public class MobileFSM {
|
|||||||
public static Boolean GuardCanAggro(Mob mob, PlayerCharacter target) {
|
public static Boolean GuardCanAggro(Mob mob, PlayerCharacter target) {
|
||||||
if (mob.getGuild().getNation().equals(target.getGuild().getNation()))
|
if (mob.getGuild().getNation().equals(target.getGuild().getNation()))
|
||||||
return false;
|
return false;
|
||||||
|
if(mob.building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
//first check condemn list for aggro allowed (allies button is checked)
|
//first check condemn list for aggro allowed (allies button is checked)
|
||||||
if (ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().reverseKOS) {
|
if (ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().reverseKOS) {
|
||||||
for (Entry<Integer, Condemned> entry : ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().getCondemned().entrySet()) {
|
for (Entry<Integer, Condemned> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
boolean swingOffhand = false;
|
||||||
|
|
||||||
//check my weapon can I do an offhand attack
|
//check my weapon can I do an offhand attack
|
||||||
Item weaponOff = pc.getCharItemManager().getEquipped().get(MBServerStatics.SLOT_OFFHAND);
|
Item weaponOff = playerCharacter.getCharItemManager().getEquipped().get(MBServerStatics.SLOT_OFFHAND);
|
||||||
Item weaponMain = pc.getCharItemManager().getEquipped().get(MBServerStatics.SLOT_MAINHAND);
|
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 you carry something in the offhand thats a weapon you get to swing it
|
||||||
if (weaponOff != null) {
|
if (weaponOff != null) {
|
||||||
@@ -120,10 +120,10 @@ public enum CombatManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//we always swing our mainhand if we are not on timer
|
//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) {
|
if (main == null) {
|
||||||
// no timers on the mainhand, lets submit a job to swing
|
// 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) {
|
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
|
only swing offhand if we have a weapon in it or are unarmed in both hands
|
||||||
and no timers running
|
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) {
|
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());
|
City playerCity = ZoneManager.getCityAtLocation(playerCharacter.getLoc());
|
||||||
if( playerCity != null)
|
if( playerCity != null && playerCity.getGuild().getNation().equals(playerCharacter.getGuild().getNation()) == false && playerCity.cityOutlaws.contains(playerCharacter.getObjectUUID()) == false)
|
||||||
for(Building barracks : playerCity.cityBarracks)
|
playerCity.cityOutlaws.add(playerCharacter.getObjectUUID());
|
||||||
for(Map.Entry<AbstractCharacter,Integer> entry : barracks.getHirelings().entrySet())
|
|
||||||
if(entry.getKey().getCombatTarget() == null){
|
|
||||||
if(MobileFSM.GuardCanAggro((Mob) entry.getKey(),pc))
|
|
||||||
entry.getKey().setCombatTarget(pc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setAttackTarget(PetAttackMsg msg, ClientConnection origin) throws MsgSendException {
|
public static void setAttackTarget(PetAttackMsg msg, ClientConnection origin) throws MsgSendException {
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ public class City extends AbstractWorldObject {
|
|||||||
public volatile boolean protectionEnforced = true;
|
public volatile boolean protectionEnforced = true;
|
||||||
private String hash;
|
private String hash;
|
||||||
public ArrayList<Building>cityBarracks;
|
public ArrayList<Building>cityBarracks;
|
||||||
|
public ArrayList<Integer> cityOutlaws;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ResultSet Constructor
|
* ResultSet Constructor
|
||||||
@@ -1080,7 +1081,8 @@ public class City extends AbstractWorldObject {
|
|||||||
// so store it in a temporary collection
|
// so store it in a temporary collection
|
||||||
|
|
||||||
toRemove.add(playerUUID);
|
toRemove.add(playerUUID);
|
||||||
|
if(cityOutlaws.contains(playerUUID))
|
||||||
|
cityOutlaws.remove(playerUUID);
|
||||||
// ***For debugging
|
// ***For debugging
|
||||||
// Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size());
|
// Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user