summaryrefslogtreecommitdiff
path: root/src/map/pc.c
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-06-05 15:05:49 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-06-05 15:05:49 +0000
commitf7cf35aaad2512e7f329954946aac5e2a24cdfb7 (patch)
tree93dff649c7a49c0f6758a18adb23105968dd9df2 /src/map/pc.c
parentc05a7a22feec3a93445654f0ce1eead31052e6b9 (diff)
downloadhercules-f7cf35aaad2512e7f329954946aac5e2a24cdfb7.tar.gz
hercules-f7cf35aaad2512e7f329954946aac5e2a24cdfb7.tar.bz2
hercules-f7cf35aaad2512e7f329954946aac5e2a24cdfb7.tar.xz
hercules-f7cf35aaad2512e7f329954946aac5e2a24cdfb7.zip
- Corrected cloaking not ending on attack if you are near a wall.
- Moved define cap_value to map.h as it's quite handy. - Updated pc_bonus to use cap_value on all status_data modifiers to prevent overflows/underflows. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6979 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/pc.c')
-rw-r--r--src/map/pc.c107
1 files changed, 65 insertions, 42 deletions
diff --git a/src/map/pc.c b/src/map/pc.c
index 89e4a523b..60d6ae749 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -1200,6 +1200,7 @@ static int pc_bonus_item_drop(struct s_add_drop *drop, short *count, short id, s
int pc_bonus(struct map_session_data *sd,int type,int val)
{
struct status_data *status;
+ int bonus;
nullpo_retr(0, sd);
status = &sd->base_status;
@@ -1246,50 +1247,52 @@ int pc_bonus(struct map_session_data *sd,int type,int val)
break;
case SP_DEF1:
if(sd->state.lr_flag != 2) {
- if (val < 0 && status->def < -val)
- status->def = 0;
- else if (val > 0 && val > UCHAR_MAX - status->def)
- status->def = UCHAR_MAX;
- else
- status->def+=val;
+ bonus = status->def + val;
+ status->def = cap_value(bonus, 0, UCHAR_MAX);
}
break;
case SP_DEF2:
- if(sd->state.lr_flag != 2)
- status->def2+=val;
+ if(sd->state.lr_flag != 2) {
+ bonus = status->def2 + val;
+ status->def2 = cap_value(bonus, 0, USHRT_MAX);
+ }
break;
case SP_MDEF1:
- if(sd->state.lr_flag != 2)
- status->mdef+=val;
+ if(sd->state.lr_flag != 2) {
+ bonus = status->mdef + val;
+ status->mdef = cap_value(bonus, 0, UCHAR_MAX);
+ }
break;
case SP_MDEF2:
if(sd->state.lr_flag != 2) {
- if (val < 0 && status->mdef < -val)
- status->mdef = 0;
- else if (val > 0 && val > UCHAR_MAX - status->mdef)
- status->mdef = UCHAR_MAX;
- else
- status->mdef+=val;
+ bonus = status->mdef2 + val;
+ status->mdef2 = cap_value(bonus, 0, USHRT_MAX);
}
break;
case SP_HIT:
- if(sd->state.lr_flag != 2)
- status->hit+=val;
- else
+ if(sd->state.lr_flag != 2) {
+ bonus = status->hit + val;
+ status->hit = cap_value(bonus, 0, USHRT_MAX);
+ } else
sd->arrow_hit+=val;
break;
case SP_FLEE1:
- if(sd->state.lr_flag != 2)
- status->flee+=val;
+ if(sd->state.lr_flag != 2) {
+ bonus = status->flee + val;
+ status->flee = cap_value(bonus, 0, USHRT_MAX);
+ }
break;
case SP_FLEE2:
- if(sd->state.lr_flag != 2)
- status->flee2+=val*10;
+ if(sd->state.lr_flag != 2) {
+ bonus = status->flee2 + val*10;
+ status->flee2 = cap_value(bonus, 0, USHRT_MAX);
+ }
break;
case SP_CRITICAL:
- if(sd->state.lr_flag != 2)
- status->cri+=val*10;
- else
+ if(sd->state.lr_flag != 2) {
+ bonus = status->cri + val*10;
+ status->cri = cap_value(bonus, 0, USHRT_MAX);
+ } else
sd->arrow_cri += val*10;
break;
case SP_ATKELE:
@@ -1298,12 +1301,18 @@ int pc_bonus(struct map_session_data *sd,int type,int val)
ShowError("pc_bonus: SP_ATKELE: Invalid element %d\n", val);
break;
}
- if(!sd->state.lr_flag)
- status->rhw.ele=val;
- else if(sd->state.lr_flag == 1)
- status->lhw->ele=val;
- else if(sd->state.lr_flag == 2)
+ switch (sd->state.lr_flag)
+ {
+ case 2:
sd->arrow_ele=val;
+ break;
+ case 1:
+ status->lhw->ele=val;
+ break;
+ default:
+ status->rhw.ele=val;
+ break;
+ }
break;
case SP_DEFELE:
if(val >= ELE_MAX) {
@@ -1315,12 +1324,20 @@ int pc_bonus(struct map_session_data *sd,int type,int val)
status->def_ele=val;
break;
case SP_MAXHP:
- if(sd->state.lr_flag != 2)
- status->max_hp+=val;
+ if(sd->state.lr_flag != 2) {
+ if (val < 0 && status->max_hp <= -val)
+ status->max_hp = 1;
+ else
+ status->max_hp+=val;
+ }
break;
case SP_MAXSP:
- if(sd->state.lr_flag != 2)
- status->max_sp+=val;
+ if(sd->state.lr_flag != 2) {
+ if (val < 0 && status->max_sp <= -val)
+ status->max_sp = 1;
+ else
+ status->max_sp+=val;
+ }
break;
case SP_CASTRATE:
if(sd->state.lr_flag != 2)
@@ -1339,11 +1356,8 @@ int pc_bonus(struct map_session_data *sd,int type,int val)
sd->dsprate+=val;
break;
case SP_ATTACKRANGE:
- if(!sd->state.lr_flag)
- status->rhw.range += val;
- else if(sd->state.lr_flag == 1)
- status->lhw->range += val;
- else if(sd->state.lr_flag == 2) {
+ switch (sd->state.lr_flag) {
+ case 2:
switch (sd->status.weapon) {
case W_BOW:
case W_REVOLVER:
@@ -1353,11 +1367,20 @@ int pc_bonus(struct map_session_data *sd,int type,int val)
case W_GRENADE:
status->rhw.range += val;
}
+ break;
+ case 1:
+ status->lhw->range += val;
+ break;
+ default:
+ status->rhw.range += val;
+ break;
}
break;
case SP_ADD_SPEED: //Raw increase
- if(sd->state.lr_flag != 2)
- status->speed -= val;
+ if(sd->state.lr_flag != 2) {
+ bonus = status->speed - val;
+ status->speed = cap_value(bonus, 0, USHRT_MAX);
+ }
break;
case SP_SPEED_RATE: //Non stackable increase
if(sd->state.lr_flag != 2 && sd->speed_rate > 100-val)