Skip to content

Commit

Permalink
Merge pull request #3227 from csnv/fix/unavailable_skill_delete
Browse files Browse the repository at this point in the history
Individually delete unavailable skills on status refresh
  • Loading branch information
MishimaHaruna authored Aug 16, 2023
2 parents 224e9d6 + 5773971 commit db4a096
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/map/atcommand.c
Original file line number Diff line number Diff line change
Expand Up @@ -3475,7 +3475,7 @@ ACMD(lostskill)

sd->status.skill[index].lv = 0;
sd->status.skill[index].flag = 0;
clif->deleteskill(sd,skill_id);
clif->deleteskill(sd, skill_id, false);
clif->message(fd, msg_fd(fd,71)); // You have forgotten the skill.

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/map/chrif.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,15 +870,15 @@ static void chrif_deadopt(int father_id, int mother_id, int child_id)
sd->status.skill[idx].id = 0;
sd->status.skill[idx].lv = 0;
sd->status.skill[idx].flag = 0;
clif->deleteskill(sd,WE_CALLBABY);
clif->deleteskill(sd, WE_CALLBABY, false);
}

if( mother_id && ( sd = map->charid2sd(mother_id) ) != NULL && sd->status.child == child_id ) {
sd->status.child = 0;
sd->status.skill[idx].id = 0;
sd->status.skill[idx].lv = 0;
sd->status.skill[idx].flag = 0;
clif->deleteskill(sd,WE_CALLBABY);
clif->deleteskill(sd, WE_CALLBABY, false);
}

}
Expand Down
8 changes: 6 additions & 2 deletions src/map/clif.c
Original file line number Diff line number Diff line change
Expand Up @@ -5681,7 +5681,7 @@ static void clif_addskill(struct map_session_data *sd, int id)

/// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
/// 0441 <skill id>.W
static void clif_deleteskill(struct map_session_data *sd, int id)
static void clif_deleteskill(struct map_session_data *sd, int id, bool skip_infoblock)
{
#if PACKETVER >= 20081217
int fd;
Expand All @@ -5695,7 +5695,11 @@ static void clif_deleteskill(struct map_session_data *sd, int id)
WFIFOW(fd,2) = id;
WFIFOSET(fd,packet_len(0x441));
#endif
clif->skillinfoblock(sd);

#if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190918
if (!skip_infoblock)
#endif
clif->skillinfoblock(sd);
}

/// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
Expand Down
2 changes: 1 addition & 1 deletion src/map/clif.h
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ struct clif_interface {
void (*skillup) (struct map_session_data *sd, uint16 skill_id, int skill_lv, int flag);
void (*skillinfo) (struct map_session_data *sd,int skill_id, int inf);
void (*addskill) (struct map_session_data *sd, int id);
void (*deleteskill) (struct map_session_data *sd, int id);
void (*deleteskill) (struct map_session_data *sd, int id, bool skip_infoblock);
void (*playerSkillToPacket) (struct map_session_data *sd, struct SKILLDATA *skillData, int skillId, int idx, bool newSkill);
/* party-specific */
void (*party_created) (struct map_session_data *sd,int result);
Expand Down
12 changes: 4 additions & 8 deletions src/map/pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4323,7 +4323,7 @@ static int pc_skill(struct map_session_data *sd, int id, int level, int flag)
sd->status.skill[index].flag = SKILL_FLAG_PERMANENT;
if( level == 0 ) { //Remove skill.
sd->status.skill[index].id = 0;
clif->deleteskill(sd,id);
clif->deleteskill(sd, id, false);
} else
clif->addskill(sd,id);
if( !skill->dbs->db[index].inf ) //Only recalculate for passive skills.
Expand Down Expand Up @@ -4357,7 +4357,7 @@ static int pc_skill(struct map_session_data *sd, int id, int level, int flag)
sd->status.skill[index].flag = SKILL_FLAG_PERM_GRANTED;
if( level == 0 ) { //Remove skill.
sd->status.skill[index].id = 0;
clif->deleteskill(sd,id);
clif->deleteskill(sd, id, false);
} else
clif->addskill(sd,id);
if( !skill->dbs->db[index].inf ) //Only recalculate for passive skills.
Expand Down Expand Up @@ -9121,7 +9121,7 @@ static int pc_jobchange(struct map_session_data *sd, int class, int upper)
sd->status.skill[idx].id = 0;
sd->status.skill[idx].lv = 0;
sd->status.skill[idx].flag = 0;
clif->deleteskill(sd,sd->cloneskill_id);
clif->deleteskill(sd, sd->cloneskill_id, false);
}
sd->cloneskill_id = 0;
pc_setglobalreg(sd, script->add_variable("CLONE_SKILL"), 0);
Expand All @@ -9134,7 +9134,7 @@ static int pc_jobchange(struct map_session_data *sd, int class, int upper)
sd->status.skill[idx].id = 0;
sd->status.skill[idx].lv = 0;
sd->status.skill[idx].flag = 0;
clif->deleteskill(sd,sd->reproduceskill_id);
clif->deleteskill(sd, sd->reproduceskill_id, false);
}
sd->reproduceskill_id = 0;
pc_setglobalreg(sd, script->add_variable("REPRODUCE_SKILL"),0);
Expand Down Expand Up @@ -9206,10 +9206,6 @@ static int pc_jobchange(struct map_session_data *sd, int class, int upper)
if (sd->vd.body_style)
clif->changelook(&sd->bl,LOOK_BODY2,sd->vd.body_style);

