1
1

_Positioner.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /// <reference path="../Forest.ts" />
  2. /// <reference path="ForestBed.ts" />
  3. /// <reference path="OrcVillage.ts" />
  4. /// <reference path="WitchHut.ts" />
  5. /// <reference path="MazeEntrance.ts" />
  6. /// <reference path="TheObelisk.ts" />
  7. /// <reference path="CentaurVillage.ts" />
  8. /// <reference path="OminousCave.ts" />
  9. PlayBegins.rulebook.addRule(new Rule({
  10. name : "Randomize Forest Region",
  11. firstPriority : Rule.PRIORITY_HIGHEST,
  12. code : async runner => {
  13. await Forest.region.randomize();
  14. }
  15. }));
  16. RegionRandom.rulebookRandomizeRegion.addRule(new Rule({
  17. name : "Add the first rooms to guarantee position.",
  18. firstPriority : Rule.PRIORITY_HIGHEST,
  19. code : async runner => {
  20. // Add the clearing in the woods
  21. let cells = [
  22. Forest.ForestBed,
  23. Forest.OrcVillageSouthGates,
  24. Forest.CentaurVillageSoutheastGates,
  25. Forest.Pond,
  26. Forest.WitchHut,
  27. Forest.MazeEntrance,
  28. Forest.OminousCave,
  29. Forest.TheObelisk,
  30. ];
  31. for (let i = 0; i < cells.length; i++) {
  32. let options : RandomizingRoomOptions = {
  33. map : Forest.region.map,
  34. room : cells[i],
  35. region : Forest.region
  36. };
  37. await RegionRandom.rulebookBeforePlaceRoom.execute({noun : options});
  38. await RegionRandom.rulebookPlaceRoom.execute({noun : options});
  39. await RegionRandom.rulebookAfterPlaceRoom.execute({noun : options});
  40. }
  41. let minimumAmountOfRooms = cells.length * 7;
  42. let placed = Forest.region.getRooms().length; // At this stage, every room is placed
  43. for (let i = (minimumAmountOfRooms - placed); i > 0; i--) {
  44. Forest.region.place(new Forest.region.fodderRoomClass());
  45. }
  46. },
  47. conditions : runner => {
  48. return runner.noun == Forest.region;
  49. }
  50. }));
  51. RegionRandom.rulebookRandomizeRegion.createAndAddRule({
  52. name : "Beautify the Forest - Plainify",
  53. firstPriority : RegionRandom.ruleAddExtraConnections.firstPriority,
  54. priority : RegionRandom.ruleAddExtraConnections.priority + 1,
  55. code : () => {
  56. ForestFodder.definedRooms(<Array<ForestFodder>> Forest.region.getRooms().filter((room : RoomRandom) => {
  57. return room.placed && room instanceof ForestFodder;
  58. }));
  59. }
  60. });
  61. RegionRandom.rulebookRandomizeRegion.createAndAddRule({
  62. name : "Beautify the Forest - Make Beaten Paths",
  63. firstPriority : RegionRandom.ruleAddExtraConnections.firstPriority,
  64. priority : RegionRandom.ruleAddExtraConnections.priority - 1,
  65. code : () => {
  66. ForestFodder.makePaths(<Array<ForestFodder>> Forest.region.getRooms().filter((room : RoomRandom) => {
  67. return room.placed && room instanceof ForestFodder;
  68. }));
  69. }
  70. });
  71. RegionRandom.rulebookRandomizeRegion.createAndAddRule({
  72. name : "Beautify the Forest - Just give descriptions to them",
  73. firstPriority : RegionRandom.ruleAddExtraConnections.firstPriority,
  74. priority : RegionRandom.ruleAddExtraConnections.priority - 2,
  75. code : () => {
  76. ForestFodder.panicModeBeautify(<Array<ForestFodder>> Forest.region.getRooms().filter((room : RoomRandom) => {
  77. return room.placed && room instanceof ForestFodder;
  78. }));
  79. }
  80. });
  81. RegionRandom.rulebookRandomizeRegion.addRule(new Rule({
  82. name : "After placing and doing extra connections",
  83. firstPriority : -1,
  84. code : async runner => {
  85. // Add the clearing in the woods
  86. let cells = [
  87. ];
  88. for (let i = 0; i < cells.length; i++) {
  89. let options : RandomizingRoomOptions = {
  90. map : Forest.region.map,
  91. room : cells[i],
  92. region : Forest.region
  93. };
  94. await RegionRandom.rulebookBeforePlaceRoom.execute({noun : options});
  95. await RegionRandom.rulebookPlaceRoom.execute({noun : options});
  96. await RegionRandom.rulebookAfterPlaceRoom.execute({noun : options});
  97. }
  98. },
  99. conditions : runner => {
  100. return runner.noun == Forest.region;
  101. }
  102. }));