summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-08-07 21:13:07 +0300
committerAndrei Karas <akaras@inbox.ru>2015-08-10 23:06:08 +0300
commitc0367b69fd226be21643cd4b620fff2aadb0e742 (patch)
tree94b6cb16c7c5232020a22896496813be378a340e /src/map
parent5ad96bcc2af2a5a76348fca87e52a0f038461808 (diff)
downloadhercules-c0367b69fd226be21643cd4b620fff2aadb0e742.tar.gz
hercules-c0367b69fd226be21643cd4b620fff2aadb0e742.tar.bz2
hercules-c0367b69fd226be21643cd4b620fff2aadb0e742.tar.xz
hercules-c0367b69fd226be21643cd4b620fff2aadb0e742.zip
Move use item script function call into function script_run_use_script.
Diffstat (limited to 'src/map')
-rw-r--r--src/map/pc.c19
-rw-r--r--src/map/script.c21
-rw-r--r--src/map/script.h1
-rw-r--r--src/map/skill.c4
-rw-r--r--src/map/status.c14
5 files changed, 36 insertions, 23 deletions
diff --git a/src/map/pc.c b/src/map/pc.c
index 5abf1050f..1589ae910 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -4882,7 +4882,6 @@ int pc_isUseitem(struct map_session_data *sd,int n)
int pc_useitem(struct map_session_data *sd,int n) {
int64 tick = timer->gettick();
int amount, nameid, i;
- struct script_code *item_script;
nullpo_ret(sd);
@@ -4994,7 +4993,6 @@ int pc_useitem(struct map_session_data *sd,int n) {
sd->catch_target_class = -1;
amount = sd->status.inventory[n].amount;
- item_script = sd->inventory_data[n]->script;
//Check if the item is to be consumed immediately [Skotlex]
if (sd->inventory_data[n]->flag.delay_consume || sd->inventory_data[n]->flag.keepafteruse)
clif->useitemack(sd,n,amount,true);
@@ -5006,26 +5004,23 @@ int pc_useitem(struct map_session_data *sd,int n) {
clif->useitemack(sd, n, 0, false);
}
}
+
if(sd->status.inventory[n].card[0]==CARD0_CREATE &&
pc->famerank(MakeDWord(sd->status.inventory[n].card[2],sd->status.inventory[n].card[3]), MAPID_ALCHEMIST))
{
- script->potion_flag = 2; // Famous player's potions have 50% more efficiency
- if (sd->sc.data[SC_SOULLINK] && sd->sc.data[SC_SOULLINK]->val2 == SL_ROGUE)
- script->potion_flag = 3; //Even more effective potions.
+ script->potion_flag = 2; // Famous player's potions have 50% more efficiency
+ if (sd->sc.data[SC_SOULLINK] && sd->sc.data[SC_SOULLINK]->val2 == SL_ROGUE)
+ script->potion_flag = 3; //Even more effective potions.
}
//Update item use time.
sd->canuseitem_tick = tick + battle_config.item_use_interval;
if( itemdb_iscashfood(nameid) )
sd->canusecashfood_tick = tick + battle_config.cashfood_use_interval;
-
- script->current_item_id = nameid;
-
- script->run(item_script,0,sd->bl.id,npc->fake_nd->bl.id);
-
- script->current_item_id = 0;
+
+ script->run_use_script(sd, sd->inventory_data[n], npc->fake_nd->bl.id);
+
script->potion_flag = 0;
-
return 1;
}
diff --git a/src/map/script.c b/src/map/script.c
index 4c669bf20..1290d96e1 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -10453,7 +10453,7 @@ BUILDIN(itemeffect) {
}
}
- script->run( item_data->script, 0, sd->bl.id, nd->bl.id );
+ script->run_use_script(sd, item_data, nd->bl.id);
return true;
}
@@ -19834,6 +19834,22 @@ bool script_hp_add(char *name, char *args, bool (*func)(struct script_state *st)
return script->add_builtin(&buildin, true);
}
+void script_run_use_script(struct map_session_data *sd, struct item_data *data, int oid) __attribute__((nonnull (1)));
+
+/**
+ * Run use script for item.
+ *
+ * @param sd player session data. Must be correct and checked before.
+ * @param n item index in inventory. Must be correct and checked before.
+ * @param oid npc id. Can be also 0 or fake npc id.
+ */
+void script_run_use_script(struct map_session_data *sd, struct item_data *data, int oid)
+{
+ script->current_item_id = data->nameid;
+ script->run(data->script, 0, sd->bl.id, oid);
+ script->current_item_id = 0;
+}
+
#define BUILDIN_DEF(x,args) { buildin_ ## x , #x , args, false }
#define BUILDIN_DEF2(x,x2,args) { buildin_ ## x , x2 , args, false }
#define BUILDIN_DEF_DEPRECATED(x,args) { buildin_ ## x , #x , args, true }
@@ -20778,5 +20794,6 @@ void script_defaults(void) {
script->add_language = script_add_language;
script->get_translation_file_name = script_get_translation_file_name;
script->parser_clean_leftovers = script_parser_clean_leftovers;
-
+
+ script->run_use_script = script_run_use_script;
}
diff --git a/src/map/script.h b/src/map/script.h
index 93d60f416..bdd6e20ac 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -765,6 +765,7 @@ struct script_interface {
uint8 (*add_language) (const char *name);
const char *(*get_translation_file_name) (const char *file);
void (*parser_clean_leftovers) (void);
+ void (*run_use_script) (struct map_session_data *sd, struct item_data *data, int oid);
};
struct script_interface *script;
diff --git a/src/map/skill.c b/src/map/skill.c
index f2154aa22..e3f85f8d1 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -6858,7 +6858,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
script->potion_flag = 1;
script->potion_hp = script->potion_sp = script->potion_per_hp = script->potion_per_sp = 0;
script->potion_target = bl->id;
- script->run(sd->inventory_data[i]->script,0,sd->bl.id,0);
+ script->run_use_script(sd, sd->inventory_data[i], 0);
script->potion_flag = script->potion_target = 0;
if( sd->sc.data[SC_SOULLINK] && sd->sc.data[SC_SOULLINK]->val2 == SL_ALCHEMIST )
bonus += sd->status.base_level;
@@ -10539,7 +10539,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
script->potion_flag = 1;
script->potion_hp = 0;
script->potion_sp = 0;
- script->run(sd->inventory_data[j]->script,0,sd->bl.id,0);
+ script->run_use_script(sd, sd->inventory_data[j], 0);
script->potion_flag = 0;
//Apply skill bonuses
i = pc->checkskill(sd,CR_SLIMPITCHER)*10
diff --git a/src/map/status.c b/src/map/status.c
index b513c6975..d19ce0511 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -2308,10 +2308,10 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
if(sd->inventory_data[index]->script) {
if (wd == &sd->left_weapon) {
sd->state.lr_flag = 1;
- script->run(sd->inventory_data[index]->script,0,sd->bl.id,0);
+ script->run_use_script(sd, sd->inventory_data[index], 0);
sd->state.lr_flag = 0;
} else
- script->run(sd->inventory_data[index]->script,0,sd->bl.id,0);
+ script->run_use_script(sd, sd->inventory_data[index], 0);
if (!calculating) //Abort, script->run retriggered this. [Skotlex]
return 1;
}
@@ -2334,7 +2334,7 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
if(sd->inventory_data[index]->script) {
if( i == EQI_HAND_L ) //Shield
sd->state.lr_flag = 3;
- script->run(sd->inventory_data[index]->script,0,sd->bl.id,0);
+ script->run_use_script(sd, sd->inventory_data[index], 0);
if( i == EQI_HAND_L ) //Shield
sd->state.lr_flag = 0;
if (!calculating) //Abort, script->run retriggered this. [Skotlex]
@@ -2350,7 +2350,7 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
sd->bonus.arrow_atk += sd->inventory_data[index]->atk;
sd->state.lr_flag = 2;
if( !itemdb_is_GNthrowable(sd->inventory_data[index]->nameid) ) //don't run scripts on throwable items
- script->run(sd->inventory_data[index]->script,0,sd->bl.id,0);
+ script->run_use_script(sd, sd->inventory_data[index], 0);
sd->state.lr_flag = 0;
if (!calculating) //Abort, script->run retriggered status_calc_pc. [Skotlex]
return 1;
@@ -2438,10 +2438,10 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
if(i == EQI_HAND_L && sd->status.inventory[index].equip == EQP_HAND_L) { //Left hand status.
sd->state.lr_flag = 1;
- script->run(data->script,0,sd->bl.id,0);
+ script->run_use_script(sd, data, 0);
sd->state.lr_flag = 0;
} else
- script->run(data->script,0,sd->bl.id,0);
+ script->run_use_script(sd, data, 0);
if (!calculating) //Abort, script->run his function. [Skotlex]
return 1;
}
@@ -2451,7 +2451,7 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
if( sc->count && sc->data[SC_ITEMSCRIPT] ) {
struct item_data *data = itemdb->exists(sc->data[SC_ITEMSCRIPT]->val1);
if( data && data->script )
- script->run(data->script,0,sd->bl.id,0);
+ script->run_use_script(sd, data, 0);
}
status->calc_pc_additional(sd, opt);