crunch
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

813 wiersze
23 KiB

  1. let world = null;
  2. let currentRoom = null;
  3. let currentDialog = null;
  4. let currentFoe = null;
  5. let dirButtons = [];
  6. let actionButtons = [];
  7. let mode = "explore";
  8. let actions = [];
  9. let time = 9*60*60;
  10. let date = 1;
  11. let newline = " ";
  12. let player = new Player();
  13. let playerAttacks = [];
  14. let struggles = [];
  15. let killingBlow = null;
  16. let deaths = [];
  17. let respawnRoom;
  18. let noLog = false;
  19. let MIDNIGHT = 0;
  20. let MORNING = 21600;
  21. let NOON = 43200;
  22. let EVENING = 64800;
  23. function toggleLog() {
  24. noLog = !noLog;
  25. if (noLog) {
  26. document.getElementById("log-button").innerHTML = "Log: Disabled";
  27. } else {
  28. document.getElementById("log-button").innerHTML = "Log: Enabled";
  29. }
  30. }
  31. function join(things) {
  32. if (things.length == 1) {
  33. return things[0].description("a");
  34. } else if (things.length == 2) {
  35. return things[0].description("a") + " and " + things[1].description("a");
  36. } else {
  37. let line = "";
  38. line = things.slice(0,-1).reduce((line, prey) => line + prey.description("a") + ", ", line);
  39. line += " and " + things[things.length-1].description("a");
  40. return line;
  41. }
  42. }
  43. function pickRandom(list) {
  44. return list[Math.floor(Math.random() * list.length)];
  45. }
  46. function pick(list, attacker, defender) {
  47. if (list.length == 0)
  48. return null;
  49. else {
  50. let sum = list.reduce((sum, choice) => choice.weight == undefined ? sum + 1 : sum + choice.weight(attacker, defender), 0);
  51. let target = Math.random() * sum;
  52. for (let i = 0; i < list.length; i++) {
  53. sum -= list[i].weight == undefined ? 1 : list[i].weight(attacker, defender);
  54. if (sum <= target) {
  55. return list[i];
  56. }
  57. }
  58. return list[list.length-1];
  59. }
  60. }
  61. function filterValid(options, attacker, defender) {
  62. let filtered = options.filter(option => option.conditions == undefined || option.conditions.reduce((result, test) => result && test(attacker, defender), true));
  63. return filtered.filter(option => option.requirements == undefined || option.requirements.reduce((result, test) => result && test(attacker, defender), true));
  64. }
  65. function filterPriority(options) {
  66. let max = options.reduce((max, option) => option.priority > max ? option.priority : max, -1000);
  67. return options.filter(option => option.priority == max);
  68. }
  69. function round(number, digits) {
  70. return Math.round(number * Math.pow(10,digits)) / Math.pow(10,digits);
  71. }
  72. function updateExploreCompass() {
  73. for (let i = 0; i < dirButtons.length; i++) {
  74. let button = dirButtons[i];
  75. button.classList.remove("active-button");
  76. button.classList.remove("inactive-button");
  77. button.classList.remove("disabled-button");
  78. if (currentRoom.exits[i] == null) {
  79. button.disabled = true;
  80. button.classList.add("inactive-button");
  81. button.innerHTML = "";
  82. } else {
  83. if (currentRoom.exits[i].conditions.reduce((result, test) => result && test(player.prefs), true)) {
  84. button.disabled = false;
  85. button.classList.add("active-button");
  86. button.innerHTML = currentRoom.exits[i].name;
  87. } else {
  88. button.disabled = true;
  89. button.classList.add("disabled-button");
  90. button.innerHTML = currentRoom.exits[i].name;
  91. }
  92. }
  93. }
  94. }
  95. function updateExploreActions() {
  96. for (let i = 0; i < actionButtons.length; i++) {
  97. if (i < actions.length) {
  98. actionButtons[i].disabled = false;
  99. actionButtons[i].innerHTML = actions[i].name;
  100. actionButtons[i].classList.remove("inactive-button");
  101. actionButtons[i].classList.add("active-button");
  102. }
  103. else {
  104. actionButtons[i].disabled = true;
  105. actionButtons[i].innerHTML = "";
  106. actionButtons[i].classList.remove("active-button");
  107. actionButtons[i].classList.add("inactive-button");
  108. }
  109. }
  110. }
  111. function updateExplore() {
  112. updateExploreCompass();
  113. updateExploreActions();
  114. }
  115. function updateEaten() {
  116. let list = document.getElementById("eaten");
  117. while(list.firstChild) {
  118. list.removeChild(list.firstChild);
  119. }
  120. if (player.health > 0)
  121. struggles = filterValid(currentFoe.struggles, currentFoe, player);
  122. else
  123. struggles = [submit(currentFoe)];
  124. for (let i = 0; i < struggles.length; i++) {
  125. let li = document.createElement("li");
  126. let button = document.createElement("button");
  127. button.classList.add("eaten-button");
  128. button.innerHTML = struggles[i].name;
  129. button.addEventListener("click", function() { struggleClicked(i); } );
  130. button.addEventListener("mouseover", function() { struggleHovered(i); } );
  131. button.addEventListener("mouseout", function() { document.getElementById("eaten-desc").innerHTML = ""; } );
  132. li.appendChild(button);
  133. list.appendChild(li);
  134. }
  135. }
  136. function updateCombat() {
  137. let list = document.getElementById("combat");
  138. while(list.firstChild) {
  139. list.removeChild(list.firstChild);
  140. }
  141. if (player.health > 0)
  142. if (currentFoe.playerAttacks == undefined)
  143. playerAttacks = filterValid(player.attacks, player, currentFoe);
  144. else
  145. playerAttacks = filterValid(currentFoe.playerAttacks.map(attack => attack(player)), player, currentFoe);
  146. else
  147. playerAttacks = [pass(player)];
  148. if (playerAttacks.length == 0)
  149. playerAttacks = [player.backupAttack];
  150. for (let i = 0; i < playerAttacks.length; i++) {
  151. let li = document.createElement("li");
  152. let button = document.createElement("button");
  153. button.classList.add("combat-button");
  154. button.innerHTML = playerAttacks[i].name;
  155. button.addEventListener("click", function() { attackClicked(i); } );
  156. button.addEventListener("mouseover", function() { attackHovered(i); } );
  157. button.addEventListener("mouseout", function() { document.getElementById("combat-desc").innerHTML = ""; } );
  158. li.appendChild(button);
  159. list.appendChild(li);
  160. }
  161. document.getElementById("stat-foe-name").innerHTML = "Name: " + currentFoe.name;
  162. document.getElementById("stat-foe-health").innerHTML = "Health: " + currentFoe.health + "/" + currentFoe.maxHealth;
  163. document.getElementById("stat-foe-stamina").innerHTML = "Stamina: " + currentFoe.stamina + "/" + currentFoe.maxStamina;
  164. document.getElementById("stat-foe-str").innerHTML = "Str: " + currentFoe.str;
  165. document.getElementById("stat-foe-dex").innerHTML = "Dex: " + currentFoe.dex;
  166. document.getElementById("stat-foe-con").innerHTML = "Con: " + currentFoe.con;
  167. }
  168. function updateDialog() {
  169. let list = document.getElementById("dialog");
  170. while(list.firstChild) {
  171. list.removeChild(list.firstChild);
  172. }
  173. for (let i = 0; i < currentDialog.choices.length; i++) {
  174. let activated = currentDialog.choices[i].node.requirements == undefined || currentDialog.choices[i].node.requirements.reduce((result, test) => result && test(player, currentFoe), true);
  175. let li = document.createElement("li");
  176. let button = document.createElement("button");
  177. button.classList.add("dialog-button");
  178. button.innerHTML = currentDialog.choices[i].text;
  179. button.addEventListener("click", function() { dialogClicked(i); });
  180. if (!activated) {
  181. button.classList.add("disabled-button");
  182. button.disabled = true;
  183. }
  184. li.appendChild(button);
  185. list.appendChild(li);
  186. }
  187. }
  188. function updateDisplay() {
  189. document.querySelectorAll(".selector").forEach(function (x) {
  190. x.style.display = "none";
  191. });
  192. switch(mode) {
  193. case "explore":
  194. document.getElementById("selector-explore").style.display = "flex";
  195. updateExplore();
  196. break;
  197. case "combat":
  198. document.getElementById("selector-combat").style.display = "flex";
  199. updateCombat();
  200. break;
  201. case "dialog":
  202. document.getElementById("selector-dialog").style.display = "flex";
  203. updateDialog();
  204. break;
  205. case "eaten":
  206. document.getElementById("selector-eaten").style.display = "flex";
  207. updateEaten();
  208. break;
  209. }
  210. document.getElementById("time").innerHTML = "Time: " + renderTime(time);
  211. document.getElementById("date").innerHTML = "Day " + date;
  212. document.getElementById("stat-name").innerHTML = "Name: " + player.name;
  213. document.getElementById("stat-health").innerHTML = "Health: " + round(player.health,0) + "/" + round(player.maxHealth,0);
  214. document.getElementById("stat-cash").innerHTML = "Cash: $" + round(player.cash,0);
  215. document.getElementById("stat-stamina").innerHTML = "Stamina: " + round(player.stamina,0) + "/" + round(player.maxStamina,0);
  216. document.getElementById("stat-str").innerHTML = "Str: " + player.str;
  217. document.getElementById("stat-dex").innerHTML = "Dex: " + player.dex;
  218. document.getElementById("stat-con").innerHTML = "Con: " + player.con;
  219. document.getElementById("stat-fullness").innerHTML = "Fullness: " + round(player.fullness(),0);
  220. if (player.prefs.scat) {
  221. document.getElementById("stat-bowels").innerHTML = "Bowels: " + round(player.bowels.fullness,0);
  222. } else {
  223. document.getElementById("stat-bowels").innerHTML = "";
  224. }
  225. }
  226. function advanceTimeTo(newTime) {
  227. advanceTime((86400 + newTime - time) % 86400);
  228. }
  229. function advanceTime(amount) {
  230. time = (time + amount);
  231. date += Math.floor(time / 86400);
  232. time = time % 86400;
  233. player.restoreHealth(amount);
  234. player.restoreStamina(amount);
  235. update(player.stomach.digest(amount));
  236. update(player.butt.digest(amount));
  237. }
  238. function renderTime(time) {
  239. let suffix = (time < 43200) ? "AM" : "PM";
  240. let hour = Math.floor((time % 43200) / 3600);
  241. if (hour == 0)
  242. hour = 12;
  243. let minute = Math.floor(time / 60) % 60;
  244. if (minute < 9)
  245. minute = "0" + minute;
  246. return hour + ":" + minute + " " + suffix;
  247. }
  248. function move(direction) {
  249. if (noLog)
  250. clearScreen();
  251. let target = currentRoom.exits[direction];
  252. if (target == null) {
  253. alert("Tried to move to an empty room!");
  254. return;
  255. }
  256. moveTo(target,currentRoom.exitDescs[direction]);
  257. }
  258. function moveToByName(roomName, desc="You go places lol", loading=false) {
  259. moveTo(world[roomName], desc, loading);
  260. }
  261. function moveTo(room,desc="You go places lol", loading=false) {
  262. actions = [];
  263. currentRoom = room;
  264. if (!loading)
  265. advanceTime(30);
  266. currentRoom.objects.forEach(function (object) {
  267. object.actions.forEach(function (action) {
  268. if (action.conditions == undefined || action.conditions.reduce((result, cond) => result && cond(player.prefs), true))
  269. actions.push(action);
  270. });
  271. });
  272. update([desc,newline]);
  273. currentRoom.visit();
  274. }
  275. window.addEventListener('load', function(event) {
  276. document.getElementById("start-button").addEventListener("click", start, false);
  277. });
  278. function start() {
  279. applySettings(generateSettings());
  280. transformVorePrefs(player.prefs);
  281. document.getElementById("create").style.display = "none";
  282. document.getElementById("game").style.display = "block";
  283. document.getElementById("stat-button-status").addEventListener("click", status, false);
  284. document.getElementById("log-button").addEventListener("click", toggleLog, false);
  285. loadActions();
  286. loadCompass();
  287. loadDialog();
  288. world = createWorld();
  289. currentRoom = world["Bedroom"];
  290. respawnRoom = currentRoom;
  291. moveTo(currentRoom,"");
  292. updateDisplay();
  293. }
  294. // copied from Stroll LUL
  295. function generateSettings() {
  296. let form = document.forms.namedItem("character-form");
  297. let settings = {};
  298. for (let i=0; i<form.length; i++) {
  299. let value = form[i].value == "" ? form[i].placeholder : form[i].value;
  300. if (form[i].type == "text")
  301. if (form[i].value == "")
  302. settings[form[i].name] = form[i].placeholder;
  303. else
  304. settings[form[i].name] = value;
  305. else if (form[i].type == "number")
  306. settings[form[i].name] = parseFloat(value);
  307. else if (form[i].type == "checkbox") {
  308. settings[form[i].name] = form[i].checked;
  309. } else if (form[i].type == "radio") {
  310. let name = form[i].name;
  311. if (form[i].checked)
  312. settings[name] = form[i].value;
  313. } else if (form[i].type == "select-one") {
  314. settings[form[i].name] = form[i][form[i].selectedIndex].value;
  315. }
  316. }
  317. return settings;
  318. }
  319. function applySettings(settings) {
  320. player.name = settings.name;
  321. player.species = settings.species;
  322. for (let key in settings) {
  323. if (settings.hasOwnProperty(key)) {
  324. if (key.match(/prefs/)) {
  325. let tokens = key.split("-");
  326. let pref = player.prefs;
  327. pref = tokens.slice(1,-1).reduce(function(pref, key) {
  328. if (pref[key] == undefined)
  329. pref[key] = {};
  330. return pref[key];
  331. }, pref);
  332. pref[tokens.slice(-1)[0]] = settings[key];
  333. }
  334. }
  335. }
  336. }
  337. // turn things like "1" into a number
  338. function transformVorePrefs(prefs) {
  339. for (let key in prefs.vore) {
  340. if (prefs.vore.hasOwnProperty(key)) {
  341. switch(prefs.vore[key]) {
  342. case "0": prefs.vore[key] = 0; break;
  343. case "1": prefs.vore[key] = 0.5; break;
  344. case "2": prefs.vore[key] = 1; break;
  345. case "3": prefs.vore[key] = 2; break;
  346. }
  347. }
  348. }
  349. return prefs;
  350. }
  351. function saveSettings() {
  352. window.localStorage.setItem("settings", JSON.stringify(generateSettings()));
  353. }
  354. function retrieveSettings() {
  355. return JSON.parse(window.localStorage.getItem("settings"));
  356. }
  357. function clearScreen() {
  358. let log = document.getElementById("log");
  359. let child = log.firstChild;
  360. while (child != null) {
  361. log.removeChild(child);
  362. child = log.firstChild;
  363. }
  364. }
  365. function update(lines=[]) {
  366. let log = document.getElementById("log");
  367. for (let i=0; i<lines.length; i++) {
  368. let div = document.createElement("div");
  369. div.innerHTML = lines[i];
  370. log.appendChild(div);
  371. }
  372. log.scrollTop = log.scrollHeight;
  373. updateDisplay();
  374. }
  375. function changeMode(newMode) {
  376. mode = newMode;
  377. let body = document.querySelector("body");
  378. document.getElementById("foe-stats").style.display = "none";
  379. body.className = "";
  380. switch(mode) {
  381. case "explore":
  382. case "dialog":
  383. body.classList.add("explore");
  384. break;
  385. case "combat":
  386. body.classList.add("combat");
  387. document.getElementById("foe-stats").style.display = "block";
  388. break;
  389. case "eaten":
  390. body.classList.add("eaten");
  391. document.getElementById("foe-stats").style.display = "block";
  392. break;
  393. }
  394. updateDisplay();
  395. }
  396. // make it look like eaten mode, even when in combat
  397. function changeBackground(newMode) {
  398. let body = document.querySelector("body");
  399. document.getElementById("foe-stats").style.display = "none";
  400. body.className = "";
  401. switch(newMode) {
  402. case "explore":
  403. case "dialog":
  404. body.classList.add("explore");
  405. break;
  406. case "combat":
  407. body.classList.add("combat");
  408. document.getElementById("foe-stats").style.display = "block";
  409. break;
  410. case "eaten":
  411. body.classList.add("eaten");
  412. document.getElementById("foe-stats").style.display = "block";
  413. break;
  414. }
  415. }
  416. function respawn(respawnRoom) {
  417. if (killingBlow.gameover == undefined) {
  418. if (player.prefs.prey) {
  419. deaths.push("Digested by " + currentFoe.description("a") + " at " + renderTime(time) + " on day " + date);
  420. } else {
  421. deaths.push("Defeated by " + currentFoe.description("a") + " at " + renderTime(time) + " on day " + date);
  422. }
  423. } else {
  424. deaths.push(killingBlow.gameover() + " at " + renderTime(time) + " on day " + date);
  425. }
  426. moveTo(respawnRoom,"You drift through space and time...");
  427. player.clear();
  428. player.stomach.contents = [];
  429. player.butt.contents = [];
  430. player.bowels.contents = [];
  431. player.bowels.fullness = 0;
  432. advanceTime(Math.floor(86400 / 2 * (Math.random() * 0.5 - 0.25 + 1)));
  433. changeMode("explore");
  434. player.health = 100;
  435. update(["You wake back up in your bed."]);
  436. }
  437. function startCombat(opponent) {
  438. currentFoe = opponent;
  439. changeMode("combat");
  440. update(opponent.startCombat(player).concat([newline]));
  441. }
  442. function attackClicked(index) {
  443. if (noLog)
  444. clearScreen();
  445. update(playerAttacks[index].attack(currentFoe).concat([newline]));
  446. if (currentFoe.health <= 0) {
  447. currentFoe.defeated();
  448. } else if (mode == "combat") {
  449. let attack = pick(filterPriority(filterValid(currentFoe.attacks, currentFoe, player)), currentFoe, player);
  450. if (attack == null) {
  451. attack = currentFoe.backupAttack;
  452. }
  453. update(attack.attackPlayer(player).concat([newline]));
  454. if (player.health <= -100) {
  455. killingBlow = attack;
  456. if (currentFoe.finishCombat != undefined)
  457. update(currentFoe.finishCombat().concat([newline]));
  458. update(["You die..."]);
  459. respawn(respawnRoom);
  460. } else if (player.health <= 0) {
  461. update(["You're too weak to do anything..."]);
  462. if (player.prefs.prey) {
  463. // nada
  464. } else {
  465. killingBlow = attack;
  466. update(["You die..."]);
  467. respawn(respawnRoom);
  468. }
  469. }
  470. if (currentFoe.status != undefined) {
  471. let status = currentFoe.status();
  472. if (status.length > 0)
  473. update(status.concat([newline]));
  474. }
  475. }
  476. }
  477. function attackHovered(index) {
  478. document.getElementById("combat-desc").innerHTML = playerAttacks[index].desc;
  479. }
  480. function struggleClicked(index) {
  481. if (noLog)
  482. clearScreen();
  483. let struggle = struggles[index];
  484. let result = struggle.struggle(player);
  485. update(result.lines.concat([newline]));
  486. if (result.escape == "stay") {
  487. changeMode("combat");
  488. } else if (result.escape == "escape") {
  489. changeMode("explore");
  490. } else {
  491. let digest = pick(filterValid(currentFoe.digests, currentFoe, player), currentFoe, player);
  492. if (digest == null) {
  493. digest = currentFoe.backupDigest;
  494. }
  495. update(digest.digest(player).concat([newline]));
  496. if (player.health <= -100) {
  497. killingBlow = digest;
  498. update(currentFoe.finishDigest().concat([newline]));
  499. respawn(respawnRoom);
  500. }
  501. }
  502. }
  503. function struggleHovered(index) {
  504. document.getElementById("eaten-desc").innerHTML = currentFoe.struggles[index].desc;
  505. }
  506. function startDialog(dialog) {
  507. if (noLog)
  508. clearScreen();
  509. currentDialog = dialog;
  510. changeMode("dialog");
  511. update(currentDialog.text.concat([newline]));
  512. currentDialog.visit();
  513. updateDisplay();
  514. }
  515. function dialogClicked(index) {
  516. currentDialog = currentDialog.choices[index].node;
  517. update(currentDialog.text.concat([newline]));
  518. currentDialog.visit();
  519. if (currentDialog.choices.length == 0 && mode == "dialog") {
  520. changeMode("explore");
  521. updateDisplay();
  522. }
  523. }
  524. function loadDialog() {
  525. dialogButtons = Array.from( document.querySelectorAll(".dialog-button"));
  526. for (let i = 0; i < dialogButtons.length; i++) {
  527. dialogButtons[i].addEventListener("click", function() { dialogClicked(i); });
  528. }
  529. }
  530. function actionClicked(index) {
  531. actions[index].action();
  532. }
  533. function loadActions() {
  534. actionButtons = Array.from( document.querySelectorAll(".action-button"));
  535. for (let i = 0; i < actionButtons.length; i++) {
  536. actionButtons[i].addEventListener("click", function() { actionClicked(i); });
  537. }
  538. }
  539. function loadCompass() {
  540. dirButtons[NORTH_WEST] = document.getElementById("compass-north-west");
  541. dirButtons[NORTH_WEST].addEventListener("click", function() {
  542. move(NORTH_WEST);
  543. });
  544. dirButtons[NORTH] = document.getElementById("compass-north");
  545. dirButtons[NORTH].addEventListener("click", function() {
  546. move(NORTH);
  547. });
  548. dirButtons[NORTH_EAST] = document.getElementById("compass-north-east");
  549. dirButtons[NORTH_EAST].addEventListener("click", function() {
  550. move(NORTH_EAST);
  551. });
  552. dirButtons[WEST] = document.getElementById("compass-west");
  553. dirButtons[WEST].addEventListener("click", function() {
  554. move(WEST);
  555. });
  556. dirButtons[EAST] = document.getElementById("compass-east");
  557. dirButtons[EAST].addEventListener("click", function() {
  558. move(EAST);
  559. });
  560. dirButtons[SOUTH_WEST] = document.getElementById("compass-south-west");
  561. dirButtons[SOUTH_WEST].addEventListener("click", function() {
  562. move(SOUTH_WEST);
  563. });
  564. dirButtons[SOUTH] = document.getElementById("compass-south");
  565. dirButtons[SOUTH].addEventListener("click", function() {
  566. move(SOUTH);
  567. });
  568. dirButtons[SOUTH_EAST] = document.getElementById("compass-south-east");
  569. dirButtons[SOUTH_EAST].addEventListener("click", function() {
  570. move(SOUTH_EAST);
  571. });
  572. document.getElementById("compass-look").addEventListener("click", look, false);
  573. }
  574. function look() {
  575. update([currentRoom.description]);
  576. }
  577. function status() {
  578. let lines = [];
  579. lines.push("You are a " + player.species);
  580. lines.push(newline);
  581. if (player.stomach.contents.length > 0) {
  582. lines.push("Your stomach bulges with prey.");
  583. player.stomach.contents.map(function(prey) {
  584. let state = "";
  585. let healthRatio = prey.health / prey.maxHealth;
  586. if (healthRatio > 0.75) {
  587. state = "is thrashing in your gut";
  588. } else if (healthRatio > 0.5) {
  589. state = "is squirming in your belly";
  590. } else if (healthRatio > 0.25) {
  591. state = "is pressing out at your stomach walls";
  592. } else if (healthRatio > 0) {
  593. state = "is weakly squirming";
  594. } else {
  595. state = "has stopped moving";
  596. }
  597. lines.push(prey.description("A") + " " + state);
  598. });
  599. lines.push(newline);
  600. }
  601. if (player.butt.contents.length > 0) {
  602. lines.push("Your bowels churn with prey.");
  603. player.butt.contents.map(function(prey) {
  604. let state = "";
  605. let healthRatio = prey.health / prey.maxHealth;
  606. if (healthRatio > 0.75) {
  607. state = "is writhing in your bowels";
  608. } else if (healthRatio > 0.5) {
  609. state = "is struggling against your intestines";
  610. } else if (healthRatio > 0.25) {
  611. state = "is bulging out of your lower belly";
  612. } else if (healthRatio > 0) {
  613. state = "is squirming weakly, slipping deeper and deeper";
  614. } else {
  615. state = "has succumbed to your bowels";
  616. }
  617. lines.push(prey.description("A") + " " + state);
  618. });
  619. lines.push(newline);
  620. }
  621. update(lines);
  622. }
  623. let toSave = ["str","dex","con","name","species","health","stamina"];
  624. function saveGame() {
  625. let save = {};
  626. save.player = JSON.stringify(player, function(key, value) {
  627. if (toSave.includes(key) || key == "") {
  628. return value;
  629. } else {
  630. return undefined;
  631. }
  632. });
  633. save.prefs = JSON.stringify(player.prefs);
  634. save.position = currentRoom.name;
  635. save.date = date;
  636. save.time = time;
  637. save.deaths = deaths;
  638. let stringified = JSON.stringify(save);
  639. window.localStorage.setItem("save", stringified);
  640. }
  641. function loadGame() {
  642. changeMode("explore");
  643. let save = JSON.parse(window.localStorage.getItem("save"));
  644. let playerSave = JSON.parse(save.player);
  645. for (let key in playerSave) {
  646. if (playerSave.hasOwnProperty(key)) {
  647. player[key] = playerSave[key];
  648. }
  649. }
  650. player.prefs = JSON.parse(save.prefs);
  651. deaths = save.deaths;
  652. date = save.date;
  653. time = save.time;
  654. clearScreen();
  655. moveToByName(save.position, "");
  656. }
  657. // wow polyfills
  658. if (![].includes) {
  659. Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
  660. 'use strict';
  661. var O = Object(this);
  662. var len = parseInt(O.length) || 0;
  663. if (len === 0) {
  664. return false;
  665. }
  666. var n = parseInt(arguments[1]) || 0;
  667. var k;
  668. if (n >= 0) {
  669. k = n;
  670. } else {
  671. k = len + n;
  672. if (k < 0) {k = 0;}
  673. }
  674. var currentElement;
  675. while (k < len) {
  676. currentElement = O[k];
  677. if (searchElement === currentElement ||
  678. (searchElement !== searchElement && currentElement !== currentElement)) {
  679. return true;
  680. }
  681. k++;
  682. }
  683. return false;
  684. };
  685. }