EveryTurn.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /// <reference path="./Classes/Rulebook.ts" />
  2. /// <reference path="./Classes/Rule.ts" />
  3. /// <reference path="Classes/Things/Person.ts" />
  4. module EveryTurn {
  5. export var EveryTurn = new Rulebook("Every Turn");
  6. export var RunAIRule = EveryTurn.createAndAddRule({
  7. name : "Run NPC AI Rule",
  8. code : async function () {
  9. function isAIAvailable (person : Person) {
  10. return (person != WorldState.player
  11. && ((person.getRoom() instanceof RoomRandom
  12. && (<RoomRandom> person.getRoom()).placed)));
  13. }
  14. let people = <Array<Person>> Thing.InsideRoomRelation.getAnyRightType(Person).filter(isAIAvailable);
  15. for (let i = 0; i < people.length; i++) {
  16. let person = people[i];
  17. if (person.getHealthOnScale() > 0) {
  18. let action = await people[i].AI.execute();
  19. let visible = people[i].isVisibleTo(WorldState.player);
  20. if (action != undefined) {
  21. let printValue: Say = await action.execute();
  22. if (
  23. (
  24. visible ||
  25. person.isVisibleTo(WorldState.player)
  26. ) && printValue != undefined) {
  27. Elements.CurrentTurnHandler.printAsContent(printValue);
  28. }
  29. }
  30. }
  31. }
  32. }
  33. });
  34. export var incrementTurnCounterRule = EveryTurn.createAndAddRule({
  35. firstPriority: Rule.PRIORITY_LOWEST,
  36. priority: Rule.PRIORITY_LOWEST,
  37. name: "Increment Turn Counter",
  38. code: function () {
  39. WorldState.incrementWorldTurn();
  40. }
  41. });
  42. }