package hero import ( "math/rand" "github.com/denisovdennis/autohero/internal/constants" "github.com/denisovdennis/autohero/internal/model" "github.com/denisovdennis/autohero/internal/tuning" ) func UsePotionOnHero(hero *model.Hero, force bool) int { if force != true { if hero == nil || hero.Potions <= 0 || hero.HP <= 0 { return 0 } hpThresh := int(float64(hero.MaxHP) * constants.OfflineAutoPotionHPThresh) if hero.HP >= hpThresh { return 0 } if rand.Float64() >= (1.0 - (1.0 - float64(hero.HP / hpThresh))) / 1.2 + constants.OfflineAutoPotionChance { return 0 } } hero.Potions-- healAmount := int(float64(hero.MaxHP) * tuning.Get().PotionHealPercent) if healAmount < 1 { healAmount = 1 } hero.HP += healAmount if hero.HP > hero.MaxHP { hero.HP = hero.MaxHP } return healAmount; }