crunch
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

987 lines
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("start-button").addEventListener("click", start, false);
  302. });
  303. function start() {
  304. applySettings(generateSettings());
  305. transformVorePrefs(player.prefs);
  306. document.getElementById("create").style.display = "none";
  307. document.getElementById("game").style.display = "block";
  308. document.getElementById("stat-button-status").addEventListener("click", status, false);
  309. document.getElementById("log-button").addEventListener("click", toggleLog, false);
  310. loadCompass();
  311. loadDialog();
  312. world = createWorld();
  313. currentRoom = world["Bedroom"];
  314. respawnRoom = currentRoom;
  315. update(new Array(50).fill(newline));
  316. update(["Welcome to Feast."]);
  317. moveTo(currentRoom,"");
  318. updateDisplay();
  319. }
  320. // copied from Stroll LUL
  321. function generateSettings() {
  322. let form = document.forms.namedItem("character-form");
  323. let settings = {};
  324. for (let i=0; i<form.length; i++) {
  325. let value = form[i].value == "" ? form[i].placeholder : form[i].value;
  326. if (form[i].type == "text")
  327. if (form[i].value == "")
  328. settings[form[i].name] = form[i].placeholder;
  329. else
  330. settings[form[i].name] = value;
  331. else if (form[i].type == "number")
  332. settings[form[i].name] = parseFloat(value);
  333. else if (form[i].type == "checkbox") {
  334. settings[form[i].name] = form[i].checked;
  335. } else if (form[i].type == "radio") {
  336. let name = form[i].name;
  337. if (form[i].checked) {
  338. if (form[i].value == "true")
  339. settings[name] = true;
  340. else if (form[i].value == "false")
  341. settings[name] = false;
  342. else
  343. settings[name] = form[i].value;
  344. }
  345. } else if (form[i].type == "select-one") {
  346. settings[form[i].name] = form[i][form[i].selectedIndex].value;
  347. }
  348. }
  349. return settings;
  350. }
  351. function applySettings(settings) {
  352. player.name = settings.name;
  353. player.species = settings.species;
  354. for (let key in settings) {
  355. if (settings.hasOwnProperty(key)) {
  356. if (key.match(/prefs/)) {
  357. let tokens = key.split("-");
  358. let pref = player.prefs;
  359. // construct missing child dictionaries if needed :)
  360. pref = tokens.slice(1,-1).reduce(function(pref, key) {
  361. if (pref[key] == undefined)
  362. pref[key] = {};
  363. return pref[key];
  364. }, pref);
  365. pref[tokens.slice(-1)[0]] = settings[key];
  366. } else if(key.match(/parts/)) {
  367. let tokens = key.split("-");
  368. player.parts[tokens[1]] = settings[key] >= 1;
  369. if (player.prefs.pred == undefined)
  370. player.prefs.pred = {};
  371. player.prefs.pred[tokens[1]] = settings[key] >= 2;
  372. }
  373. }
  374. }
  375. }
  376. // turn things like "1" into a number
  377. function transformVorePrefs(prefs) {
  378. let prey = false;
  379. for (let key in prefs.vore) {
  380. if (prefs.vore.hasOwnProperty(key)) {
  381. switch(prefs.vore[key]) {
  382. case "0": prefs.vore[key] = 0; break;
  383. case "1": prefs.vore[key] = 0.5; prey = true; break;
  384. case "2": prefs.vore[key] = 1; prey = true; break;
  385. case "3": prefs.vore[key] = 2; prey = true; break;
  386. }
  387. }
  388. }
  389. prefs.prey = prey;
  390. return prefs;
  391. }
  392. function saveSettings() {
  393. window.localStorage.setItem("settings", JSON.stringify(generateSettings()));
  394. }
  395. function retrieveSettings() {
  396. return JSON.parse(window.localStorage.getItem("settings"));
  397. }
  398. function clearScreen() {
  399. let log = document.getElementById("log");
  400. let child = log.firstChild;
  401. while (child != null) {
  402. log.removeChild(child);
  403. child = log.firstChild;
  404. }
  405. }
  406. function update(lines=[]) {
  407. let log = document.getElementById("log");
  408. for (let i=0; i<lines.length; i++) {
  409. let div = document.createElement("div");
  410. div.innerHTML = lines[i];
  411. if (logPadLine === undefined && !noLog) {
  412. logPadLine = div;
  413. logPadLine.classList.add("log-entry-padded");
  414. }
  415. log.appendChild(div);
  416. }
  417. log.scrollTop = log.scrollHeight;
  418. updateDisplay();
  419. }
  420. function clearLogBreak() {
  421. if (logPadLine !== undefined) {
  422. logPadLine.classList.remove("log-entry-padded");
  423. logPadLine = undefined;
  424. }
  425. }
  426. function changeMode(newMode) {
  427. mode = newMode;
  428. let body = document.querySelector("body");
  429. document.getElementById("foe-stats").style.display = "none";
  430. body.className = "";
  431. switch(mode) {
  432. case "explore":
  433. case "dialog":
  434. body.classList.add("explore");
  435. break;
  436. case "combat":
  437. body.classList.add("combat");
  438. document.getElementById("foe-stats").style.display = "block";
  439. break;
  440. case "eaten":
  441. body.classList.add("eaten");
  442. document.getElementById("foe-stats").style.display = "block";
  443. break;
  444. }
  445. updateDisplay();
  446. }
  447. // make it look like eaten mode, even when in combat
  448. function changeBackground(newMode) {
  449. let body = document.querySelector("body");
  450. document.getElementById("foe-stats").style.display = "none";
  451. body.className = "";
  452. switch(newMode) {
  453. case "explore":
  454. case "dialog":
  455. body.classList.add("explore");
  456. break;
  457. case "combat":
  458. body.classList.add("combat");
  459. document.getElementById("foe-stats").style.display = "block";
  460. break;
  461. case "eaten":
  462. body.classList.add("eaten");
  463. document.getElementById("foe-stats").style.display = "block";
  464. break;
  465. }
  466. }
  467. function respawn(respawnRoom) {
  468. if (killingBlow.gameover == undefined) {
  469. if (player.prefs.prey) {
  470. deaths.push("Digested by " + currentFoe.description("a") + " at " + renderTime(time) + " on day " + date);
  471. } else {
  472. deaths.push("Defeated by " + currentFoe.description("a") + " at " + renderTime(time) + " on day " + date);
  473. }
  474. } else {
  475. deaths.push(killingBlow.gameover() + " at " + renderTime(time) + " on day " + date);
  476. }
  477. moveTo(respawnRoom,"You drift through space and time...");
  478. player.clear();
  479. player.stomach.contents = [];
  480. player.bowels.contents = [];
  481. player.bowels.waste = 0;
  482. player.bowels.digested = [];
  483. player.womb.contents = [];
  484. player.womb.waste = 0;
  485. player.womb.digested = [];
  486. player.balls.contents = [];
  487. player.balls.waste = 0;
  488. player.balls.digested = [];
  489. player.breasts.contents = [];
  490. player.breasts.waste = 0;
  491. player.breasts.digested = [];
  492. advanceTime(Math.floor(86400 / 2 * (Math.random() * 0.5 - 0.25 + 1)), false);
  493. changeMode("explore");
  494. player.health = 100;
  495. update(["You wake back up in your bed."]);
  496. }
  497. function startCombat(opponent) {
  498. currentFoe = opponent;
  499. changeMode("combat");
  500. update(opponent.startCombat(player).concat([newline]));
  501. }
  502. function attackClicked(index) {
  503. if (noLog)
  504. clearScreen();
  505. else
  506. clearLogBreak();
  507. update(playerAttacks[index].attack(currentFoe).concat([newline]));
  508. if (currentFoe.health <= 0) {
  509. currentFoe.defeated();
  510. } else if (mode == "combat") {
  511. let attack = pick(filterPriority(filterValid(currentFoe.attacks, currentFoe, player)), currentFoe, player);
  512. if (attack == null) {
  513. attack = currentFoe.backupAttack;
  514. }
  515. update(attack.attackPlayer(player).concat([newline]));
  516. if (player.health <= -100) {
  517. killingBlow = attack;
  518. if (currentFoe.finishCombat != undefined)
  519. update(currentFoe.finishCombat().concat([newline]));
  520. update(["You die..."]);
  521. respawn(respawnRoom);
  522. } else if (player.health <= 0) {
  523. update(["You're too weak to do anything..."]);
  524. if (player.prefs.prey) {
  525. // nada
  526. } else {
  527. killingBlow = attack;
  528. update(["You die..."]);
  529. respawn(respawnRoom);
  530. }
  531. }
  532. if (currentFoe.status != undefined) {
  533. let status = currentFoe.status();
  534. if (status.length > 0)
  535. update(status.concat([newline]));
  536. }
  537. }
  538. }
  539. function attackHovered(index) {
  540. document.getElementById("combat-desc").innerHTML = playerAttacks[index].desc;
  541. }
  542. function struggleClicked(index) {
  543. if (noLog)
  544. clearScreen();
  545. else
  546. clearLogBreak();
  547. let struggle = struggles[index];
  548. let result = struggle.struggle(player);
  549. update(result.lines.concat([newline]));
  550. if (result.escape == "stay") {
  551. changeMode("combat");
  552. } else if (result.escape == "escape") {
  553. changeMode("explore");
  554. } else {
  555. let digest = pick(filterValid(currentFoe.digests, currentFoe, player), currentFoe, player);
  556. if (digest == null) {
  557. digest = currentFoe.backupDigest;
  558. }
  559. update(digest.digest(player).concat([newline]));
  560. if (player.health <= -100) {
  561. killingBlow = digest;
  562. update(currentFoe.finishDigest().concat([newline]));
  563. respawn(respawnRoom);
  564. }
  565. }
  566. }
  567. function struggleHovered(index) {
  568. document.getElementById("eaten-desc").innerHTML = currentFoe.struggles[index].desc;
  569. }
  570. function startDialog(dialog) {
  571. if (noLog)
  572. clearScreen();
  573. else
  574. clearLogBreak();
  575. currentDialog = dialog;
  576. changeMode("dialog");
  577. update(currentDialog.text.concat([newline]));
  578. currentDialog.visit();
  579. updateDisplay();
  580. }
  581. function dialogClicked(index) {
  582. currentDialog = currentDialog.choices[index].node;
  583. update(currentDialog.text.concat([newline]));
  584. currentDialog.visit();
  585. if (currentDialog.choices.length == 0 && mode == "dialog") {
  586. changeMode("explore");
  587. updateDisplay();
  588. }
  589. }
  590. function loadDialog() {
  591. dialogButtons = Array.from( document.querySelectorAll(".dialog-button"));
  592. for (let i = 0; i < dialogButtons.length; i++) {
  593. dialogButtons[i].addEventListener("click", function() { dialogClicked(i); });
  594. }
  595. }
  596. function loadCompass() {
  597. dirButtons[NORTH_WEST] = document.getElementById("compass-north-west");
  598. dirButtons[NORTH_WEST].addEventListener("click", function() {
  599. move(NORTH_WEST);
  600. });
  601. dirButtons[NORTH] = document.getElementById("compass-north");
  602. dirButtons[NORTH].addEventListener("click", function() {
  603. move(NORTH);
  604. });
  605. dirButtons[NORTH_EAST] = document.getElementById("compass-north-east");
  606. dirButtons[NORTH_EAST].addEventListener("click", function() {
  607. move(NORTH_EAST);
  608. });
  609. dirButtons[WEST] = document.getElementById("compass-west");
  610. dirButtons[WEST].addEventListener("click", function() {
  611. move(WEST);
  612. });
  613. dirButtons[EAST] = document.getElementById("compass-east");
  614. dirButtons[EAST].addEventListener("click", function() {
  615. move(EAST);
  616. });
  617. dirButtons[SOUTH_WEST] = document.getElementById("compass-south-west");
  618. dirButtons[SOUTH_WEST].addEventListener("click", function() {
  619. move(SOUTH_WEST);
  620. });
  621. dirButtons[SOUTH] = document.getElementById("compass-south");
  622. dirButtons[SOUTH].addEventListener("click", function() {
  623. move(SOUTH);
  624. });
  625. dirButtons[SOUTH_EAST] = document.getElementById("compass-south-east");
  626. dirButtons[SOUTH_EAST].addEventListener("click", function() {
  627. move(SOUTH_EAST);
  628. });
  629. document.getElementById("compass-look").addEventListener("click", look, false);
  630. }
  631. function look() {
  632. update([currentRoom.description]);
  633. }
  634. function status() {
  635. let lines = [];
  636. lines.push("You are a " + player.species);
  637. lines.push(newline);
  638. if (player.stomach.contents.length > 0) {
  639. lines.push("Your stomach bulges with prey.");
  640. player.stomach.contents.map(function(prey) {
  641. let state = "";
  642. let healthRatio = prey.health / prey.maxHealth;
  643. if (healthRatio > 0.75) {
  644. state = "is thrashing in your gut";
  645. } else if (healthRatio > 0.5) {
  646. state = "is squirming in your belly";
  647. } else if (healthRatio > 0.25) {
  648. state = "is pressing out at your stomach walls";
  649. } else if (healthRatio > 0) {
  650. state = "is weakly squirming";
  651. } else {
  652. state = "has stopped moving";
  653. }
  654. lines.push(prey.description("A") + " " + state);
  655. });
  656. lines.push(newline);
  657. }
  658. if (player.bowels.contents.length > 0) {
  659. lines.push("Your bowels churn with prey.");
  660. player.bowels.contents.map(function(prey) {
  661. let state = "";
  662. let healthRatio = prey.health / prey.maxHealth;
  663. if (healthRatio > 0.75) {
  664. state = "is writhing in your bowels";
  665. } else if (healthRatio > 0.5) {
  666. state = "is struggling against your intestines";
  667. } else if (healthRatio > 0.25) {
  668. state = "is bulging out of your lower belly";
  669. } else if (healthRatio > 0) {
  670. state = "is squirming weakly, slipping deeper and deeper";
  671. } else {
  672. state = "has succumbed to your bowels";
  673. }
  674. lines.push(prey.description("A") + " " + state);
  675. });
  676. lines.push(newline);
  677. }
  678. if (player.parts.cock) {
  679. if (player.balls.contents.length > 0) {
  680. lines.push("Your balls are bulging with prey.");
  681. player.balls.contents.map(function(prey) {
  682. let state = "";
  683. let healthRatio = prey.health / prey.maxHealth;
  684. if (healthRatio > 0.75) {
  685. state = "is writhing in your sac";
  686. } else if (healthRatio > 0.5) {
  687. state = "is struggling in a pool of cum";
  688. } else if (healthRatio > 0.25) {
  689. state = "is starting to turn soft";
  690. } else if (healthRatio > 0) {
  691. state = "is barely visible anymore";
  692. } else {
  693. state = "has succumbed to your balls";
  694. }
  695. lines.push(prey.description("A") + " " + state);
  696. });
  697. lines.push(newline);
  698. } else {
  699. if (player.balls.waste > 0) {
  700. lines.push("Your balls are heavy with cum.");
  701. lines.push(newline);
  702. }
  703. }
  704. }
  705. if (player.parts.unbirth) {
  706. if (player.womb.contents.length > 0) {
  707. lines.push("Your slit drips, hinting at prey trapped within.");
  708. player.womb.contents.map(function(prey) {
  709. let state = "";
  710. let healthRatio = prey.health / prey.maxHealth;
  711. if (healthRatio > 0.75) {
  712. state = "is thrashing in your womb";
  713. } else if (healthRatio > 0.5) {
  714. state = "is pressing out inside your lower belly";
  715. } else if (healthRatio > 0.25) {
  716. state = "is still trying to escape";
  717. } else if (healthRatio > 0) {
  718. state = "is barely moving";
  719. } else {
  720. state = "is dissolving into femcum";
  721. }
  722. lines.push(prey.description("A") + " " + state);
  723. });
  724. lines.push(newline);
  725. } else {
  726. if (player.womb.waste > 0) {
  727. lines.push("Your slit drips, holding back a tide of femcum.");
  728. lines.push(newline);
  729. }
  730. }
  731. }
  732. if (player.parts.breast) {
  733. if (player.breasts.contents.length > 0) {
  734. lines.push("Your breasts are bulging with prey.");
  735. player.breasts.contents.map(function(prey) {
  736. let state = "";
  737. let healthRatio = prey.health / prey.maxHealth;
  738. if (healthRatio > 0.75) {
  739. state = "is struggling to escape";
  740. } else if (healthRatio > 0.5) {
  741. state = "is putting up a fight";
  742. } else if (healthRatio > 0.25) {
  743. state = "is starting to weaken";
  744. } else if (healthRatio > 0) {
  745. state = "is struggling to keep their head free of your milk";
  746. } else {
  747. state = "has succumbed, swiftly melting into milk";
  748. }
  749. lines.push(prey.description("A") + " " + state);
  750. });
  751. lines.push(newline);
  752. } else {
  753. if (player.breasts.waste > 0) {
  754. lines.push("Your breasts slosh with milk.");
  755. lines.push(newline);
  756. }
  757. }
  758. }
  759. update(lines);
  760. }
  761. let toSave = ["str","dex","con","name","species","health","stamina"];
  762. function saveGame() {
  763. let save = {};
  764. save.player = {};
  765. save.player.str = player.str;
  766. save.player.dex = player.dex;
  767. save.player.con = player.con;
  768. save.player.name = player.name;
  769. save.player.species = player.species;
  770. save.player.health = player.health;
  771. save.player.health = player.stamina;
  772. save.prefs = JSON.stringify(player.prefs);
  773. save.position = currentRoom.name;
  774. save.date = date;
  775. save.time = time;
  776. save.deaths = deaths;
  777. let stringified = JSON.stringify(save);
  778. window.localStorage.setItem("save", stringified);
  779. }
  780. function loadGame() {
  781. changeMode("explore");
  782. let save = JSON.parse(window.localStorage.getItem("save"));
  783. let playerSave = save.player;
  784. for (let key in playerSave) {
  785. if (playerSave.hasOwnProperty(key)) {
  786. player[key] = playerSave[key];
  787. }
  788. }
  789. player.prefs = JSON.parse(save.prefs);
  790. deaths = save.deaths;
  791. date = save.date;
  792. time = save.time;
  793. clearScreen();
  794. moveToByName(save.position, "");
  795. }
  796. // wow polyfills
  797. if (![].includes) {
  798. Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
  799. 'use strict';
  800. var O = Object(this);
  801. var len = parseInt(O.length) || 0;
  802. if (len === 0) {
  803. return false;
  804. }
  805. var n = parseInt(arguments[1]) || 0;
  806. var k;
  807. if (n >= 0) {
  808. k = n;
  809. } else {
  810. k = len + n;
  811. if (k < 0) {k = 0;}
  812. }
  813. var currentElement;
  814. while (k < len) {
  815. currentElement = O[k];
  816. if (searchElement === currentElement ||
  817. (searchElement !== searchElement && currentElement !== currentElement)) {
  818. return true;
  819. }
  820. k++;
  821. }
  822. return false;
  823. };
  824. }