ID:151348
 
I've been wondering on how to do a shop protocol where the items get more expensive the less of them there are. EG when the shop has 10 longswords they are 400 each, but for every one sold the price goes up by 20.

How would you go about this? I'm not asking code sheets here, just guidelines to get me started, some procs I might want to use, or how I need to go about it the most effecient way..
Does anyone has an idea? Every reply is welcome!

Yours truly, Raimo.
If for every sword sold it goes up by 20 then it's linear change. You could define sword price to 600, and discount per stock to 20. Then when player attempts to buy simply do "price = itemPrice - stock * discountPerStock".
edit learned some new stuff. Associated list holds initial stock, initial price, and price variation per unit in stock.

mob/FruitSalesman
var/list/stock = list("Apple" = list(5,200,20),"Orange" = list(5,250,10),"Banana" = list(4,300,30))
verb/Buy()
set src in oview(1)
var/choice = input("What do you want?") in stock
if(stock[choice][1] <= 0) return
var/FinalPrice = stock[choice][2] - stock[choice][1] * stock[choice][3]
usr << (FinalPrice<=0 ? "I have too many [choice]s, take one, its on me." : "There is only [stock[choice][1]] [choice]\s left. I need atleast [FinalPrice] dollar\s.")
stock[choice][1] --
In response to Zaoshi
I like to simplify things. I would do this:
*setting up*
store.itemlist// list of the store's items.
store.itemlist["potion"]//then store a potion in this slot.
stroe.itemlist["potion"]=var/obj/Potion/Xp
Xp.Quantity+=100//assuming the object has a quantity and price
Xp.Price=50

//--later---

proc
getdifference()//get the difference.
var/dif=100-Xp.Quantity
return diff

shop()//proc for shopping
var/inflation=getdifference()
var/newprice=Xp.Price+(inflation*10)//lets say the price increases by 10.
//then simply subtract the gold and place the item in the inventory and decrease the shop items quantity by however many were bought.