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

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