1
1

AIHitBack.ts 946 B

123456789101112131415161718192021222324
  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. !(value instanceof Person) || value.stance != PersonStance.KNOCKEDOUT
  12. ); // by default, stop hitting unconscious people.
  13. });
  14. if (hostiles.length > 0) {
  15. hostiles.sort((a, b) => {
  16. return person.AI.getHostilityTo(b) - person.AI.getHostilityTo(a);
  17. });
  18. return new ActionAttack(person, hostiles[0]);
  19. }
  20. }
  21. });
  22. }