search for items with consume skill if no item provided

switch snowball to use consume as well
This commit is contained in:
Kent Rasmussen
2023-11-22 13:08:07 +09:00
parent 791e7851c6
commit a280356db4
2 changed files with 19 additions and 24 deletions
+1 -1
View File
@@ -145,7 +145,7 @@ skills={
"snowball":{
"type":"skill",
"skin":"snowball",
"inventory":["snowball"],
"consume":"snowball",
"name":"Snowball",
"explanation":"Throw a snowball at someone!",
"condition":"frozen",
+18 -23
View File
@@ -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);