So I am creating a battle system for my own personal enjoyment and am trying to tackle the healing portion of it. When I use a healing item it increases the max health, when the value exceeds the current max health, to whatever the value of the healing affect was.
I looked it up and some people suggested Saturation Arithmetic, but I couldn't find anything on google that explained that process. Then I found another topic on Stack that explained the same problem and had an answer, however when I tried it it's not working. Long story short.
Here is the block of code I'm working with currently.
public void useHealItem2(CharStats hero, Enemy enemy, Battle battle){
Math.min(hero.hp += 500, hero.hp);
battle.herodmg = enemy.att - hero.def;
hero.hp -= battle.herodmg;
}
So I am trying to set the max to a variable amount rather then a fixed number. So as the hero's hp increases this will automatically scale. I think this is having problems because it's setting the hp first so the maximum that it's going off of is already at 500. If that makes sense. But that's just what I'm thinking, I really don't know for sure.
I would suggest saying hero.hp = Math.min(hero.currentHealth+500, hero.maxHealth)
, where currentHealth
and maxHealth
are exactly what they sound like.