munch
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

412 行
8.1 KiB

  1. "use strict";
  2. /*jshint browser: true*/
  3. /*jshint devel: true*/
  4. let NORTH = 0;
  5. let NORTH_EAST = 1;
  6. let EAST = 2;
  7. let SOUTH_EAST = 3;
  8. let SOUTH = 4;
  9. let SOUTH_WEST = 5;
  10. let WEST = 6;
  11. let NORTH_WEST = 7;
  12. let locations = {};
  13. let locationsSrc = [
  14. {
  15. "name": "Bedroom",
  16. "desc": "A bedroom. It has a bed in it.",
  17. "conn": [
  18. {
  19. "name": "Bathroom",
  20. "dir": EAST,
  21. "desc": "You step into your bathroom."
  22. },
  23. {
  24. "name": "Living Room",
  25. "dir": NORTH,
  26. "desc": "You walk into the living room."
  27. }
  28. ],
  29. "objs": [
  30. Bed,
  31. Journal
  32. ],
  33. },
  34. {
  35. "name": "Bathroom",
  36. "desc": "Your modest bathroom.",
  37. "conn": [
  38. {
  39. "name": "Bedroom",
  40. "dir": WEST,
  41. "desc": "You walk back into your bedroom."
  42. }
  43. ],
  44. "objs": [
  45. Toilet
  46. ]
  47. },
  48. {
  49. "name": "Living Room",
  50. "desc": "A bare living room",
  51. "conn": [
  52. {
  53. "name": "Lobby",
  54. "dir": NORTH,
  55. "desc": "You leave your apartment and head to the lobby."
  56. },
  57. {
  58. "name": "Bedroom",
  59. "dir": SOUTH,
  60. "desc": "You walk into your bedroom."
  61. }
  62. ],
  63. "objs": [
  64. TV,
  65. Phone
  66. ]
  67. },
  68. {
  69. "name": "North Street",
  70. "desc": "It's a street",
  71. "conn": [
  72. {
  73. "name": "Alley",
  74. "dir": WEST,
  75. "desc": "You wander into the dark alley"
  76. },
  77. {
  78. "name": "Lobby",
  79. "dir": EAST,
  80. "desc": "You step into your apartment's lobby"
  81. },
  82. {
  83. "name": "Crossroads",
  84. "dir": SOUTH,
  85. "desc": "You walk south"
  86. },
  87. {
  88. "name": "DANGER ZONE",
  89. "dir": NORTH,
  90. "desc": "You walk into the DANGER ZONE"
  91. }
  92. ],
  93. "objs": [
  94. Nerd
  95. ]
  96. },
  97. {
  98. "name": "Lobby",
  99. "desc": "The modest lobby of your modest apartment complex",
  100. "conn": [
  101. {
  102. "name": "North Street",
  103. "dir": WEST,
  104. "desc": "You walk out into the street"
  105. },
  106. {
  107. "name": "Living Room",
  108. "dir": SOUTH,
  109. "desc": "You walk back into your apartment"
  110. }
  111. ],
  112. "objs": [
  113. VendingMachine
  114. ]
  115. },
  116. {
  117. "name": "Alley",
  118. "desc": "A suspicious alley",
  119. "conn": [
  120. {
  121. "name": "North Street",
  122. "dir": EAST,
  123. "desc": "You hurry back into the open street."
  124. },
  125. {
  126. "name": "Seedy Bar",
  127. "dir": NORTH,
  128. "desc": "You step into the bar."
  129. }
  130. ]
  131. },
  132. {
  133. "name": "Seedy Bar",
  134. "desc": "God this place is seedy",
  135. "conn": [
  136. {
  137. "name": "Alley",
  138. "dir": SOUTH,
  139. "desc": "You step out of the bar"
  140. }
  141. ],
  142. "objs": [
  143. PoojawaEncounter
  144. ]
  145. },
  146. {
  147. "name": "Crossroads",
  148. "desc": "Where the roads cross",
  149. "conn": [
  150. {
  151. "name": "North Street",
  152. "dir": NORTH,
  153. "desc": "You walk north"
  154. },
  155. {
  156. "name": "East Street",
  157. "dir": EAST,
  158. "desc": "You walk east"
  159. },
  160. {
  161. "name": "South Street",
  162. "dir": SOUTH,
  163. "desc": "You walk south"
  164. },
  165. {
  166. "name": "Corner Mart",
  167. "dir": SOUTH_EAST,
  168. "desc": "You walk into the convenience store"
  169. }
  170. ]
  171. },
  172. {
  173. "name": "East Street",
  174. "desc": "This street is in the east",
  175. "conn": [
  176. {
  177. "name": "Crossroads",
  178. "dir": WEST,
  179. "desc": "You walk to the crossroads"
  180. },
  181. {
  182. "name": "East Trail",
  183. "dir": EAST,
  184. "desc": "You head out on the road."
  185. }
  186. ]
  187. },
  188. {
  189. "name": "East Trail",
  190. "desc": "A trail from your hometown to lands beyond",
  191. "conn": [
  192. {
  193. "name": "East Street",
  194. "dir": WEST,
  195. "desc": "You walk back into town"
  196. },
  197. {
  198. "name": "Woods",
  199. "dir": NORTH,
  200. "desc": "You wander into the woods."
  201. },
  202. {
  203. "name": "Mountains",
  204. "dir": EAST,
  205. "desc": "You head up into the mountains."
  206. },
  207. {
  208. "name": "Woods",
  209. "dir": SOUTH,
  210. "desc": "You wander into the woods."
  211. },
  212. ]
  213. },
  214. {
  215. "name": "Woods",
  216. "desc": "A thick forest. It's easy to get lost here, but it's not too dangerous, at least.",
  217. "conn": [
  218. ],
  219. "objs": [
  220. ForestExplore,
  221. ],
  222. "hooks": [
  223. function() {
  224. currentRoom.flags.exit = false;
  225. }
  226. ]
  227. },
  228. {
  229. "name": "South Street",
  230. "desc": "This street is in the south",
  231. "conn": [
  232. {
  233. "name": "Crossroads",
  234. "dir": NORTH,
  235. "desc": "You walk to the crossroads"
  236. },
  237. {
  238. "name": "Nature Trail",
  239. "dir": SOUTH,
  240. "desc": "You head out into the woods"
  241. }
  242. ]
  243. },
  244. {
  245. "name": "Nature Trail",
  246. "desc": "A winding train cutting through a thick forest",
  247. "conn": [
  248. {
  249. "name": "South Street",
  250. "dir": NORTH,
  251. "desc": "You return to town."
  252. },
  253. {
  254. "name": "Wilderness",
  255. "dir": SOUTH,
  256. "desc": "You wander into the wilderness...and immediately get lost."
  257. }
  258. ],
  259. "objs": [
  260. NatureTrailExercise,
  261. GetaObj
  262. ]
  263. },
  264. {
  265. "name": "Wilderness",
  266. "desc": "Pretty spooky",
  267. "conn": [
  268. ],
  269. "objs": [
  270. WildernessExplore
  271. ]
  272. },
  273. {
  274. "name": "DANGER ZONE",
  275. "desc": "THE DANGER ZONE",
  276. "conn": [
  277. {
  278. "name": "North Street",
  279. "dir": SOUTH,
  280. "desc": "You walk out of the DANGER ZONE"
  281. },
  282. {
  283. "name": "SUPER DANGER ZONE",
  284. "dir": NORTH,
  285. "desc": "Getting eaten is fun!",
  286. }
  287. ],
  288. "hooks": [
  289. function() {
  290. startCombat(new Anthro());
  291. }
  292. ]
  293. },
  294. {
  295. "name": "SUPER DANGER ZONE",
  296. "desc": "Very dangerous",
  297. "conn": [
  298. {
  299. "name": "DANGER ZONE",
  300. "dir": SOUTH,
  301. "desc": "You hurriedly leave the SUPER DANGER ZONE"
  302. }
  303. ],
  304. "hooks": [
  305. function() {
  306. startCombat(new Fen());
  307. }
  308. ]
  309. },
  310. {
  311. "name": "Corner Mart",
  312. "desc": "A convenience store with a variety of snacks and supplies",
  313. "conn": [
  314. {
  315. "name": "Crossroads",
  316. "dir": NORTH_WEST,
  317. "desc": "You leave the store."
  318. }
  319. ]
  320. },
  321. {
  322. "name": "Mountains",
  323. "desc": "Steep, chilly slopes.",
  324. "conn": [
  325. {
  326. "name": "East Trail",
  327. "dir": WEST,
  328. "desc": "You clamber down from the mountains."
  329. }
  330. ],
  331. "objs": [
  332. MountainExplore
  333. ]
  334. }
  335. ];
  336. function Location(name="Nowhere",desc="Nada") {
  337. this.name = name;
  338. this.description = desc;
  339. this.exits = [null,null,null,null,null,null,null,null];
  340. this.exitDescs = [null,null,null,null,null,null,null,null];
  341. this.objects = [];
  342. this.hooks = [];
  343. this.conditions = [];
  344. this.flags = [];
  345. this.visit = function() {
  346. this.hooks.forEach(function (x) {
  347. x();
  348. });
  349. };
  350. }
  351. function opposite(direction) {
  352. return (direction + 4) % 8;
  353. }
  354. function connectLocations(loc1,loc2,dir,desc) {
  355. if (loc1.exits[dir] != null) {
  356. alert(loc1.name + " is already connected to " + loc1.exits[dir].name);
  357. return;
  358. } else {
  359. if (dir >= 0 && dir <= 7) {
  360. loc1.exits[dir] = loc2;
  361. loc1.exitDescs[dir] = desc;
  362. } else {
  363. alert("Invalid direction given when linking " + loc1.name + " and " + loc2.name + ": " + dir);
  364. }
  365. }
  366. }
  367. function createWorld() {
  368. for (let i = 0; i < locationsSrc.length; i++) {
  369. let src = locationsSrc[i];
  370. let location = new Location(src.name,src.desc);
  371. locations[src.name] = location;
  372. if (src.objs != undefined) {
  373. src.objs.forEach(function (obj) {
  374. location.objects.push(new obj());
  375. });
  376. }
  377. if (src.hooks != undefined) {
  378. src.hooks.forEach(function (hook) {
  379. location.hooks.push(hook);
  380. });
  381. }
  382. if (src.conditions != undefined) {
  383. src.conditions.forEach(function (cond) {
  384. location.conditions.push(cond);
  385. });
  386. }
  387. }
  388. for (let i = 0; i < locationsSrc.length; i++) {
  389. let src = locationsSrc[i];
  390. let from = locations[src.name];
  391. for (let j = 0; j < src.conn.length; j++) {
  392. let to = locations[src.conn[j].name];
  393. connectLocations(from, to, src.conn[j].dir, src.conn[j].desc);
  394. }
  395. }
  396. return locations;
  397. }