summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog-Trunk.txt1
-rw-r--r--src/map/pc.c45
2 files changed, 28 insertions, 18 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 94c34030d..73c173742 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -5,6 +5,7 @@ IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. EV
GOES INTO TRUNK AND WILL BE MERGED INTO STABLE BY VALARIS AND WIZPUTER. -- VALARIS
2006/03/23
+ * Modified the function pc_percent_heal to prevent overflow problems. [Skotlex]
* Changed the second entry in the water_height.txt listing to specify
directly the .rsw file (instead of .gat). [Skotlex]
* Fixed Potion Pitcher sometimes crashing the server. [Skotlex]
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)