Skip to content

Commit

Permalink
refactor char current hp from flat into ratio (genshinsim#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
k0l11 authored Jun 21, 2023
1 parent f67b55a commit 388cbc7
Show file tree
Hide file tree
Showing 39 changed files with 111 additions and 75 deletions.
3 changes: 1 addition & 2 deletions internal/artifacts/berserker/berserker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ func NewSet(c *core.Core, char *character.CharWrapper, count int, param map[stri
char.AddAttackMod(character.AttackMod{
Base: modifier.NewBase("berserker-4pc", -1),
Amount: func(atk *combat.AttackEvent, t combat.Target) ([]float64, bool) {
maxhp := char.MaxHP()
if char.HPCurrent > 0.70*maxhp {
if char.CurrentHPRatio() > 0.7 {
return nil, false
}
return m, true
Expand Down
4 changes: 2 additions & 2 deletions internal/characters/baizhu/asc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (c *char) a1() {
AffectedStat: attributes.Heal,
Amount: func() ([]float64, bool) {
active := c.Core.Player.ActiveChar()
if active.HPCurrent/active.MaxHP() < 0.5 {
if active.CurrentHPRatio() < 0.5 {
return mHeal, true
}
return nil, false
Expand All @@ -40,7 +40,7 @@ func (c *char) a1() {
AffectedStat: attributes.DendroP,
Amount: func() ([]float64, bool) {
active := c.Core.Player.ActiveChar()
if active.HPCurrent/active.MaxHP() >= 0.5 {
if active.CurrentHPRatio() >= 0.5 {
return mDendroP, true
}
return nil, false
Expand Down
4 changes: 2 additions & 2 deletions internal/characters/barbara/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func (c *char) checkc6() {
//grab the active char
char := c.Core.Player.ActiveChar()
//if dead, revive back to 1 hp
if char.HPCurrent <= -1 {
c.HPCurrent = c.MaxHP()
if char.CurrentHPRatio() <= 0 {
char.SetHPByAmount(1)
}

c.c6icd = c.Core.F + 60*60*15
Expand Down
4 changes: 2 additions & 2 deletions internal/characters/bennett/burst.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *char) applyBennettField(stats [attributes.EndStatType]float64) func() {

active := c.Core.Player.ActiveChar()
//heal if under 70%
if active.HPCurrent/active.MaxHP() < .7 {
if active.CurrentHPRatio() < 0.7 {
c.Core.Player.Heal(player.HealInfo{
Caller: c.Index,
Target: active.Index,
Expand All @@ -117,7 +117,7 @@ func (c *char) applyBennettField(stats [attributes.EndStatType]float64) func() {
threshold = 0
}
// Activate attack buff
if active.HPCurrent/active.MaxHP() > threshold {
if active.CurrentHPRatio() > threshold {
// add weapon infusion
if c.Base.Cons >= 6 {
switch active.Weapon.Class {
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/bennett/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (c *char) c2() {
Base: modifier.NewBase("bennett-c2", -1),
AffectedStat: attributes.ER,
Amount: func() ([]float64, bool) {
return m, c.HPCurrent/c.MaxHP() < 0.7
return m, c.CurrentHPRatio() < 0.7
},
})
}
2 changes: 1 addition & 1 deletion internal/characters/chongyun/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *char) c6() {
if !ok {
return nil, false
}
if x.HP()/x.MaxHP() < c.HPCurrent/c.MaxHP() {
if x.HP()/x.MaxHP() < c.CurrentHPRatio() {
return m, true
}
return nil, false
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/diona/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c *char) c6() {
}
//add 200EM to active char
active := c.Core.Player.ActiveChar()
if active.HPCurrent/active.MaxHP() > 0.5 {
if active.CurrentHPRatio() > 0.5 {
active.AddStatMod(character.StatMod{
Base: modifier.NewBaseWithHitlag("diona-c6", 120),
AffectedStat: attributes.EM,
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/dori/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c *char) c2(travel int) {
// ·When their Energy is less than 50%, they gain 30% Energy Recharge.
func (c *char) c4() {
active := c.Core.Player.ActiveChar()
if active.HPCurrent/active.MaxHP() < 0.5 {
if active.CurrentHPRatio() < 0.5 {
active.AddHealBonusMod(character.HealBonusMod{
Base: modifier.NewBaseWithHitlag("dori-c4-healbonus", 48),
Amount: func() (float64, bool) {
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/heizou/heizou.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *char) Init() error {

// make sure to use the same key everywhere so that these passives don't stack
c.Core.Player.AddStamPercentMod("utility-dash", -1, func(a action.Action) (float64, bool) {
if a == action.ActionDash && c.HPCurrent > 0 {
if a == action.ActionDash && c.CurrentHPRatio() > 0 {
return -0.2, false
}
return 0, false
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/hutao/asc.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *char) a4() {
Base: modifier.NewBase("hutao-a4", -1),
AffectedStat: attributes.PyroP,
Amount: func() ([]float64, bool) {
if c.HPCurrent/c.MaxHP() <= 0.5 {
if c.CurrentHPRatio() <= 0.5 {
return c.a4buff, true
}
return nil, false
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/hutao/burst.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func init() {
}

func (c *char) Burst(p map[string]int) action.ActionInfo {
low := (c.HPCurrent / c.MaxHP()) <= 0.5
low := c.CurrentHPRatio() <= 0.5
mult := burst[c.TalentLvlBurst()]
regen := regen[c.TalentLvlBurst()]
if low {
Expand Down
8 changes: 4 additions & 4 deletions internal/characters/hutao/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ func (c *char) checkc6(check1HP bool) {
return
}
// check if hp less than 25%
if c.HPCurrent/c.MaxHP() > .25 {
if c.CurrentHPRatio() > 0.25 {
return
}
// check if hp is less than 2 for the 2s check
if check1HP && c.HPCurrent >= 2 {
if check1HP && c.CurrentHP() >= 2 {
return
}
// if dead, revive back to 1 hp
if c.HPCurrent <= -1 {
c.HPCurrent = 1
if c.CurrentHPRatio() <= 0 {
c.SetHPByAmount(1)
}

//increase crit rate to 100%
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/hutao/skill.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *char) Skill(p map[string]int) action.ActionInfo {
c.Core.Player.Drain(player.DrainInfo{
ActorIndex: c.Index,
Abil: "Paramita Papilio",
Amount: .30 * c.HPCurrent,
Amount: 0.30 * c.CurrentHP(),
})

//trigger 0 damage attack; matters because this breaks freeze
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/kaeya/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *char) c4() {
return false
}
maxhp := c.MaxHP()
if c.HPCurrent/maxhp < .2 {
if c.CurrentHPRatio() < 0.2 {
c.c4icd = c.Core.F + 3600
c.Core.Player.Shields.Add(&shield.Tmpl{
ActorIndex: c.Index,
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/kaeya/kaeya.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewChar(s *core.Core, w *character.CharWrapper, _ profile.CharacterProfile)
func (c *char) Init() error {
// make sure to use the same key everywhere so that these passives don't stack
c.Core.Player.AddStamPercentMod("utility-dash", -1, func(a action.Action) (float64, bool) {
if a == action.ActionDash && c.HPCurrent > 0 {
if a == action.ActionDash && c.CurrentHPRatio() > 0 {
return -0.2, false
}
return 0, false
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/kazuha/kazuha.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *char) Init() error {

// make sure to use the same key everywhere so that these passives don't stack
c.Core.Player.AddStamPercentMod("utility-dash", -1, func(a action.Action) (float64, bool) {
if a == action.ActionDash && c.HPCurrent > 0 {
if a == action.ActionDash && c.CurrentHPRatio() > 0 {
return -0.2, false
}
return 0, false
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/kokomi/burst.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (c *char) makeBurstHealCB() combat.AttackCBFunc {
// C2 handling
// Sangonomiya Kokomi gains the following Healing Bonuses with regard to characters with 50% or less HP via the following methods:
// Nereid's Ascension Normal and Charged Attacks: 0.6% of Kokomi's Max HP.
if c.Base.Cons >= 2 && char.HPCurrent/char.MaxHP() <= .5 {
if c.Base.Cons >= 2 && char.CurrentHPRatio() <= 0.5 {
bonus := 0.006 * c.MaxHP()
src += bonus
c.Core.Log.NewEvent("kokomi c2 proc'd", glog.LogCharacterEvent, char.Index).
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/kokomi/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *char) c6() {
m := make([]float64, attributes.EndStatType)
m[attributes.HydroP] = .4
for _, char := range c.Core.Player.Chars() {
if char.HPCurrent/char.MaxHP() < .8 {
if char.CurrentHPRatio() < 0.8 {
continue
}
c.AddStatMod(character.StatMod{
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/kokomi/skill.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *char) skillTick(d *combat.AttackEvent) {
// Kurage's Oath Bake-Kurage: 4.5% of Kokomi's Max HP.
if c.Base.Cons >= 2 {
active := c.Core.Player.ActiveChar()
if active.HPCurrent/active.MaxHP() <= .5 {
if active.CurrentHPRatio() <= 0.5 {
bonus := 0.045 * maxhp
src += bonus
c.Core.Log.NewEvent("kokomi c2 proc'd", glog.LogCharacterEvent, active.Index).
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/kuki/asc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (c *char) a1() {
Base: modifier.NewBase("kuki-a1", -1),
AffectedStat: attributes.Heal,
Amount: func() ([]float64, bool) {
if c.HPCurrent/c.MaxHP() <= 0.5 {
if c.CurrentHPRatio() <= 0.5 {
return m, true
}
return nil, false
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/kuki/burst.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *char) Burst(p map[string]int) action.ActionInfo {
snap := c.Snapshot(&ai)

count := 7 //can be 11 at low HP
if (c.HPCurrent / c.MaxHP()) <= 0.5 {
if c.CurrentHPRatio() <= 0.5 {
count = 12
}
interval := 2 * 60 / 7
Expand Down
6 changes: 3 additions & 3 deletions internal/characters/kuki/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ func (c *char) c6() {
return false
}
//check if hp less than 25%
if c.HPCurrent/c.MaxHP() > .25 {
if c.CurrentHPRatio() > 0.25 {
return false
}
//if dead, revive back to 1 hp
if c.HPCurrent <= -1 {
c.HPCurrent = 1
if c.CurrentHPRatio() <= 0 {
c.SetHPByAmount(1)
}
c.AddStatus(c6IcdKey, 3600, false) // 60s * 60

Expand Down
10 changes: 6 additions & 4 deletions internal/characters/kuki/skill.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ func init() {

func (c *char) Skill(p map[string]int) action.ActionInfo {
// only drain HP when above 20% HP
if c.HPCurrent/c.MaxHP() > hpDrainThreshold {
hpdrain := 0.3 * c.HPCurrent
if c.CurrentHPRatio() > hpDrainThreshold {
currentHP := c.CurrentHP()
maxHP := c.MaxHP()
hpdrain := 0.3 * currentHP
// The HP consumption from using this skill can only bring her to 20% HP.
if (c.HPCurrent-hpdrain)/c.MaxHP() <= hpDrainThreshold {
hpdrain = c.HPCurrent - hpDrainThreshold*c.MaxHP()
if (currentHP-hpdrain)/maxHP <= hpDrainThreshold {
hpdrain = currentHP - hpDrainThreshold*maxHP
}
c.Core.Player.Drain(player.DrainInfo{
ActorIndex: c.Index,
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/noelle/asc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *char) a1() {
return false
}
active := c.Core.Player.ActiveChar()
if active.HPCurrent/active.MaxHP() >= 0.3 {
if active.CurrentHPRatio() >= 0.3 {
return false
}
c.AddStatus(a1IcdKey, 3600, false)
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/razor/razor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *char) Init() error {

// make sure to use the same key everywhere so that these passives don't stack
c.Core.Player.AddStamPercentMod("utility-dash", -1, func(a action.Action) (float64, bool) {
if a == action.ActionDash && c.HPCurrent > 0 {
if a == action.ActionDash && c.CurrentHPRatio() > 0 {
return -0.2, false
}
return 0, false
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/sayu/burst.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (c *char) Burst(p map[string]int) action.ActionInfo {
char := c.Core.Player.ActiveChar()
hasC1 := c.Base.Cons >= 1
// C1 ignores HP limit
needHeal := c.Core.Combat.Player().IsWithinArea(burstArea) && (char.HPCurrent/char.MaxHP() <= 0.7 || hasC1)
needHeal := c.Core.Combat.Player().IsWithinArea(burstArea) && (char.CurrentHPRatio() <= 0.7 || hasC1)

// check for enemy
enemy := c.Core.Combat.ClosestEnemyWithinArea(burstArea, nil)
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/xiao/burst.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *char) Burst(p map[string]int) action.ActionInfo {
c.Core.Player.Drain(player.DrainInfo{
ActorIndex: c.Index,
Abil: "Bane of All Evil",
Amount: burstDrain[c.TalentLvlBurst()] * c.HPCurrent,
Amount: burstDrain[c.TalentLvlBurst()] * c.CurrentHP(),
})
}
}, i)
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/xiao/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *char) c4() {
Base: modifier.NewBase("xiao-c4", -1),
AffectedStat: attributes.DEFP,
Amount: func() ([]float64, bool) {
if c.HPCurrent/c.MaxHP() <= 0.5 {
if c.CurrentHPRatio() <= 0.5 {
return m, true
}
return nil, false
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/yaoyao/yuegui.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (yg *yuegui) makeParticleCB() combat.AttackCBFunc {

func (yg *yuegui) throw() {
yg.Gadget.ThinkInterval = 60
currHPPerc := yg.Core.Player.ActiveChar().HPCurrent / yg.Core.Player.ActiveChar().MaxHP()
currHPPerc := yg.Core.Player.ActiveChar().CurrentHPRatio()
enemy := yg.Core.Combat.RandomEnemyWithinArea(yg.aoe, nil)

var target geometry.Point
Expand Down
2 changes: 1 addition & 1 deletion internal/characters/yoimiya/burst.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (c *char) burstHook() {
if c.Core.Flags.DamageMode {
//add check for if yoimiya dies
c.Core.Events.Subscribe(event.OnPlayerHPDrain, func(_ ...interface{}) bool {
if c.HPCurrent <= 0 {
if c.CurrentHPRatio() <= 0 {
// remove Aurous Blaze from target
for _, x := range c.Core.Combat.Enemies() {
trg := x.(*enemy.Enemy)
Expand Down
3 changes: 1 addition & 2 deletions internal/weapons/claymore/ferrousshadow/ferrousshadow.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func NewWeapon(c *core.Core, char *character.CharWrapper, p weapon.WeaponProfile
return nil, false
}
// don't apply buff if above hp threshold
maxhp := char.MaxHP()
if char.HPCurrent > hp_check*maxhp {
if char.CurrentHPRatio() > hp_check {
return nil, false
}
return m, true
Expand Down
2 changes: 1 addition & 1 deletion internal/weapons/spear/homa/homa.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewWeapon(c *core.Core, char *character.CharWrapper, p weapon.WeaponProfile
Amount: func() ([]float64, bool) {
maxhp := char.MaxHP()
per := atkp
if char.HPCurrent <= 0.5*maxhp {
if char.CurrentHPRatio() <= 0.5 {
per += lowhp
}
mATK[attributes.ATK] = per * maxhp
Expand Down
2 changes: 1 addition & 1 deletion internal/weapons/sword/harbinger/harbinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewWeapon(c *core.Core, char *character.CharWrapper, p weapon.WeaponProfile
Base: modifier.NewBase("harbinger", -1),
AffectedStat: attributes.CR,
Amount: func() ([]float64, bool) {
return m, char.HPCurrent/char.MaxHP() >= 0.9
return m, char.CurrentHPRatio() >= 0.9
},
})
return w, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ func (c *Core) AddChar(p profile.CharacterProfile) (int, error) {
}
index := c.Player.AddChar(char)

// set the hp
char.HPCurrent = -1
// get starting hp
char.StartHP = -1
if hp, ok := p.Params["start_hp"]; ok {
char.HPCurrent = float64(hp)
char.StartHP = hp
}

// set the energy
Expand Down
Loading

0 comments on commit 388cbc7

Please sign in to comment.