Skip to content

Commit

Permalink
refactor SA_AUTOSPELL selected skill processing
Browse files Browse the repository at this point in the history
- replace if chain with array lookup/config file
- renamed skill_autospell to skill_autospell_spell_selected
  • Loading branch information
guilherme-gm committed Oct 17, 2023
1 parent 1f5212e commit a8c998b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/map/clif.c
Original file line number Diff line number Diff line change
Expand Up @@ -14196,7 +14196,7 @@ static void clif_parse_AutoSpell(int fd, struct map_session_data *sd)
if( !skill_id )
return;

skill->autospell(sd, skill_id);
skill->autospell_spell_selected(sd, skill_id);
clif_menuskill_clear(sd);
}

Expand Down
59 changes: 29 additions & 30 deletions src/map/skill.c
Original file line number Diff line number Diff line change
Expand Up @@ -17873,42 +17873,41 @@ static void skill_autospell_select_spell(struct block_list *bl, int skill_lv)
skill->get_time(SA_AUTOSPELL, skill_lv), SA_AUTOSPELL);
}

static int skill_autospell(struct map_session_data *sd, uint16 skill_id)
/**
* Initiates AutoSpell effect on player based on the skill they chose.
*
* // @FIXME: Why this always returns 0? Does it even make sense?
* @param sd player casting the skill
* @param skill_id selected skill
* @returns always returns 0
*/
static int skill_autospell_spell_selected(struct map_session_data *sd, uint16 skill_id)
{
uint16 skill_lv;
int maxlv=1,lv;

nullpo_ret(sd);

skill_lv = sd->menuskill_val;
lv=pc->checkskill(sd,skill_id);
uint16 autospell_lv = sd->menuskill_val;
int skill_lv = pc->checkskill(sd, skill_id);

if(!skill_lv || !lv) return 0; // Player must learn the skill before doing auto-spell [Lance]
if(autospell_lv == 0 || skill_lv == 0)
return 0; // Player must learn the skill before doing auto-spell [Lance]

if(skill_id==MG_NAPALMBEAT) maxlv=3;
else if(skill_id==MG_COLDBOLT || skill_id==MG_FIREBOLT || skill_id==MG_LIGHTNINGBOLT){
if (sd->sc.data[SC_SOULLINK] && sd->sc.data[SC_SOULLINK]->val2 == SL_SAGE)
maxlv =10; //Soul Linker bonus. [Skotlex]
else if(skill_lv==2) maxlv=1;
else if(skill_lv==3) maxlv=2;
else if(skill_lv>=4) maxlv=3;
}
else if(skill_id==MG_SOULSTRIKE){
if(skill_lv==5) maxlv=1;
else if(skill_lv==6) maxlv=2;
else if(skill_lv>=7) maxlv=3;
}
else if(skill_id==MG_FIREBALL){
if(skill_lv==8) maxlv=1;
else if(skill_lv>=9) maxlv=2;
}
else if(skill_id==MG_FROSTDIVER) maxlv=1;
else return 0;
int skill_idx;
ARR_FIND(0, MAX_AUTOSPELL_DB, skill_idx, skill->dbs->autospell_db[skill_idx].skill_id == skill_id);
if (skill_idx == MAX_AUTOSPELL_DB)
return 0; // Not an AutoSpell skill (exploit attempt?)

const struct s_autospell_db *sk = &skill->dbs->autospell_db[skill_idx];
if (sk->autospell_level > autospell_lv)
return 0; // Don't have enough level to use

int max_lv = sk->skill_lv[autospell_lv - 1];
if (sk->spirit_boost && sd->sc.data[SC_SOULLINK] != NULL && sd->sc.data[SC_SOULLINK]->val2 == SL_SAGE)
max_lv = skill->dbs->db[skill->get_index(skill_id)].max; // Soul Linker bonus. [Skotlex]

if(maxlv > lv)
maxlv = lv;
if (max_lv > skill_lv)
max_lv = skill_lv;

sc_start4(&sd->bl,&sd->bl,SC_AUTOSPELL,100,skill_lv,skill_id,maxlv,0,
sc_start4(&sd->bl, &sd->bl, SC_AUTOSPELL, 100, skill_lv, skill_id, max_lv, 0,
skill->get_time(SA_AUTOSPELL, skill_lv), SA_AUTOSPELL);
return 0;
}
Expand Down Expand Up @@ -25281,7 +25280,7 @@ void skill_defaults(void)
skill->weaponrefine = skill_weaponrefine;
skill->autospell_select_spell = skill_autospell_select_spell;
skill->autospell_select_spell_pc = skill_autospell_select_spell_pc;
skill->autospell = skill_autospell;
skill->autospell_spell_selected = skill_autospell_spell_selected;
skill->calc_heal = skill_calc_heal;
skill->check_cloaking = skill_check_cloaking;
skill->check_cloaking_end = skill_check_cloaking_end;
Expand Down
2 changes: 1 addition & 1 deletion src/map/skill.h
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ struct skill_interface {
void (*weaponrefine) (struct map_session_data *sd,int idx);
void (*autospell_select_spell) (struct block_list *bl, int skill_lv);
void (*autospell_select_spell_pc) (struct map_session_data *sd, int skill_lv);
int (*autospell) (struct map_session_data *md,uint16 skill_id);
int (*autospell_spell_selected) (struct map_session_data *md, uint16 skill_id);
int (*calc_heal) (struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, bool heal);
bool (*check_cloaking) (struct block_list *bl, struct status_change_entry *sce);
int (*check_cloaking_end) (struct block_list *bl, va_list ap);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/HPMHooking/HPMHooking.Defs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8478,8 +8478,8 @@ typedef void (*HPMHOOK_pre_skill_autospell_select_spell) (struct block_list **bl
typedef void (*HPMHOOK_post_skill_autospell_select_spell) (struct block_list *bl, int skill_lv);
typedef void (*HPMHOOK_pre_skill_autospell_select_spell_pc) (struct map_session_data **sd, int *skill_lv);
typedef void (*HPMHOOK_post_skill_autospell_select_spell_pc) (struct map_session_data *sd, int skill_lv);
typedef int (*HPMHOOK_pre_skill_autospell) (struct map_session_data **md, uint16 *skill_id);
typedef int (*HPMHOOK_post_skill_autospell) (int retVal___, struct map_session_data *md, uint16 skill_id);
typedef int (*HPMHOOK_pre_skill_autospell_spell_selected) (struct map_session_data **md, uint16 *skill_id);
typedef int (*HPMHOOK_post_skill_autospell_spell_selected) (int retVal___, struct map_session_data *md, uint16 skill_id);
typedef int (*HPMHOOK_pre_skill_calc_heal) (struct block_list **src, struct block_list **target, uint16 *skill_id, uint16 *skill_lv, bool *heal);
typedef int (*HPMHOOK_post_skill_calc_heal) (int retVal___, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, bool heal);
typedef bool (*HPMHOOK_pre_skill_check_cloaking) (struct block_list **bl, struct status_change_entry **sce);
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6400,8 +6400,8 @@ struct {
struct HPMHookPoint *HP_skill_autospell_select_spell_post;
struct HPMHookPoint *HP_skill_autospell_select_spell_pc_pre;
struct HPMHookPoint *HP_skill_autospell_select_spell_pc_post;
struct HPMHookPoint *HP_skill_autospell_pre;
struct HPMHookPoint *HP_skill_autospell_post;
struct HPMHookPoint *HP_skill_autospell_spell_selected_pre;
struct HPMHookPoint *HP_skill_autospell_spell_selected_post;
struct HPMHookPoint *HP_skill_calc_heal_pre;
struct HPMHookPoint *HP_skill_calc_heal_post;
struct HPMHookPoint *HP_skill_check_cloaking_pre;
Expand Down Expand Up @@ -13953,8 +13953,8 @@ struct {
int HP_skill_autospell_select_spell_post;
int HP_skill_autospell_select_spell_pc_pre;
int HP_skill_autospell_select_spell_pc_post;
int HP_skill_autospell_pre;
int HP_skill_autospell_post;
int HP_skill_autospell_spell_selected_pre;
int HP_skill_autospell_spell_selected_post;
int HP_skill_calc_heal_pre;
int HP_skill_calc_heal_post;
int HP_skill_check_cloaking_pre;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3276,7 +3276,7 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(skill->weaponrefine, HP_skill_weaponrefine) },
{ HP_POP(skill->autospell_select_spell, HP_skill_autospell_select_spell) },
{ HP_POP(skill->autospell_select_spell_pc, HP_skill_autospell_select_spell_pc) },
{ HP_POP(skill->autospell, HP_skill_autospell) },
{ HP_POP(skill->autospell_spell_selected, HP_skill_autospell_spell_selected) },
{ HP_POP(skill->calc_heal, HP_skill_calc_heal) },
{ HP_POP(skill->check_cloaking, HP_skill_check_cloaking) },
{ HP_POP(skill->check_cloaking_end, HP_skill_check_cloaking_end) },
Expand Down
16 changes: 8 additions & 8 deletions src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -85389,14 +85389,14 @@ void HP_skill_autospell_select_spell_pc(struct map_session_data *sd, int skill_l
}
return;
}
int HP_skill_autospell(struct map_session_data *md, uint16 skill_id) {
int HP_skill_autospell_spell_selected(struct map_session_data *md, uint16 skill_id) {
int hIndex = 0;
int retVal___ = 0;
if (HPMHooks.count.HP_skill_autospell_pre > 0) {
if (HPMHooks.count.HP_skill_autospell_spell_selected_pre > 0) {
int (*preHookFunc) (struct map_session_data **md, uint16 *skill_id);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_autospell_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_skill_autospell_pre[hIndex].func;
for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_autospell_spell_selected_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_skill_autospell_spell_selected_pre[hIndex].func;
retVal___ = preHookFunc(&md, &skill_id);
}
if (*HPMforce_return) {
Expand All @@ -85405,12 +85405,12 @@ int HP_skill_autospell(struct map_session_data *md, uint16 skill_id) {
}
}
{
retVal___ = HPMHooks.source.skill.autospell(md, skill_id);
retVal___ = HPMHooks.source.skill.autospell_spell_selected(md, skill_id);
}
if (HPMHooks.count.HP_skill_autospell_post > 0) {
if (HPMHooks.count.HP_skill_autospell_spell_selected_post > 0) {
int (*postHookFunc) (int retVal___, struct map_session_data *md, uint16 skill_id);
for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_autospell_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_skill_autospell_post[hIndex].func;
for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_autospell_spell_selected_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_skill_autospell_spell_selected_post[hIndex].func;
retVal___ = postHookFunc(retVal___, md, skill_id);
}
}
Expand Down

0 comments on commit a8c998b

Please sign in to comment.