From aa8f501388cd8947b549fe9816df83ccda67052d Mon Sep 17 00:00:00 2001 From: Atemo Date: Thu, 8 Jun 2023 20:08:26 +0200 Subject: [PATCH] Added atcommand "setcard" (#7804) Thanks to @aleos89 and @Lemongrass3110 ! --- conf/atcommands.yml | 3 ++ conf/msg_conf/map_msg.conf | 8 ++++ doc/atcommands.txt | 21 +++++++++++ src/map/atcommand.cpp | 76 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) diff --git a/conf/atcommands.yml b/conf/atcommands.yml index 732935d27a..76b2fba84a 100644 --- a/conf/atcommands.yml +++ b/conf/atcommands.yml @@ -1019,6 +1019,9 @@ Body: - Command: roulette Help: | Opens the roulette UI. + - Command: setcard + Help: | + Adds a card or enchant to the specific slot of the equipment. Footer: Imports: diff --git a/conf/msg_conf/map_msg.conf b/conf/msg_conf/map_msg.conf index 12638d542d..49e09c276d 100644 --- a/conf/msg_conf/map_msg.conf +++ b/conf/msg_conf/map_msg.conf @@ -1807,5 +1807,13 @@ 1525: %d: Shadow Right Accessory 1526: %d: Shadow Left Accessory +// @setcard +1527: Please enter the position, the slot number and the card ID (usage: @setcard ). +1528: You are not wearing any equipment in this position. +1529: The item type must be a card or enchant. +1530: Invalid card ID. +1531: Invalid position. +1532: Invalid slot number. + //Custom translations import: conf/msg_conf/import/map_msg_eng_conf.txt diff --git a/doc/atcommands.txt b/doc/atcommands.txt index 7678f3c948..08901dd757 100644 --- a/doc/atcommands.txt +++ b/doc/atcommands.txt @@ -1207,6 +1207,27 @@ Opens the enchantgrade UI. --------------------------------------- +@setcard + +Adds a card or enchant to the specific slot of the equipment. + +: +1: Lower Headgear +2: Right Hand +4: Garment +8: Left Accessory +16: Body Armor +32: Left Hand +64: Shoes +128: Right Accessory +256: Top Headgear +512: Mid Headgear + + number: 0-3. +: Can actually be any existing card or enchant item. Put 0 to remove it. + +--------------------------------------- + ============================== | 5. Administrative Commands | ============================== diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 20b970e4f5..7bd0e3a2d0 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -10836,6 +10836,81 @@ ACMD_FUNC( roulette ){ #endif } +/** + * Replaces a card ID in an equip + * Usage: @setcard + */ +ACMD_FUNC(setcard) +{ + nullpo_retr(-1, sd); + + int position = 0, slot, card_id; + + if (!message || !*message || sscanf(message, "%11d %11d %11d", &position, &slot, &card_id) < 3) { + memset(atcmd_output, '\0', sizeof(atcmd_output)); + + clif_displaymessage(fd, msg_txt(sd,1527)); // Please enter the position, the slot number and the card ID (usage: @setcard ). + sprintf(atcmd_output, msg_txt(sd,997), EQP_HEAD_LOW); // %d: Lower Headgear + clif_displaymessage(fd, atcmd_output); + sprintf(atcmd_output, msg_txt(sd,998), EQP_HAND_R); // %d: Right Hand + clif_displaymessage(fd, atcmd_output); + sprintf(atcmd_output, msg_txt(sd,999), EQP_GARMENT); // %d: Garment + clif_displaymessage(fd, atcmd_output); + sprintf(atcmd_output, msg_txt(sd,1000), EQP_ACC_L); // %d: Left Accessory + clif_displaymessage(fd, atcmd_output); + sprintf(atcmd_output, msg_txt(sd,1001), EQP_ARMOR); // %d: Body Armor + clif_displaymessage(fd, atcmd_output); + sprintf(atcmd_output, msg_txt(sd,1002), EQP_HAND_L); // %d: Left Hand + clif_displaymessage(fd, atcmd_output); + sprintf(atcmd_output, msg_txt(sd,1003), EQP_SHOES); // %d: Shoes + clif_displaymessage(fd, atcmd_output); + sprintf(atcmd_output, msg_txt(sd,1004), EQP_ACC_R); // %d: Right Accessory + clif_displaymessage(fd, atcmd_output); + sprintf(atcmd_output, msg_txt(sd,1005), EQP_HEAD_TOP); // %d: Top Headgear + clif_displaymessage(fd, atcmd_output); + sprintf(atcmd_output, msg_txt(sd,1006), EQP_HEAD_MID); // %d: Mid Headgear + return -1; + } + if (position < EQP_HEAD_LOW || position > EQP_HEAD_MID) { + clif_displaymessage(fd, msg_txt(sd,1531)); // Invalid position. + return -1; + } + if (slot < 0 || slot >= MAX_SLOTS) { + clif_displaymessage(fd, msg_txt(sd,1532)); // Invalid slot number. + return -1; + } + if (card_id != 0) { + std::shared_ptr item_data = item_db.find( card_id ); + + if (item_data == nullptr) { + clif_displaymessage(fd, msg_txt(sd,1530)); // Invalid card ID. + return -1; + } + if (item_data->type != IT_CARD) { + clif_displaymessage(fd, msg_txt(sd,1529)); // The item type must be a card or enchant. + return -1; + } + } + + int16 i = pc_checkequip(sd, position); + + if (i < 0) { + clif_displaymessage(fd, msg_txt(sd,1528)); // You are not wearing any equipment in this position. + return -1; + } + + int current_position = sd->inventory.u.items_inventory[i].equip; + + pc_unequipitem(sd, i, 3); + log_pick_pc( sd, LOG_TYPE_COMMAND, -1, &sd->inventory.u.items_inventory[i] ); + sd->inventory.u.items_inventory[i].card[slot] = card_id; + log_pick_pc( sd, LOG_TYPE_COMMAND, 1, &sd->inventory.u.items_inventory[i] ); + clif_delitem(sd, i, 1, 0); + clif_additem(sd, i, 1, 0); + pc_equipitem(sd, i, current_position); + return 0; +} + #include /** @@ -11162,6 +11237,7 @@ void atcommand_basecommands(void) { ACMD_DEF(addfame), ACMD_DEFR(enchantgradeui, ATCMD_NOCONSOLE|ATCMD_NOAUTOTRADE), ACMD_DEFR(roulette, ATCMD_NOCONSOLE|ATCMD_NOAUTOTRADE), + ACMD_DEF(setcard), }; AtCommandInfo* atcommand; int i;