summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-11-24 20:40:33 +0300
committerAndrei Karas <akaras@inbox.ru>2018-12-12 21:18:06 +0300
commit2d33d766bd7ea81eb40c15fe45d59ab155b16fde (patch)
tree962849821b8f1bd7b62c4209756005ef7f903ce3 /src/map/script.c
parentc76f8ded8743966abe10a15a3a03604d76d2d5df (diff)
downloadhercules-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/script.c')
-rw-r--r--src/map/script.c51
1 files changed, 51 insertions, 0 deletions
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