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

992 行
28 KiB

  1. let world = null;
  2. let currentRoom = null;
  3. let currentDialog = null;
  4. let currentFoe = null;
  5. let dirButtons = [];
  6. let mode = "explore";
  7. let actions = [];
  8. let time = 9*60*60;
  9. let date = 1;
  10. let newline = " ";
  11. let player = new Player();
  12. let playerAttacks = [];
  13. let struggles = [];
  14. let killingBlow = null;
  15. let deaths = [];
  16. let respawnRoom;
  17. let noLog = false;
  18. let logPadLine = undefined;
  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. updateActions();
  97. let actionButtons = document.querySelector("#actions");
  98. actionButtons.innerHTML = "";
  99. for (let i = 0; i < actions.length; i++) {
  100. let button = document.createElement("button");
  101. button.innerHTML = actions[i].name;
  102. button.classList.add("active-button");
  103. button.classList.add("action-button");
  104. button.addEventListener("click", function() { actions[i].action(); });
  105. actionButtons.appendChild(button);
  106. }
  107. }
  108. function updateExplore() {
  109. updateExploreCompass();
  110. updateExploreActions();
  111. }
  112. function updateEaten() {
  113. let list = document.getElementById("eaten");
  114. while(list.firstChild) {
  115. list.removeChild(list.firstChild);
  116. }
  117. if (player.health > 0)
  118. struggles = filterValid(currentFoe.struggles, currentFoe, player);
  119. else
  120. struggles = [submit(currentFoe)];
  121. for (let i = 0; i < struggles.length; i++) {
  122. let li = document.createElement("li");
  123. let button = document.createElement("button");
  124. button.classList.add("eaten-button");
  125. button.innerHTML = struggles[i].name;
  126. button.addEventListener("click", function() { struggleClicked(i); } );
  127. button.addEventListener("mouseover", function() { struggleHovered(i); } );
  128. button.addEventListener("mouseout", function() { document.getElementById("eaten-desc").innerHTML = ""; } );
  129. li.appendChild(button);
  130. list.appendChild(li);
  131. }
  132. }
  133. function updateCombat() {
  134. let list = document.getElementById("combat");
  135. while(list.firstChild) {
  136. list.removeChild(list.firstChild);
  137. }
  138. if (player.health > 0)
  139. if (currentFoe.playerAttacks == undefined)
  140. playerAttacks = filterValid(player.attacks, player, currentFoe);
  141. else
  142. playerAttacks = filterValid(currentFoe.playerAttacks.map(attack => attack(player)), player, currentFoe);
  143. else
  144. playerAttacks = [pass(player)];
  145. if (playerAttacks.length == 0)
  146. playerAttacks = [player.backupAttack];
  147. for (let i = 0; i < playerAttacks.length; i++) {
  148. let li = document.createElement("li");
  149. let button = document.createElement("button");
  150. button.classList.add("combat-button");
  151. button.innerHTML = playerAttacks[i].name;
  152. button.addEventListener("click", function() { attackClicked(i); } );
  153. button.addEventListener("mouseover", function() { attackHovered(i); } );
  154. button.addEventListener("mouseout", function() { document.getElementById("combat-desc").innerHTML = ""; } );
  155. li.appendChild(button);
  156. list.appendChild(li);
  157. }
  158. document.getElementById("stat-foe-name").innerHTML = "Name: " + currentFoe.name;
  159. document.getElementById("stat-foe-health").innerHTML = "Health: " + currentFoe.health + "/" + currentFoe.maxHealth;
  160. document.getElementById("stat-foe-stamina").innerHTML = "Stamina: " + currentFoe.stamina + "/" + currentFoe.maxStamina;
  161. document.getElementById("stat-foe-str").innerHTML = "Str: " + currentFoe.str;
  162. document.getElementById("stat-foe-dex").innerHTML = "Dex: " + currentFoe.dex;
  163. document.getElementById("stat-foe-con").innerHTML = "Con: " + currentFoe.con;
  164. }
  165. function updateDialog() {
  166. let list = document.getElementById("dialog");
  167. while(list.firstChild) {
  168. list.removeChild(list.firstChild);
  169. }
  170. for (let i = 0; i < currentDialog.choices.length; i++) {
  171. let activated = currentDialog.choices[i].node.requirements == undefined || currentDialog.choices[i].node.requirements.reduce((result, test) => result && test(player, currentFoe), true);
  172. let li = document.createElement("li");
  173. let button = document.createElement("button");
  174. button.classList.add("dialog-button");
  175. button.innerHTML = currentDialog.choices[i].text;
  176. button.addEventListener("click", function() { dialogClicked(i); });
  177. if (!activated) {
  178. button.classList.add("disabled-button");
  179. button.disabled = true;
  180. }
  181. li.appendChild(button);
  182. list.appendChild(li);
  183. }
  184. }
  185. function updateDisplay() {
  186. document.querySelectorAll(".selector").forEach(function (x) {
  187. x.style.display = "none";
  188. });
  189. switch(mode) {
  190. case "explore":
  191. document.getElementById("selector-explore").style.display = "flex";
  192. updateExplore();
  193. break;
  194. case "combat":
  195. document.getElementById("selector-combat").style.display = "flex";
  196. updateCombat();
  197. break;
  198. case "dialog":
  199. document.getElementById("selector-dialog").style.display = "flex";
  200. updateDialog();
  201. break;
  202. case "eaten":
  203. document.getElementById("selector-eaten").style.display = "flex";
  204. updateEaten();
  205. break;
  206. }
  207. document.getElementById("time").innerHTML = "Time: " + renderTime(time);
  208. document.getElementById("date").innerHTML = "Day " + date;
  209. document.getElementById("stat-name").innerHTML = "Name: " + player.name;
  210. document.getElementById("stat-health").innerHTML = "Health: " + round(player.health,0) + "/" + round(player.maxHealth,0);
  211. document.getElementById("stat-cash").innerHTML = "Cash: $" + round(player.cash,0);
  212. document.getElementById("stat-stamina").innerHTML = "Stamina: " + round(player.stamina,0) + "/" + round(player.maxStamina,0);
  213. document.getElementById("stat-str").innerHTML = "Str: " + player.str;
  214. document.getElementById("stat-dex").innerHTML = "Dex: " + player.dex;
  215. document.getElementById("stat-con").innerHTML = "Con: " + player.con;
  216. document.getElementById("stat-arousal").innerHTML = "Arousal: " + round(player.arousal,0) + "/" + round(player.arousalLimit(),0);
  217. document.getElementById("stat-stomach").innerHTML = "Stomach: " + round(player.stomach.fullness(),0) + "/" + player.stomach.capacity;
  218. if (player.prefs.pred.anal || player.prefs.scat)
  219. document.getElementById("stat-bowels").innerHTML = "Bowels: " + round(player.bowels.fullness(),0) + "/" + player.bowels.capacity;
  220. else
  221. document.getElementById("stat-bowels").innerHTML = "";
  222. if (player.prefs.pred.cock)
  223. document.getElementById("stat-balls").innerHTML = "Balls: " + round(player.balls.fullness(),0) + "/" + player.balls.capacity;
  224. else
  225. document.getElementById("stat-balls").innerHTML = "";
  226. if (player.prefs.pred.unbirth)
  227. document.getElementById("stat-womb").innerHTML = "Womb: " + round(player.womb.fullness(),0) + "/" + player.womb.capacity;
  228. else
  229. document.getElementById("stat-womb").innerHTML = "";
  230. if (player.prefs.pred.breast)
  231. document.getElementById("stat-breasts").innerHTML = "Breasts: " + round(player.breasts.fullness(),0) + "/" + player.breasts.capacity;
  232. else
  233. document.getElementById("stat-breasts").innerHTML = "";
  234. }
  235. function advanceTimeTo(newTime, conscious=true) {
  236. advanceTime((86400 + newTime - time) % 86400, conscious);
  237. }
  238. function advanceTime(amount, conscious=true) {
  239. time = (time + amount);
  240. date += Math.floor(time / 86400);
  241. time = time % 86400;
  242. player.restoreHealth(amount);
  243. player.restoreStamina(amount);
  244. update(player.stomach.digest(amount));
  245. update(player.bowels.digest(amount));
  246. update(player.balls.digest(amount));
  247. update(player.womb.digest(amount));
  248. update(player.breasts.digest(amount));
  249. if (conscious) {
  250. update(player.buildArousal(amount));
  251. }
  252. }
  253. function renderTime(time) {
  254. let suffix = (time < 43200) ? "AM" : "PM";
  255. let hour = Math.floor((time % 43200) / 3600);
  256. if (hour == 0)
  257. hour = 12;
  258. let minute = Math.floor(time / 60) % 60;
  259. if (minute < 9)
  260. minute = "0" + minute;
  261. return hour + ":" + minute + " " + suffix;
  262. }
  263. function move(direction) {
  264. if (noLog)
  265. clearScreen();
  266. else
  267. clearLogBreak();
  268. let target = currentRoom.exits[direction];
  269. if (target == null) {
  270. alert("Tried to move to an empty room!");
  271. return;
  272. }
  273. moveTo(target,currentRoom.exitDescs[direction]);
  274. }
  275. function updateActions() {
  276. actions = [];
  277. currentRoom.objects.forEach(function (object) {
  278. object.actions.forEach(function (action) {
  279. if (action.conditions == undefined || action.conditions.reduce((result, cond) => result && cond(player), true))
  280. actions.push(action);
  281. });
  282. });
  283. }
  284. function moveToByName(roomName, desc="You go places lol", loading=false) {
  285. moveTo(world[roomName], desc, loading);
  286. }
  287. function moveTo(room,desc="You go places lol", loading=false) {
  288. currentRoom = room;
  289. if (!loading)
  290. advanceTime(30);
  291. update([desc,newline]);
  292. currentRoom.visit();
  293. updateDisplay();
  294. }
  295. function next_step(stage) {
  296. document.querySelector("#character-step-" + (stage - 1)).style.display = "none";
  297. document.querySelector("#character-step-" + stage).style.display = "block";
  298. }
  299. window.addEventListener('load', function(event) {
  300. document.getElementById("character-step-1-next").addEventListener("click", function() { next_step(2); });
  301. document.getElementById("character-load").addEventListener("click", startLoaded, false);
  302. document.getElementById("start-button").addEventListener("click", start, false);
  303. });
  304. function start() {
  305. applySettings(generateSettings());
  306. transformVorePrefs(player.prefs);
  307. document.getElementById("create").style.display = "none";
  308. document.getElementById("game").style.display = "block";
  309. document.getElementById("stat-button-status").addEventListener("click", status, false);
  310. document.getElementById("log-button").addEventListener("click", toggleLog, false);
  311. loadCompass();
  312. loadDialog();
  313. world = createWorld();
  314. currentRoom = world["Bedroom"];
  315. respawnRoom = currentRoom;
  316. update(new Array(50).fill(newline));
  317. update(["Welcome to Feast."]);
  318. moveTo(currentRoom,"");
  319. updateDisplay();
  320. }
  321. // copied from Stroll LUL
  322. function generateSettings() {
  323. let form = document.forms.namedItem("character-form");
  324. let settings = {};
  325. for (let i=0; i<form.length; i++) {
  326. let value = form[i].value == "" ? form[i].placeholder : form[i].value;
  327. if (form[i].type == "text")
  328. if (form[i].value == "")
  329. settings[form[i].name] = form[i].placeholder;
  330. else
  331. settings[form[i].name] = value;
  332. else if (form[i].type == "number")
  333. settings[form[i].name] = parseFloat(value);
  334. else if (form[i].type == "checkbox") {
  335. settings[form[i].name] = form[i].checked;
  336. } else if (form[i].type == "radio") {
  337. let name = form[i].name;
  338. if (form[i].checked) {
  339. if (form[i].value == "true")
  340. settings[name] = true;
  341. else if (form[i].value == "false")
  342. settings[name] = false;
  343. else
  344. settings[name] = form[i].value;
  345. }
  346. } else if (form[i].type == "select-one") {
  347. settings[form[i].name] = form[i][form[i].selectedIndex].value;
  348. }
  349. }
  350. return settings;
  351. }
  352. function applySettings(settings) {
  353. player.name = settings.name;
  354. player.species = settings.species;
  355. for (let key in settings) {
  356. if (settings.hasOwnProperty(key)) {
  357. if (key.match(/prefs/)) {
  358. let tokens = key.split("-");
  359. let pref = player.prefs;
  360. // construct missing child dictionaries if needed :)
  361. pref = tokens.slice(1,-1).reduce(function(pref, key) {
  362. if (pref[key] == undefined)
  363. pref[key] = {};
  364. return pref[key];
  365. }, pref);
  366. pref[tokens.slice(-1)[0]] = settings[key];
  367. } else if(key.match(/parts/)) {
  368. let tokens = key.split("-");
  369. player.parts[tokens[1]] = settings[key] >= 1;
  370. if (player.prefs.pred == undefined)
  371. player.prefs.pred = {};
  372. player.prefs.pred[tokens[1]] = settings[key] >= 2;
  373. }
  374. }
  375. }
  376. }
  377. // turn things like "1" into a number
  378. function transformVorePrefs(prefs) {
  379. let prey = false;
  380. for (let key in prefs.vore) {
  381. if (prefs.vore.hasOwnProperty(key)) {
  382. switch(prefs.vore[key]) {
  383. case "0": prefs.vore[key] = 0; break;
  384. case "1": prefs.vore[key] = 0.5; prey = true; break;
  385. case "2": prefs.vore[key] = 1; prey = true; break;
  386. case "3": prefs.vore[key] = 2; prey = true; break;
  387. }
  388. }
  389. }
  390. prefs.prey = prey;
  391. return prefs;
  392. }
  393. function saveSettings() {
  394. window.localStorage.setItem("settings", JSON.stringify(generateSettings()));
  395. }
  396. function retrieveSettings() {
  397. return JSON.parse(window.localStorage.getItem("settings"));
  398. }
  399. function clearScreen() {
  400. let log = document.getElementById("log");
  401. let child = log.firstChild;
  402. while (child != null) {
  403. log.removeChild(child);
  404. child = log.firstChild;
  405. }
  406. }
  407. function update(lines=[]) {
  408. let log = document.getElementById("log");
  409. for (let i=0; i<lines.length; i++) {
  410. let div = document.createElement("div");
  411. div.innerHTML = lines[i];
  412. if (logPadLine === undefined && !noLog) {
  413. logPadLine = div;
  414. logPadLine.classList.add("log-entry-padded");
  415. }
  416. log.appendChild(div);
  417. }
  418. log.scrollTop = log.scrollHeight;
  419. updateDisplay();
  420. }
  421. function clearLogBreak() {
  422. if (logPadLine !== undefined) {
  423. logPadLine.classList.remove("log-entry-padded");
  424. logPadLine = undefined;
  425. }
  426. }
  427. function changeMode(newMode) {
  428. mode = newMode;
  429. let body = document.querySelector("body");
  430. document.getElementById("foe-stats").style.display = "none";
  431. body.className = "";
  432. switch(mode) {
  433. case "explore":
  434. case "dialog":
  435. body.classList.add("explore");
  436. break;
  437. case "combat":
  438. body.classList.add("combat");
  439. document.getElementById("foe-stats").style.display = "block";
  440. break;
  441. case "eaten":
  442. body.classList.add("eaten");
  443. document.getElementById("foe-stats").style.display = "block";
  444. break;
  445. }
  446. updateDisplay();
  447. }
  448. // make it look like eaten mode, even when in combat
  449. function changeBackground(newMode) {
  450. let body = document.querySelector("body");
  451. document.getElementById("foe-stats").style.display = "none";
  452. body.className = "";
  453. switch(newMode) {
  454. case "explore":
  455. case "dialog":
  456. body.classList.add("explore");
  457. break;
  458. case "combat":
  459. body.classList.add("combat");
  460. document.getElementById("foe-stats").style.display = "block";
  461. break;
  462. case "eaten":
  463. body.classList.add("eaten");
  464. document.getElementById("foe-stats").style.display = "block";
  465. break;
  466. }
  467. }
  468. function respawn(respawnRoom) {
  469. if (killingBlow.gameover == undefined) {
  470. if (player.prefs.prey) {
  471. deaths.push("Digested by " + currentFoe.description("a") + " at " + renderTime(time) + " on day " + date);
  472. } else {
  473. deaths.push("Defeated by " + currentFoe.description("a") + " at " + renderTime(time) + " on day " + date);
  474. }
  475. } else {
  476. deaths.push(killingBlow.gameover() + " at " + renderTime(time) + " on day " + date);
  477. }
  478. moveTo(respawnRoom,"You drift through space and time...");
  479. player.clear();
  480. player.stomach.contents = [];
  481. player.bowels.contents = [];
  482. player.bowels.waste = 0;
  483. player.bowels.digested = [];
  484. player.womb.contents = [];
  485. player.womb.waste = 0;
  486. player.womb.digested = [];
  487. player.balls.contents = [];
  488. player.balls.waste = 0;
  489. player.balls.digested = [];
  490. player.breasts.contents = [];
  491. player.breasts.waste = 0;
  492. player.breasts.digested = [];
  493. advanceTime(Math.floor(86400 / 2 * (Math.random() * 0.5 - 0.25 + 1)), false);
  494. changeMode("explore");
  495. player.health = 100;
  496. update(["You wake back up in your bed."]);
  497. }
  498. function startCombat(opponent) {
  499. currentFoe = opponent;
  500. changeMode("combat");
  501. update(opponent.startCombat(player).concat([newline]));
  502. }
  503. function attackClicked(index) {
  504. if (noLog)
  505. clearScreen();
  506. else
  507. clearLogBreak();
  508. update(playerAttacks[index].attack(currentFoe).concat([newline]));
  509. if (currentFoe.health <= 0) {
  510. currentFoe.defeated();
  511. } else if (mode == "combat") {
  512. let attack = pick(filterPriority(filterValid(currentFoe.attacks, currentFoe, player)), currentFoe, player);
  513. if (attack == null) {
  514. attack = currentFoe.backupAttack;
  515. }
  516. update(attack.attackPlayer(player).concat([newline]));
  517. if (player.health <= -100) {
  518. killingBlow = attack;
  519. if (currentFoe.finishCombat != undefined)
  520. update(currentFoe.finishCombat().concat([newline]));
  521. update(["You die..."]);
  522. respawn(respawnRoom);
  523. } else if (player.health <= 0) {
  524. update(["You're too weak to do anything..."]);
  525. if (player.prefs.prey) {
  526. // nada
  527. } else {
  528. killingBlow = attack;
  529. update(["You die..."]);
  530. respawn(respawnRoom);
  531. }
  532. }
  533. if (currentFoe.status != undefined) {
  534. let status = currentFoe.status();
  535. if (status.length > 0)
  536. update(status.concat([newline]));
  537. }
  538. }
  539. }
  540. function attackHovered(index) {
  541. document.getElementById("combat-desc").innerHTML = playerAttacks[index].desc;
  542. }
  543. function struggleClicked(index) {
  544. if (noLog)
  545. clearScreen();
  546. else
  547. clearLogBreak();
  548. let struggle = struggles[index];
  549. let result = struggle.struggle(player);
  550. update(result.lines.concat([newline]));
  551. if (result.escape == "stay") {
  552. changeMode("combat");
  553. } else if (result.escape == "escape") {
  554. changeMode("explore");
  555. } else {
  556. let digest = pick(filterValid(currentFoe.digests, currentFoe, player), currentFoe, player);
  557. if (digest == null) {
  558. digest = currentFoe.backupDigest;
  559. }
  560. update(digest.digest(player).concat([newline]));
  561. if (player.health <= -100) {
  562. killingBlow = digest;
  563. update(currentFoe.finishDigest().concat([newline]));
  564. respawn(respawnRoom);
  565. }
  566. }
  567. }
  568. function struggleHovered(index) {
  569. document.getElementById("eaten-desc").innerHTML = currentFoe.struggles[index].desc;
  570. }
  571. function startDialog(dialog) {
  572. if (noLog)
  573. clearScreen();
  574. else
  575. clearLogBreak();
  576. currentDialog = dialog;
  577. changeMode("dialog");
  578. update(currentDialog.text.concat([newline]));
  579. currentDialog.visit();
  580. updateDisplay();
  581. }
  582. function dialogClicked(index) {
  583. currentDialog = currentDialog.choices[index].node;
  584. update(currentDialog.text.concat([newline]));
  585. currentDialog.visit();
  586. if (currentDialog.choices.length == 0 && mode == "dialog") {
  587. changeMode("explore");
  588. updateDisplay();
  589. }
  590. }
  591. function loadDialog() {
  592. dialogButtons = Array.from( document.querySelectorAll(".dialog-button"));
  593. for (let i = 0; i < dialogButtons.length; i++) {
  594. dialogButtons[i].addEventListener("click", function() { dialogClicked(i); });
  595. }
  596. }
  597. function loadCompass() {
  598. dirButtons[NORTH_WEST] = document.getElementById("compass-north-west");
  599. dirButtons[NORTH_WEST].addEventListener("click", function() {
  600. move(NORTH_WEST);
  601. });
  602. dirButtons[NORTH] = document.getElementById("compass-north");
  603. dirButtons[NORTH].addEventListener("click", function() {
  604. move(NORTH);
  605. });
  606. dirButtons[NORTH_EAST] = document.getElementById("compass-north-east");
  607. dirButtons[NORTH_EAST].addEventListener("click", function() {
  608. move(NORTH_EAST);
  609. });
  610. dirButtons[WEST] = document.getElementById("compass-west");
  611. dirButtons[WEST].addEventListener("click", function() {
  612. move(WEST);
  613. });
  614. dirButtons[EAST] = document.getElementById("compass-east");
  615. dirButtons[EAST].addEventListener("click", function() {
  616. move(EAST);
  617. });
  618. dirButtons[SOUTH_WEST] = document.getElementById("compass-south-west");
  619. dirButtons[SOUTH_WEST].addEventListener("click", function() {
  620. move(SOUTH_WEST);
  621. });
  622. dirButtons[SOUTH] = document.getElementById("compass-south");
  623. dirButtons[SOUTH].addEventListener("click", function() {
  624. move(SOUTH);
  625. });
  626. dirButtons[SOUTH_EAST] = document.getElementById("compass-south-east");
  627. dirButtons[SOUTH_EAST].addEventListener("click", function() {
  628. move(SOUTH_EAST);
  629. });
  630. document.getElementById("compass-look").addEventListener("click", look, false);
  631. }
  632. function look() {
  633. update([currentRoom.description]);
  634. }
  635. function status() {
  636. let lines = [];
  637. lines.push("You are a " + player.species);
  638. lines.push(newline);
  639. if (player.stomach.contents.length > 0) {
  640. lines.push("Your stomach bulges with prey.");
  641. player.stomach.contents.map(function(prey) {
  642. let state = "";
  643. let healthRatio = prey.health / prey.maxHealth;
  644. if (healthRatio > 0.75) {
  645. state = "is thrashing in your gut";
  646. } else if (healthRatio > 0.5) {
  647. state = "is squirming in your belly";
  648. } else if (healthRatio > 0.25) {
  649. state = "is pressing out at your stomach walls";
  650. } else if (healthRatio > 0) {
  651. state = "is weakly squirming";
  652. } else {
  653. state = "has stopped moving";
  654. }
  655. lines.push(prey.description("A") + " " + state);
  656. });
  657. lines.push(newline);
  658. }
  659. if (player.bowels.contents.length > 0) {
  660. lines.push("Your bowels churn with prey.");
  661. player.bowels.contents.map(function(prey) {
  662. let state = "";
  663. let healthRatio = prey.health / prey.maxHealth;
  664. if (healthRatio > 0.75) {
  665. state = "is writhing in your bowels";
  666. } else if (healthRatio > 0.5) {
  667. state = "is struggling against your intestines";
  668. } else if (healthRatio > 0.25) {
  669. state = "is bulging out of your lower belly";
  670. } else if (healthRatio > 0) {
  671. state = "is squirming weakly, slipping deeper and deeper";
  672. } else {
  673. state = "has succumbed to your bowels";
  674. }
  675. lines.push(prey.description("A") + " " + state);
  676. });
  677. lines.push(newline);
  678. }
  679. if (player.parts.cock) {
  680. if (player.balls.contents.length > 0) {
  681. lines.push("Your balls are bulging with prey.");
  682. player.balls.contents.map(function(prey) {
  683. let state = "";
  684. let healthRatio = prey.health / prey.maxHealth;
  685. if (healthRatio > 0.75) {
  686. state = "is writhing in your sac";
  687. } else if (healthRatio > 0.5) {
  688. state = "is struggling in a pool of cum";
  689. } else if (healthRatio > 0.25) {
  690. state = "is starting to turn soft";
  691. } else if (healthRatio > 0) {
  692. state = "is barely visible anymore";
  693. } else {
  694. state = "has succumbed to your balls";
  695. }
  696. lines.push(prey.description("A") + " " + state);
  697. });
  698. lines.push(newline);
  699. } else {
  700. if (player.balls.waste > 0) {
  701. lines.push("Your balls are heavy with cum.");
  702. lines.push(newline);
  703. }
  704. }
  705. }
  706. if (player.parts.unbirth) {
  707. if (player.womb.contents.length > 0) {
  708. lines.push("Your slit drips, hinting at prey trapped within.");
  709. player.womb.contents.map(function(prey) {
  710. let state = "";
  711. let healthRatio = prey.health / prey.maxHealth;
  712. if (healthRatio > 0.75) {
  713. state = "is thrashing in your womb";
  714. } else if (healthRatio > 0.5) {
  715. state = "is pressing out inside your lower belly";
  716. } else if (healthRatio > 0.25) {
  717. state = "is still trying to escape";
  718. } else if (healthRatio > 0) {
  719. state = "is barely moving";
  720. } else {
  721. state = "is dissolving into femcum";
  722. }
  723. lines.push(prey.description("A") + " " + state);
  724. });
  725. lines.push(newline);
  726. } else {
  727. if (player.womb.waste > 0) {
  728. lines.push("Your slit drips, holding back a tide of femcum.");
  729. lines.push(newline);
  730. }
  731. }
  732. }
  733. if (player.parts.breast) {
  734. if (player.breasts.contents.length > 0) {
  735. lines.push("Your breasts are bulging with prey.");
  736. player.breasts.contents.map(function(prey) {
  737. let state = "";
  738. let healthRatio = prey.health / prey.maxHealth;
  739. if (healthRatio > 0.75) {
  740. state = "is struggling to escape";
  741. } else if (healthRatio > 0.5) {
  742. state = "is putting up a fight";
  743. } else if (healthRatio > 0.25) {
  744. state = "is starting to weaken";
  745. } else if (healthRatio > 0) {
  746. state = "is struggling to keep their head free of your milk";
  747. } else {
  748. state = "has succumbed, swiftly melting into milk";
  749. }
  750. lines.push(prey.description("A") + " " + state);
  751. });
  752. lines.push(newline);
  753. } else {
  754. if (player.breasts.waste > 0) {
  755. lines.push("Your breasts slosh with milk.");
  756. lines.push(newline);
  757. }
  758. }
  759. }
  760. update(lines);
  761. }
  762. let toSave = ["str","dex","con","name","species","health","stamina"];
  763. function saveGame() {
  764. let save = {};
  765. save.player = {};
  766. save.player.str = player.str;
  767. save.player.dex = player.dex;
  768. save.player.con = player.con;
  769. save.player.name = player.name;
  770. save.player.species = player.species;
  771. save.player.health = player.health;
  772. save.player.health = player.stamina;
  773. save.prefs = JSON.stringify(player.prefs);
  774. save.position = currentRoom.name;
  775. save.date = date;
  776. save.time = time;
  777. save.deaths = deaths;
  778. let stringified = JSON.stringify(save);
  779. window.localStorage.setItem("save", stringified);
  780. }
  781. function loadGame() {
  782. changeMode("explore");
  783. let save = JSON.parse(window.localStorage.getItem("save"));
  784. let playerSave = save.player;
  785. for (let key in playerSave) {
  786. if (playerSave.hasOwnProperty(key)) {
  787. player[key] = playerSave[key];
  788. }
  789. }
  790. player.prefs = JSON.parse(save.prefs);
  791. deaths = save.deaths;
  792. date = save.date;
  793. time = save.time;
  794. clearScreen();
  795. moveToByName(save.position, "");
  796. }
  797. function startLoaded() { //used to load the game via the main menu
  798. start();
  799. loadGame();
  800. }
  801. // wow polyfills
  802. if (![].includes) {
  803. Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
  804. 'use strict';
  805. var O = Object(this);
  806. var len = parseInt(O.length) || 0;
  807. if (len === 0) {
  808. return false;
  809. }
  810. var n = parseInt(arguments[1]) || 0;
  811. var k;
  812. if (n >= 0) {
  813. k = n;
  814. } else {
  815. k = len + n;
  816. if (k < 0) {k = 0;}
  817. }
  818. var currentElement;
  819. while (k < len) {
  820. currentElement = O[k];
  821. if (searchElement === currentElement ||
  822. (searchElement !== searchElement && currentElement !== currentElement)) {
  823. return true;
  824. }
  825. k++;
  826. }
  827. return false;
  828. };
  829. }