summaryrefslogtreecommitdiff
path: root/src/emap
diff options
context:
space:
mode:
Diffstat (limited to 'src/emap')
-rw-r--r--src/emap/data/itemd.c1
-rw-r--r--src/emap/init.c3
-rw-r--r--src/emap/itemdb.c17
-rw-r--r--src/emap/itemdb.h2
-rw-r--r--src/emap/pc.c36
-rw-r--r--src/emap/pc.h5
-rw-r--r--src/emap/struct/itemdext.h1
7 files changed, 63 insertions, 2 deletions
diff --git a/src/emap/data/itemd.c b/src/emap/data/itemd.c
index fb7feed..e3ee936 100644
--- a/src/emap/data/itemd.c
+++ b/src/emap/data/itemd.c
@@ -67,6 +67,7 @@ struct ItemdExt *itemd_create(void)
data->unequipEffect = -1;
data->unequipFailEffect = -1;
data->charmItem = false;
+ data->dropScript = NULL;
memset(&data->allowedCards, 0, sizeof(data->allowedCards));
return data;
}
diff --git a/src/emap/init.c b/src/emap/init.c
index 049402a..1259ce8 100644
--- a/src/emap/init.c
+++ b/src/emap/init.c
@@ -156,6 +156,7 @@ HPExport void plugin_init (void)
addHookPre("pc->validate_levels", epc_validate_levels);
addHookPre("pc->check_job_name", epc_check_job_name);
addHookPre("pc->delitem", epc_delitem_pre);
+ addHookPre("pc->dropitem", epc_dropitem_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);
@@ -175,6 +176,7 @@ HPExport void plugin_init (void)
addHookPre("clif->pLoadEndAck", eclif_parse_LoadEndAck_pre);
addHookPre("itemdb->is_item_usable", eitemdb_is_item_usable);
addHookPre("itemdb->readdb_additional_fields", eitemdb_readdb_additional_fields);
+ addHookPre("itemdb->destroy_item_data", edestroy_item_data);
addHookPre("unit->can_move", eunit_can_move);
addHookPre("unit->walktoxy", eunit_walktoxy);
addHookPre("mail->invalid_operation", email_invalid_operation);
@@ -212,6 +214,7 @@ HPExport void plugin_init (void)
addHookPost("pc->unequipitem", epc_unequipitem_post);
addHookPost("pc->setnewpc", epc_setnewpc_post);
addHookPost("pc->delitem", epc_delitem_post);
+ addHookPost("pc->dropitem", epc_dropitem_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 a64f857..478d88c 100644
--- a/src/emap/itemdb.c
+++ b/src/emap/itemdb.c
@@ -32,10 +32,12 @@ bool eitemdb_is_item_usable(struct item_data *item)
void eitemdb_readdb_additional_fields(int *itemid,
config_setting_t *it,
int *n __attribute__ ((unused)),
- const char *source __attribute__ ((unused)))
+ const char *source)
{
struct item_data *item = itemdb->exists(*itemid);
int i32 = 0;
+ const char *str = NULL;
+
if (!item)
{
hookStop();
@@ -92,6 +94,9 @@ void eitemdb_readdb_additional_fields(int *itemid,
if (itemdb->lookup_const(it, "UnequipFailEffect", &i32))
data->unequipFailEffect = i32;
+ if (libconfig->setting_lookup_string(it, "OnDropScript", &str))
+ data->dropScript = *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)
{
@@ -120,3 +125,13 @@ void eitemdb_readdb_additional_fields(int *itemid,
hookStop();
}
+
+void edestroy_item_data(struct item_data* self, int *free_selfPtr)
+{
+ struct ItemdExt *data = itemd_get(self);
+ if (!data)
+ return;
+
+ if (data->dropScript)
+ script->free_code(data->dropScript);
+}
diff --git a/src/emap/itemdb.h b/src/emap/itemdb.h
index 8b467eb..4f0e322 100644
--- a/src/emap/itemdb.h
+++ b/src/emap/itemdb.h
@@ -5,7 +5,7 @@
#define EVOL_MAP_ITEMDB
bool eitemdb_is_item_usable(struct item_data *item);
-
void eitemdb_readdb_additional_fields(int *itemid, config_setting_t *it, int *n, const char *source);
+void edestroy_item_data(struct item_data* self, int *free_selfPtr);
#endif // EVOL_MAP_ITEMDB
diff --git a/src/emap/pc.c b/src/emap/pc.c
index c4db70b..1db0963 100644
--- a/src/emap/pc.c
+++ b/src/emap/pc.c
@@ -14,6 +14,7 @@
#include "common/strlib.h"
#include "common/timer.h"
#include "map/itemdb.h"
+#include "map/npc.h"
#include "map/pc.h"
#include "emap/clif.h"
@@ -457,3 +458,38 @@ bool epc_can_insert_card_into_post(bool retVal, struct map_session_data* sd,
return retVal;
}
+// temporary inv index and item id
+static int tempN = 0;
+static int tempId = 0;
+
+int epc_dropitem_pre(struct map_session_data *sd, int *nPtr, int *amountPtr)
+{
+ const int n = *nPtr;
+ if (n < 0 || n >= MAX_INVENTORY)
+ return 0;
+
+ tempN = n;
+ tempId = sd->status.inventory[n].nameid;
+ return 1;
+}
+
+int epc_dropitem_post(int retVal, struct map_session_data *sd, int *nPtr, int *amountPtr)
+{
+ if (retVal && *nPtr == tempN && tempId)
+ {
+ struct item_data *item = itemdb->search(tempId);
+ if (!item)
+ return retVal;
+ struct ItemdExt *data = itemd_get(item);
+ if (!data || !data->dropScript)
+ 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;
+ }
+ return retVal;
+}
diff --git a/src/emap/pc.h b/src/emap/pc.h
index 8921d4e..5c53449 100644
--- a/src/emap/pc.h
+++ b/src/emap/pc.h
@@ -50,7 +50,12 @@ int epc_delitem_pre(struct map_session_data *sd, int *nPtr, int *amountPtr,
int epc_delitem_post(int retVal, struct map_session_data *sd, int *nPtr, int *amountPtr,
int *typePtr, short *reasonPtr,
e_log_pick_type *log_type);
+
bool epc_can_insert_card_into_post(bool retVal, struct map_session_data* sd,
int *idx_card, int *idx_equip);
+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);
+
#endif // EVOL_MAP_PC
diff --git a/src/emap/struct/itemdext.h b/src/emap/struct/itemdext.h
index 60a6bfc..4cc1f3b 100644
--- a/src/emap/struct/itemdext.h
+++ b/src/emap/struct/itemdext.h
@@ -34,6 +34,7 @@ struct ItemdExt
int unequipFailEffect;
struct ItemCardExt allowedCards[100];
+ struct script_code *dropScript;
bool allowPickup;
bool charmItem;