diff options
Diffstat (limited to 'src/map/pc.c')
-rw-r--r-- | src/map/pc.c | 190 |
1 files changed, 61 insertions, 129 deletions
diff --git a/src/map/pc.c b/src/map/pc.c index 082a61aa3..a5699312d 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -4325,25 +4325,30 @@ unsigned int pc_thisjobexp(struct map_session_data *sd) return exp_table[pc_class2idx(sd->status.class_)][1][sd->status.job_level-2]; } +static int pc_getstat(struct map_session_data* sd, int type) +{ + nullpo_retr(-1, sd); + switch( type ) { + case SP_STR: return sd->status.str; + case SP_AGI: return sd->status.agi; + case SP_VIT: return sd->status.vit; + case SP_INT: return sd->status.int_; + case SP_DEX: return sd->status.dex; + case SP_LUK: return sd->status.luk; + default: + return -1; + } +} + /*========================================== * 必要ステ?タスポイント計算 *------------------------------------------*/ int pc_need_status_point(struct map_session_data *sd,int type) { - int val; - nullpo_retr(-1, sd); - - if(type<SP_STR || type>SP_LUK) + if( type < SP_STR || type > SP_LUK ) return -1; - val = - type==SP_STR ? sd->status.str : - type==SP_AGI ? sd->status.agi : - type==SP_VIT ? sd->status.vit : - type==SP_INT ? sd->status.int_: - type==SP_DEX ? sd->status.dex : sd->status.luk; - - return (val+9)/10+1; + return ( 1 + (pc_getstat(sd,type) + 9) / 10 ); } /*========================================== @@ -4355,57 +4360,31 @@ int pc_statusup(struct map_session_data *sd,int type) nullpo_retr(0, sd); - max = pc_maxparameter(sd); + // check conditions + need = pc_need_status_point(sd,type); + if( type < SP_STR || type > SP_LUK || need < 0 || need > sd->status.status_point ) + { + clif_statusupack(sd,type,0,0); + return 1; + } - need=pc_need_status_point(sd,type); - if(type<SP_STR || type>SP_LUK || need<0 || need>sd->status.status_point){ + // check limits + max = pc_maxparameter(sd); + if( pc_getstat(sd,type) >= max ) + { clif_statusupack(sd,type,0,0); return 1; } + switch(type){ - case SP_STR: - if(sd->status.str >= max) { - clif_statusupack(sd,type,0,0); - return 1; - } - val= ++sd->status.str; - break; - case SP_AGI: - if(sd->status.agi >= max) { - clif_statusupack(sd,type,0,0); - return 1; - } - val= ++sd->status.agi; - break; - case SP_VIT: - if(sd->status.vit >= max) { - clif_statusupack(sd,type,0,0); - return 1; - } - val= ++sd->status.vit; - break; - case SP_INT: - if(sd->status.int_ >= max) { - clif_statusupack(sd,type,0,0); - return 1; - } - val= ++sd->status.int_; - break; - case SP_DEX: - if(sd->status.dex >= max) { - clif_statusupack(sd,type,0,0); - return 1; - } - val= ++sd->status.dex; - break; - case SP_LUK: - if(sd->status.luk >= max) { - clif_statusupack(sd,type,0,0); - return 1; - } - val= ++sd->status.luk; - break; + case SP_STR: val= ++sd->status.str; break; + case SP_AGI: val= ++sd->status.agi; break; + case SP_VIT: val= ++sd->status.vit; break; + case SP_INT: val= ++sd->status.int_; break; + case SP_DEX: val= ++sd->status.dex; break; + case SP_LUK: val= ++sd->status.luk; break; } + sd->status.status_point-=need; if(need!=pc_need_status_point(sd,type)){ clif_updatestatus(sd,type-SP_STR+SP_USTR); @@ -4428,66 +4407,18 @@ int pc_statusup2(struct map_session_data *sd,int type,int val) max = pc_maxparameter(sd); - if(type<SP_STR || type>SP_LUK){ + switch(type){ + case SP_STR: sd->status.str = cap_value(sd->status.str + val, 1, max); break; + case SP_AGI: sd->status.agi = cap_value(sd->status.agi + val, 1, max); break; + case SP_VIT: sd->status.vit = cap_value(sd->status.vit + val, 1, max); break; + case SP_INT: sd->status.int_= cap_value(sd->status.int_+ val, 1, max); break; + case SP_DEX: sd->status.dex = cap_value(sd->status.dex + val, 1, max); break; + case SP_LUK: sd->status.luk = cap_value(sd->status.luk + val, 1, max); break; + default: clif_statusupack(sd,type,0,0); return 1; } - switch(type){ - case SP_STR: - if(sd->status.str + val >= max) - val = max; - else if(sd->status.str + val < 1) - val = 1; - else - val += sd->status.str; - sd->status.str = val; - break; - case SP_AGI: - if(sd->status.agi + val >= max) - val = max; - else if(sd->status.agi + val < 1) - val = 1; - else - val += sd->status.agi; - sd->status.agi = val; - break; - case SP_VIT: - if(sd->status.vit + val >= max) - val = max; - else if(sd->status.vit + val < 1) - val = 1; - else - val += sd->status.vit; - sd->status.vit = val; - break; - case SP_INT: - if(sd->status.int_ + val >= max) - val = max; - else if(sd->status.int_ + val < 1) - val = 1; - else - val += sd->status.int_; - sd->status.int_ = val; - break; - case SP_DEX: - if(sd->status.dex + val >= max) - val = max; - else if(sd->status.dex + val < 1) - val = 1; - else - val += sd->status.dex; - sd->status.dex = val; - break; - case SP_LUK: - if(sd->status.luk + val >= max) - val = max; - else if(sd->status.luk + val < 1) - val = 1; - else - val = sd->status.luk + val; - sd->status.luk = val; - break; - } + status_calc_pc(sd,0); clif_statusupack(sd,type,1,val); @@ -6228,15 +6159,13 @@ static int pc_eventtimer(int tid,unsigned int tick,int id,int data) int pc_addeventtimer(struct map_session_data *sd,int tick,const char *name) { int i; - char* evname; nullpo_retr(0, sd); ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == -1 ); if( i == MAX_EVENTTIMER ) return 0; - evname = aStrdup(name); - sd->eventtimer[i] = add_timer(gettick()+tick, pc_eventtimer,sd->bl.id,(int)evname); + sd->eventtimer[i] = add_timer(gettick()+tick, pc_eventtimer, sd->bl.id, (int)aStrdup(name)); sd->eventcount++; return 1; @@ -6248,25 +6177,28 @@ int pc_addeventtimer(struct map_session_data *sd,int tick,const char *name) int pc_deleventtimer(struct map_session_data *sd,const char *name) { int i; + char* p; nullpo_retr(0, sd); if (sd->eventcount <= 0) return 0; - for(i=0;i<MAX_EVENTTIMER;i++) - if( sd->eventtimer[i]!=-1 ) { - char *p = (char *)(get_timer(sd->eventtimer[i])->data); - if(p && strcmp(p, name)==0) { - delete_timer(sd->eventtimer[i],pc_eventtimer); - sd->eventtimer[i]=-1; - sd->eventcount--; - aFree(p); - return 1; - } - } + // find the named event timer + ARR_FIND( 0, MAX_EVENTTIMER, i, + sd->eventtimer[i] != -1 && + (p = (char *)(get_timer(sd->eventtimer[i])->data)) != NULL && + strcmp(p, name) == 0 + ); + if( i == MAX_EVENTTIMER ) + return 0; // not found - return 0; + delete_timer(sd->eventtimer[i],pc_eventtimer); + sd->eventtimer[i]=-1; + sd->eventcount--; + aFree(p); + + return 1; } /*========================================== |