cheaper shop prices for humans

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago - 1 year 6 months ago #6222 by JTP
JTP created the topic: cheaper shop prices for humans
I would like it to be cheaper for humans to buy from shops.

Anyone who made something similar, and can tell me how and where i need to add that in ?

Maybe also that humans get double coins from killing mobs
Last Edit: 1 year 6 months ago by JTP.

Please Log in or Create an account to join the conversation.

More
1 year 6 months ago #6223 by thomas
thomas replied the topic: cheaper shop prices for humans
This is actually relatively easy. In shop.c, all code dealing with shops is collected in one place and the code for determining prices is just one place. The function you will be needing to alter is buy_price() at github.com/tbamud/tbamud/blob/master/src/shop.c#L442
/* Shop purchase adjustment, based on charisma-difference from buyer to keeper.
   for i in `seq 15 -15`; do printf " * %3d: %6.4f\n" $i \
   `echo "scale=4; 1+$i/70" | bc`; done
   Shopkeeper higher charisma (markup)
   ^  15: 1.2142  14: 1.2000  13: 1.1857  12: 1.1714  11: 1.1571
   |  10: 1.1428   9: 1.1285   8: 1.1142   7: 1.1000   6: 1.0857
   |   5: 1.0714   4: 1.0571   3: 1.0428   2: 1.0285   1: 1.0142
   +   0: 1.0000
   |  -1: 0.9858  -2: 0.9715  -3: 0.9572  -4: 0.9429  -5: 0.9286
   |  -6: 0.9143  -7: 0.9000  -8: 0.8858  -9: 0.8715 -10: 0.8572
   v -11: 0.8429 -12: 0.8286 -13: 0.8143 -14: 0.8000 -15: 0.7858
   Player higher charisma (discount)
   Most mobiles have 11 charisma so an 18 charisma player would get a 10%
   discount beyond the basic price.  That assumes they put a lot of points
   into charisma, because on the flip side they'd get 11% inflation by
   having a 3. */
static int buy_price(struct obj_data *obj, int shop_nr, struct char_data *keeper, struct char_data *buyer)
{
  return (int) (GET_OBJ_COST(obj) * SHOP_BUYPROFIT(shop_nr)
	* (1 + (GET_CHA(keeper) - GET_CHA(buyer)) / (float)70));
}

Here, you'll want to multiply with some factor between 0 and 1 if the buyer is a human:
static int buy_price(struct obj_data *obj, int shop_nr, struct char_data *keeper, struct char_data *buyer)
{
  int HUMAN_FACTOR = .7;
  return (int) (GET_OBJ_COST(obj) * SHOP_BUYPROFIT(shop_nr)
	* (1 + (GET_CHA(keeper) - GET_CHA(buyer)) / (float)70))
        * (!IS_NPC(buyer) && GET_RACE(buyer) == RACE_HUMAN ? HUMAN_FACTOR : 1);
}

The code for dropping gold might be slightly more difficult. This needs some design decisions first, because the gold is currently created on mob death, based on the Gold the mopb was carrying. If the player is alone in the fight, the solution is relatively easy - just add a little more gold to the corpse. But what happens if the player is grouped? And one of the other group members get the kill? OR the loot?
To avoid a gold duplicationg loophole, you want to avoid altering how much gold a player can pick up from a pile once it has been created with a certain amount. Or a player would just become a gazillionaire by dropping and getting the same pile of gold.

Please Log in or Create an account to join the conversation.

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago #6224 by JTP
JTP replied the topic: cheaper shop prices for humans
So the charisma and race_human can stack or will the human disregard the charisma ?

Please Log in or Create an account to join the conversation.

More
1 year 6 months ago #6225 by thomas
thomas replied the topic: cheaper shop prices for humans
The bonuses will stack. The calculation will in practice be cost * profit * charismabonus * race bonus

Please Log in or Create an account to join the conversation.

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago #6226 by JTP
JTP replied the topic: cheaper shop prices for humans
Ouch that made the prices be 0

Please Log in or Create an account to join the conversation.

More
1 year 6 months ago #6227 by thomas
thomas replied the topic: cheaper shop prices for humans
ACK my bad - the human factor should be a float instead of an int (.7 = 0 as an int)

