From d4d7f86d150e1acb49d8aeec5ae61e0ed5676beb Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Wed, 14 Mar 2018 11:03:13 -0400 Subject: [PATCH] Added weights for basic enemy attacks. Fixed the pick() function not taking the attacker and defender --- combat.js | 5 ++++- feast.js | 12 +++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/combat.js b/combat.js index 118615d..254247a 100644 --- a/combat.js +++ b/combat.js @@ -42,6 +42,7 @@ function punchAttack(attacker) { function(attacker, defender) { return isNormal(attacker) && isNormal(defender); } ], priority: 1, + weight: function(attacker, defender) { return defender.health / defender.maxHealth; } }; } @@ -58,6 +59,7 @@ function flankAttack(attacker) { function(attacker, defender) { return isNormal(attacker) && isNormal(defender); } ], priority: 1, + weight: function(attacker, defender) { return defender.health / defender.maxHealth; } }; } @@ -87,6 +89,7 @@ function grapple(attacker) { function(attacker, defender) { return isNormal(attacker) && isNormal(defender); } ], priority: 1, + weight: function(attacker, defender) { return 1 - defender.health / defender.maxHealth; } }; } @@ -295,6 +298,6 @@ function instakillPlayerStomach(pedator) { return "The stomach walls churn, clench, and swiftly crush you into nothingnes."; }, priority: 1, - weight: function(attacker, defender) { return 1/3 }, + weight: function(attacker, defender) { return 1/3; }, }; } diff --git a/feast.js b/feast.js index 9687a31..3bd0333 100644 --- a/feast.js +++ b/feast.js @@ -21,16 +21,16 @@ let prefs = { } }; -function pick(list) { +function pick(list, attacker, defender) { if (list.length == 0) return null; else { - let sum = list.reduce((sum, choice) => choice.weight == undefined ? 1 : choice.weight() + sum, 0); + let sum = list.reduce((sum, choice) => choice.weight == undefined ? 1 : choice.weight(attacker, defender) + sum, 0); let target = Math.random() * sum; for (let i = 0; i < list.length; i++) { - sum -= list[i].weight == undefined ? 1 : list[i].weight(); + sum -= list[i].weight == undefined ? 1 : list[i].weight(attacker, defender); if (sum <= target) { return list[i]; } @@ -341,6 +341,8 @@ function changeMode(newMode) { function respawn(respawnRoom) { moveTo(respawnRoom,"You drift through space and time..."); + player.stomach.contents = []; + player.butt.contents = []; advanceTime(86400/2); changeMode("explore"); player.health = 100; @@ -360,7 +362,7 @@ function attackClicked(index) { update(["The " + currentFoe.description() + " falls to the ground!"]); startDialog(new FallenFoe(currentFoe)); } else if (mode == "combat") { - let attack = pick(filterPriority(filterValid(currentFoe.attacks, currentFoe, player))); + let attack = pick(filterPriority(filterValid(currentFoe.attacks, currentFoe, player)), currentFoe, player); if (attack == null) { attack = currentFoe.backupAttack; @@ -393,7 +395,7 @@ function struggleClicked(index) { if (result.escape) { changeMode("explore"); } else { - let digest = pick(filterValid(currentFoe.digests, currentFoe, player)); + let digest = pick(filterValid(currentFoe.digests, currentFoe, player), currentFoe, player); if (digest == null) { digest = currentFoe.backupDigest;