1
1

BasicCombat.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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;
  35. }
  36. });
  37. export var rngHit = AI.rules.createAndAddRule({
  38. name: "Hit someone else RNGly",
  39. firstPriority: AIRules.PRIORITY_ACTING_ON_IDLE,
  40. priority: AIRules.PRIORITY_ACTING_ON_SITUATION,
  41. code: (runner: RulebookRunner<Person>) => {
  42. for (let i = 0; i < runner.noun.AI.newNoticed.length; i++) {
  43. if (runner.noun.AI.newNoticed[i] instanceof Person && runner.noun.AI.newNoticed[i] != WorldState.player) {
  44. return new ActionAttack(runner.noun, runner.noun.AI.newNoticed[i]);
  45. }
  46. }
  47. },
  48. conditions: (runner: RulebookRunner<Person>) => {
  49. return (Math.random() * 100) >= 50;
  50. }
  51. });
  52. }