///
///
module AIRules {
export var standUp = new Rule({
name: "Stand if down",
firstPriority : AIRules.PRIORITY_ACTING_ON_SITUATION,
priority : AIRules.PRIORITY_ACTING_ON_SITUATION,
conditions : (runner : RulebookRunner) => {
let person = runner.noun;
return (person.stance != PersonStance.STANDING)
},
code : (runner : RulebookRunner) => {
return new ActionStand(runner.noun);
}
});
AI.combatRules.addRule(standUp);
AI.rules.addRule(standUp);
export var Hunt = AI.rules.createAndAddRule({
name: "Follow based on grudge",
firstPriority: AIRules.PRIORITY_ACTING_ON_SITUATION,
priority: AIRules.PRIORITY_ACTING_ON_IDLE,
code: (runner: RulebookRunner) => {
let person = runner.noun;
let hostiles = [...runner.noun.AI.hostileTargets].sort((a, b) => {
return person.AI.getHostilityTo(b) - person.AI.getHostilityTo(a);
});
for (let i = 0; i < hostiles.length; i++) {
if (ActionFollow.isCloseEnough(person, hostiles[i])) {
return new ActionFollow(person, hostiles[i]);
}
}
},
conditions: (runner: RulebookRunner) => {
return runner.noun.AI.hostileTargets.length > 0 && Math.random() < 0.5; // add randomness to allow escape
}
});
}