From a7f0aab600e4cdee089160c4941cfc9a992d3e21 Mon Sep 17 00:00:00 2001 From: AshiHanna Date: Tue, 12 Dec 2023 21:12:06 +0800 Subject: [PATCH] Add the stockall command (#8008) * The command will transfer all items from the cart to the inventory based on the item type. --- conf/atcommands.yml | 4 +++ conf/msg_conf/map_msg.conf | 5 ++++ doc/atcommands.txt | 22 +++++++++++++++ src/map/atcommand.cpp | 57 ++++++++++++++++++++++++++++++++++++++ src/map/pc.cpp | 9 +++--- src/map/pc.hpp | 2 +- 6 files changed, 94 insertions(+), 5 deletions(-) diff --git a/conf/atcommands.yml b/conf/atcommands.yml index 806a8f3a1f..b6b65281f0 100644 --- a/conf/atcommands.yml +++ b/conf/atcommands.yml @@ -365,6 +365,10 @@ Body: Help: | Params: [] Throws all your possession on the ground. No type specified will drop all items. + - Command: stockall + Help: | + Params: [] + Transfer items from cart to your inventory. No type specified will transfer all items. - Command: storeall Help: | Puts all your possessions in storage. diff --git a/conf/msg_conf/map_msg.conf b/conf/msg_conf/map_msg.conf index 49e09c276d..c9eb476354 100644 --- a/conf/msg_conf/map_msg.conf +++ b/conf/msg_conf/map_msg.conf @@ -1815,5 +1815,10 @@ 1531: Invalid position. 1532: Invalid slot number. +//@stockall +1533: You do not have a cart. +1534: Usage: @stockall {} +1535: %d items are transferred (%d skipped)! + //Custom translations import: conf/msg_conf/import/map_msg_eng_conf.txt diff --git a/doc/atcommands.txt b/doc/atcommands.txt index 08901dd757..077c630735 100644 --- a/doc/atcommands.txt +++ b/doc/atcommands.txt @@ -780,6 +780,28 @@ To drop all weapons in inventory... --------------------------------------- +@stockall {} + +Transfer all items from cart to inventory based on the item type. + +Valid item types: + -1 = All (default) + 0 = Healing + 2 = Usable + 3 = Etc + 4 = Armors + 5 = Weapons + 6 = Cards + 7 = Pet Eggs + 8 = Pet Armors + 10 = Ammunition + +Example: +To transfer all weapons from cart to inventory... +@stockall 5 + +--------------------------------------- + @storeall Places all inventory and equipped items directly into your Kafra Storage. diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index ff5f07be77..87f5deb895 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -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 {} + 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 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(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), diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 9d04474852..00513d279e 100755 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -6567,17 +6567,17 @@ int pc_cartitem_amount(map_session_data* sd, int idx, int amount) /*========================================== * Retrieve an item at index idx from cart. *------------------------------------------*/ -void pc_getitemfromcart(map_session_data *sd,int idx,int amount) +bool pc_getitemfromcart(map_session_data *sd,int idx,int amount) { - nullpo_retv(sd); + nullpo_retr(1, sd); if (idx < 0 || idx >= MAX_CART) //Invalid index check [Skotlex] - return; + return false; struct item *item_data=&sd->cart.u.items_cart[idx]; if (item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending || sd->state.prevend) - return; + return false; enum e_additem_result flag = pc_additem(sd, item_data, amount, LOG_TYPE_NONE); @@ -6588,6 +6588,7 @@ void pc_getitemfromcart(map_session_data *sd,int idx,int amount) clif_additem(sd, idx, amount, flag); clif_cart_additem(sd, idx, amount); } + return true; } /*========================================== diff --git a/src/map/pc.hpp b/src/map/pc.hpp index c37cd4fb59..22e2c8a66c 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -1438,7 +1438,7 @@ int pc_getcash( map_session_data *sd, int cash, int points, e_log_pick_type type enum e_additem_result pc_cart_additem(map_session_data *sd,struct item *item_data,int amount,e_log_pick_type log_type); void pc_cart_delitem(map_session_data *sd,int n,int amount,int type,e_log_pick_type log_type); void pc_putitemtocart(map_session_data *sd,int idx,int amount); -void pc_getitemfromcart(map_session_data *sd,int idx,int amount); +bool pc_getitemfromcart(map_session_data *sd,int idx,int amount); int pc_cartitem_amount(map_session_data *sd,int idx,int amount); bool pc_takeitem(map_session_data *sd,struct flooritem_data *fitem);