diff --git a/design/skills.py b/design/skills.py index 9e44276..f5c6626 100644 --- a/design/skills.py +++ b/design/skills.py @@ -145,7 +145,7 @@ skills={ "snowball":{ "type":"skill", "skin":"snowball", - "inventory":["snowball"], + "consume":"snowball", "name":"Snowball", "explanation":"Throw a snowball at someone!", "condition":"frozen", diff --git a/node/server.js b/node/server.js index 3866d41..f6ba695 100644 --- a/node/server.js +++ b/node/server.js @@ -8216,14 +8216,27 @@ function init_io() { // Consume item check if (gSkill.consume) { - const item = player.items[data.num] + let item; + if(data.num === undefined || data.num === null) { + // No item was provided, search for one + for (let i = player.isize - 1; i >= 0; i--) { + const potentialItem = player.items[i] + if(!potentialItem) continue + if(potentialItem.name !== gSkill.consume) continue + + // We found the item + data.num = i + item = potentialItem + break + } + } else { + item = player.items[data.num] + } if (!item || item.name != gSkill.consume) { return fail_response("skill_cant_item", data.name); } } - // TODO: Can we consume_mp here? - if ([ "attack", "heal", @@ -8237,7 +8250,8 @@ function init_io() { "zapperzap", "burst", "piercingshot", - "selfheal" + "selfheal", + "snowball" ].includes(data.name)) { const attack = commence_attack(player, target, data.name); if (!attack.failed) { @@ -8434,25 +8448,6 @@ function init_io() { reject = attack; cool = false; } - } else if (data.name == "snowball") { - let found = false; - for (let i = player.isize - 1; i >= 0; i--) { - if (player.items[i] && player.items[i].name == "snowball") { - consume_one(player, i); - found = true; - break; - } - } - if (!found) { - return fail_response("skill_cant_item", data.name); - } - const attack = commence_attack(player, target, "snowball"); - if (!attack.failed) { - resolve = attack; - } else { - reject = attack; - cool = false; - } } else if (data.name == "entangle" || data.name == "tangle") { if (target.s.invincible) { return fail_response("target_invincible", data.name);