EveryTurn.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 action = await people[i].AI.execute();
  17. let person = people[i];
  18. let visible = people[i].isVisibleTo(WorldState.player);
  19. if (action != undefined) {
  20. let printValue: Say = await action.execute();
  21. if (
  22. (
  23. visible ||
  24. person.isVisibleTo(WorldState.player)
  25. ) && printValue != undefined) {
  26. Elements.CurrentTurnHandler.printAsContent(printValue);
  27. }
  28. }
  29. }
  30. }
  31. });
  32. export var incrementTurnCounterRule = EveryTurn.createAndAddRule({
  33. firstPriority: Rule.PRIORITY_LOWEST,
  34. priority: Rule.PRIORITY_LOWEST,
  35. name: "Increment Turn Counter",
  36. code: function () {
  37. WorldState.incrementWorldTurn();
  38. }
  39. });
  40. }