AIHitBack.ts 745 B

123456789101112131415161718192021
  1. /// <reference path="../AI.ts" />
  2. module AIRules {
  3. export var attackInRange = AI.combatRules.createAndAddRule({
  4. name : "Attack highest aggro",
  5. firstPriority : AIRules.PRIORITY_ACTING_ON_SITUATION,
  6. code : (runner : RulebookRunner<Person>) => {
  7. let person = runner.noun;
  8. let hostiles = [...person.AI.hostileTargets].filter(value => {
  9. return person.AI.newNoticed.includes(value);
  10. });
  11. if (hostiles.length > 0) {
  12. hostiles.sort((a, b) => {
  13. return person.AI.getHostilityTo(b) - person.AI.getHostilityTo(a);
  14. });
  15. return new ActionAttack(person, hostiles[0]);
  16. }
  17. }
  18. });
  19. }