1
1

EveryTurn.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. && (person.lastActionTurn < WorldState.getCurrentTurn()));
  14. }
  15. let people = <Array<Person>> Thing.InsideRoomRelation.getAnyRightType(Person).filter(isAIAvailable);
  16. for (let i = 0; i < people.length; i++) {
  17. let person = people[i];
  18. if (person.getHealthOnScale() > 0) {
  19. let action = await people[i].AI.execute();
  20. let visible = people[i].isVisibleTo(WorldState.player);
  21. if (action == undefined) action = new ActionWait(person);
  22. let printValue: Say = await action.execute();
  23. if (
  24. (
  25. visible ||
  26. person.isVisibleTo(WorldState.player)
  27. ) && printValue != undefined) {
  28. Elements.CurrentTurnHandler.printAsContent(printValue);
  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. }