small refactoring + autopotions
parent
57312f176d
commit
9f2fc34316
@ -0,0 +1,11 @@
|
||||
package constants
|
||||
|
||||
const (
|
||||
OfflineAutoPotionChance = 0.10
|
||||
OfflineAutoPotionHPThresh = 0.60
|
||||
|
||||
// CombatSimMaxStepsDefault is the iteration cap when CombatSimOptions.MaxSteps <= 0 (offline, tests).
|
||||
CombatSimMaxStepsDefault = 200_000
|
||||
// CombatSimMaxStepsLong is used by balance CLIs and admin combat sim so long fights (DoT/regen) are not cut off early.
|
||||
CombatSimMaxStepsLong = 3_000_000
|
||||
)
|
||||
@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
Loading…
Reference in New Issue