From 2d33d766bd7ea81eb40c15fe45d59ab155b16fde Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 24 Nov 2018 20:40:33 +0300 Subject: Add script command for insert cards into equipped items. enchantitem(, , ) --- src/map/clif.c | 9 ++++++--- src/map/clif.h | 2 +- src/map/script.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/map/clif.c b/src/map/clif.c index 00d3d8908..4d298f520 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -21992,17 +21992,20 @@ static void clif_item_preview(struct map_session_data *sd, int n) } // insert cardId into equipped item in pos equipment slot into slot cardSlot. -static void clif_enchant_equipment(struct map_session_data *sd, enum equip_pos pos, int cardSlot, int cardId) +static bool clif_enchant_equipment(struct map_session_data *sd, enum equip_pos pos, int cardSlot, int cardId) { #if PACKETVER_MAIN_NUM >= 20160831 || PACKETVER_RE_NUM >= 20151118 || defined(PACKETVER_ZERO) - nullpo_retv(sd); - Assert_retv(cardSlot >= 0 && cardSlot <= 3); + nullpo_ret(sd); + Assert_ret(cardSlot >= 0 && cardSlot < MAX_SLOTS); struct PACKET_ZC_ENCHANT_EQUIPMENT p; p.packetType = HEADER_ZC_ENCHANT_EQUIPMENT; p.wearState = pos; p.cardSlot = cardSlot; p.itemId = cardId; clif->send(&p, sizeof(p), &sd->bl, SELF); + return true; +#else + return false; #endif } diff --git a/src/map/clif.h b/src/map/clif.h index 088e7827e..2aab4c227 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -1554,7 +1554,7 @@ struct clif_interface { void (*camera_showWindow) (struct map_session_data *sd); void (*camera_change) (struct map_session_data *sd, float range, float rotation, float latitude, enum send_target target); void (*item_preview) (struct map_session_data *sd, int n); - void (*enchant_equipment) (struct map_session_data *sd, enum equip_pos pos, int cardSlot, int cardId); + bool (*enchant_equipment) (struct map_session_data *sd, enum equip_pos pos, int cardSlot, int cardId); }; #ifdef HERCULES_CORE diff --git a/src/map/script.c b/src/map/script.c index 41f21cd72..4760fd4a0 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -24790,6 +24790,56 @@ static BUILDIN(itempreview) return true; } +// insert or remove card into equipped item +static BUILDIN(enchantitem) +{ + struct map_session_data *sd = script_rid2sd(st); + if (sd == NULL) + return false; + const int pos = script_getnum(st, 2); + if ((pos < EQI_ACC_L || pos > EQI_HAND_R) && pos != EQI_AMMO) { + ShowError("Wrong equip position: %d\n", pos); + script->reportfunc(st); + script->reportsrc(st); + script_pushint(st, false); + return true; + } + const int cardId = script_getnum(st, 4); + struct item_data *it = itemdb->exists(cardId); + if (it == NULL || it->type != IT_CARD) { + ShowError("Item id is not card or not exists: %d\n", cardId); + script->reportfunc(st); + script->reportsrc(st); + script_pushint(st, false); + return true; + } + const int n = sd->equip_index[pos]; + if (n < 0) { + ShowError("Item in equipment slot %d is not equipped\n", pos); + script->reportfunc(st); + script->reportsrc(st); + script_pushint(st, false); + return true; + } + const int cardSlot = script_getnum(st, 3); + if (cardSlot < 0 || cardSlot >= MAX_SLOTS) { + ShowError("Wrong card slot %d. Must be in range 0-3.\n", cardSlot); + script->reportfunc(st); + script->reportsrc(st); + script_pushint(st, false); + return true; + } + const bool res = clif->enchant_equipment(sd, pc->equip_pos[pos], cardSlot, cardId); + if (res) { + logs->pick_pc(sd, LOG_TYPE_CARD, -1, &sd->status.inventory[n],sd->inventory_data[n]); + sd->status.inventory[n].card[cardSlot] = cardId; + logs->pick_pc(sd, LOG_TYPE_CARD, 1, &sd->status.inventory[n],sd->inventory_data[n]); + status_calc_pc(sd, SCO_NONE); + } + script_pushint(st, res); + return true; +} + /** * Adds a built-in script function. * @@ -25528,6 +25578,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(changecamera, "iii?"), BUILDIN_DEF(itempreview, "i"), + BUILDIN_DEF(enchantitem, "iii"), }; int i, len = ARRAYLENGTH(BUILDIN); RECREATE(script->buildin, char *, script->buildin_count + len); // Pre-alloc to speed up -- cgit v1.2.3-60-g2f50