diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-11-24 20:40:33 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-12-12 21:18:06 +0300 |
commit | 2d33d766bd7ea81eb40c15fe45d59ab155b16fde (patch) | |
tree | 962849821b8f1bd7b62c4209756005ef7f903ce3 /src/map | |
parent | c76f8ded8743966abe10a15a3a03604d76d2d5df (diff) | |
download | hercules-2d33d766bd7ea81eb40c15fe45d59ab155b16fde.tar.gz hercules-2d33d766bd7ea81eb40c15fe45d59ab155b16fde.tar.bz2 hercules-2d33d766bd7ea81eb40c15fe45d59ab155b16fde.tar.xz hercules-2d33d766bd7ea81eb40c15fe45d59ab155b16fde.zip |
Add script command for insert cards into equipped items.
enchantitem(<equip_pos>, <card_slot>, <card_id>)
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/clif.c | 9 | ||||
-rw-r--r-- | src/map/clif.h | 2 | ||||
-rw-r--r-- | src/map/script.c | 51 |
3 files changed, 58 insertions, 4 deletions
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 |