Formula with a minimum result.

In my project, I've allowed the player to increase their stats as they level up. One of these stats is the Pharmacology stat. Some items, such as healing potions, become more potent with the users PHA.

This is what the formula looks like: a.pha/2 * 30

The scaling is meant to be a base of 30 HP recovered, adding in the users PHA stat, halved. Of course, PHA being a percentage, I must combine it using a multiplier, not an addition.

All well and good and it's very balanced for someone who went a PHA build. However, for the people who didn't invest in PHA, an unforeseen (but, in hindsight, pretty obvious) problem has arisen. You'll heal 15 HP, because if your base PHA is 100%, then it's cut in half, it becomes 50%, which of course halves the end-result.

So, my question is, is there any way to enforce a minimum? Like, if the user has less than 100% total PHA after calculation, set the PHA in the calculation to 100%.

In example, if Actor 1 has 140% PHA, but because it's cut in half for this particular formula, ends up having 70% PHA just for sake of this formula, their PHA is calculated as 100% after being cut in half instead, this way actors that aren't heavily invested in the PHA stat don't get so heavily punished.

A possibility is checking the users base PHA. For example, knowing it will be halved, it can be something like, if the users base PHA is less than 200% for the calculation, then disregard the PHA check in the formula entirely, because after that less-than-200% is halved, it would of course be less than 100%.

Just not sure how to go about implementing it. Any help is appreciated.
Spoiler
You could do something like

30 + 30*(pha-1.00)/2

This way at pha of 100% (1.00) it recovers 30 HP and every 1% increase in pha will increase healing by 0.5% of 30

So if your actor has 140% pha, the formula will be

30 + 30*(1.4-1.00)/2
30 + 30*(0.4)/2
30 + 30*0.2
30 + 6
36

Practically the formula is

base + base*(pha-1.00)/2

or

base + (base/2)*(pha-1.00)

The scaling is meant to be a base of 30 HP recovered, adding in the users PHA stat, halved. Of course, PHA being a percentage, I must combine it using a multiplier, not an addition.

If thats your end goal, your formula should be

30 + (a.pha*100/2)

or simply

30 + a.pha*50

This formula gives you exactly 30 plus half of the user's pha stat

at 100% PHA, it will heal 80 HP
at 150% PHA, it will heal 105 HP

or if you mean (30+pha) halved, then the formula would be

(30+a.pha*100)/2

at 100% PHA, it will heal 65 HP
at 150% PHA, it will heal 90 HP

Note:

If you want to get the whole number equivalent of the percentage values, simply multiply it by 100. That is why here we use a.pha*100. Now we can use it easily with addition operators.
For later use, if you just want to force a minimum on a formula you can use Math.max(n, formula) eg

Code:
Math.max(30, a.pha/2 * 30)

This will never return less than 30.

Thank you for the detailed explanation. My issue is that everyone has 100% PHA by default, so it giving more than 30 with this base is a problem. None-the-less, the way you did the formulas is enlightening and well explained.

For later use, if you just want to force a minimum on a formula you can use Math.max(n, formula) eg

Code:
Math.max(30, a.pha/2 * 30)

This will never return less than 30.

You know what, I knew of the math syntax, but for some reason just assumed it wouldn't work in the formula field. That's what I get for not just trying.
The formula that @Engr. Adiktuzmiko provided within the spoiler will only give 30 with 100% PHA.

Code:
30 + 30*(pha-1.00)/2
Yeah, the only difference between my original 30 + xxx formula and the math.max one by @Silva is that the Math.max one will only give greater than 30 when your PHA is greater than 200% because thats at any point below 200%, the formula will always be less than 30.

Formula 1:

30 + 30*(a.pha-1.00)/2
or simply
30 + 15*(a.pha-1.00)

Formula 2 (by Silva)

Math.max(30,a.pha*30/2)
or simply
Math.max(30,a.pha*15)

at 100% PHA

F1: 30+15*(1.00-1.00) = 30
F2: Math.max(30,1.00*15) = 30

at 150% PHA

F1: 30 + 15*(1.5-1) = 37.5
F2: Math.max(30,1.5*15) = 30

So practically F1 scales with your PHA right away while F2 will wait until more 200% PHA to scale

Just pick which one suits your game better. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/formula-with-a-minimum-result.106018/