From 001acf46e2e54ef95133d7c3fb1dae54f119a1e9 Mon Sep 17 00:00:00 2001 From: Daegaladh Date: Tue, 6 Aug 2024 09:51:28 +0200 Subject: [PATCH] Applied suggestions from code review --- src/map/clif.cpp | 53 +++++++++++++++++++----------------------- src/map/homunculus.cpp | 9 +++---- src/map/homunculus.hpp | 2 +- src/map/status.cpp | 4 ++-- 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index c8863c4a89..dcf6ea40a8 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -1749,7 +1749,7 @@ int clif_spawn( struct block_list *bl, bool walking ){ return 0; } -/// Notifies client of a change in an elemental's status parameter. +/// Notifies client of a change in an homunculus' status parameter. /// 0x7db .W .L (ZC_HO_PAR_CHANGE) /// 0xba5 .W .Q (ZC_HO_PAR_CHANGE2) 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) { case SP_BASEEXP: - p.value = static_cast(sd.hd->homunculus.exp); + p.value = static_cast( std::minhomunculus.exp)>( sd.hd->homunculus.exp, std::numeric_limits::max() ) ); break; case SP_HP: - p.value = static_cast(status->hp); + if (status->max_hp > (std::numeric_limits::max() / 200)) + p.value = status->hp / (status->max_hp / 100); + else + p.value = static_cast(status->hp); break; case SP_SP: - p.value = static_cast(status->sp); + if (status->max_sp > (std::numeric_limits::max() / 200)) + p.value = status->sp / (status->max_sp / 100); + else + p.value = static_cast(status->sp); break; + default: + ShowError("clif_homunculus_updatestatus: Unsupported type %d.\n", type); + return; } 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 p.flee = status->flee; p.amotion = (flag) ? 0 : status->amotion; -#if PACKETVER >= 20141016 - // 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 HP bar - if( status->max_hp > ( INT32_MAX / 100 ) ){ + // Homunculus HP and SP bars will screw up if the percentage calculation exceeds signed values + // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the bars + if( status->max_hp > ( std::numeric_limits::max() / 200 ) ){ p.hp = status->hp / ( status->max_hp / 100 ); p.maxHp = 100; }else{ - p.hp = status->hp; - p.maxHp = status->max_hp; + p.hp = static_cast(status->hp); + p.maxHp = static_cast(status->max_hp); } -#else - 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 ){ + if( status->max_sp > ( std::numeric_limits::max() / 200) ){ p.sp = status->sp / ( status->max_sp / 100 ); p.maxSp = 100; }else{ - p.sp = status->sp; - p.maxSp = status->max_sp; + p.sp = static_cast(status->sp); + p.maxSp = static_cast(status->max_sp); } -#if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103 - p.exp = hd->homunculus.exp; - p.expNext = hd->exp_next; -#else - p.exp = (uint32)hd->homunculus.exp; - p.expNext = (uint32)hd->exp_next; -#endif + p.exp = static_cast( std::minhomunculus.exp)>( hd->homunculus.exp, std::numeric_limits::max() ) ); + p.expNext = static_cast( std::minexp_next)>( hd->exp_next, std::numeric_limits::max() ) ); + switch( hom_class2type( hd->homunculus.class_ ) ){ case HT_REG: case HT_EVO: diff --git a/src/map/homunculus.cpp b/src/map/homunculus.cpp index e78b6929ef..919bfd638b 100644 --- a/src/map/homunculus.cpp +++ b/src/map/homunculus.cpp @@ -688,6 +688,7 @@ int hom_mutate(struct homun_data *hd, int homun_id) status_calc_homunculus(hd, SCO_FIRST); clif_hominfo(sd, hd, 0); + hom_calc_skilltree(hd); if (!(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL)) 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 sp SP amount */ -void hom_heal(struct homun_data *hd, int hp, int sp) { - if (hd->master == nullptr) +void hom_heal(homun_data& hd, bool hp, bool sp) { + if (hd.master == nullptr) return; if (hp) - clif_homunculus_updatestatus(*hd->master, SP_HP); + clif_homunculus_updatestatus(*hd.master, SP_HP); if (sp) - clif_homunculus_updatestatus(*hd->master, SP_SP); + clif_homunculus_updatestatus(*hd.master, SP_SP); } /** diff --git a/src/map/homunculus.hpp b/src/map/homunculus.hpp index 6d749f9861..27283ca295 100644 --- a/src/map/homunculus.hpp +++ b/src/map/homunculus.hpp @@ -216,7 +216,7 @@ void hom_gainexp(struct homun_data *hd,t_exp exp); int hom_levelup(struct homun_data *hd); int hom_evolution(struct homun_data *hd); 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_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); diff --git a/src/map/status.cpp b/src/map/status.cpp index e7f8a46895..3d4673c57d 100644 --- a/src/map/status.cpp +++ b/src/map/status.cpp @@ -1588,7 +1588,7 @@ int status_damage(struct block_list *src,struct block_list *target,int64 dhp, in mob_damage(reinterpret_cast(target), src, (int)dhp); break; case BL_HOM: - hom_heal(reinterpret_cast(target), hp, sp); + hom_heal(reinterpret_cast(*target), hp != 0, sp != 0); break; case BL_MER: mercenary_heal(reinterpret_cast(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(bl), hp); break; case BL_HOM: - hom_heal(reinterpret_cast(bl), hp, sp); + hom_heal(reinterpret_cast(*bl), hp != 0, sp != 0); break; case BL_MER: mercenary_heal(reinterpret_cast(bl), hp, sp);