theripper93/Boss-Bar

Hp bar not properly substracting below 0

Closed this issue · 2 comments

Too lazy for pr so here we go:

Fix is:

  get hpPercent() {
    let hpHolder = this.currentHp;
    if(hpHolder < 0) {
      hpHolder = 0;
    }
    
    return Math.round((100 * hpHolder) / this.maxHp);
  }

Before it calculated the following:

return Math.round((100 * this.currentHp) / this.maxHp);

maxHp = 30

If I calculate ((100 * -1) / 30) = (-100 / 30) = -3.33%

The bossbar only shows values between 0-100%.

Math 101

I was not aware of systems having hp below 0, what’s the system in question ? anyways addeed this fix

get hpPercent() { return Math.max(0, Math.round((100 * this.currentHp) / this.maxHp)); }

The system in question is 3.5e by Rughalt.
You are "dying" as soon as you hit -1 hp and you are "Dead" as soon as you hit -10 hp.
As people usually don't use the death-saving rules for npc's/bosses just ignoring the whole yada yada and setting it to 0 seemed appropriate.

Great fix tho, thank you 👍