//Update skill tree.
pc->calc_skilltree(sd);
clif->skillinfoblock(sd);

if (old_overhealweightrate != pc_overhealweightrate(sd))
clif->overweight_percent(sd);

Expand Down
4 changes: 2 additions & 2 deletions src/map/skill.c
Original file line number Diff line number Diff line change
Expand Up @@ -3661,7 +3661,7 @@ static int skill_attack(int attack_type, struct block_list *src, struct block_li
tsd->status.skill[idx].id = 0;
tsd->status.skill[idx].lv = 0;
tsd->status.skill[idx].flag = 0;
clif->deleteskill(tsd, tsd->cloneskill_id);
clif->deleteskill(tsd, tsd->cloneskill_id, false);
}
}

Expand All @@ -3686,7 +3686,7 @@ static int skill_attack(int attack_type, struct block_list *src, struct block_li
tsd->status.skill[idx].id = 0;
tsd->status.skill[idx].lv = 0;
tsd->status.skill[idx].flag = 0;
clif->deleteskill(tsd, tsd->reproduceskill_id);
clif->deleteskill(tsd, tsd->reproduceskill_id, false);
}
}
lv = min(lv, skill->get_max(copy_skill));
Expand Down
12 changes: 11 additions & 1 deletion src/map/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -2388,8 +2388,18 @@ static int status_calc_pc_(struct map_session_data *sd, enum e_status_calc_opt o
calculating = 0;
return 0;
}
if(memcmp(b_skill,sd->status.skill,sizeof(sd->status.skill)))

if (memcmp(b_skill, sd->status.skill, sizeof(sd->status.skill))) {
#if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190918
// Client doesn't delete unavailable skills even if we refresh
// the skill tree, individually delete them.
for (i = 0; i < MAX_SKILL_DB; i++) {
if (b_skill[i].id != 0 && sd->status.skill[i].id == 0)
clif->deleteskill(sd, b_skill[i].id, true);
}
#endif
clif->skillinfoblock(sd);
}
if(b_weight != sd->weight)
clif->updatestatus(sd,SP_WEIGHT);
if(b_max_weight != sd->max_weight) {
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 @@ -1964,8 +1964,8 @@ typedef void (*HPMHOOK_pre_clif_skillinfo) (struct map_session_data **sd, int *s
typedef void (*HPMHOOK_post_clif_skillinfo) (struct map_session_data *sd, int skill_id, int inf);
typedef void (*HPMHOOK_pre_clif_addskill) (struct map_session_data **sd, int *id);
typedef void (*HPMHOOK_post_clif_addskill) (struct map_session_data *sd, int id);
typedef void (*HPMHOOK_pre_clif_deleteskill) (struct map_session_data **sd, int *id);
typedef void (*HPMHOOK_post_clif_deleteskill) (struct map_session_data *sd, int id);
typedef void (*HPMHOOK_pre_clif_deleteskill) (struct map_session_data **sd, int *id, bool *skip_infoblock);
typedef void (*HPMHOOK_post_clif_deleteskill) (struct map_session_data *sd, int id, bool skip_infoblock);
typedef void (*HPMHOOK_pre_clif_playerSkillToPacket) (struct map_session_data **sd, struct SKILLDATA **skillData, int *skillId, int *idx, bool *newSkill);
typedef void (*HPMHOOK_post_clif_playerSkillToPacket) (struct map_session_data *sd, struct SKILLDATA *skillData, int skillId, int idx, bool newSkill);
typedef void (*HPMHOOK_pre_clif_party_created) (struct map_session_data **sd, int *result);
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17265,28 +17265,28 @@ void HP_clif_addskill(struct map_session_data *sd, int id) {
}
return;
}
void HP_clif_deleteskill(struct map_session_data *sd, int id) {
void HP_clif_deleteskill(struct map_session_data *sd, int id, bool skip_infoblock) {
int hIndex = 0;
if (HPMHooks.count.HP_clif_deleteskill_pre > 0) {
void (*preHookFunc) (struct map_session_data **sd, int *id);
void (*preHookFunc) (struct map_session_data **sd, int *id, bool *skip_infoblock);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_deleteskill_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_clif_deleteskill_pre[hIndex].func;
preHookFunc(&sd, &id);
preHookFunc(&sd, &id, &skip_infoblock);
}
if (*HPMforce_return) {
*HPMforce_return = false;
return;
}
}
{
HPMHooks.source.clif.deleteskill(sd, id);
HPMHooks.source.clif.deleteskill(sd, id, skip_infoblock);
}
if (HPMHooks.count.HP_clif_deleteskill_post > 0) {
void (*postHookFunc) (struct map_session_data *sd, int id);
void (*postHookFunc) (struct map_session_data *sd, int id, bool skip_infoblock);
for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_deleteskill_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_clif_deleteskill_post[hIndex].func;
postHookFunc(sd, id);
postHookFunc(sd, id, skip_infoblock);
}
}
return;
Expand Down

0 comments on commit db4a096

Please sign in to comment.