BasicCombat.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /// <reference path="../../AI.ts" />
  2. /// <reference path="../../Things/Person.ts" />
  3. module AIRules {
  4. export var standUp = new Rule({
  5. name: "Stand if down",
  6. firstPriority : AIRules.PRIORITY_ACTING_ON_SITUATION,
  7. priority : AIRules.PRIORITY_ACTING_ON_SITUATION,
  8. conditions : (runner : RulebookRunner<Person>) => {
  9. let person = runner.noun;
  10. return (person.stance != PersonStance.STANDING)
  11. },
  12. code : (runner : RulebookRunner<Person>) => {
  13. return new ActionStand(runner.noun);
  14. }
  15. });
  16. AI.combatRules.addRule(standUp);
  17. AI.rules.addRule(standUp);
  18. export var Hunt = AI.rules.createAndAddRule({
  19. name: "Follow based on grudge",
  20. firstPriority: AIRules.PRIORITY_ACTING_ON_SITUATION,
  21. priority: AIRules.PRIORITY_ACTING_ON_IDLE,
  22. code: (runner: RulebookRunner<Person>) => {
  23. let person = runner.noun;
  24. let hostiles = [...runner.noun.AI.hostileTargets].sort((a, b) => {
  25. return person.AI.getHostilityTo(b) - person.AI.getHostilityTo(a);
  26. });
  27. for (let i = 0; i < hostiles.length; i++) {
  28. if (ActionFollow.isCloseEnough(person, hostiles[i])) {
  29. return new ActionFollow(person, hostiles[i]);
  30. }
  31. }
  32. },
  33. conditions: (runner: RulebookRunner<Person>) => {
  34. return runner.noun.AI.hostileTargets.length > 0 && Math.random() < 0.5; // add randomness to allow escape
  35. }
  36. });
  37. }