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.
 
 
 

463 line
11 KiB

  1. "use strict";
  2. function Creature(name = "Creature", str=10, dex=10, con=10) {
  3. this.name = name;
  4. this.mass = 80;
  5. this.bowels = new Bowels();
  6. this.stomach = new Stomach(this,this.bowels);
  7. this.butt = new Butt(this,this.bowels,this.stomach);
  8. this.attacks = [];
  9. this.str = str;
  10. this.dex = dex;
  11. this.con = con;
  12. this.hasName = false;
  13. Object.defineProperty(this, "maxHealth", {get: function() { return this.str * 5 + this.con * 10 }});
  14. this.health = this.maxHealth;
  15. Object.defineProperty(this, "maxStamina", {get: function() { return this.dex * 5 + this.con * 10 }});
  16. this.stamina = this.maxStamina;
  17. // fraction of max health per second
  18. this.healthRate = 1 / 86400 * 4;
  19. this.staminaRate = 1 / 86400 * 6;
  20. this.restoreHealth = function(time) {
  21. this.health = Math.min(this.maxHealth, this.health + this.maxHealth * time * this.healthRate);
  22. };
  23. this.restoreStamina = function(time) {
  24. this.stamina = Math.min(this.maxStamina, this.stamina + this.maxStamina * time * this.staminaRate);
  25. };
  26. this.flags = {};
  27. this.clear = function() {
  28. this.flags = {};
  29. };
  30. this.prefs = {
  31. prey: true,
  32. scat: true,
  33. analVore: true,
  34. gore: true
  35. };
  36. this.cash = Math.floor(Math.random() * 10 + 5);
  37. this.text = {};
  38. this.startCombat = function() { return [this.description("A") + " appears. It's a fight!"]; };
  39. this.finishCombat = function() { return [this.description("The") + " scoops up your limp body and gulps you down."]; };
  40. this.finishDigest = function() { return [this.description("The") + " digests you..."]; };
  41. this.defeated = function() { startDialog(new FallenFoe(this)); };
  42. this.changeStamina = function(amount) {
  43. this.stamina += amount;
  44. this.stamina = Math.min(this.maxStamina, this.stamina);
  45. this.stamina = Math.max(0, this.stamina);
  46. };
  47. }
  48. function Player(name = "Player") {
  49. Creature.call(this, name, 15, 15, 15);
  50. this.fullness = function() {
  51. return this.stomach.fullness() + this.butt.fullness();
  52. };
  53. this.attacks.push(new punchAttack(this));
  54. this.attacks.push(new flankAttack(this));
  55. this.attacks.push(new grapple(this));
  56. this.attacks.push(new grappleSubdue(this));
  57. this.attacks.push(new grappleDevour(this));
  58. this.attacks.push(new grappleAnalVore(this));
  59. this.attacks.push(new grappleRelease(this));
  60. this.attacks.push(new grappledStruggle(this));
  61. this.attacks.push(new grappledReverse(this));
  62. this.attacks.push(new shrunkGrapple(this));
  63. this.attacks.push(new shrunkSwallow(this));
  64. this.attacks.push(new shrunkStomp(this));
  65. this.attacks.push(new flee(this));
  66. this.backupAttack = new pass(this);
  67. this.cash = 100;
  68. }
  69. function Anthro(name="Anthro") {
  70. this.build = pickRandom(["skinny", "fat", "muscular", "sickly", "ordinary"]);
  71. switch(this.build) {
  72. case "skinny":
  73. Creature.call(this, name, 8, 12, 8);
  74. this.mass *= ( Math.random() * 0.2 + 0.7 );
  75. break;
  76. case "fat":
  77. Creature.call(this, name, 10, 7, 15);
  78. this.mass *= ( Math.random() * 0.4 + 1.1);
  79. break;
  80. case "muscular":
  81. Creature.call(this, name, 13, 11, 13);
  82. this.mass *= ( Math.random() * 0.1 + 1.1);
  83. break;
  84. case "sickly":
  85. Creature.call(this, name, 6, 8, 6);
  86. this.mass *= ( Math.random() * 0.2 + 0.6 );
  87. break;
  88. case "ordinary":
  89. Creature.call(this, name, 10, 10, 10);
  90. break;
  91. }
  92. this.species = pickRandom(["dog","cat","lizard","deer","wolf","fox"]);
  93. // todo better lol
  94. this.description = function(prefix="") {
  95. if (this.build == "")
  96. if (prefix == "")
  97. return this.species;
  98. else
  99. return prefix + " " + this.species;
  100. else
  101. if (prefix == "")
  102. return this.build + " " + this.species;
  103. else
  104. return prefix + " " + this.build + " " + this.species;
  105. };
  106. this.attacks.push(new punchAttack(this));
  107. this.attacks.push(new flankAttack(this));
  108. this.attacks.push(new grapple(this));
  109. this.attacks.push(new grappleDevour(this));
  110. this.attacks.push(new grappledStruggle(this));
  111. this.attacks.push(new grappledReverse(this));
  112. this.backupAttack = new pass(this);
  113. this.struggles = [];
  114. this.struggles.push(new plead(this));
  115. this.struggles.push(new struggle(this));
  116. this.digests = [];
  117. this.digests.push(new digestPlayerStomach(this,20));
  118. this.backupDigest = new digestPlayerStomach(this,20);
  119. }
  120. function Fen() {
  121. Creature.call(this, name, 1000000, 1099900, 1000000);
  122. this.build = "loomy";
  123. this.species = "crux";
  124. this.description = function(prefix) { return "Fen"; };
  125. this.attacks = [];
  126. this.attacks.push(new devourPlayer(this));
  127. this.attacks.push(new leer(this));
  128. this.backupAttack = new poke(this);
  129. this.struggles = [];
  130. this.struggles.push(new rub(this));
  131. this.digests = [];
  132. this.digests.push(new digestPlayerStomach(this,50));
  133. this.digests.push(new instakillPlayerStomach(this));
  134. this.backupDigest = new digestPlayerStomach(this,50);
  135. }
  136. function Micro() {
  137. Creature.call(this, name);
  138. this.health = 5;
  139. this.mass = 0.1 * (Math.random()/2 - 0.25 + 1);
  140. this.species = pick(["dog","cat","lizard","deer","wolf","fox"]);
  141. this.description = function(prefix = "") {
  142. if (prefix == "")
  143. return "micro " + this.species;
  144. else
  145. return prefix + " micro " + this.species;
  146. };
  147. }
  148. // vore stuff here
  149. class Container {
  150. constructor(owner) {
  151. this.owner = owner;
  152. this.contents = [];
  153. // health/sec
  154. this.damageRate = 15*100/86400;
  155. // kg/sec
  156. this.digestRate = 80/8640;
  157. }
  158. digest(time) {
  159. let lines = [];
  160. this.contents.forEach(function(prey) {
  161. if (prey.health > 0) {
  162. let damage = Math.min(prey.health, this.damageRate * time);
  163. prey.health -= damage;
  164. time -= damage / this.damageRate;
  165. if (prey.health + damage > 50 && prey.health <= 50) {
  166. lines.push(this.describeDamage(prey));
  167. }
  168. if (prey.health <= 0) {
  169. lines.push(this.describeKill(prey));
  170. }
  171. }
  172. if (prey.health <= 0) {
  173. let digested = Math.min(prey.mass, this.digestRate * time);
  174. prey.mass -= digested;
  175. this.owner.changeStamina(digested*10);
  176. this.fill(digested);
  177. }
  178. if (prey.mass <= 0) {
  179. lines.push(this.describeFinish(prey));
  180. this.finish(prey);
  181. }
  182. }, this);
  183. this.contents = this.contents.filter(function(prey) {
  184. return prey.mass > 0;
  185. });
  186. return lines;
  187. }
  188. feed(prey) {
  189. this.contents.push(prey);
  190. }
  191. fullness() {
  192. return this.contents.reduce((total, prey) => total + prey.mass, 0);
  193. }
  194. }
  195. class Stomach extends Container {
  196. constructor(owner,bowels) {
  197. super(owner);
  198. this.bowels = bowels;
  199. }
  200. describeDamage(prey) {
  201. return "Your guts gurgle and churn, slowly wearing down " + prey.description("the") + " trapped within.";
  202. }
  203. describeKill(prey) {
  204. return prey.description("The") + "'s struggles wane as your stomach overpowers them.";
  205. }
  206. describeFinish(prey) {
  207. return "Your churning guts have reduced " + prey.description("a") + " to meaty chyme.";
  208. }
  209. fill(amount) {
  210. this.bowels.add(amount);
  211. }
  212. finish(prey) {
  213. this.bowels.finish(prey);
  214. }
  215. }
  216. class Butt extends Container {
  217. constructor(owner, bowels, stomach) {
  218. super(owner);
  219. this.bowels = bowels;
  220. this.stomach = stomach;
  221. }
  222. digest(time) {
  223. this.contents.forEach(function (x) {
  224. x.timeInButt += time;
  225. });
  226. let lines = super.digest(time);
  227. let pushed = this.contents.filter(prey => prey.timeInButt >= 60 * 30);
  228. pushed.forEach(function(x) {
  229. this.stomach.feed(x);
  230. lines.push("Your winding guts squeeze " + x.description("the") + " into your stomach.");
  231. },this);
  232. this.contents = this.contents.filter(prey => prey.timeInButt < 60 * 30);
  233. return lines;
  234. }
  235. describeDamage(prey) {
  236. return "Your bowels gurgle and squeeze, working to wear down " + prey.description("the") + " trapped in those musky confines.";
  237. }
  238. describeKill(prey) {
  239. return prey.description("The") + " abruptly stops struggling, overpowered by your winding intestines.";
  240. }
  241. describeFinish(prey) {
  242. return "That delicious " + prey.description() + " didn't even make it to your stomach...now they're gone.";
  243. }
  244. feed(prey) {
  245. prey.timeInButt = 0;
  246. super.feed(prey);
  247. }
  248. fill(amount) {
  249. this.bowels.add(amount);
  250. }
  251. finish(prey) {
  252. this.bowels.finish(prey);
  253. }
  254. }
  255. function WasteContainer(name) {
  256. this.name = name;
  257. this.fullness = 0;
  258. this.contents = [];
  259. this.add = function(amount) {
  260. this.fullness += amount;
  261. };
  262. this.finish = function(prey) {
  263. if (prey.prefs.scat)
  264. this.contents.push(prey);
  265. };
  266. }
  267. function Bowels() {
  268. WasteContainer.call(this, "Bowels");
  269. }
  270. // PLAYER PREY
  271. function plead(predator) {
  272. return {
  273. name: "Plead",
  274. desc: "Ask very, very nicely for the predator to let you go. More effective if you haven't hurt your predator.",
  275. struggle: function(player) {
  276. let escape = Math.random() < predator.health / predator.maxHealth && Math.random() < 0.33;
  277. if (player.health <= 0) {
  278. escape = escape && Math.random() < 0.25;
  279. }
  280. if (escape) {
  281. player.clear();
  282. predator.clear();
  283. return {
  284. "escape": "escape",
  285. "lines": ["You plead for " + predator.description("the") + " to let you free, and they begrudingly agree, horking you up and leaving you shivering on the ground"]
  286. };
  287. } else {
  288. return {
  289. "escape": "stuck",
  290. "lines": ["You plead with " + predator.description("the") + " to let you go, but they refuse."]
  291. };
  292. }
  293. }
  294. };
  295. }
  296. function struggle(predator) {
  297. return {
  298. name: "Struggle",
  299. desc: "Try to squirm free. More effective if you've hurt your predator.",
  300. struggle: function(player) {
  301. let escape = Math.random() > predator.health / predator.maxHealth && Math.random() < 0.33;
  302. if (player.health <= 0 || player.stamina <= 0) {
  303. escape = escape && Math.random() < 0.25;
  304. }
  305. if (escape) {
  306. player.clear();
  307. predator.clear();
  308. return {
  309. "escape": "escape",
  310. "lines": ["You struggle and squirm, forcing " + predator.description("the") + " to hork you up. They groan and stumble away, exhausted by your efforts."]
  311. };
  312. } else {
  313. return {
  314. "escape": "stuck",
  315. "lines": ["You squirm and writhe within " + predator.description("the") + " to no avail."]
  316. };
  317. }
  318. }
  319. };
  320. }
  321. function struggleStay(predator) {
  322. return {
  323. name: "Struggle",
  324. desc: "Try to squirm free. More effective if you've hurt your predator.",
  325. struggle: function(player) {
  326. let escape = Math.random() > predator.health / predator.maxHealth && Math.random() < 0.33;
  327. if (player.health <= 0 || player.stamina <= 0) {
  328. escape = escape && Math.random() < 0.25;
  329. }
  330. if (escape) {
  331. player.clear();
  332. predator.clear();
  333. return {
  334. "escape": "stay",
  335. "lines": ["You struggle and squirm, forcing " + predator.description("the") + " to hork you up. They're not done with you yet..."]
  336. };
  337. } else {
  338. return {
  339. "escape": "stuck",
  340. "lines": ["You squirm and writhe within " + predator.description("the") + " to no avail."]
  341. };
  342. }
  343. }
  344. };
  345. }
  346. function rub(predator) {
  347. return {
  348. name: "Rub",
  349. desc: "Rub rub rub",
  350. struggle: function(player) {
  351. return {
  352. "escape": "stuck",
  353. "lines": ["You rub the walls of your predator's belly. At least " + predator.description("the") + " is getting something out of this."]
  354. };
  355. }
  356. };
  357. }