From 2bddf4bb26fa224fd1a72b6ae1391095df7194ae Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Mon, 12 Mar 2018 23:44:16 -0400 Subject: [PATCH] Healing over time happens on the creature side. Added priority for attacks --- combat.js | 36 ++++++++++++++++++++++++------------ feast.js | 10 ++++++++-- vore.js | 12 ++++++++++++ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/combat.js b/combat.js index cb44b69..7f607a6 100644 --- a/combat.js +++ b/combat.js @@ -25,7 +25,8 @@ function punchAttack(attacker) { return "The " + attacker.description() + " punches you for " + attack(attacker, defender, attacker.str) + " damage"; }, requirements: [ function(attacker, defender) { return isNormal(attacker) && isNormal(defender); } - ] + ], + priority: 1, }; } @@ -40,7 +41,8 @@ function flankAttack(attacker) { return "The " + attacker.description() + " runs past you, then turns and hits you for " + attack(attacker, defender, attacker.str) + " damage"; }, requirements: [ function(attacker, defender) { return isNormal(attacker) && isNormal(defender); } - ] + ], + priority: 1, }; } @@ -68,7 +70,8 @@ function grapple(attacker) { }, requirements: [ function(attacker, defender) { return isNormal(attacker) && isNormal(defender); } - ] + ], + priority: 1, }; } @@ -100,7 +103,8 @@ function grappleDevour(attacker) { function(attacker, defender) { return isNormal(attacker) && isGrappled(defender); } ], conditions: [ function(prefs, player=false) { return player || prefs.player.prey; } - ] + ], + priority: 1, }; } @@ -122,7 +126,8 @@ function grappleAnalVore(attacker) { function(attacker, defender) { return isNormal(attacker) && isGrappled(defender); } ], conditions: [ function(prefs, player=false) { return player || prefs.player.prey; } - ] + ], + priority: 1, }; } @@ -135,7 +140,8 @@ function grappleRelease(attacker) { return "You throw the " + defender.description() + " back, dealing " + attack(attacker, defender, attacker.str*1.5) + " damage"; }, requirements: [ function(attacker, defender) { return isNormal(attacker) && isGrappled(defender); } - ] + ], + priority: 1, }; } @@ -163,7 +169,8 @@ function grappledStruggle(attacker) { }, requirements: [ function(attacker, defender) { return isGrappled(attacker) && isNormal(defender); } - ] + ], + priority: 1, }; } @@ -176,7 +183,8 @@ function pass(attacker) { }, attackPlayer: function(defender) { return "The " + attacker.description() + " does nothing."; - } + }, + priority: 0, }; } @@ -193,7 +201,8 @@ function devourPlayer(attacker) { attackPlayer: function(defender) { changeMode("eaten"); return "The voracious " + attacker.description() + " pins you down and devours you in seconds."; - } + }, + priority: 1, }; } @@ -207,7 +216,8 @@ function leer(attacker) { }, requirements: [ function(attacker, defender) { return attacker.leering != true && attacker.grappled != true; } - ] + ], + priority: 1, }; } @@ -217,7 +227,8 @@ function poke(attacker) { desc: "Poke a nerd", attackPlayer: function(defender) { return "The " + attacker.description() + " pokes you on the snout for " + attack(attacker, defender, 1e12) + " damage"; - } + }, + priority: 1, }; } @@ -226,6 +237,7 @@ function digestPlayerStomach(predator,damage=20) { digest: function(player) { attack(predator, player, damage); return "The " + predator.description() + "'s stomach grinds over your body, swiftly digesting you."; - } + }, + priority: 1, }; } diff --git a/feast.js b/feast.js index 7248ffb..d09cb5f 100644 --- a/feast.js +++ b/feast.js @@ -26,6 +26,11 @@ function filterValid(options, attacker, defender) { return filtered.filter(option => option.requirements == undefined || option.requirements.reduce((result, test) => result && test(attacker, defender), true)); } +function filterPriority(options) { + let max = options.reduce((max, option) => option.priority > max ? option.priority : max, -1000); + return options.filter(option => option.priority == max); +} + function round(number, digits) { return Math.round(number * Math.pow(10,digits)) / Math.pow(10,digits); } @@ -171,7 +176,8 @@ function updateDisplay() { function advanceTime(amount) { time = (time + amount) % 86400; - player.health = Math.min(amount * player.maxHealth / 86400 * 12 + player.health, player.maxHealth); + player.restoreHealth(amount); + player.restoreStamina(amount); update(player.stomach.digest(amount)); update(player.butt.digest(amount)); } @@ -335,7 +341,7 @@ function attackClicked(index) { update(["The " + currentFoe.description() + " falls to the ground!"]); startDialog(new FallenFoe(currentFoe)); } else if (mode == "combat") { - let attack = pick(filterValid(currentFoe.attacks, currentFoe, player)); + let attack = pick(filterPriority(filterValid(currentFoe.attacks, currentFoe, player))); if (attack == null) { attack = currentFoe.backupAttack; diff --git a/vore.js b/vore.js index 2db2abd..6719c5a 100644 --- a/vore.js +++ b/vore.js @@ -24,6 +24,18 @@ function Creature(name = "Creature", str=10, dex=10, con=10) { this.health = this.maxHealth; Object.defineProperty(this, "maxStamina", {get: function() { return this.dex * 5 + this.con * 10 }}); this.stamina = this.maxStamina; + + // fraction of max health per second + this.healthRate = 1 / 86400 * 12; + this.staminaRate = 1 / 86400 * 48; + + this.restoreHealth = function(time) { + this.health = Math.min(this.maxHealth, this.health + this.maxHealth * time * this.healthRate); + }; + + this.restoreStamina = function(time) { + this.stamina = Math.min(this.maxStamina, this.stamina + this.maxStamina * time * this.staminaRate); + }; } function Player(name = "Player") {