Applied suggestions from code review

This commit is contained in:
Daegaladh 2024-08-06 09:51:28 +02:00
parent 9f5f13266b
commit 001acf46e2
4 changed files with 32 additions and 36 deletions

View File

@ -1749,7 +1749,7 @@ int clif_spawn( struct block_list *bl, bool walking ){
return 0; return 0;
} }
/// Notifies client of a change in an elemental's status parameter. /// Notifies client of a change in an homunculus' status parameter.
/// 0x7db <type>.W <value>.L (ZC_HO_PAR_CHANGE) /// 0x7db <type>.W <value>.L (ZC_HO_PAR_CHANGE)
/// 0xba5 <type>.W <value>.Q (ZC_HO_PAR_CHANGE2) /// 0xba5 <type>.W <value>.Q (ZC_HO_PAR_CHANGE2)
void clif_homunculus_updatestatus(map_session_data& sd, _sp type) { void clif_homunculus_updatestatus(map_session_data& sd, _sp type) {
@ -1765,14 +1765,23 @@ void clif_homunculus_updatestatus(map_session_data& sd, _sp type) {
switch (type) { switch (type) {
case SP_BASEEXP: case SP_BASEEXP:
p.value = static_cast<decltype(p.value)>(sd.hd->homunculus.exp); p.value = static_cast<decltype(p.value)>( std::min<decltype(sd.hd->homunculus.exp)>( sd.hd->homunculus.exp, std::numeric_limits<decltype(PACKET_ZC_PROPERTY_HOMUN::exp)>::max() ) );
break; break;
case SP_HP: case SP_HP:
if (status->max_hp > (std::numeric_limits<decltype(PACKET_ZC_PROPERTY_HOMUN::hp)>::max() / 200))
p.value = status->hp / (status->max_hp / 100);
else
p.value = static_cast<decltype(p.value)>(status->hp); p.value = static_cast<decltype(p.value)>(status->hp);
break; break;
case SP_SP: case SP_SP:
if (status->max_sp > (std::numeric_limits<decltype(PACKET_ZC_PROPERTY_HOMUN::sp)>::max() / 200))
p.value = status->sp / (status->max_sp / 100);
else
p.value = static_cast<decltype(p.value)>(status->sp); p.value = static_cast<decltype(p.value)>(status->sp);
break; break;
default:
ShowError("clif_homunculus_updatestatus: Unsupported type %d.\n", type);
return;
} }
clif_send(&p, sizeof(p), &sd.bl, SELF); clif_send(&p, sizeof(p), &sd.bl, SELF);
@ -1817,39 +1826,25 @@ void clif_hominfo( map_session_data *sd, struct homun_data *hd, int flag ){
#endif #endif
p.flee = status->flee; p.flee = status->flee;
p.amotion = (flag) ? 0 : status->amotion; p.amotion = (flag) ? 0 : status->amotion;
#if PACKETVER >= 20141016 // Homunculus HP and SP bars will screw up if the percentage calculation exceeds signed values
// Homunculus HP bar will screw up if the percentage calculation exceeds signed values // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the bars
// Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar if( status->max_hp > ( std::numeric_limits<decltype(p.hp)>::max() / 200 ) ){
if( status->max_hp > ( INT32_MAX / 100 ) ){
p.hp = status->hp / ( status->max_hp / 100 ); p.hp = status->hp / ( status->max_hp / 100 );
p.maxHp = 100; p.maxHp = 100;
}else{ }else{
p.hp = status->hp; p.hp = static_cast<decltype(p.hp)>(status->hp);
p.maxHp = status->max_hp; p.maxHp = static_cast<decltype(p.maxHp)>(status->max_hp);
} }
#else if( status->max_sp > ( std::numeric_limits<decltype(p.sp)>::max() / 200) ){
if( status->max_hp > INT16_MAX ){
p.hp = status->hp / ( status->max_hp / 100 );
p.maxHp = 100;
}else{
p.hp = status->hp;
p.maxHp = status->max_hp;
}
#endif
if( status->max_sp > INT16_MAX ){
p.sp = status->sp / ( status->max_sp / 100 ); p.sp = status->sp / ( status->max_sp / 100 );
p.maxSp = 100; p.maxSp = 100;
}else{ }else{
p.sp = status->sp; p.sp = static_cast<decltype(p.sp)>(status->sp);
p.maxSp = status->max_sp; p.maxSp = static_cast<decltype(p.maxSp)>(status->max_sp);
} }
#if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103 p.exp = static_cast<decltype(p.exp)>( std::min<decltype(hd->homunculus.exp)>( hd->homunculus.exp, std::numeric_limits<decltype(p.exp)>::max() ) );
p.exp = hd->homunculus.exp; p.expNext = static_cast<decltype(p.expNext)>( std::min<decltype(hd->exp_next)>( hd->exp_next, std::numeric_limits<decltype(p.expNext)>::max() ) );
p.expNext = hd->exp_next;
#else
p.exp = (uint32)hd->homunculus.exp;
p.expNext = (uint32)hd->exp_next;
#endif
switch( hom_class2type( hd->homunculus.class_ ) ){ switch( hom_class2type( hd->homunculus.class_ ) ){
case HT_REG: case HT_REG:
case HT_EVO: case HT_EVO:

View File

@ -688,6 +688,7 @@ int hom_mutate(struct homun_data *hd, int homun_id)
status_calc_homunculus(hd, SCO_FIRST); status_calc_homunculus(hd, SCO_FIRST);
clif_hominfo(sd, hd, 0); clif_hominfo(sd, hd, 0);
hom_calc_skilltree(hd);
if (!(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL)) if (!(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL))
skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
@ -787,14 +788,14 @@ int hom_decrease_intimacy(struct homun_data * hd, unsigned int value)
* @param hp HP amount * @param hp HP amount
* @param sp SP amount * @param sp SP amount
*/ */
void hom_heal(struct homun_data *hd, int hp, int sp) { void hom_heal(homun_data& hd, bool hp, bool sp) {
if (hd->master == nullptr) if (hd.master == nullptr)
return; return;
if (hp) if (hp)
clif_homunculus_updatestatus(*hd->master, SP_HP); clif_homunculus_updatestatus(*hd.master, SP_HP);
if (sp) if (sp)
clif_homunculus_updatestatus(*hd->master, SP_SP); clif_homunculus_updatestatus(*hd.master, SP_SP);
} }
/** /**

View File

@ -216,7 +216,7 @@ void hom_gainexp(struct homun_data *hd,t_exp exp);
int hom_levelup(struct homun_data *hd); int hom_levelup(struct homun_data *hd);
int hom_evolution(struct homun_data *hd); int hom_evolution(struct homun_data *hd);
int hom_mutate(struct homun_data *hd,int homun_id); int hom_mutate(struct homun_data *hd,int homun_id);
void hom_heal(struct homun_data* hd, int hp, int sp); void hom_heal(homun_data& hd, bool hp, bool sp);
int hom_vaporize(map_session_data *sd, int flag); int hom_vaporize(map_session_data *sd, int flag);
int hom_ressurect(map_session_data *sd, unsigned char per, short x, short y); int hom_ressurect(map_session_data *sd, unsigned char per, short x, short y);
void hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp); void hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp);

View File

@ -1588,7 +1588,7 @@ int status_damage(struct block_list *src,struct block_list *target,int64 dhp, in
mob_damage(reinterpret_cast<mob_data*>(target), src, (int)dhp); mob_damage(reinterpret_cast<mob_data*>(target), src, (int)dhp);
break; break;
case BL_HOM: case BL_HOM:
hom_heal(reinterpret_cast<homun_data*>(target), hp, sp); hom_heal(reinterpret_cast<homun_data&>(*target), hp != 0, sp != 0);
break; break;
case BL_MER: case BL_MER:
mercenary_heal(reinterpret_cast<s_mercenary_data*>(target), hp, sp); mercenary_heal(reinterpret_cast<s_mercenary_data*>(target), hp, sp);
@ -1811,7 +1811,7 @@ int status_heal(struct block_list *bl,int64 hhp,int64 hsp, int64 hap, int flag)
mob_heal(reinterpret_cast<mob_data*>(bl), hp); mob_heal(reinterpret_cast<mob_data*>(bl), hp);
break; break;
case BL_HOM: case BL_HOM:
hom_heal(reinterpret_cast<homun_data*>(bl), hp, sp); hom_heal(reinterpret_cast<homun_data&>(*bl), hp != 0, sp != 0);
break; break;
case BL_MER: case BL_MER:
mercenary_heal(reinterpret_cast<s_mercenary_data*>(bl), hp, sp); mercenary_heal(reinterpret_cast<s_mercenary_data*>(bl), hp, sp);