From 08e3879a38da10dc3f0bdd3f7278c0355a1d263a Mon Sep 17 00:00:00 2001 From: skotlex Date: Thu, 23 Mar 2006 18:21:36 +0000 Subject: - Modified pc_percent_heal to avoid overflow problems. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@5718 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/pc.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'src/map/pc.c') diff --git a/src/map/pc.c b/src/map/pc.c index 324b90c40..40b323f46 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -5224,7 +5224,7 @@ int pc_heal(struct map_session_data *sd,int hp,int sp) // if(sp > 0 && pc_checkoversp(sd)) // sp = 0; - if(sd->sc.count && sd->sc.data[SC_BERSERK].timer!=-1) //バ?サ?ク中は回復させないらしい + if(sd->sc.count && sd->sc.data[SC_BERSERK].timer!=-1 && hp+sp>0) return 0; if(hp > sd->status.max_hp - sd->status.hp) @@ -5324,7 +5324,7 @@ int pc_itemheal(struct map_session_data *sd,int hp,int sp) int pc_percentheal(struct map_session_data *sd,int hp,int sp) { nullpo_retr(0, sd); - +/* Shouldn't be needed, these functions are proof of bad coding xP if(pc_checkoverhp(sd)) { if(hp > 0) hp = 0; @@ -5333,38 +5333,47 @@ int pc_percentheal(struct map_session_data *sd,int hp,int sp) if(sp > 0) sp = 0; } +*/ if(hp) { - if(hp >= 100) { + if(hp >= 100) sd->status.hp = sd->status.max_hp; - } else if(hp <= -100) { sd->status.hp = 0; pc_damage(NULL,sd,1); } - else { - sd->status.hp += sd->status.max_hp*hp/100; - if(sd->status.hp > sd->status.max_hp) + else if (hp > 0) { + hp = sd->status.max_hp*hp/100; + if (sd->status.max_hp - sd->status.hp < hp) sd->status.hp = sd->status.max_hp; - if(sd->status.hp <= 0) { + else + sd->status.hp += hp; + } + else { //hp < 0 + hp = sd->status.max_hp*hp/100; + if (sd->status.hp <= hp) { sd->status.hp = 0; pc_damage(NULL,sd,1); - hp = 0; - } + } else + sd->status.hp -= hp; } } if(sp) { - if(sp >= 100) { + if(sp >= 100) sd->status.sp = sd->status.max_sp; - } - else if(sp <= -100) { + else if(sp <= -100) sd->status.sp = 0; - } - else { - sd->status.sp += sd->status.max_sp*sp/100; - if(sd->status.sp > sd->status.max_sp) + else if(sp > 0) { + sp = sd->status.max_sp*sp/100; + if (sd->status.max_sp - sd->status.sp < sp) sd->status.sp = sd->status.max_sp; - if(sd->status.sp < 0) + else + sd->status.sp += sp; + } else { //sp < 0 + sp = sd->status.max_sp*sp/100; + if (sd->status.sp <= sp) sd->status.sp = 0; + else + sd->status.sp -= sp; } } if(hp) -- cgit v1.2.3-70-g09d2