diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-10-13 21:08:48 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-10-13 21:09:15 +0300 |
commit | ab731862f899dd87b84613ebf12a82cdc73e094f (patch) | |
tree | e0dff28ea24a942d0ad6d07783aadbccfc5022a7 /src/emap | |
parent | f7cce6ac2d1c010af4865212dc6ddc2a7aea66a4 (diff) | |
download | plugin-ab731862f899dd87b84613ebf12a82cdc73e094f.tar.gz plugin-ab731862f899dd87b84613ebf12a82cdc73e094f.tar.bz2 plugin-ab731862f899dd87b84613ebf12a82cdc73e094f.tar.xz plugin-ab731862f899dd87b84613ebf12a82cdc73e094f.zip |
Add support for take (pickup) script for items taked from ground by player.
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 | 45 | ||||
-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, 64 insertions, 8 deletions
diff --git a/src/emap/data/itemd.c b/src/emap/data/itemd.c index e3ee936..a32c308 100644 --- a/src/emap/data/itemd.c +++ b/src/emap/data/itemd.c @@ -68,6 +68,7 @@ struct ItemdExt *itemd_create(void) data->unequipFailEffect = -1; data->charmItem = false; data->dropScript = NULL; + data->takeScript = NULL; memset(&data->allowedCards, 0, sizeof(data->allowedCards)); return data; } diff --git a/src/emap/init.c b/src/emap/init.c index 1259ce8..271f98a 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -157,6 +157,7 @@ HPExport void plugin_init (void) addHookPre("pc->check_job_name", epc_check_job_name); addHookPre("pc->delitem", epc_delitem_pre); addHookPre("pc->dropitem", epc_dropitem_pre); + addHookPre("pc->takeitem", epc_takeitem_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); @@ -215,6 +216,7 @@ HPExport void plugin_init (void) addHookPost("pc->setnewpc", epc_setnewpc_post); addHookPost("pc->delitem", epc_delitem_post); addHookPost("pc->dropitem", epc_dropitem_post); + addHookPost("pc->takeitem", epc_takeitem_post); addHookPost("pc->can_insert_card_into", epc_can_insert_card_into_post); langScriptId = script->add_str("Lang"); diff --git a/src/emap/itemdb.c b/src/emap/itemdb.c index 478d88c..a689613 100644 --- a/src/emap/itemdb.c +++ b/src/emap/itemdb.c @@ -96,6 +96,8 @@ void eitemdb_readdb_additional_fields(int *itemid, if (libconfig->setting_lookup_string(it, "OnDropScript", &str)) 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; config_setting_t *group = libconfig->setting_get_member(it, "AllowCards"); if (group) @@ -134,4 +136,6 @@ void edestroy_item_data(struct item_data* self, int *free_selfPtr) if (data->dropScript) script->free_code(data->dropScript); + if (data->takeScript) + script->free_code(data->takeScript); } diff --git a/src/emap/pc.c b/src/emap/pc.c index 1db0963..705c3dc 100644 --- a/src/emap/pc.c +++ b/src/emap/pc.c @@ -19,6 +19,7 @@ #include "emap/clif.h" #include "emap/pc.h" +#include "emap/script.h" #include "emap/data/itemd.h" #include "emap/data/mapd.h" #include "emap/data/session.h" @@ -461,12 +462,17 @@ bool epc_can_insert_card_into_post(bool retVal, struct map_session_data* sd, // temporary inv index and item id static int tempN = 0; static int tempId = 0; +static int tempAmount = 0; int epc_dropitem_pre(struct map_session_data *sd, int *nPtr, int *amountPtr) { const int n = *nPtr; if (n < 0 || n >= MAX_INVENTORY) + { + tempN = 0; + tempId = 0; return 0; + } tempN = n; tempId = sd->status.inventory[n].nameid; @@ -481,15 +487,38 @@ int epc_dropitem_post(int retVal, struct map_session_data *sd, int *nPtr, int *a if (!item) return retVal; struct ItemdExt *data = itemd_get(item); - if (!data || !data->dropScript) + if (!data) + return retVal; + script_run_item_amount_script(sd, data->dropScript, tempId, *amountPtr); + } + return retVal; +} + +int epc_takeitem_pre(struct map_session_data *sd, struct flooritem_data *fitem) +{ + if (!fitem) + { + tempN = 0; + tempId = 0; + return 0; + } + tempN = -1; + tempId = fitem->item_data.nameid; + tempAmount = fitem->item_data.amount; + return 1; +} + +int epc_takeitem_post(int retVal, struct map_session_data *sd, struct flooritem_data *fitem) +{ + if (retVal && tempN == -1 && tempId) + { + struct item_data *item = itemdb->search(tempId); + if (!item) + return retVal; + struct ItemdExt *data = itemd_get(item); + if (!data) return retVal; - script->current_item_id = tempId; - pc->setreg(sd, script->add_str("@itemId"), tempId); - pc->setreg(sd, script->add_str("@itemAmount"), *amountPtr); - script->run(data->dropScript, 0, sd->bl.id, npc->fake_nd->bl.id); - pc->setreg(sd, script->add_str("@itemId"), 0); - pc->setreg(sd, script->add_str("@itemAmount"), 0); - script->current_item_id = 0; + script_run_item_amount_script(sd, data->takeScript, tempId, tempAmount); } return retVal; } diff --git a/src/emap/pc.h b/src/emap/pc.h index 5c53449..3e58cf0 100644 --- a/src/emap/pc.h +++ b/src/emap/pc.h @@ -58,4 +58,8 @@ int epc_dropitem_pre(struct map_session_data *sd, int *nPtr, int *amountPtr); int epc_dropitem_post(int retVal, struct map_session_data *sd, int *nPtr, int *amountPtr); +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); + #endif // EVOL_MAP_PC diff --git a/src/emap/script.c b/src/emap/script.c index 962f28f..7eaa074 100644 --- a/src/emap/script.c +++ b/src/emap/script.c @@ -304,6 +304,20 @@ char *eget_val_npcscope_str(struct script_state* st, struct reg_db *n, struct sc return NULL; } +void script_run_item_amount_script(TBL_PC *sd, struct script_code *itemScript, int itemId, int amount) +{ + if (!itemScript) + return; + + script->current_item_id = itemId; + pc->setreg(sd, script->add_str("@itemId"), itemId); + pc->setreg(sd, script->add_str("@itemAmount"), amount); + 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("@itemAmount"), 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 b8245cd..8e6ad3c 100644 --- a/src/emap/script.h +++ b/src/emap/script.h @@ -8,6 +8,7 @@ void eset_reg_npcscope_num(struct script_state* st, struct reg_db *n, int64 *num int eget_val_npcscope_num(struct script_state* st, struct reg_db *n, struct script_data* data); 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); BUILDIN(l); BUILDIN(lg); diff --git a/src/emap/struct/itemdext.h b/src/emap/struct/itemdext.h index 4cc1f3b..8ce5997 100644 --- a/src/emap/struct/itemdext.h +++ b/src/emap/struct/itemdext.h @@ -35,6 +35,7 @@ struct ItemdExt struct ItemCardExt allowedCards[100]; struct script_code *dropScript; + struct script_code *takeScript; bool allowPickup; bool charmItem; |