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.c2
-rw-r--r--src/emap/parse.c36
-rw-r--r--src/emap/parse.h1
-rw-r--r--src/emap/script.c38
-rw-r--r--src/emap/script.h3
-rw-r--r--src/emap/struct/itemdext.h2
7 files changed, 83 insertions, 0 deletions
diff --git a/src/emap/data/itemd.c b/src/emap/data/itemd.c
index f9dde73..146557e 100644
--- a/src/emap/data/itemd.c
+++ b/src/emap/data/itemd.c
@@ -76,5 +76,6 @@ struct ItemdExt *itemd_create(void)
data->subX = 8;
data->subY = 8;
data->minRange = 0;
+ data->tmpUseType = 0;
return data;
}
diff --git a/src/emap/init.c b/src/emap/init.c
index ccdc25c..404b0bb 100644
--- a/src/emap/init.c
+++ b/src/emap/init.c
@@ -206,6 +206,7 @@ HPExport void plugin_init (void)
addPacket(0xb13, -1, map_parse_homun_say, hpClif_Parse);
addPacket(0xb14, 3, map_parse_homun_emote, hpClif_Parse);
addPacket(0xb15, 9, map_parse_homun_dir, hpClif_Parse);
+ addPacket(0xb26, 6, map_clif_parse_useitem2, hpClif_Parse);
addHookPre(atcommand, msgfd, eatcommand_msgfd_pre);
addHookPre(atcommand, msgsd, eatcommand_msgsd_pre);
@@ -275,6 +276,7 @@ HPExport void plugin_init (void)
addHookPre(script, load_translations, escript_load_translations_pre);
addHookPre(script, load_parameters, escript_load_parameters_pre);
addHookPre(script, hardcoded_constants, escript_hardcoded_constants_pre);
+ addHookPre(script, run_use_script, escript_run_use_script_pre);
addHookPre(status, calc_pc_additional, estatus_calc_pc_additional_pre);
addHookPre(status, set_viewdata, estatus_set_viewdata_pre);
addHookPre(homun, gainexp, ehomunculus_gainexp_pre);
diff --git a/src/emap/parse.c b/src/emap/parse.c
index c893a5f..1d620f4 100644
--- a/src/emap/parse.c
+++ b/src/emap/parse.c
@@ -23,7 +23,9 @@
#include "emap/parse.h"
#include "emap/send.h"
#include "emap/map.h"
+#include "emap/data/itemd.h"
#include "emap/data/session.h"
+#include "emap/struct/itemdext.h"
#include "emap/struct/sessionext.h"
void map_parse_version(int fd)
@@ -225,3 +227,37 @@ void map_parse_homun_dir(int fd)
else if (sd->hd && homun_alive(sd->hd))
unit->setdir(&sd->hd->bl, RFIFOB(fd, 8));
}
+
+void map_clif_parse_useitem2(int fd)
+{
+ TBL_PC* sd = (TBL_PC*)sockt->session[fd]->session_data;
+ if (!sd)
+ return;
+
+ if (pc_isdead(sd))
+ {
+ clif->clearunit_area(&sd->bl, CLR_DEAD);
+ return;
+ }
+
+ if ((!sd->npc_id && pc_istrading(sd)) || sd->chat_id != 0)
+ return;
+
+ // Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
+ pc->update_idle_time(sd, BCIDLE_USEITEM);
+ const int n = RFIFOW(fd, 2) - 2;
+ if (n < 0 || n >= MAX_INVENTORY)
+ return;
+
+ struct item_data *item = itemdb->exists(sd->inventory_data[n]->nameid);
+
+ if (!item)
+ return;
+ struct ItemdExt *data = itemd_get(item);
+ if (!data)
+ return;
+
+ data->tmpUseType = RFIFOW(fd, 4);
+ if (!pc->useitem(sd, n))
+ clif->useitemack(sd, n, 0, false); //Send an empty ack packet or the client gets stuck.
+}
diff --git a/src/emap/parse.h b/src/emap/parse.h
index ca67838..1a1d49c 100644
--- a/src/emap/parse.h
+++ b/src/emap/parse.h
@@ -16,5 +16,6 @@ void map_parse_pet_dir(int fd);
void map_parse_homun_say(int fd);
void map_parse_homun_emote(int fd);
void map_parse_homun_dir(int fd);
+void map_clif_parse_useitem2(int fd);
#endif // EVOL_MAP_PARSE
diff --git a/src/emap/script.c b/src/emap/script.c
index 73854ce..5b39e8a 100644
--- a/src/emap/script.c
+++ b/src/emap/script.c
@@ -9,6 +9,7 @@
#include "common/HPMi.h"
#include "common/memmgr.h"
+#include "common/nullpo.h"
#include "map/npc.h"
#include "map/pc.h"
#include "map/script.h"
@@ -17,7 +18,9 @@
#include "emap/script.h"
#include "emap/map.h"
+#include "emap/data/itemd.h"
#include "emap/data/npcd.h"
+#include "emap/struct/itemdext.h"
#include "emap/struct/npcdext.h"
#include "emap/skill_const.h"
@@ -397,6 +400,41 @@ char *eget_val_npcscope_str_pre(struct script_state **stPtr,
return NULL;
}
+void escript_run_use_script_pre(struct map_session_data **sdPtr,
+ struct item_data **itemDataPtr,
+ int *oidPtr)
+{
+ nullpo_retv(*itemDataPtr);
+ struct map_session_data *sd = *sdPtr;
+ struct item_data *itemData = *itemDataPtr;
+ const int oid = *oidPtr;
+ if (oid == 0)
+ {
+ pc->setreg(sd, script->add_str("@useType"), 0);
+ script->current_item_id = itemData->nameid;
+ script->run(itemData->script, 0, sd->bl.id, oid);
+ script->current_item_id = 0;
+ }
+ else
+ {
+ struct ItemdExt *data = itemd_get(itemData);
+ if (!data)
+ {
+ data->tmpUseType = 0;
+ hookStop();
+ return;
+ }
+
+ pc->setreg(sd, script->add_str("@useType"), data->tmpUseType);
+ script->current_item_id = itemData->nameid;
+ script->run(itemData->script, 0, sd->bl.id, oid);
+ script->current_item_id = 0;
+ pc->setreg(sd, script->add_str("@useType"), 0);
+ data->tmpUseType = 0;
+ }
+ hookStop();
+}
+
void script_run_item_amount_script(TBL_PC *sd,
struct script_code *itemScript,
int itemId,
diff --git a/src/emap/script.h b/src/emap/script.h
index cd29816..06aa7b2 100644
--- a/src/emap/script.h
+++ b/src/emap/script.h
@@ -24,6 +24,9 @@ void eset_reg_npcscope_str_pre(struct script_state **stPtr,
char *eget_val_npcscope_str_pre(struct script_state **stPtr,
struct reg_db **nPtr,
struct script_data **dataPtr);
+void escript_run_use_script_pre(struct map_session_data **sdPtr,
+ struct item_data **itemDataPtr,
+ int *oidPtr);
void script_run_item_amount_script(TBL_PC *sd,
struct script_code *itemScript,
int itemId,
diff --git a/src/emap/struct/itemdext.h b/src/emap/struct/itemdext.h
index f30d94c..65f0729 100644
--- a/src/emap/struct/itemdext.h
+++ b/src/emap/struct/itemdext.h
@@ -36,6 +36,8 @@ struct ItemdExt
int minRange;
+ int tmpUseType;
+
VECTOR_DECL(int) allowedAmmo;
VECTOR_DECL(struct ItemCardExt) allowedCards;
struct script_code *dropScript;