From cb7b9267c7bd268ddc9b26f4f133bc2e5f75a6bc Mon Sep 17 00:00:00 2001 From: Playtester Date: Wed, 29 Oct 2014 13:50:42 +0100 Subject: [PATCH] MaxHP, MaxSP and Autotrade fixes - Percentual bonuses to MaxHP and MaxSP will now always be rounded down (Aegis style) - Added a security check when calculating MaxHP and MaxSP so there can't be a number underflow (bugreport:9369) - When an auto-vendor gets logged out because of at_timeout, his store will be deleted and no longer restored after server restart (bugreport:9370) --- src/map/status.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/map/status.c b/src/map/status.c index 680940df55..629016795a 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -2760,14 +2760,17 @@ static unsigned int status_calc_maxhpsp_pc(struct map_session_data* sd, unsigned if (isHP) { //Calculates MaxHP max = job_info[idx].base_hp[level-1] * (1 + (max(stat,1) * 0.01)) * ((sd->class_&JOBL_UPPER)?1.25:1); max += status_get_hpbonus(&sd->bl,STATUS_BONUS_FIX); - max *= (1 + status_get_hpbonus(&sd->bl,STATUS_BONUS_RATE) * 0.01); + max += (int64)(max * status_get_hpbonus(&sd->bl,STATUS_BONUS_RATE) / 100); //Aegis accuracy } else { //Calculates MaxSP max = job_info[idx].base_sp[level-1] * (1 + (max(stat,1) * 0.01)) * ((sd->class_&JOBL_UPPER)?1.25:1); max += status_get_spbonus(&sd->bl,STATUS_BONUS_FIX); - max *= (1 + status_get_spbonus(&sd->bl,STATUS_BONUS_RATE) * 0.01); + max += (int64)(max * status_get_spbonus(&sd->bl,STATUS_BONUS_RATE) / 100); //Aegis accuracy } + //Make sure it's not negative before casting to unsigned int + if(max < 1) max = 1; + return cap_value((unsigned int)max,1,UINT_MAX); } @@ -10837,8 +10840,8 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const case SC_AUTOTRADE: if (tid == INVALID_TIMER) break; - // Note: vending/buying is closed by unit_remove_map, no - // need to do it here. + // Vending is not automatically closed for autovenders + vending_closevending(sd); map_quit(sd); // Because map_quit calls status_change_end with tid -1 // from here it's not neccesary to continue