Please Log in or Create an account to join the conversation.

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago #6228 by JTP
JTP replied the topic: cheaper shop prices for humans
ehh im confused, how ?

Please Log in or Create an account to join the conversation.

More
1 year 6 months ago #6229 by thomas
thomas replied the topic: cheaper shop prices for humans
-   int HUMAN_FACTOR = .7;
+   float HUMAN_FACTOR = .7;

Please Log in or Create an account to join the conversation.

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago - 1 year 6 months ago #6230 by JTP
JTP replied the topic: cheaper shop prices for humans
ahhh that worked brilliantly

Can it also be done similar with sell prices, just give better sell prices ?
Last Edit: 1 year 6 months ago by JTP.

Please Log in or Create an account to join the conversation.

More
1 year 6 months ago #6231 by thomas
thomas replied the topic: cheaper shop prices for humans
I suggest you try it out :)

Please Log in or Create an account to join the conversation.

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago #6235 by JTP
JTP replied the topic: cheaper shop prices for humans
Figured it out with human_factor 1.25 :)

Please Log in or Create an account to join the conversation.

More
1 year 6 months ago #6237 by thomas
thomas replied the topic: cheaper shop prices for humans
I suggest you read the comment above the function. It suggests that the comparison in the middle is there to prevent money making loopholes where you can sell something at a higher price than you can buy it for.
To make this still work, the alterations must happen before that check.
So, you add the same change as in the buy_price function (to calculate the correct buy factor) and then tweak the sell factor by dividing by the HUMAN_FACTOR:
static int sell_price(struct obj_data *obj, int shop_nr, struct char_data *keeper, struct char_data *seller)
{
  float HUMAN_FACTOR = .7;
  float sell_cost_modifier = SHOP_SELLPROFIT(shop_nr) * (1 - (GET_CHA(keeper) - GET_CHA(seller)) / (float)70) 
       / (!IS_NPC(seller) && GET_RACE(seller) == RACE_HUMAN ? HUMAN_FACTOR : 1);
  float buy_cost_modifier = SHOP_BUYPROFIT(shop_nr) * (1 + (GET_CHA(keeper) - GET_CHA(seller)) / (float)70)
       * (!IS_NPC(seller) && GET_RACE(seller) == RACE_HUMAN ? HUMAN_FACTOR : 1);

  if (sell_cost_modifier > buy_cost_modifier)
    sell_cost_modifier = buy_cost_modifier;

  return (int) (GET_OBJ_COST(obj) * sell_cost_modifier);
}
as always, browser code, you may need to tweak it :)

Please Log in or Create an account to join the conversation.

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago - 1 year 6 months ago #6241 by JTP
JTP replied the topic: cheaper shop prices for humans
I tried this:

static int sell_price(struct obj_data *obj, int shop_nr, struct char_data *keeper, struct char_data *seller)
{
  float HUMAN_FACTOR = 1.1;
  float sell_cost_modifier = SHOP_SELLPROFIT(shop_nr) * (1 - (GET_CHA(keeper) - GET_CHA(seller)) / (float)70);
  float buy_cost_modifier = SHOP_BUYPROFIT(shop_nr) * (1 + (GET_CHA(keeper) - GET_CHA(seller)) / (float)70);

  if (sell_cost_modifier > buy_cost_modifier)
    sell_cost_modifier = buy_cost_modifier;

  return (int) (GET_OBJ_COST(obj) * sell_cost_modifier)
        * (!IS_NPC(seller) && GET_RACE(seller) == RACE_HUMAN ? HUMAN_FACTOR : 1);
}

With a human with cha 18 and another race with cha 18
The human only gained extra 7-8 coins more when selling the same item. So seems to Work, but i can try your version, if you think its will be better.
Last Edit: 1 year 6 months ago by JTP.

Please Log in or Create an account to join the conversation.

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago #6249 by JTP
JTP replied the topic: cheaper shop prices for humans
Could you try explain to me what the difference is between the way i did it, and the way you just showed it ?

I just had 2 chars with cha 18 sell the same small sword, the non human got 37 coins, the human got 40.

Much apreciated

Please Log in or Create an account to join the conversation.

More
1 year 6 months ago #6250 by thomas
thomas replied the topic: cheaper shop prices for humans
I will try :)

Let's assume you have a very "cheap" shop, with 10% profit on sales and buying things at price.
This means that SHOP_SELLPROFIT() = 1.1 and SHOP_BUYPROFIT() = 1.
The shopkeeper is an ordinary mob, and thus has CHA = 11.
The player has high CHA, 18, with all spells and items.

The original calculation in sell_price would be like this:
sell_cost_modifier = 1.1 * (1 - (11 - 18) / 70) = 1.21
buy_cost_modifier = 1 * (1 + (11 -18) / 70) = 0.9

Now, this means, if we just stop there, that the player will sell an item with value 100 for 121, and buy it for 90. This is a goldmaking loophole - a player can sell/buy the same item over and over again, making a profit each time. With triggers, a player can be a millionaire in seconds.
So, the code makes sure that you can't sell for more than you buy for, with the next check.

So before actually calculating the price, we have sell_cost_modifier = buy_cost_modifier = 0.9. This way, the player will get the same amount of money when selling as he spends when buying.

If we at this point change the sell price based on race, we reopen the loophole:
(return) sell_price_for_humans = cost * 0.9 * 1.1 = cost * .99
buy price is lower, too.
So we need to change the sell_price_modifier BEFORE the loophole check.

And, because we've changed the calculation in buy_price(), we need to change it here as well.

I suspect this may be muddying the waters even more, but I hope it helps.

Please Log in or Create an account to join the conversation.

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago #6252 by JTP
JTP replied the topic: cheaper shop prices for humans
With .7 in both sell and buy Price.

Then as human i could sell it for the same as i could rebuy it for..

So i had to do .6 in sell_price

.5 gave me same sell Price as a non human

Please Log in or Create an account to join the conversation.

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
6 months 3 weeks ago #7037 by JTP
JTP replied the topic: cheaper shop prices for humans
static int buy_price(struct obj_data *obj, int shop_nr, struct char_data *keeper, struct char_data *buyer)
{
  float HUMAN_FACTOR = .8;
  return (int) (GET_OBJ_COST(obj) * SHOP_BUYPROFIT(shop_nr)
        * (1 + (GET_CHA(keeper) - GET_CHA(buyer)) / (float)70))
        * (!IS_NPC(buyer) && GET_RACE(buyer) == RACE_HUMAN ? HUMAN_FACTOR : 1);
}

/* When the shopkeeper is buying, we reverse the discount. Also make sure
   we don't buy for more than we sell for, to prevent infinite money-making. */
static int sell_price(struct obj_data *obj, int shop_nr, struct char_data *keeper, struct char_data *seller)
{
  float HUMAN_FACTOR = .6;
  float sell_cost_modifier = SHOP_SELLPROFIT(shop_nr) * (1 - (GET_CHA(keeper) - GET_CHA(seller)) / (float)70)
        / (!IS_NPC(seller) && GET_RACE(seller) == RACE_HUMAN ? HUMAN_FACTOR : 1);
  float buy_cost_modifier = SHOP_BUYPROFIT(shop_nr) * (1 + (GET_CHA(keeper) - GET_CHA(seller)) / (float)70)
        * (!IS_NPC(seller) && GET_RACE(seller) == RACE_HUMAN ? HUMAN_FACTOR : 1);

If i wanted to add on to this so that is buyer or seller has the skill haggle, they also get better prices.

Would it just be:
* (!IS_NPC(seller) && GET_SKILL(seller) == SKILL_HAGGLE || GET_RACE(seller) == RACE_HUMAN ? HUMAN_FACTOR : 1);

?

Please Log in or Create an account to join the conversation.

More
6 months 3 weeks ago #7038 by thomas
thomas replied the topic: cheaper shop prices for humans
Almost - you'd need a parenthesis there, to prevent GET_RACE() from triggering on an npc:
* (!IS_NPC(seller) && (GET_SKILL(seller, SKILL_HAGGLE) > 0 || GET_RACE(seller) == RACE_HUMAN) ? HUMAN_FACTOR : 1);
The following user(s) said Thank You: JTP

Please Log in or Create an account to join the conversation.

Time to create page: 1.606 seconds