///
module AIRules {
export var attackInRange = AI.combatRules.createAndAddRule({
name : "Attack highest aggro",
firstPriority : AIRules.PRIORITY_ACTING_ON_SITUATION,
code : (runner : RulebookRunner) => {
let person = runner.noun;
let hostiles = [...person.AI.hostileTargets].filter(value => {
return person.AI.newNoticed.includes(value);
});
if (hostiles.length > 0) {
hostiles.sort((a, b) => {
return person.AI.getHostilityTo(b) - person.AI.getHostilityTo(a);
});
return new ActionAttack(person, hostiles[0]);
}
}
});
}