In my project, the player have some cash, some element to buy and the possibility to buy these element by pack (x10, x100, xMax…)
The price of an element is calculated by this formula : “initialCost x coeff^itemLvl” For example, an Iron Suit lvl45 cost : “11 x 1.15^45” so 5.926gold.
I want to make a function which allow the player to buy the max lvl of the item according to the cash he has (each item bought increases its itemLevel by 1) For example, the player has 200gold. Actually, he’s at Iron Suit lvl 5. The function show him how many item he can buy, so 5 Iron Suit.
I try to use a “while” iteration to calculating that, but this consume too much performance with many different item.
Also I thought about math Series/Sequence, but I can’t find a solution to match with my situation…
If you have any advice for me so I can find the solution, thanks in advance
To clarify these are ways of working out the highest cost level that can be purchased. It doesn’t let you factor in the cost of purchasing each level on the way up. Depending on your design this may be a factor.
If I can purchase just level 45 then this formula is great.
If to purchase level 45 I need to buy level 44, 43, 42, 41 … then a solution based on integration is required.
And yes BoredMormon, to buy the item lvl45, the player has to purchase the precedent levels.
So the function will show him how many item he can purchase according to his money.
Okay, after many attempts I have solved my problem, my math lessons are far far away.
Thanks everyone for your advices
For an item price as “initialCost x coeff^itemLvl”, and if any item bought increase its level by one, there is the formula to calculate the number of item purchasable :