munch
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

414 行
8.2 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. "name": "Dark Alley",
  132. "dir": WEST,
  133. "desc": "You step into the darkness..."
  134. }
  135. ]
  136. },
  137. {
  138. "name": "Dark Alley",
  139. "desc": "A dark, claustrophobic alley",
  140. "conn": [
  141. {
  142. "name": "Alley",
  143. "dir": EAST,
  144. "desc": "You emerge from the darkness"
  145. }
  146. ],
  147. "hooks": [
  148. function() {
  149. startCombat(new KuroLuxray());
  150. }
  151. ]
  152. },
  153. {
  154. "name": "Seedy Bar",
  155. "desc": "God this place is seedy",
  156. "conn": [
  157. {
  158. "name": "Alley",
  159. "dir": SOUTH,
  160. "desc": "You step out of the bar"
  161. }
  162. ],
  163. "objs": [
  164. PoojawaEncounter
  165. ]
  166. },
  167. {
  168. "name": "Crossroads",
  169. "desc": "Where the roads cross",
  170. "conn": [
  171. {
  172. "name": "North Street",
  173. "dir": NORTH,
  174. "desc": "You walk north"
  175. },
  176. {
  177. "name": "East Street",
  178. "dir": EAST,
  179. "desc": "You walk east"
  180. },
  181. {
  182. "name": "South Street",
  183. "dir": SOUTH,
  184. "desc": "You walk south"
  185. },
  186. {
  187. "name": "Corner Mart",
  188. "dir": SOUTH_EAST,
  189. "desc": "You walk into the convenience store"
  190. }
  191. ]
  192. },
  193. {
  194. "name": "East Street",
  195. "desc": "This street is in the east",
  196. "conn": [
  197. {
  198. "name": "Crossroads",
  199. "dir": WEST,
  200. "desc": "You walk to the crossroads"
  201. },
  202. {
  203. "name": "East Trail",
  204. "dir": EAST,
  205. "desc": "You head out on the road."
  206. }
  207. ]
  208. },
  209. {
  210. "name": "East Trail",
  211. "desc": "A trail from your hometown to lands beyond",
  212. "conn": [
  213. {
  214. "name": "East Street",
  215. "dir": WEST,
  216. "desc": "You walk back into town"
  217. },
  218. {
  219. "name": "Woods",
  220. "dir": NORTH,
  221. "desc": "You wander into the woods."
  222. },
  223. {
  224. "name": "Woods",
  225. "dir": SOUTH,
  226. "desc": "You wander into the woods."
  227. },
  228. ]
  229. },
  230. {
  231. "name": "Woods",
  232. "desc": "A thick forest. It's easy to get lost here, but it's not too dangerous, at least.",
  233. "conn": [
  234. ],
  235. "objs": [
  236. ForestExplore,
  237. ],
  238. "hooks": [
  239. function() {
  240. currentRoom.flags.exit = false;
  241. }
  242. ]
  243. },
  244. {
  245. "name": "South Street",
  246. "desc": "This street is in the south",
  247. "conn": [
  248. {
  249. "name": "Crossroads",
  250. "dir": NORTH,
  251. "desc": "You walk to the crossroads"
  252. },
  253. {
  254. "name": "Nature Trail",
  255. "dir": SOUTH,
  256. "desc": "You head out into the woods"
  257. }
  258. ]
  259. },
  260. {
  261. "name": "Nature Trail",
  262. "desc": "A winding train cutting through a thick forest",
  263. "conn": [
  264. {
  265. "name": "South Street",
  266. "dir": NORTH,
  267. "desc": "You return to town."
  268. },
  269. {
  270. "name": "Wilderness",
  271. "dir": SOUTH,
  272. "desc": "You wander into the wilderness...and immediately get lost."
  273. }
  274. ],
  275. "objs": [
  276. NatureTrailExercise,
  277. GetaObj
  278. ]
  279. },
  280. {
  281. "name": "Wilderness",
  282. "desc": "Pretty spooky",
  283. "conn": [
  284. ],
  285. "objs": [
  286. WildernessExplore
  287. ]
  288. },
  289. {
  290. "name": "DANGER ZONE",
  291. "desc": "THE DANGER ZONE",
  292. "conn": [
  293. {
  294. "name": "North Street",
  295. "dir": SOUTH,
  296. "desc": "You walk out of the DANGER ZONE"
  297. },
  298. {
  299. "name": "SUPER DANGER ZONE",
  300. "dir": NORTH,
  301. "desc": "Getting eaten is fun!",
  302. }
  303. ],
  304. "hooks": [
  305. function() {
  306. startCombat(new Anthro());
  307. }
  308. ]
  309. },
  310. {
  311. "name": "SUPER DANGER ZONE",
  312. "desc": "Very dangerous",
  313. "conn": [
  314. {
  315. "name": "DANGER ZONE",
  316. "dir": SOUTH,
  317. "desc": "You hurriedly leave the SUPER DANGER ZONE"
  318. }
  319. ],
  320. "hooks": [
  321. function() {
  322. startCombat(new Fen());
  323. }
  324. ]
  325. },
  326. {
  327. "name": "Corner Mart",
  328. "desc": "A convenience store with a variety of snacks and supplies",
  329. "conn": [
  330. {
  331. "name": "Crossroads",
  332. "dir": NORTH_WEST,
  333. "desc": "You leave the store."
  334. }
  335. ]
  336. }
  337. ];
  338. function Location(name="Nowhere",desc="Nada") {
  339. this.name = name;
  340. this.description = desc;
  341. this.exits = [null,null,null,null,null,null,null,null];
  342. this.exitDescs = [null,null,null,null,null,null,null,null];
  343. this.objects = [];
  344. this.hooks = [];
  345. this.conditions = [];
  346. this.flags = [];
  347. this.visit = function() {
  348. this.hooks.forEach(function (x) {
  349. x();
  350. });
  351. };
  352. }
  353. function opposite(direction) {
  354. return (direction + 4) % 8;
  355. }
  356. function connectLocations(loc1,loc2,dir,desc) {
  357. if (loc1.exits[dir] != null) {
  358. alert(loc1.name + " is already connected to " + loc1.exits[dir].name);
  359. return;
  360. } else {
  361. if (dir >= 0 && dir <= 7) {
  362. loc1.exits[dir] = loc2;
  363. loc1.exitDescs[dir] = desc;
  364. } else {
  365. alert("Invalid direction given when linking " + loc1.name + " and " + loc2.name + ": " + dir);
  366. }
  367. }
  368. }
  369. function createWorld() {
  370. for (let i = 0; i < locationsSrc.length; i++) {
  371. let src = locationsSrc[i];
  372. let location = new Location(src.name,src.desc);
  373. locations[src.name] = location;
  374. if (src.objs != undefined) {
  375. src.objs.forEach(function (obj) {
  376. location.objects.push(new obj());
  377. });
  378. }
  379. if (src.hooks != undefined) {
  380. src.hooks.forEach(function (hook) {
  381. location.hooks.push(hook);
  382. });
  383. }
  384. if (src.conditions != undefined) {
  385. src.conditions.forEach(function (cond) {
  386. location.conditions.push(cond);
  387. });
  388. }
  389. }
  390. for (let i = 0; i < locationsSrc.length; i++) {
  391. let src = locationsSrc[i];
  392. let from = locations[src.name];
  393. for (let j = 0; j < src.conn.length; j++) {
  394. let to = locations[src.conn[j].name];
  395. connectLocations(from, to, src.conn[j].dir, src.conn[j].desc);
  396. }
  397. }
  398. return locations;
  399. }