new mob aggro system
This commit is contained in:
@@ -1006,6 +1006,16 @@ public enum CombatManager {
|
|||||||
if (ac.isAlive() && tarAc != null && tarAc.isAlive())
|
if (ac.isAlive() && tarAc != null && tarAc.isAlive())
|
||||||
handleDamageShields(ac, tarAc, damage);
|
handleDamageShields(ac, tarAc, damage);
|
||||||
|
|
||||||
|
//handle mob hate values
|
||||||
|
if(target.getObjectType().equals(GameObjectType.Mob) && ac.getObjectType().equals(GameObjectType.PlayerCharacter)){
|
||||||
|
Mob mobTarget = (Mob)target;
|
||||||
|
if(mobTarget.hate_values.containsKey((PlayerCharacter) ac)){
|
||||||
|
mobTarget.hate_values.put((PlayerCharacter) ac,mobTarget.hate_values.get((PlayerCharacter) ac) + damage);
|
||||||
|
}else{
|
||||||
|
mobTarget.hate_values.put((PlayerCharacter) ac, damage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Apply Weapon power effect if any.
|
// Apply Weapon power effect if any.
|
||||||
|
|||||||
@@ -1015,6 +1015,19 @@ public enum PowersManager {
|
|||||||
|
|
||||||
playerCharacter.setHateValue(pb.getHateValue(trains));
|
playerCharacter.setHateValue(pb.getHateValue(trains));
|
||||||
|
|
||||||
|
//handle mob hate values
|
||||||
|
HashSet<AbstractWorldObject> mobs = WorldGrid.getObjectsInRangePartial(playerCharacter.loc,60.0f,MBServerStatics.MASK_MOB);
|
||||||
|
for(AbstractWorldObject awo : mobs){
|
||||||
|
Mob mobTarget = (Mob)awo;
|
||||||
|
if(mobTarget.hate_values.containsKey(playerCharacter)){
|
||||||
|
mobTarget.hate_values.put(playerCharacter,mobTarget.hate_values.get(playerCharacter) + pb.getHateValue(trains));
|
||||||
|
}else{
|
||||||
|
mobTarget.hate_values.put(playerCharacter, pb.getHateValue(trains));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Send Cast Message.
|
//Send Cast Message.
|
||||||
// PerformActionMsg castMsg = new PerformActionMsg(msg);
|
// PerformActionMsg castMsg = new PerformActionMsg(msg);
|
||||||
// castMsg.setNumTrains(9999);
|
// castMsg.setNumTrains(9999);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import engine.server.MBServerStatics;
|
|||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -738,6 +739,8 @@ public class MobAI {
|
|||||||
|
|
||||||
private static void CheckForAggro(Mob aiAgent) {
|
private static void CheckForAggro(Mob aiAgent) {
|
||||||
|
|
||||||
|
|
||||||
|
//old system
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//looks for and sets mobs combatTarget
|
//looks for and sets mobs combatTarget
|
||||||
@@ -772,13 +775,11 @@ public class MobAI {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// No aggro for this race type
|
// No aggro for this race type
|
||||||
|
if (aiAgent.notEnemy.size() > 0 && aiAgent.notEnemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType()))
|
||||||
if (aiAgent.notEnemy.size() > 0 && aiAgent.notEnemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType()) == true)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//mob has enemies and this player race is not it
|
//mob has enemies and this player race is not it
|
||||||
|
if (aiAgent.enemy.size() > 0 && !aiAgent.enemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType()))
|
||||||
if (aiAgent.enemy.size() > 0 && aiAgent.enemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType()) == false)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) {
|
if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) {
|
||||||
@@ -975,7 +976,8 @@ public class MobAI {
|
|||||||
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal())
|
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal())
|
||||||
CheckForPlayerGuardAggro(mob);
|
CheckForPlayerGuardAggro(mob);
|
||||||
} else {
|
} else {
|
||||||
CheckForAggro(mob);
|
//CheckForAggro(mob);
|
||||||
|
NewAggroMechanic(mob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1107,17 +1109,6 @@ public class MobAI {
|
|||||||
if (mob.getCombatTarget() == null)
|
if (mob.getCombatTarget() == null)
|
||||||
CheckForPlayerGuardAggro(mob);
|
CheckForPlayerGuardAggro(mob);
|
||||||
|
|
||||||
AbstractWorldObject newTarget = ChangeTargetFromHateValue(mob);
|
|
||||||
|
|
||||||
if (newTarget != null) {
|
|
||||||
|
|
||||||
if (newTarget.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) {
|
|
||||||
if (GuardCanAggro(mob, (PlayerCharacter) newTarget))
|
|
||||||
mob.setCombatTarget(newTarget);
|
|
||||||
} else
|
|
||||||
mob.setCombatTarget(newTarget);
|
|
||||||
|
|
||||||
}
|
|
||||||
CheckMobMovement(mob);
|
CheckMobMovement(mob);
|
||||||
CheckForAttack(mob);
|
CheckForAttack(mob);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -1209,17 +1200,11 @@ public class MobAI {
|
|||||||
|
|
||||||
if (mob.BehaviourType.isAgressive) {
|
if (mob.BehaviourType.isAgressive) {
|
||||||
|
|
||||||
AbstractWorldObject newTarget = ChangeTargetFromHateValue(mob);
|
if (mob.getCombatTarget() == null) {
|
||||||
|
if (mob.BehaviourType == Enum.MobBehaviourType.HamletGuard)
|
||||||
if (newTarget != null)
|
SafeGuardAggro(mob); //safehold guard
|
||||||
mob.setCombatTarget(newTarget);
|
else
|
||||||
else {
|
NewAggroMechanic(mob);//CheckForAggro(mob); //normal aggro
|
||||||
if (mob.getCombatTarget() == null) {
|
|
||||||
if (mob.BehaviourType == Enum.MobBehaviourType.HamletGuard)
|
|
||||||
SafeGuardAggro(mob); //safehold guard
|
|
||||||
else
|
|
||||||
CheckForAggro(mob); //normal aggro
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1401,37 +1386,6 @@ public class MobAI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AbstractWorldObject ChangeTargetFromHateValue(Mob mob) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
float CurrentHateValue = 0;
|
|
||||||
|
|
||||||
if (mob.getCombatTarget() != null && mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter))
|
|
||||||
CurrentHateValue = ((PlayerCharacter) mob.getCombatTarget()).getHateValue();
|
|
||||||
|
|
||||||
AbstractWorldObject mostHatedTarget = null;
|
|
||||||
|
|
||||||
for (Entry playerEntry : mob.playerAgroMap.entrySet()) {
|
|
||||||
|
|
||||||
PlayerCharacter potentialTarget = PlayerCharacter.getFromCache((int) playerEntry.getKey());
|
|
||||||
|
|
||||||
if (potentialTarget.equals(mob.getCombatTarget()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (potentialTarget != null && potentialTarget.getHateValue() > CurrentHateValue && MovementUtilities.inRangeToAggro(mob, potentialTarget)) {
|
|
||||||
CurrentHateValue = potentialTarget.getHateValue();
|
|
||||||
mostHatedTarget = potentialTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return mostHatedTarget;
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: ChangeTargetFromMostHated" + " " + e.getMessage());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RecoverHealth(Mob mob) {
|
public static void RecoverHealth(Mob mob) {
|
||||||
//recover health
|
//recover health
|
||||||
try {
|
try {
|
||||||
@@ -1459,4 +1413,59 @@ public class MobAI {
|
|||||||
rwss.setPlayer(mob);
|
rwss.setPlayer(mob);
|
||||||
DispatchMessage.sendToAllInRange(mob, rwss);
|
DispatchMessage.sendToAllInRange(mob, rwss);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void NewAggroMechanic(Mob mob){
|
||||||
|
|
||||||
|
if(mob == null || !mob.isAlive()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<AbstractWorldObject> inRange = WorldGrid.getObjectsInRangePartial(mob.loc,60.0f,MBServerStatics.MASK_PLAYER);
|
||||||
|
|
||||||
|
if(inRange.isEmpty()){
|
||||||
|
mob.setCombatTarget(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//clear out any players who are not in hated range anymore
|
||||||
|
ArrayList<PlayerCharacter> toRemove = new ArrayList<>();
|
||||||
|
for(PlayerCharacter pc : mob.hate_values.keySet()){
|
||||||
|
if(!inRange.contains(pc))
|
||||||
|
toRemove.add(pc);
|
||||||
|
}
|
||||||
|
for(PlayerCharacter pc : toRemove){
|
||||||
|
mob.hate_values.remove(pc);
|
||||||
|
}
|
||||||
|
|
||||||
|
//find most hated target
|
||||||
|
PlayerCharacter mostHated = (PlayerCharacter)inRange.iterator().next();
|
||||||
|
for(AbstractWorldObject awo : inRange){
|
||||||
|
PlayerCharacter loadedPlayer = (PlayerCharacter)awo;
|
||||||
|
if (loadedPlayer == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//Player is Dead, Mob no longer needs to attempt to aggro. Remove them from aggro map.
|
||||||
|
if (!loadedPlayer.isAlive())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//Can't see target, skip aggro.
|
||||||
|
if (!mob.canSee(loadedPlayer))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// No aggro for this race type
|
||||||
|
if (mob.notEnemy != null && mob.notEnemy.size() > 0 && mob.notEnemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//mob has enemies and this player race is not it
|
||||||
|
if (mob.enemy != null && mob.enemy.size() > 0 && !mob.enemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(mob.hate_values.containsKey(loadedPlayer))
|
||||||
|
if(mob.hate_values.get(loadedPlayer) > mob.hate_values.get(mostHated))
|
||||||
|
mostHated = loadedPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mostHated != null)
|
||||||
|
mob.setCombatTarget(mostHated);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -111,6 +111,8 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
public boolean StrongholdEpic = false;
|
public boolean StrongholdEpic = false;
|
||||||
public boolean isDropper = false;
|
public boolean isDropper = false;
|
||||||
|
|
||||||
|
public HashMap<PlayerCharacter,Float> hate_values;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No Id Constructor
|
* No Id Constructor
|
||||||
@@ -1450,6 +1452,7 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
this.stopPatrolTime = 0;
|
this.stopPatrolTime = 0;
|
||||||
this.lastPatrolPointIndex = 0;
|
this.lastPatrolPointIndex = 0;
|
||||||
InterestManager.setObjectDirty(this);
|
InterestManager.setObjectDirty(this);
|
||||||
|
this.hate_values = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void despawn() {
|
public void despawn() {
|
||||||
|
|||||||
Reference in New Issue
Block a user