… | |
… | |
79 | int no_bargain; |
79 | int no_bargain; |
80 | int identified; |
80 | int identified; |
81 | int not_cursed; |
81 | int not_cursed; |
82 | int approximate; |
82 | int approximate; |
83 | int shop; |
83 | int shop; |
84 | double diff; |
|
|
85 | |
84 | |
86 | approx_range = 0; |
85 | approx_range = 0; |
87 | |
86 | |
88 | no_bargain = flag & F_NO_BARGAIN; |
87 | no_bargain = flag & F_NO_BARGAIN; |
89 | identified = flag & F_IDENTIFIED; |
88 | identified = flag & F_IDENTIFIED; |
… | |
… | |
190 | * AND Cha = 30 will get optimal price. |
189 | * AND Cha = 30 will get optimal price. |
191 | * Thus charisma will never get useless. |
190 | * Thus charisma will never get useless. |
192 | * -b.e. edler@heydernet.de |
191 | * -b.e. edler@heydernet.de |
193 | */ |
192 | */ |
194 | |
193 | |
195 | if (who && who->type == PLAYER) |
194 | if (who && who->is_player ()) |
196 | { |
195 | { |
197 | int lev_bargain = 0; |
196 | int lev_bargain = 0; |
198 | int lev_identify = 0; |
197 | int lev_identify = 0; |
199 | |
198 | |
200 | if (find_skill_by_number (who, SK_BARGAINING)) |
199 | if (!no_bargain) |
201 | lev_bargain = find_skill_by_number (who, SK_BARGAINING)->level; |
200 | if (object *skill = find_skill_by_name (who, shstr_bargaining)) |
|
|
201 | lev_bargain = skill->level; |
202 | |
202 | |
203 | if (const typedata *tmptype = get_typedata (tmp->type)) |
203 | if (const typedata *tmptype = get_typedata (tmp->type)) |
204 | { |
204 | { |
205 | if (int idskill1 = tmptype->identifyskill) |
205 | if (int idskill1 = tmptype->identifyskill) |
206 | { |
206 | { |
… | |
… | |
217 | /* ratio determines how much of the price modification |
217 | /* ratio determines how much of the price modification |
218 | * will come from the basic stat charisma |
218 | * will come from the basic stat charisma |
219 | * the rest will come from the level in bargaining skill |
219 | * the rest will come from the level in bargaining skill |
220 | */ |
220 | */ |
221 | const double cha_ratio = 0.40; |
221 | const double cha_ratio = 0.40; |
222 | |
222 | double bargaining = max (0., 1. - powf (double (lev_bargain) / MAXLEVEL_TREASURE, 0.25)); |
223 | diff = no_bargain ? 1.0 : 1. - pow (lev_bargain / MAXLEVEL_TREASURE, 0.25); |
|
|
224 | diff = (1. - cha_ratio) * diff + cha_ratio * (cha_bonus[who->stats.Cha] - 1.) / (cha_bonus[who->stats.Cha] + 1.); |
223 | double charisma = (cha_bonus[who->stats.Cha] - 1.) / (cha_bonus[who->stats.Cha] + 1.); |
225 | diff = .02 + (.80 - .02) * diff; |
224 | |
|
|
225 | double factor = (1. - cha_ratio) * bargaining + cha_ratio * charisma; |
|
|
226 | |
|
|
227 | // scale 0..1 to 2 .. 80% |
|
|
228 | factor = lerp (factor, 0., 1., 0.02, 0.80); |
226 | |
229 | |
227 | if (flag == F_BUY) |
230 | if (flag == F_BUY) |
228 | val += val * diff; |
231 | val += val * factor; |
229 | else if (flag == F_SELL) |
232 | else if (flag == F_SELL) |
230 | val -= val * diff; |
233 | val -= val * factor; |
231 | |
234 | |
232 | // now find a price range. the less good we can judge, the larger the range is |
235 | // now find a price range. the less good we can judge, the larger the range is |
233 | // then the range is adjusted randomly around the correct value |
236 | // then the range is adjusted randomly around the correct value |
234 | if (approximate) |
237 | if (approximate) |
235 | approx_range = val / sqrt (lev_identify * 3 + 1); |
238 | approx_range = val / sqrt (lev_identify * 3 + 1); |
… | |
… | |
380 | { |
383 | { |
381 | if (!idskill1 || !find_skill_by_number (who, idskill1)) |
384 | if (!idskill1 || !find_skill_by_number (who, idskill1)) |
382 | { |
385 | { |
383 | if (!idskill2 || !find_skill_by_number (who, idskill2)) |
386 | if (!idskill2 || !find_skill_by_number (who, idskill2)) |
384 | { |
387 | { |
385 | if (!find_skill_by_number (who, SK_BARGAINING)) |
388 | if (!find_skill_by_name (who, shstr_bargaining)) |
386 | { |
389 | { |
387 | int num, cointype = 0; |
390 | int num, cointype = 0; |
388 | archetype *coin = find_next_coin (real_value, &cointype); |
391 | archetype *coin = find_next_coin (real_value, &cointype); |
389 | |
392 | |
390 | if (!coin) |
393 | if (!coin) |
… | |
… | |
497 | * This determins the amount of exp (if any) gained for bargaining. |
500 | * This determins the amount of exp (if any) gained for bargaining. |
498 | */ |
501 | */ |
499 | saved_money = query_cost (op, pl, F_BUY | F_NO_BARGAIN | F_SHOP) - to_pay; |
502 | saved_money = query_cost (op, pl, F_BUY | F_NO_BARGAIN | F_SHOP) - to_pay; |
500 | |
503 | |
501 | if (saved_money > 0) |
504 | if (saved_money > 0) |
502 | change_exp (pl, saved_money, "bargaining", SK_EXP_NONE); |
505 | change_exp (pl, saved_money, shstr_bargaining, SK_EXP_NONE); |
503 | |
506 | |
504 | pay_from_container (pl, pl, to_pay); |
507 | pay_from_container (pl, pl, to_pay); |
505 | |
508 | |
506 | for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below) |
509 | for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below) |
507 | if (pouch->type == CONTAINER && pouch->flag [FLAG_APPLIED] && (!pouch->race || pouch->race.contains ("gold"))) |
510 | if (pouch->type == CONTAINER && pouch->flag [FLAG_APPLIED] && (!pouch->race || pouch->race.contains ("gold"))) |
… | |
… | |
819 | * exp/10 -> 1 for each gold coin |
822 | * exp/10 -> 1 for each gold coin |
820 | */ |
823 | */ |
821 | extra_gain = amount - query_cost (op, pl, F_SELL | F_NO_BARGAIN | F_SHOP); |
824 | extra_gain = amount - query_cost (op, pl, F_SELL | F_NO_BARGAIN | F_SHOP); |
822 | |
825 | |
823 | if (extra_gain > 0) |
826 | if (extra_gain > 0) |
824 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
827 | change_exp (pl, extra_gain / 10, shstr_bargaining, SK_EXP_NONE); |
825 | |
828 | |
826 | pay_player (pl, amount); |
829 | pay_player (pl, amount); |
827 | |
830 | |
828 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.", |
831 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.", |
829 | query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op)); |
832 | query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op)); |