PlayBegins.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /// <reference path="./Classes/Rulebook.ts" />
  2. /// <reference path="./Classes/Rule.ts" />
  3. /// <reference path="MachineBegins.ts" />
  4. module PlayBegins {
  5. export var rulebook = new Rulebook<void>("Play Begins");
  6. export var LOAD_FAILED = false;
  7. export let startingRoom;
  8. export function execute () {
  9. rulebook.execute({});
  10. }
  11. export function setStartingRoom (room : Room) {
  12. if (startingRoom != undefined) {
  13. console.warn("[InitialRoom] Multiple requests for starting room, please check.", startingRoom, room);
  14. }
  15. startingRoom = room;
  16. }
  17. export let PutPlayerIntoFirstRoom = rulebook.createAndAddRule({
  18. name : "Place player into initial room",
  19. firstPriority : Rule.PRIORITY_HIGHEST,
  20. priority : Rule.PRIORITY_MEDIUM,
  21. code : () => {
  22. if (WorldState.player.getRoom() != undefined) {
  23. console.debug(Rulebook.getIndentation() + "[InitialRoom] Player already in a room.", WorldState.player.getRoom());
  24. } else {
  25. startingRoom.place(WorldState.player);
  26. }
  27. }
  28. });
  29. export var RunEmptyTurnSequenceRule = new Rule ({
  30. name : "Run Empty Turn Sequence Rule",
  31. firstPriority : Rule.PRIORITY_LOWEST,
  32. priority : Rule.PRIORITY_LOWEST,
  33. code : (rulebook2 : RulebookRunner<void>) => {
  34. TurnSequence.execute();
  35. }
  36. });
  37. rulebook.addRule(RunEmptyTurnSequenceRule);
  38. }
  39. module MachineBegins {
  40. export let RunPlayBegins = MachineBegins.rulebook.createAndAddRule({
  41. firstPriority : Rule.PRIORITY_LOW,
  42. name : "Run Play Begins",
  43. code : () => {
  44. PlayBegins.execute();
  45. }
  46. });
  47. }