Fix removing wrong item when eating
This commit is contained in:
parent
248b211708
commit
1f8ef214e3
|
@ -13,26 +13,28 @@ export const eat = new Command(
|
||||||
async ({ id, command, args, prefix, part, user }) => {
|
async ({ id, command, args, prefix, part, user }) => {
|
||||||
const eating = args[0];
|
const eating = args[0];
|
||||||
if (!eating) return `What do you want to ${prefix}eat?`;
|
if (!eating) return `What do you want to ${prefix}eat?`;
|
||||||
|
|
||||||
const inventory = await getInventory(user.inventoryId);
|
const inventory = await getInventory(user.inventoryId);
|
||||||
if (!inventory) return;
|
if (!inventory) return;
|
||||||
|
|
||||||
let foundObject: IObject | undefined;
|
let foundObject: IObject | undefined;
|
||||||
let tryChangingColor = false;
|
let tryChangingColor = false;
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
for (const item of inventory.items as unknown as IItem[]) {
|
for (const item of inventory.items as unknown as IItem[]) {
|
||||||
if (!item.name.toLowerCase().includes(eating.toLowerCase()))
|
if (!item.name.toLowerCase().includes(eating.toLowerCase())) {
|
||||||
|
i++;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
foundObject = item;
|
foundObject = item;
|
||||||
|
|
||||||
let shouldRemove = false;
|
let shouldRemove = false;
|
||||||
|
|
||||||
if (item.count) {
|
if (typeof item.count !== "undefined") {
|
||||||
if (item.count > 1) {
|
if (item.count > 1) {
|
||||||
shouldRemove = false;
|
shouldRemove = false;
|
||||||
((inventory.items as unknown as IItem[])[
|
((inventory.items as TInventoryItems)[i].count as number)--;
|
||||||
(inventory.items as unknown as IItem[]).indexOf(item)
|
|
||||||
].count as number)--;
|
|
||||||
} else {
|
} else {
|
||||||
shouldRemove = true;
|
shouldRemove = true;
|
||||||
}
|
}
|
||||||
|
@ -40,29 +42,26 @@ export const eat = new Command(
|
||||||
shouldRemove = true;
|
shouldRemove = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRemove)
|
if (shouldRemove) (inventory.items as TInventoryItems).splice(i, 1);
|
||||||
(inventory.items as unknown as IItem[]).splice(
|
|
||||||
(inventory.items as unknown as IItem[]).indexOf(item, 1)
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const pokemon of inventory.pokemon as unknown as IPokemon[]) {
|
i = 0;
|
||||||
if (!pokemon.name.toLowerCase().includes(eating.toLowerCase()))
|
|
||||||
|
for (const pokemon of inventory.pokemon as TPokemonSack) {
|
||||||
|
if (!pokemon.name.toLowerCase().includes(eating.toLowerCase())) {
|
||||||
|
i++;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
foundObject = pokemon as unknown as IObject;
|
foundObject = pokemon as unknown as IObject;
|
||||||
|
|
||||||
let shouldRemove = false;
|
let shouldRemove = false;
|
||||||
|
|
||||||
if (pokemon.count) {
|
if (typeof pokemon.count !== "undefined") {
|
||||||
if (pokemon.count > 1) {
|
if (pokemon.count > 1) {
|
||||||
shouldRemove = false;
|
shouldRemove = false;
|
||||||
((inventory.pokemon as unknown as IPokemon[])[
|
((inventory.pokemon as TPokemonSack)[i].count as number)--;
|
||||||
(inventory.pokemon as unknown as IPokemon[]).indexOf(
|
|
||||||
pokemon
|
|
||||||
)
|
|
||||||
].count as number)--;
|
|
||||||
} else {
|
} else {
|
||||||
shouldRemove = true;
|
shouldRemove = true;
|
||||||
}
|
}
|
||||||
|
@ -70,30 +69,26 @@ export const eat = new Command(
|
||||||
shouldRemove = true;
|
shouldRemove = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRemove)
|
if (shouldRemove) (inventory.pokemon as TPokemonSack).splice(i, 1);
|
||||||
(inventory.pokemon as unknown as IPokemon[]).splice(
|
|
||||||
(inventory.pokemon as unknown as IPokemon[]).indexOf(
|
|
||||||
pokemon,
|
|
||||||
1
|
|
||||||
)
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const fish of inventory.fishSack as unknown as IFish[]) {
|
i = 0;
|
||||||
if (!fish.name.toLowerCase().includes(eating.toLowerCase()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
foundObject = fish as unknown as IObject;
|
for (const fish of inventory.fishSack as TFishSack) {
|
||||||
|
if (!fish.name.toLowerCase().includes(eating.toLowerCase())) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foundObject = fish;
|
||||||
|
|
||||||
let shouldRemove = false;
|
let shouldRemove = false;
|
||||||
|
|
||||||
if (fish.count) {
|
if (typeof fish.count !== "undefined") {
|
||||||
if (fish.count > 1) {
|
if (fish.count > 1) {
|
||||||
shouldRemove = false;
|
shouldRemove = false;
|
||||||
((inventory.fishSack as unknown as IFish[])[
|
((inventory.fishSack as TFishSack)[i].count as number)--;
|
||||||
(inventory.fishSack as unknown as IFish[]).indexOf(fish)
|
|
||||||
].count as number)--;
|
|
||||||
} else {
|
} else {
|
||||||
shouldRemove = true;
|
shouldRemove = true;
|
||||||
}
|
}
|
||||||
|
@ -101,10 +96,7 @@ export const eat = new Command(
|
||||||
shouldRemove = true;
|
shouldRemove = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRemove)
|
if (shouldRemove) (inventory.fishSack as TFishSack).splice(i, 1);
|
||||||
(inventory.fishSack as unknown as IFish[]).splice(
|
|
||||||
(inventory.fishSack as unknown as IFish[]).indexOf(fish, 1)
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,11 +129,11 @@ export const eat = new Command(
|
||||||
color: color.toHexa()
|
color: color.toHexa()
|
||||||
});
|
});
|
||||||
|
|
||||||
return `Our friend ${part.name} at his/her ${
|
return `Our friend ${part.name} ate his/her ${
|
||||||
foundObject.name
|
foundObject.name
|
||||||
} and it made him/her turn ${color.getName().toLowerCase()}.`;
|
} and it made him/her turn ${color.getName().toLowerCase()}.`;
|
||||||
} else {
|
} else {
|
||||||
return `Our friend ${part.name} at his/her ${foundObject.name}.`;
|
return `Our friend ${part.name} ate his/her ${foundObject.name}.`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue