AIGrudge.ts 788 B

123456789101112131415161718192021
  1. /// <reference path="../AI.ts" />
  2. module AIRules {
  3. export var Grudge = AI.rules.createAndAddRule({
  4. name : "Grudge",
  5. firstPriority : AIRules.PRIORITY_ACTING_ON_SITUATION,
  6. conditions : (runner : RulebookRunner<Person>) => {
  7. let person = runner.noun;
  8. return person.AI.hostileTo.length > 0 && (Math.random() * 100) <= person.AI.grudgeRate;
  9. },
  10. code : (runner : RulebookRunner<Person>) => {
  11. let person = runner.noun;
  12. let hostileTo = person.AI.hostileTo;
  13. for (let i = 0; i < hostileTo.length; i++) {
  14. if (ActionFollow.isCloseEnough(person, hostileTo[i])) {
  15. return new ActionFollow(person, hostileTo[i]);
  16. }
  17. }
  18. }
  19. });
  20. }