summaryrefslogtreecommitdiff
path: root/src/map/party.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/party.c')
-rw-r--r--src/map/party.c53
1 files changed, 18 insertions, 35 deletions
diff --git a/src/map/party.c b/src/map/party.c
index 5117ce5ed..2427dab98 100644
--- a/src/map/party.c
+++ b/src/map/party.c
@@ -702,20 +702,20 @@ int party_send_xy_clear(struct party_data *p)
}
// exp share and added zeny share [Valaris]
-int party_exp_share(struct party_data *p,struct block_list *src,unsigned int base_exp,unsigned int job_exp,int zeny)
+int party_exp_share(struct party_data* p, struct block_list* src, unsigned int base_exp, unsigned int job_exp, int zeny)
{
struct map_session_data* sd[MAX_PARTY];
- int i;
- unsigned short c;
+ unsigned int i, c;
nullpo_retr(0, p);
- for (i = c = 0; i < MAX_PARTY; i++)
- if ((sd[c] = p->data[i].sd)!=NULL && sd[c]->bl.m == src->m && !pc_isdead(sd[c])) {
- if (battle_config.idle_no_share && (sd[c]->chatID || sd[c]->vender_id || (sd[c]->idletime < (last_tick - battle_config.idle_no_share))))
- continue;
- c++;
- }
+ // count the number of players eligible for exp sharing
+ for (i = c = 0; i < MAX_PARTY; i++) {
+ if( (sd[c] = p->data[i].sd) == NULL || sd[c]->bl.m != src->m || pc_isdead(sd[c]) ||
+ battle_config.idle_no_share && (sd[c]->chatID || sd[c]->vender_id || sd[c]->idletime < last_tick - battle_config.idle_no_share) )
+ continue;
+ c++;
+ }
if (c < 1)
return 0;
@@ -723,32 +723,15 @@ int party_exp_share(struct party_data *p,struct block_list *src,unsigned int bas
job_exp/=c;
zeny/=c;
- if (battle_config.party_even_share_bonus && c > 1) {
- unsigned short bonus =100 + battle_config.party_even_share_bonus*(c-1);
- if (base_exp) {
- if (base_exp/100 > UINT_MAX/bonus)
- base_exp= UINT_MAX; //Exp overflow
- else if (base_exp > 10000)
- base_exp = (base_exp/100)*bonus; //Calculation overflow protection
- else
- base_exp = base_exp*bonus/100;
- }
- if (job_exp) {
- if (job_exp/100 > UINT_MAX/bonus)
- job_exp = UINT_MAX;
- else if (job_exp > 10000)
- job_exp = (job_exp/100)*bonus;
- else
- job_exp = job_exp*bonus/100;
- }
- if (zeny) {
- if (zeny/100 > INT_MAX/bonus)
- zeny = INT_MAX;
- else if (zeny > 10000)
- zeny = (zeny/100)*bonus;
- else
- zeny = zeny*bonus/100;
- }
+ if (battle_config.party_even_share_bonus && c > 1)
+ {
+ double bonus = 100 + battle_config.party_even_share_bonus*(c-1);
+ if (base_exp)
+ base_exp = (unsigned int) cap_value(base_exp * bonus/100, 0, UINT_MAX);
+ if (job_exp)
+ job_exp = (unsigned int) cap_value(job_exp * bonus/100, 0, UINT_MAX);
+ if (zeny)
+ zeny = (unsigned int) cap_value(zeny * bonus/100, INT_MIN, INT_MAX);
}
for (i = 0; i < c; i++)