diff options
author | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-03-23 18:21:36 +0000 |
---|---|---|
committer | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-03-23 18:21:36 +0000 |
commit | 08e3879a38da10dc3f0bdd3f7278c0355a1d263a (patch) | |
tree | 2ae7ff0a8b02331d3e4047ae50234d6ea9537d69 | |
parent | 80e4f1be607a232e0165e51f901fbe51a39ad8c0 (diff) | |
download | hercules-08e3879a38da10dc3f0bdd3f7278c0355a1d263a.tar.gz hercules-08e3879a38da10dc3f0bdd3f7278c0355a1d263a.tar.bz2 hercules-08e3879a38da10dc3f0bdd3f7278c0355a1d263a.tar.xz hercules-08e3879a38da10dc3f0bdd3f7278c0355a1d263a.zip |
- 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
-rw-r--r-- | Changelog-Trunk.txt | 1 | ||||
-rw-r--r-- | src/map/pc.c | 45 |
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)
|