diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-10-17 16:15:51 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-10-17 16:15:51 +0300 |
commit | 0e55e85e9e9a6a4028a29e8c214b69cbc3a54ffe (patch) | |
tree | 7e6205674b8baf6c8f450a747dadb3ac705ab04f /src/emap | |
parent | 6d6c12a1721f1432cb576606917dc68db2c9708b (diff) | |
download | evol-hercules-0e55e85e9e9a6a4028a29e8c214b69cbc3a54ffe.tar.gz evol-hercules-0e55e85e9e9a6a4028a29e8c214b69cbc3a54ffe.tar.bz2 evol-hercules-0e55e85e9e9a6a4028a29e8c214b69cbc3a54ffe.tar.xz evol-hercules-0e55e85e9e9a6a4028a29e8c214b69cbc3a54ffe.zip |
Add support for insert cards script.
Diffstat (limited to 'src/emap')
-rw-r--r-- | src/emap/data/itemd.c | 1 | ||||
-rw-r--r-- | src/emap/init.c | 2 | ||||
-rw-r--r-- | src/emap/itemdb.c | 4 | ||||
-rw-r--r-- | src/emap/pc.c | 31 | ||||
-rw-r--r-- | src/emap/pc.h | 4 | ||||
-rw-r--r-- | src/emap/script.c | 14 | ||||
-rw-r--r-- | src/emap/script.h | 1 | ||||
-rw-r--r-- | src/emap/struct/itemdext.h | 1 |
8 files changed, 58 insertions, 0 deletions
diff --git a/src/emap/data/itemd.c b/src/emap/data/itemd.c index a32c308..c5ae309 100644 --- a/src/emap/data/itemd.c +++ b/src/emap/data/itemd.c @@ -69,6 +69,7 @@ struct ItemdExt *itemd_create(void) data->charmItem = false; data->dropScript = NULL; data->takeScript = NULL; + data->insertScript = NULL; memset(&data->allowedCards, 0, sizeof(data->allowedCards)); return data; } diff --git a/src/emap/init.c b/src/emap/init.c index 19fbc10..08a0a4d 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -160,6 +160,7 @@ HPExport void plugin_init (void) addHookPre("pc->delitem", epc_delitem_pre); addHookPre("pc->dropitem", epc_dropitem_pre); addHookPre("pc->takeitem", epc_takeitem_pre); + addHookPre("pc->insert_card", epc_insert_card_pre); addHookPre("mob->deleteslave_sub", emob_deleteslave_sub); addHookPre("mob->read_db_additional_fields", emob_read_db_additional_fields); addHookPre("npc->parse_unknown_mapflag", enpc_parse_unknown_mapflag); @@ -224,6 +225,7 @@ HPExport void plugin_init (void) addHookPost("pc->dropitem", epc_dropitem_post); addHookPost("pc->takeitem", epc_takeitem_post); addHookPost("pc->can_insert_card_into", epc_can_insert_card_into_post); + addHookPost("pc->insert_card", epc_insert_card_post); langScriptId = script->add_str("Lang"); } diff --git a/src/emap/itemdb.c b/src/emap/itemdb.c index a689613..9b0aabb 100644 --- a/src/emap/itemdb.c +++ b/src/emap/itemdb.c @@ -98,6 +98,8 @@ void eitemdb_readdb_additional_fields(int *itemid, data->dropScript = *str ? script->parse(str, source, -item->nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS, NULL) : NULL; if (libconfig->setting_lookup_string(it, "OnTakeScript", &str)) data->takeScript = *str ? script->parse(str, source, -item->nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS, NULL) : NULL; + if (libconfig->setting_lookup_string(it, "OnInsertCardScript", &str)) + data->insertScript = *str ? script->parse(str, source, -item->nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS, NULL) : NULL; config_setting_t *group = libconfig->setting_get_member(it, "AllowCards"); if (group) @@ -138,4 +140,6 @@ void edestroy_item_data(struct item_data* self, int *free_selfPtr) script->free_code(data->dropScript); if (data->takeScript) script->free_code(data->takeScript); + if (data->insertScript) + script->free_code(data->insertScript); } diff --git a/src/emap/pc.c b/src/emap/pc.c index 705c3dc..9e599ee 100644 --- a/src/emap/pc.c +++ b/src/emap/pc.c @@ -522,3 +522,34 @@ int epc_takeitem_post(int retVal, struct map_session_data *sd, struct flooritem_ } return retVal; } + +int epc_insert_card_pre(struct map_session_data* sd, int *idx_card, int *idx_equip) +{ + if (!sd || *idx_equip < 0 || *idx_equip >= MAX_INVENTORY || + *idx_card < 0 || *idx_card >= MAX_INVENTORY) + { + tempN = 0; + tempId = 0; + tempAmount = 0; + return 0; + } + tempN = *idx_equip; + tempId = sd->status.inventory[*idx_equip].nameid; + tempAmount = sd->status.inventory[*idx_card].nameid; + return 1; +} + +int epc_insert_card_post(int retVal, struct map_session_data* sd, int *idx_card, int *idx_equip) +{ + if (retVal && *idx_equip == tempN && tempId) + { + struct item_data *item = itemdb->search(tempId); + if (!item) + return retVal; + struct ItemdExt *data = itemd_get(item); + if (!data) + return retVal; + script_run_card_script(sd, data->insertScript, tempId, tempAmount); + } + return retVal; +} diff --git a/src/emap/pc.h b/src/emap/pc.h index 3e58cf0..92af4cf 100644 --- a/src/emap/pc.h +++ b/src/emap/pc.h @@ -62,4 +62,8 @@ int epc_takeitem_pre(struct map_session_data *sd, struct flooritem_data *fitem); int epc_takeitem_post(int retVal, struct map_session_data *sd, struct flooritem_data *fitem); +int epc_insert_card_pre(struct map_session_data* sd, int *idx_card, int *idx_equip); + +int epc_insert_card_post(int retVal, struct map_session_data* sd, int *idx_card, int *idx_equip); + #endif // EVOL_MAP_PC diff --git a/src/emap/script.c b/src/emap/script.c index 905bcf5..098fc6e 100644 --- a/src/emap/script.c +++ b/src/emap/script.c @@ -319,6 +319,20 @@ void script_run_item_amount_script(TBL_PC *sd, struct script_code *itemScript, i script->current_item_id = 0; } +void script_run_card_script(TBL_PC *sd, struct script_code *itemScript, int itemId, int cardId) +{ + if (!itemScript) + return; + + script->current_item_id = itemId; + pc->setreg(sd, script->add_str("@itemId"), itemId); + pc->setreg(sd, script->add_str("@cardId"), cardId); + script->run(itemScript, 0, sd->bl.id, npc->fake_nd->bl.id); + pc->setreg(sd, script->add_str("@itemId"), 0); + pc->setreg(sd, script->add_str("@cardId"), 0); + script->current_item_id = 0; +} + uint32 MakeDWord(uint16 word0, uint16 word1) { return ((uint32)(word0)) | ((uint32)(word1 << 0x10)); diff --git a/src/emap/script.h b/src/emap/script.h index e6b8c70..edbd010 100644 --- a/src/emap/script.h +++ b/src/emap/script.h @@ -9,6 +9,7 @@ int eget_val_npcscope_num(struct script_state* st, struct reg_db *n, struct scri void eset_reg_npcscope_str(struct script_state* st, struct reg_db *n, int64 *num, const char* name, const char *str); char *eget_val_npcscope_str(struct script_state* st, struct reg_db *n, struct script_data* data); void script_run_item_amount_script(TBL_PC *sd, struct script_code *itemScript, int itemId, int amount); +void script_run_card_script(TBL_PC *sd, struct script_code *itemScript, int itemId, int cardId); BUILDIN(l); BUILDIN(lg); diff --git a/src/emap/struct/itemdext.h b/src/emap/struct/itemdext.h index 8ce5997..5fd7159 100644 --- a/src/emap/struct/itemdext.h +++ b/src/emap/struct/itemdext.h @@ -36,6 +36,7 @@ struct ItemdExt struct ItemCardExt allowedCards[100]; struct script_code *dropScript; struct script_code *takeScript; + struct script_code *insertScript; bool allowPickup; bool charmItem; |