From 7b003f2028906218bb6cff68e5e97ec47ad6681e Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sun, 26 Jan 2020 21:52:43 +0100 Subject: Added pc_itemskill_clear() function. --- src/map/clif.c | 1 + src/map/pc.c | 21 +++++++++++++++++++++ src/map/pc.h | 1 + src/map/script.c | 11 +++++------ src/map/skill.c | 5 +++++ src/map/unit.c | 20 ++++---------------- 6 files changed, 37 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/map/clif.c b/src/map/clif.c index 50b81d25d..24de61ec0 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -12932,6 +12932,7 @@ static void clif_parse_UseSkillMap(int fd, struct map_session_data *sd) pc->delinvincibletimer(sd); skill->castend_map(sd,skill_id,map_name); + pc->itemskill_clear(sd); } static void clif_parse_RequestMemo(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); diff --git a/src/map/pc.c b/src/map/pc.c index a404d93e7..c96e957c7 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -5321,6 +5321,26 @@ static int pc_useitem(struct map_session_data *sd, int n) return 1; } +/** + * Sets state flags and helper variables, used by itemskill() script command, to 0. + * + * @param sd The character's session data. + * @return 0 if parameter sd is NULL, otherwise 1. + */ +static int pc_itemskill_clear(struct map_session_data *sd) +{ + nullpo_ret(sd); + + sd->itemskill_id = 0; + sd->itemskill_lv = 0; + sd->state.itemskill_conditions_checked = 0; + sd->state.itemskill_no_conditions = 0; + sd->state.itemskill_no_casttime = 0; + sd->state.itemskill_castonself = 0; + + return 1; +} + /*========================================== * Add item on cart for given index. * Return: @@ -12662,6 +12682,7 @@ void pc_defaults(void) pc->unequipitem_pos = pc_unequipitem_pos; pc->checkitem = pc_checkitem; pc->useitem = pc_useitem; + pc->itemskill_clear = pc_itemskill_clear; pc->skillatk_bonus = pc_skillatk_bonus; pc->skillheal_bonus = pc_skillheal_bonus; diff --git a/src/map/pc.h b/src/map/pc.h index 26e33a400..e940c3310 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -1034,6 +1034,7 @@ END_ZEROED_BLOCK; /* End */ void (*unequipitem_pos) (struct map_session_data *sd, int n, int pos); int (*checkitem) (struct map_session_data *sd); int (*useitem) (struct map_session_data *sd,int n); + int (*itemskill_clear) (struct map_session_data *sd); int (*skillatk_bonus) (struct map_session_data *sd, uint16 skill_id); int (*skillheal_bonus) (struct map_session_data *sd, uint16 skill_id); diff --git a/src/map/script.c b/src/map/script.c index b87a46785..c1eb2e8b7 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -11007,7 +11007,7 @@ static BUILDIN(itemskill) int flag = script_hasdata(st, 4) ? script_getnum(st, 4) : ISF_NONE; - sd->state.itemskill_no_conditions = ((flag & ISF_IGNORECONDITIONS) == ISF_IGNORECONDITIONS) ? 1 : 0; // Unset in unit_skilluse_id()/unit_skilluse_pos() if skill was not aborted while target selection. + sd->state.itemskill_no_conditions = ((flag & ISF_IGNORECONDITIONS) == ISF_IGNORECONDITIONS) ? 1 : 0; // Unset in pc_itemskill_clear(). if (sd->state.itemskill_no_conditions == 0) { if (skill->check_condition_castbegin(sd, sd->skillitem, sd->skillitemlv) == 0 @@ -11015,14 +11015,13 @@ static BUILDIN(itemskill) return true; } - sd->state.itemskill_conditions_checked = 1; // Unset in unit_skilluse_id()/unit_skilluse_pos() if skill was not aborted while target selection. + sd->state.itemskill_conditions_checked = 1; // Unset in pc_itemskill_clear(). } - sd->state.itemskill_no_casttime = ((flag & ISF_INSTANTCAST) == ISF_INSTANTCAST) ? 1 : 0; // Unset in unit_skilluse_id()/unit_skilluse_pos() if skill was not aborted while target selection. - sd->state.itemskill_castonself = ((flag & ISF_CASTONSELF) == ISF_CASTONSELF) ? 1 : 0; // Unset in unit_skilluse_id()/unit_skilluse_pos() if skill was not aborted while target selection. + sd->state.itemskill_no_casttime = ((flag & ISF_INSTANTCAST) == ISF_INSTANTCAST) ? 1 : 0; // Unset in pc_itemskill_clear(). + sd->state.itemskill_castonself = ((flag & ISF_CASTONSELF) == ISF_CASTONSELF) ? 1 : 0; // Unset in pc_itemskill_clear(). - // itemskill_conditions_checked/itemskill_no_conditions/itemskill_no_casttime/itemskill_castonself abuse prevention. - // Unset in unit_skilluse_id()/unit_skilluse_pos() if skill was not aborted while target selection. + // itemskill_conditions_checked/itemskill_no_conditions/itemskill_no_casttime/itemskill_castonself abuse prevention. Unset in pc_itemskill_clear(). sd->itemskill_id = sd->skillitem; sd->itemskill_lv = sd->skillitemlv; diff --git a/src/map/skill.c b/src/map/skill.c index e853bcc1d..6f0cb424b 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -4190,6 +4190,11 @@ static void skill_castend_type(int type, struct block_list *src, struct block_li skill->castend_damage_id(src, bl, skill_id, skill_lv, tick, flag); break; } + + struct map_session_data *sd = BL_CAST(BL_PC, src); + + if (sd != NULL) + pc->itemskill_clear(sd); } /*========================================== diff --git a/src/map/unit.c b/src/map/unit.c index 3ad94d20a..0a6008247 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -1046,14 +1046,8 @@ static int unit_skilluse_id(struct block_list *src, int target_id, uint16 skill_ int ret = unit->skilluse_id2(src, target_id, skill_id, skill_lv, casttime, castcancel); struct map_session_data *sd = BL_CAST(BL_PC, src); - if (sd != NULL) { - sd->itemskill_id = 0; - sd->itemskill_lv = 0; - sd->state.itemskill_conditions_checked = 0; - sd->state.itemskill_no_conditions = 0; - sd->state.itemskill_no_casttime = 0; - sd->state.itemskill_castonself = 0; - } + if (sd != NULL) + pc->itemskill_clear(sd); return ret; } @@ -1691,14 +1685,8 @@ static int unit_skilluse_pos(struct block_list *src, short skill_x, short skill_ int ret = unit->skilluse_pos2(src, skill_x, skill_y, skill_id, skill_lv, casttime, castcancel); struct map_session_data *sd = BL_CAST(BL_PC, src); - if (sd != NULL) { - sd->itemskill_id = 0; - sd->itemskill_lv = 0; - sd->state.itemskill_conditions_checked = 0; - sd->state.itemskill_no_conditions = 0; - sd->state.itemskill_no_casttime = 0; - sd->state.itemskill_castonself = 0; - } + if (sd != NULL) + pc->itemskill_clear(sd); return ret; } -- cgit v1.2.3-70-g09d2