summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-12-20 02:24:07 +0100
committerHaru <haru@dotalux.com>2016-01-29 10:58:57 +0100
commit8121e1d12dca0c85892ad45f0bb765e7eba770aa (patch)
treee2a322db5989a8c657dbd3fd9b697c14eb48d291 /src/map
parentb7c5b53cccac17765fd7445b390853f5a0eb1a4d (diff)
downloadhercules-8121e1d12dca0c85892ad45f0bb765e7eba770aa.tar.gz
hercules-8121e1d12dca0c85892ad45f0bb765e7eba770aa.tar.bz2
hercules-8121e1d12dca0c85892ad45f0bb765e7eba770aa.tar.xz
hercules-8121e1d12dca0c85892ad45f0bb765e7eba770aa.zip
Replaced several floating-point operations with integer operations
This fixes several rounding errors happening in various places (i.e. the base exp for HORONG being calculated as 819 instead of 820 when the server rates are set to 1x) Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/mob.c28
-rw-r--r--src/map/npc.c30
-rw-r--r--src/map/pc.c101
-rw-r--r--src/map/script.c30
-rw-r--r--src/map/vending.c12
5 files changed, 101 insertions, 100 deletions
diff --git a/src/map/mob.c b/src/map/mob.c
index 820376508..5da9a7162 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -2482,15 +2482,15 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) {
if(mvp_sd && md->db->mexp > 0 && md->special_state.ai == AI_NONE) {
int log_mvp[2] = {0};
unsigned int mexp;
- double exp;
+ int64 exp;
//mapflag: noexp check [Lorky]
- if (map->list[m].flag.nobaseexp || type&2)
- exp =1;
- else {
+ if (map->list[m].flag.nobaseexp || type&2) {
+ exp = 1;
+ } else {
exp = md->db->mexp;
if (count > 1)
- exp += exp*(battle_config.exp_bonus_attacker*(count-1))/100.; //[Gengar]
+ exp += apply_percentrate64(exp, battle_config.exp_bonus_attacker * (count-1), 100); //[Gengar]
}
mexp = (unsigned int)cap_value(exp, 1, UINT_MAX);
@@ -3632,7 +3632,7 @@ int mob_makedummymobdb(int class_)
//Adjusts the drop rate of item according to the criteria given. [Skotlex]
unsigned int mob_drop_adjust(int baserate, int rate_adjust, unsigned short rate_min, unsigned short rate_max)
{
- double rate = baserate;
+ int64 rate = baserate;
if (battle_config.logarithmic_drops && rate_adjust > 0 && rate_adjust != 100 && baserate > 0) //Logarithmic drops equation by Ishizu-Chan
//Equation: Droprate(x,y) = x * (5 - log(x)) ^ (ln(y) / ln(5))
@@ -3640,7 +3640,7 @@ unsigned int mob_drop_adjust(int baserate, int rate_adjust, unsigned short rate_
rate = rate * pow((5.0 - log10(rate)), (log(rate_adjust/100.) / log(5.0))) + 0.5;
else
//Classical linear rate adjustment.
- rate = rate * rate_adjust/100;
+ rate = apply_percentrate64(rate, rate_adjust, 100);
return (unsigned int)cap_value(rate,rate_min,rate_max);
}
@@ -4173,12 +4173,12 @@ int mob_read_db_sub(config_setting_t *mobt, int n, const char *source)
}
if (mob->lookup_const(mobt, "Exp", &i32) && i32 >= 0) {
- double exp = (double)(i32) * (double)battle_config.base_exp_rate / 100.;
+ int64 exp = apply_percentrate64(i32, battle_config.base_exp_rate, 100);
md.base_exp = (unsigned int)cap_value(exp, 0, UINT_MAX);
}
if (mob->lookup_const(mobt, "JExp", &i32) && i32 >= 0) {
- double exp = (double)(i32) * (double)battle_config.job_exp_rate / 100.;
+ int64 exp = apply_percentrate64(i32, battle_config.job_exp_rate, 100);
md.job_exp = (unsigned int)cap_value(exp, 0, UINT_MAX);
}
@@ -4302,19 +4302,17 @@ int mob_read_db_sub(config_setting_t *mobt, int n, const char *source)
// MVP EXP Bonus: MEXP
if (mob->lookup_const(mobt, "MvpExp", &i32) && i32 >= 0) {
// Some new MVP's MEXP multiple by high exp-rate cause overflow. [LuzZza]
- double exp = (double)i32 * (double)battle_config.mvp_exp_rate / 100.;
+ int64 exp = apply_percentrate64(i32, battle_config.mvp_exp_rate, 100);
md.mexp = (unsigned int)cap_value(exp, 0, UINT_MAX);
}
if (maxhpUpdated) {
// Now that we know if it is an mvp or not, apply battle_config modifiers [Skotlex]
- double maxhp = (double)md.status.max_hp;
+ int64 maxhp = md.status.max_hp;
if (md.mexp > 0) { //Mvp
- if (battle_config.mvp_hp_rate != 100)
- maxhp = maxhp * (double)battle_config.mvp_hp_rate / 100.;
+ maxhp = apply_percentrate64(maxhp, battle_config.mvp_hp_rate, 100);
} else { //Normal mob
- if (battle_config.monster_hp_rate != 100)
- maxhp = maxhp * (double)battle_config.monster_hp_rate / 100.;
+ maxhp = apply_percentrate64(maxhp, battle_config.monster_hp_rate, 100);
}
md.status.max_hp = (unsigned int)cap_value(maxhp, 1, UINT_MAX);
}
diff --git a/src/map/npc.c b/src/map/npc.c
index acecff6d0..c70964e5e 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -1769,7 +1769,7 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po
if( w + sd->weight > sd->max_weight )
return ERROR_TYPE_INVENTORY_WEIGHT;
- if( (double)shop[i].value * amount > INT_MAX ) {
+ if ((int64)shop[i].value * amount > INT_MAX) {
ShowWarning("npc_cashshop_buy: Item '%s' (%d) price overflow attempt!\n", item->name, nameid);
ShowDebug("(NPC:'%s' (%s,%d,%d), player:'%s' (%d/%d), value:%d, amount:%d)\n",
nd->exname, map->list[nd->bl.m].name, nd->bl.x, nd->bl.y,
@@ -1812,7 +1812,7 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po
int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list) {
struct npc_data* nd;
struct npc_item_list *shop = NULL;
- double z;
+ int64 z;
int i,j,w,skill_t,new_, idx = skill->get_index(MC_DISCOUNT);
unsigned short shop_size = 0;
@@ -1883,21 +1883,21 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list) {
value = pc->modifybuyvalue(sd,value);
- z += (double)value * amount;
+ z += (int64)value * amount;
w += itemdb_weight(nameid) * amount;
}
if( nd->master_nd != NULL ) //Script-based shops.
return npc->buylist_sub(sd,n,item_list,nd->master_nd);
- if( z > (double)sd->status.zeny )
+ if (z > sd->status.zeny)
return 1; // Not enough Zeny
if( w + sd->weight > sd->max_weight )
return 2; // Too heavy
if( pc->inventoryblank(sd) < new_ )
return 3; // Not enough space to store items
- pc->payzeny(sd,(int)z,LOG_TYPE_NPC, NULL);
+ pc->payzeny(sd, (int)z, LOG_TYPE_NPC, NULL);
for( i = 0; i < n; ++i ) {
int nameid = item_list[i*2+1];
@@ -1921,10 +1921,10 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list) {
skill_t = sd->status.skill[idx].flag - SKILL_FLAG_REPLACED_LV_0;
if( skill_t > 0 ) {
- z = z * (double)skill_t * (double)battle_config.shop_exp/10000.;
- if( z < 1 )
+ z = apply_percentrate64(z, skill_t * battle_config.shop_exp, 10000);
+ if (z < 1)
z = 1;
- pc->gainexp(sd,NULL,0,(int)z, false);
+ pc->gainexp(sd, NULL, 0, (int)z, false);
}
}
@@ -1937,7 +1937,7 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list) {
int npc_market_buylist(struct map_session_data* sd, unsigned short list_size, struct packet_npc_market_purchase *p) {
struct npc_data* nd;
struct npc_item_list *shop = NULL;
- double z;
+ int64 z;
int i,j,w,new_;
unsigned short shop_size = 0;
@@ -1997,11 +1997,11 @@ int npc_market_buylist(struct map_session_data* sd, unsigned short list_size, st
return 1;
}
- z += (double)value * amount;
+ z += (int64)value * amount;
w += itemdb_weight(nameid) * amount;
}
- if( z > (double)sd->status.zeny ) /* TODO find official response for this */
+ if (z > sd->status.zeny) /* TODO find official response for this */
return 1; // Not enough Zeny
if( w + sd->weight > sd->max_weight ) /* TODO find official response for this */
@@ -2098,7 +2098,7 @@ int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short* item_li
/// @param item_list 'n' pairs <index,amount>
/// @return result code for clif->parse_NpcSellListSend
int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list) {
- double z;
+ int64 z;
int i,skill_t, skill_idx = skill->get_index(MC_OVERCHARGE);
struct npc_data *nd;
bool duplicates[MAX_INVENTORY] = { 0 };
@@ -2147,7 +2147,7 @@ int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list)
value = pc->modifysellvalue(sd, sd->inventory_data[idx]->value_sell);
- z += (double)value*amount;
+ z += (int64)value * amount;
}
if( nd->master_nd ) { // Script-controlled shops
@@ -2181,8 +2181,8 @@ int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list)
skill_t = sd->status.skill[skill_idx].flag - SKILL_FLAG_REPLACED_LV_0;
if( skill_t > 0 ) {
- z = z * (double)skill_t * (double)battle_config.shop_exp/10000.;
- if( z < 1 )
+ z = apply_percentrate64(z, skill_t * battle_config.shop_exp, 10000);
+ if (z < 1)
z = 1;
pc->gainexp(sd, NULL, 0, (int)z, false);
}
diff --git a/src/map/pc.c b/src/map/pc.c
index 491584385..8d1df71a9 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -4156,34 +4156,39 @@ int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip)
/*==========================================
* Update buying value by skills
*------------------------------------------*/
-int pc_modifybuyvalue(struct map_session_data *sd,int orig_value) {
- int skill_lv,val = orig_value,rate1 = 0,rate2 = 0;
- if((skill_lv=pc->checkskill(sd,MC_DISCOUNT))>0) // merchant discount
+int pc_modifybuyvalue(struct map_session_data *sd, int orig_value)
+{
+ int skill_lv, rate1 = 0, rate2 = 0;
+ if (orig_value <= 0)
+ return 0;
+ if ((skill_lv=pc->checkskill(sd,MC_DISCOUNT)) > 0) // merchant discount
rate1 = 5+skill_lv*2-((skill_lv==10)? 1:0);
- if((skill_lv=pc->checkskill(sd,RG_COMPULSION))>0) // rogue discount
+ if ((skill_lv=pc->checkskill(sd,RG_COMPULSION)) > 0) // rogue discount
rate2 = 5+skill_lv*4;
- if(rate1 < rate2) rate1 = rate2;
- if(rate1)
- val = (int)((double)orig_value*(double)(100-rate1)/100.);
- if(val < 0) val = 0;
- if(orig_value > 0 && val < 1) val = 1;
-
- return val;
+ if (rate1 < rate2)
+ rate1 = rate2;
+ if (rate1 != 0)
+ orig_value = apply_percentrate(orig_value, 100-rate1, 100);
+ if (orig_value < 1)
+ orig_value = 1;
+ return orig_value;
}
/*==========================================
* Update selling value by skills
*------------------------------------------*/
-int pc_modifysellvalue(struct map_session_data *sd,int orig_value) {
- int skill_lv,val = orig_value,rate = 0;
- if((skill_lv=pc->checkskill(sd,MC_OVERCHARGE))>0) //OverCharge
+int pc_modifysellvalue(struct map_session_data *sd, int orig_value)
+{
+ int skill_lv, rate = 0;
+ if (orig_value <= 0)
+ return 0;
+ if ((skill_lv=pc->checkskill(sd,MC_OVERCHARGE)) > 0) //OverCharge
rate = 5+skill_lv*2-((skill_lv==10)? 1:0);
- if(rate)
- val = (int)((double)orig_value*(double)(100+rate)/100.);
- if(val < 0) val = 0;
- if(orig_value > 0 && val < 1) val = 1;
-
- return val;
+ if (rate != 0)
+ orig_value = apply_percentrate(orig_value, 100+rate, 100);
+ if (orig_value < 1)
+ orig_value = 1;
+ return orig_value;
}
/*==========================================
@@ -5259,7 +5264,7 @@ int pc_show_steal(struct block_list *bl,va_list ap)
int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skill_lv)
{
int i,itemid,flag;
- double rate;
+ int rate;
struct status_data *sd_status, *md_status;
struct mob_data *md = BL_CAST(BL_MOB, bl);
struct item tmp_item;
@@ -5284,18 +5289,22 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skil
}
// base skill success chance (percentual)
- rate = (sd_status->dex - md_status->dex)/2 + skill_lv*6 + 4;
- rate += sd->bonus.add_steal_rate;
+ rate = (sd_status->dex - md_status->dex)/2 + skill_lv*6 + 4 + sd->bonus.add_steal_rate;
if( rate < 1 )
return 0;
// Try dropping one item, in the order from first to last possible slot.
// Droprate is affected by the skill success rate.
- for( i = 0; i < MAX_STEAL_DROP; i++ )
- if (md->db->dropitem[i].nameid > 0 && (data = itemdb->exists(md->db->dropitem[i].nameid)) != NULL && rnd() % 10000 < md->db->dropitem[i].p * rate/100.)
+ for (i = 0; i < MAX_STEAL_DROP; i++) {
+ if (md->db->dropitem[i].nameid == 0)
+ continue;
+ if ((data = itemdb->exists(md->db->dropitem[i].nameid)) == NULL)
+ continue;
+ if (rnd() % 10000 < apply_percentrate(md->db->dropitem[i].p, rate, 100))
break;
- if( i == MAX_STEAL_DROP )
+ }
+ if (i == MAX_STEAL_DROP)
return 0;
itemid = md->db->dropitem[i].nameid;
@@ -6612,16 +6621,16 @@ void pc_calcexp(struct map_session_data *sd, unsigned int *base_exp, unsigned in
if (sd->sc.data[SC_OVERLAPEXPUP])
bonus += sd->sc.data[SC_OVERLAPEXPUP]->val1;
- *base_exp = (unsigned int) cap_value(*base_exp + (double)*base_exp * bonus/100., 1, UINT_MAX);
+ *base_exp = (unsigned int) cap_value(*base_exp + apply_percentrate64(*base_exp, bonus, 100), 1, UINT_MAX);
if (sd->sc.data[SC_CASH_PLUSONLYJOBEXP])
bonus += sd->sc.data[SC_CASH_PLUSONLYJOBEXP]->val1;
- *job_exp = (unsigned int) cap_value(*job_exp + (double)*job_exp * bonus/100., 1, UINT_MAX);
+ *job_exp = (unsigned int) cap_value(*job_exp + apply_percentrate64(*job_exp, bonus, 100), 1, UINT_MAX);
- if( sd->status.mod_exp != 100 ) {
- *base_exp = (unsigned int) cap_value((double)*base_exp * sd->status.mod_exp/100., 1, UINT_MAX);
- *job_exp = (unsigned int) cap_value((double)*job_exp * sd->status.mod_exp/100., 1, UINT_MAX);
+ if (sd->status.mod_exp != 100) {
+ *base_exp = (unsigned int) cap_value(apply_percentrate64(*base_exp, sd->status.mod_exp, 100), 1, UINT_MAX);
+ *job_exp = (unsigned int) cap_value(apply_percentrate64(*job_exp, sd->status.mod_exp, 100), 1, UINT_MAX);
}
}
@@ -7713,18 +7722,18 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) {
&& !map->list[sd->bl.m].flag.noexppenalty && !map_flag_gvg2(sd->bl.m)
&& !sd->sc.data[SC_BABY] && !sd->sc.data[SC_CASH_DEATHPENALTY]
) {
- unsigned int base_penalty = 0;
if (battle_config.death_penalty_base > 0) {
+ unsigned int base_penalty = 0;
switch (battle_config.death_penalty_type) {
case 1:
- base_penalty = (unsigned int) ((double)pc->nextbaseexp(sd) * (double)battle_config.death_penalty_base/10000);
+ base_penalty = (unsigned int) apply_percentrate64(pc->nextbaseexp(sd), battle_config.death_penalty_base, 10000);
break;
case 2:
- base_penalty = (unsigned int) ((double)sd->status.base_exp * (double)battle_config.death_penalty_base/10000);
+ base_penalty = (unsigned int) apply_percentrate64(sd->status.base_exp, battle_config.death_penalty_base, 10000);
break;
}
- if(base_penalty) {
+ if (base_penalty != 0) {
if (battle_config.pk_mode && src && src->type==BL_PC)
base_penalty*=2;
if( sd->status.mod_death != 100 )
@@ -7735,31 +7744,31 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) {
}
if(battle_config.death_penalty_job > 0) {
- base_penalty = 0;
+ unsigned int job_penalty = 0;
switch (battle_config.death_penalty_type) {
case 1:
- base_penalty = (unsigned int) ((double)pc->nextjobexp(sd) * (double)battle_config.death_penalty_job/10000);
+ job_penalty = (unsigned int) apply_percentrate64(pc->nextjobexp(sd), battle_config.death_penalty_job, 10000);
break;
case 2:
- base_penalty = (unsigned int) ((double)sd->status.job_exp * (double)battle_config.death_penalty_job/10000);
+ job_penalty = (unsigned int) apply_percentrate64(sd->status.job_exp, battle_config.death_penalty_job, 10000);
break;
}
- if(base_penalty) {
+ if (job_penalty != 0) {
if (battle_config.pk_mode && src && src->type==BL_PC)
- base_penalty*=2;
+ job_penalty*=2;
if( sd->status.mod_death != 100 )
- base_penalty = base_penalty * sd->status.mod_death / 100;
- sd->status.job_exp -= min(sd->status.job_exp, base_penalty);
+ job_penalty = job_penalty * sd->status.mod_death / 100;
+ sd->status.job_exp -= min(sd->status.job_exp, job_penalty);
clif->updatestatus(sd,SP_JOBEXP);
}
}
- if(battle_config.zeny_penalty > 0 && !map->list[sd->bl.m].flag.nozenypenalty) {
- base_penalty = (unsigned int)((double)sd->status.zeny * (double)battle_config.zeny_penalty / 10000.);
- if(base_penalty)
- pc->payzeny(sd, base_penalty, LOG_TYPE_PICKDROP_PLAYER, NULL);
+ if (battle_config.zeny_penalty > 0 && !map->list[sd->bl.m].flag.nozenypenalty) {
+ int zeny_penalty = apply_percentrate(sd->status.zeny, battle_config.zeny_penalty, 10000);
+ if (zeny_penalty != 0)
+ pc->payzeny(sd, zeny_penalty, LOG_TYPE_PICKDROP_PLAYER, NULL);
}
}
diff --git a/src/map/script.c b/src/map/script.c
index ca53b6f6d..9e113a6f9 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -3851,7 +3851,7 @@ void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
void op_2num(struct script_state* st, int op, int i1, int i2)
{
int ret;
- double ret_double;
+ int64 ret64;
switch( op ) {
case C_AND: ret = i1 & i2; break;
@@ -3883,25 +3883,21 @@ void op_2num(struct script_state* st, int op, int i1, int i2)
ret = i1 % i2;
break;
default:
- switch( op )
- {// operators that can overflow/underflow
- case C_ADD: ret = i1 + i2; ret_double = (double)i1 + (double)i2; break;
- case C_SUB: ret = i1 - i2; ret_double = (double)i1 - (double)i2; break;
- case C_MUL: ret = i1 * i2; ret_double = (double)i1 * (double)i2; break;
+ switch (op) { // operators that can overflow/underflow
+ case C_ADD: ret = i1 + i2; ret64 = (int64)i1 + i2; break;
+ case C_SUB: ret = i1 - i2; ret64 = (int64)i1 - i2; break;
+ case C_MUL: ret = i1 * i2; ret64 = (int64)i1 * i2; break;
default:
ShowError("script:op_2num: unexpected number operator %s i1=%d i2=%d\n", script->op2name(op), i1, i2);
script->reportsrc(st);
script_pushnil(st);
return;
}
- if( ret_double < (double)INT_MIN )
- {
+ if (ret64 < INT_MIN) {
ShowWarning("script:op_2num: underflow detected op=%s i1=%d i2=%d\n", script->op2name(op), i1, i2);
script->reportsrc(st);
ret = INT_MIN;
- }
- else if( ret_double > (double)INT_MAX )
- {
+ } else if (ret64 > INT_MAX) {
ShowWarning("script:op_2num: overflow detected op=%s i1=%d i2=%d\n", script->op2name(op), i1, i2);
script->reportsrc(st);
ret = INT_MAX;
@@ -9710,20 +9706,18 @@ BUILDIN(makepet)
BUILDIN(getexp)
{
int base=0,job=0;
- double bonus;
struct map_session_data *sd = script->rid2sd(st);
if (sd == NULL)
return true;
- base=script_getnum(st,2);
- job =script_getnum(st,3);
- if(base<0 || job<0)
+ base = script_getnum(st,2);
+ job = script_getnum(st,3);
+ if (base < 0 || job < 0)
return true;
// bonus for npc-given exp
- bonus = battle_config.quest_exp_rate / 100.;
- base = (int) cap_value(base * bonus, 0, INT_MAX);
- job = (int) cap_value(job * bonus, 0, INT_MAX);
+ base = cap_value(apply_percentrate(base, battle_config.quest_exp_rate, 100), 0, INT_MAX);
+ job = cap_value(apply_percentrate(job, battle_config.quest_exp_rate, 100), 0, INT_MAX);
pc->gainexp(sd, &sd->bl, base, job, true);
diff --git a/src/map/vending.c b/src/map/vending.c
index 810e6b07a..6e74e6c3e 100644
--- a/src/map/vending.c
+++ b/src/map/vending.c
@@ -89,7 +89,7 @@ void vending_vendinglistreq(struct map_session_data* sd, unsigned int id) {
*------------------------------------------*/
void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid, const uint8* data, int count) {
int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING];
- double z;
+ int64 z;
struct s_vending vend[MAX_VENDING]; // against duplicate packets
struct map_session_data* vsd = map->id2sd(aid);
@@ -116,7 +116,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid,
memcpy(&vend, &vsd->vending, sizeof(vsd->vending)); // copy vending list
// some checks
- z = 0.; // zeny counter
+ z = 0; // zeny counter
w = 0; // weight counter
for( i = 0; i < count; i++ ) {
short amount = *(uint16*)(data + 4*i + 0);
@@ -136,12 +136,12 @@ void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid,
else
vend_list[i] = j;
- z += ((double)vsd->vending[j].value * (double)amount);
- if( z > (double)sd->status.zeny || z < 0. || z > (double)MAX_ZENY ) {
+ z += (int64)vsd->vending[j].value * amount;
+ if (z > sd->status.zeny || z < 0 || z > MAX_ZENY) {
clif->buyvending(sd, idx, amount, 1); // you don't have enough zeny
return;
}
- if( z + (double)vsd->status.zeny > (double)MAX_ZENY && !battle_config.vending_over_max ) {
+ if (z > MAX_ZENY - vsd->status.zeny && !battle_config.vending_over_max) {
clif->buyvending(sd, idx, vsd->vending[j].amount, 4); // too much zeny = overflow
return;
@@ -181,7 +181,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid,
pc->payzeny(sd, (int)z, LOG_TYPE_VENDING, vsd);
if( battle_config.vending_tax )
- z -= z * (battle_config.vending_tax/10000.);
+ z -= apply_percentrate64(z, battle_config.vending_tax, 10000);
pc->getzeny(vsd, (int)z, LOG_TYPE_VENDING, sd);
for( i = 0; i < count; i++ ) {