Add the stockall command (#8008)

* The command will transfer all items from the cart to the inventory based on the item type.
This commit is contained in:
AshiHanna
2023-12-12 21:12:06 +08:00
committed by GitHub
parent 53f1c5bb80
commit a7f0aab600
6 changed files with 94 additions and 5 deletions

View File

@@ -5960,6 +5960,62 @@ ACMD_FUNC(dropall)
return 0;
}
/*==========================================
* @stockall by [Hanashi]
* transfer items from cart to inventory
*------------------------------------------*/
ACMD_FUNC(stockall)
{
nullpo_retr(-1, sd);
if (!pc_iscarton(sd)) {
clif_displaymessage(fd, msg_txt(sd,1533)); // You do not have a cart.
return -1;
}
int8 type = -1;
if ( message[0] ) {
type = atoi(message);
switch (type) {
case -1:
case IT_HEALING:
case IT_USABLE:
case IT_ETC:
case IT_WEAPON:
case IT_ARMOR:
case IT_CARD:
case IT_PETEGG:
case IT_PETARMOR:
case IT_AMMO:
break;
default:
clif_displaymessage(fd, msg_txt(sd, 1534)); // Usage: @stockall {<type>}
clif_displaymessage(fd, msg_txt(sd, 1493)); // Type List: (default) all = -1, healing = 0, usable = 2, etc = 3, armor = 4, weapon = 5, card = 6, petegg = 7, petarmor = 8, ammo = 10
return -1;
}
}
uint16 count = 0, count2 = 0;
for ( uint16 i = 0; i < MAX_CART; i++ ) {
if ( sd->cart.u.items_cart[i].amount > 0 ) {
std::shared_ptr<item_data> id = item_db.find(sd->cart.u.items_cart[i].nameid);
if ( id == nullptr ) {
ShowDebug("Non-existent item %u on stockall list (account_id: %d, char_id: %d)\n", sd->cart.u.items_cart[i].nameid, sd->status.account_id, sd->status.char_id);
continue;
}
if ( type == -1 || static_cast<item_types>(type) == id->type ) {
if (pc_getitemfromcart(sd, i, sd->cart.u.items_cart[i].amount))
count += sd->cart.u.items_cart[i].amount;
else
count2 += sd->cart.u.items_cart[i].amount;
}
}
}
sprintf(atcmd_output, msg_txt(sd,1535), count,count2); // %d items are transferred (%d skipped)!
clif_displaymessage(fd, atcmd_output);
return 0;
}
/*==========================================
* @storeall by [MouseJstr]
* Put everything into storage
@@ -11078,6 +11134,7 @@ void atcommand_basecommands(void) {
ACMD_DEF(npcmove),
ACMD_DEF(killable),
ACMD_DEF(dropall),
ACMD_DEF(stockall),
ACMD_DEF(storeall),
ACMD_DEF(skillid),
ACMD_DEF(useskill),