Fixed points command using negative numbers (#3867)

This commit is contained in:
Daegaladh 2019-01-20 22:42:44 +01:00 committed by GitHub
parent 79dffbd789
commit 6c1d1a84d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 31 deletions

View File

@ -8490,6 +8490,8 @@ ACMD_FUNC(cash)
}
else clif_displaymessage(fd, msg_txt(sd,149)); // Impossible to increase the number/value.
} else {
if (-value > sd->kafraPoints) //By command, if cash < value, force it to remove all
value = -sd->kafraPoints;
if( (ret=pc_paycash(sd, 0, -value, LOG_TYPE_COMMAND)) >= 0){
sprintf(output, msg_txt(sd,411), ret, sd->kafraPoints); // Removed %d kafra points. Total %d points.
clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);

View File

@ -4393,28 +4393,17 @@ char pc_getzeny(struct map_session_data *sd, int zeny, enum e_log_pick_type type
/**
* Attempts to remove Cash Points from player
* @param sd: Player
* @param price: Points player has to pay
* @param points: Points player has
* @param price: Total points (cash + kafra) the player has to pay
* @param points: Kafra points the player has to pay
* @param type: Log type
* @return -2: Paying negative points, -1: Not enough points, otherwise success (cash+points)
* @return -1: Not enough points, otherwise success (cash+points)
*/
int pc_paycash(struct map_session_data *sd, int price, int points, e_log_pick_type type)
{
int cash;
nullpo_retr(-1,sd);
points = cap_value(points,-MAX_ZENY,MAX_ZENY); //prevent command UB
if( price < 0 || points < 0 )
{
ShowError("pc_paycash: Paying negative points (price=%d, points=%d, account_id=%d, char_id=%d).\n", price, points, sd->status.account_id, sd->status.char_id);
return -2;
}
if( points > price )
{
ShowWarning("pc_paycash: More kafra points provided than needed (price=%d, points=%d, account_id=%d, char_id=%d).\n", price, points, sd->status.account_id, sd->status.char_id);
points = price;
}
points = cap_value(points, 0, MAX_ZENY); //prevent command UB
cash = price-points;
@ -4449,10 +4438,10 @@ int pc_paycash(struct map_session_data *sd, int price, int points, e_log_pick_ty
/**
* Attempts to give Cash Points to player
* @param sd: Player
* @param cash: Cash player gets
* @param points: Points player has
* @param cash: Cash points the player gets
* @param points: Kafra points the player gets
* @param type: Log type
* @return -2: Error, -1: Giving negative cash/points, otherwise success (cash or points)
* @return -1: Error, otherwise success (cash or points)
*/
int pc_getcash(struct map_session_data *sd, int cash, int points, e_log_pick_type type)
{
@ -4460,8 +4449,8 @@ int pc_getcash(struct map_session_data *sd, int cash, int points, e_log_pick_typ
nullpo_retr(-1,sd);
cash = cap_value(cash,-MAX_ZENY,MAX_ZENY); //prevent command UB
points = cap_value(points,-MAX_ZENY,MAX_ZENY); //prevent command UB
cash = cap_value(cash, 0, MAX_ZENY); //prevent command UB
points = cap_value(points, 0, MAX_ZENY); //prevent command UB
if( cash > 0 )
{
if( cash > MAX_ZENY-sd->cashPoints )
@ -4481,11 +4470,6 @@ int pc_getcash(struct map_session_data *sd, int cash, int points, e_log_pick_typ
}
return cash;
}
else if( cash < 0 )
{
ShowError("pc_getcash: Obtaining negative cash points (cash=%d, account_id=%d, char_id=%d).\n", cash, sd->status.account_id, sd->status.char_id);
return -1;
}
if( points > 0 )
{
@ -4506,12 +4490,8 @@ int pc_getcash(struct map_session_data *sd, int cash, int points, e_log_pick_typ
}
return points;
}
else if( points < 0 )
{
ShowError("pc_getcash: Obtaining negative kafra points (points=%d, account_id=%d, char_id=%d).\n", points, sd->status.account_id, sd->status.char_id);
return -1;
}
return -2; //shouldn't happen but just in case
return -1; //shouldn't happen but just in case
}
/**