summaryrefslogtreecommitdiff
path: root/src/map/pc.c
diff options
context:
space:
mode:
authorNormynator <Norman.Ziebal@web.de>2017-01-04 16:23:09 +0100
committerNorman Ziebal <s8nozieb@stud.uni-saarland.de>2018-02-19 22:57:29 +0100
commit2691fcbedb580f5a8994a345b4476e95af2fc442 (patch)
tree9d68f8290b89f37d5377198b02b44568f112aeeb /src/map/pc.c
parent38914c4b3362a055468e3d3d8c26204c4a2d50d2 (diff)
downloadhercules-2691fcbedb580f5a8994a345b4476e95af2fc442.tar.gz
hercules-2691fcbedb580f5a8994a345b4476e95af2fc442.tar.bz2
hercules-2691fcbedb580f5a8994a345b4476e95af2fc442.tar.xz
hercules-2691fcbedb580f5a8994a345b4476e95af2fc442.zip
Changed Kafrapoints calculation.
Kafrapoints should now be used correctly. Issue #1540 Changed opening braces according to coding styl. Changed some lines according to coding styl. new-line-before-return ? more styling code changes changes in coding style coding style changes Fixed message output on acted cash. Removed unsupported and not needed var ret. Update pc.c Update atcommand.c Coding style added function description added return validation used wrong method in validation Fixed typo in clif.c Moved temp var to block start
Diffstat (limited to 'src/map/pc.c')
-rw-r--r--src/map/pc.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/map/pc.c b/src/map/pc.c
index 0b30b1221..cd4b2a54f 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -4448,46 +4448,54 @@ int pc_payzeny(struct map_session_data *sd,int zeny, enum e_log_pick_type type,
return 0;
}
-/*==========================================
- * Cash Shop
- *------------------------------------------*/
+/**
+ * Calculates leftover cashpoints and kafrapoints when buying an item from cashshop
+ *
+ * @param price Price of the item.
+ * @param points Provided kafra points.
+ *
+ * @return points Leftover kafra points.
+ */
+//Changed Kafrapoints calculation. [Normynator]
int pc_paycash(struct map_session_data *sd, int price, int points)
{
int cash;
- nullpo_retr(-1,sd);
+ int mempoints;
+ nullpo_retr(-1, sd);
- points = cap_value(points,-MAX_ZENY,MAX_ZENY); //prevent command UB
- if( price < 0 || points < 0 )
- {
+ 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 )
- {
+ 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 = points - price;
+ mempoints = price;
+ cash = 0;
+ } else {
+ cash = price - points;
+ mempoints = points;
+ points = 0;
}
- cash = price-points;
-
- if( sd->cashPoints < cash || sd->kafraPoints < points )
- {
+ if (sd->cashPoints < cash || sd->kafraPoints < mempoints) {
ShowError("pc_paycash: Not enough points (cash=%d, kafra=%d) to cover the price (cash=%d, kafra=%d) (account_id=%d, char_id=%d).\n", sd->cashPoints, sd->kafraPoints, cash, points, sd->status.account_id, sd->status.char_id);
return -1;
}
- pc_setaccountreg(sd, script->add_str("#CASHPOINTS"), sd->cashPoints-cash);
- pc_setaccountreg(sd, script->add_str("#KAFRAPOINTS"), sd->kafraPoints-points);
+ pc_setaccountreg(sd, script->add_str("#CASHPOINTS"), sd->cashPoints - cash);
+ pc_setaccountreg(sd, script->add_str("#KAFRAPOINTS"), sd->kafraPoints - mempoints);
- if( battle_config.cashshop_show_points )
- {
+ if (battle_config.cashshop_show_points) {
char output[128];
sprintf(output, msg_sd(sd,504), points, cash, sd->kafraPoints, sd->cashPoints);
clif_disp_onlyself(sd, output);
}
- return cash+points;
+
+ return points;
}
int pc_getcash(struct map_session_data *sd, int cash, int points)