ForestFodder.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. class ForestFodder extends RoomRandomFodder {
  2. constructor () {
  3. super();
  4. //this.cloneInterface(ForestFodder.POSSIBILITIES.getOne());
  5. this.backgroundImage = "roomForestFodder";
  6. }
  7. public static beautified : Array<ForestFodder> = [];
  8. // This defines the important rooms first
  9. public static definedRooms (rooms : Array<ForestFodder>) {
  10. let plainifyAround = [
  11. [Forest.CentaurCoordinates[0] - 1, Forest.CentaurCoordinates[1] + 1, 5, Forest.CentaurCoordinates],
  12. [Forest.OrcCoordinates[0] + 1, Forest.OrcCoordinates[1] + 1, 5, Forest.OrcCoordinates]
  13. ];
  14. plainifyAround.forEach((coordinates) => {
  15. let availRooms = rooms.filter(room => {
  16. return !ForestFodder.beautified.includes(room) && room instanceof ForestFodder && room.getDistanceToCoordinates(<any> coordinates) <= coordinates[2];
  17. });
  18. availRooms.forEach((room) => {
  19. ForestFodder.beautified.push(room);
  20. room.cloneInterface(ForestFodder.PlainsPossibility);
  21. if (coordinates[3] == Forest.CentaurCoordinates) {
  22. let directionTo = room.getOverallDirectionTo(coordinates);
  23. room.description.add("You can see a settlement with wooden walls to the " + DirectionNames[directionTo] + ".");
  24. }
  25. if (coordinates[3] == Forest.OrcCoordinates) {
  26. let directionTo = room.getOverallDirectionTo(coordinates);
  27. room.description.add("You can see a fortified settlement with spiked defensive walls to the " + DirectionNames[directionTo] + ".");
  28. }
  29. room.extraConnectionChance = 100;
  30. });
  31. });
  32. }
  33. // This makes the paths and mustbe done AFTER the extra connections happen
  34. public static makePaths (rooms : Array<ForestFodder>) {
  35. // initial rules:
  36. // There is a beaten path from the Witch Hut to the Centaur Village
  37. // There will be a beaten path from the Orc Village to the Ominous Cave.
  38. let beatenPath : Array<ForestFodder> = [];
  39. let destinations : Array<Room> = [Forest.WitchHut, Forest.CentaurVillageSoutheastGates];
  40. function makePath (start, end) {
  41. let pathTo = start.getAStarPathTo(end);
  42. pathTo.forEach((path) => {
  43. let room = path.room;
  44. if (room instanceof ForestFodder && !beatenPath.includes(room)) {
  45. beatenPath.push(room);
  46. }
  47. });
  48. if (!destinations.includes(start)) destinations.push(start);
  49. if (!destinations.includes(end)) destinations.push(end);
  50. }
  51. makePath(Forest.WitchHut, Forest.CentaurVillageSoutheastGates);
  52. makePath(Forest.WitchHut, Forest.MazeEntrance);
  53. makePath(Forest.OrcVillageNorthwestGates, Forest.OminousCave);
  54. // makePath(Forest.OrcVillageSouthGates, Forest.Pond);
  55. // makePath(Forest.CentaurVillageSoutheastGates, Forest.Pond);
  56. beatenPath.forEach(room => {
  57. room.cloneInterface(ForestFodder.BeatenPathPossibility);
  58. if (!ForestFodder.beautified.includes(room)) ForestFodder.beautified.push(room);
  59. let pathFollows = "The path continues ";
  60. let directions = [];
  61. room.connections.forEach((room : RoomRandom, direction : Direction) => {
  62. if (beatenPath.includes(<any> room) || destinations.includes(room)) {
  63. directions.push(DirectionNames[direction].toLowerCase());
  64. }
  65. });
  66. for (let i = 0; i < directions.length; i++) {
  67. if ((i + 1) == directions.length) {
  68. pathFollows += " and ";
  69. }
  70. pathFollows += directions[i];
  71. if ((i + 1) < directions.length && directions.length > 2) {
  72. pathFollows += ", ";
  73. }
  74. }
  75. pathFollows += ".";
  76. room.description.add(pathFollows);
  77. });
  78. }
  79. // Last resort to find purpose for rooms.
  80. public static panicModeBeautify (rooms : Array<ForestFodder>) {
  81. // Give purpose to rooms without purpose
  82. let realFodder = 0;
  83. rooms.forEach(room => {
  84. if (!ForestFodder.beautified.includes(room)) {
  85. room.cloneInterface(ForestFodder.POSSIBILITIES.getOne());
  86. realFodder +=1;
  87. }
  88. });
  89. console.log(realFodder.toString() + " rooms were left without real purpose, out of " + rooms.length.toString() + " rooms.");
  90. }
  91. public static POSSIBILITIES : OneOf = new OneOf(OneOf.ROTATING_RANDOM);
  92. public static addPossibility (...pos : Array<FodderPossibility>) {
  93. ForestFodder.POSSIBILITIES.addPossibilities(...pos);
  94. }
  95. public static BeatenPathPossibility : FodderPossibility = {
  96. name : "Beaten path",
  97. description: "You are in a beaten path through the woods. "
  98. };
  99. public static PlainsPossibility : FodderPossibility = {
  100. name : "Plains",
  101. description : "The woods have mostly cleared up, leaving you in open fields with lush green grass. "
  102. }
  103. }
  104. ForestFodder.addPossibility({
  105. name : "Clearing in the Woods",
  106. description : new Say("The trees have cleared around here and you can finally see something other than leaves up ahead, even though the lush green plains leave you exposed.")
  107. });
  108. ForestFodder.addPossibility({
  109. name : "Dense Forest",
  110. description : new Say("There are so many trees around that you can barely see where you are going, the floor is littered with sticks and leaves.")
  111. });
  112. ForestFodder.addPossibility({
  113. name : "Flowery Plains",
  114. description : new Say("This colorful area has dozens of types of flowers all around.")
  115. });
  116. ForestFodder.addPossibility({
  117. name : "Pond",
  118. description : new Say("The forest opens up to a crystalline pond.")
  119. });