Skip to content

Commit

Permalink
Merge pull request #2687 from wowsims/cleanups
Browse files Browse the repository at this point in the history
Move most resource metrics out of Spell
  • Loading branch information
jimmyt857 authored Feb 20, 2023
2 parents 7801f81 + 9d4ab0f commit 06c70cf
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 59 deletions.
22 changes: 16 additions & 6 deletions sim/core/energy.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ type EnergyCostOptions struct {
RefundMetrics *ResourceMetrics // Optional, will default to unit.EnergyRefundMetrics if not supplied.
}
type EnergyCost struct {
Refund float64
RefundMetrics *ResourceMetrics
ResourceMetrics *ResourceMetrics
Refund float64
RefundMetrics *ResourceMetrics
ResourceMetrics *ResourceMetrics
ComboPointMetrics *ResourceMetrics
}

func newEnergyCost(spell *Spell, options EnergyCostOptions) *EnergyCost {
Expand All @@ -184,9 +185,10 @@ func newEnergyCost(spell *Spell, options EnergyCostOptions) *EnergyCost {
}

return &EnergyCost{
Refund: options.Refund,
RefundMetrics: options.RefundMetrics,
ResourceMetrics: spell.Unit.NewEnergyMetrics(spell.ActionID),
Refund: options.Refund,
RefundMetrics: options.RefundMetrics,
ResourceMetrics: spell.Unit.NewEnergyMetrics(spell.ActionID),
ComboPointMetrics: spell.Unit.NewComboPointMetrics(spell.ActionID),
}
}

Expand All @@ -209,3 +211,11 @@ func (ec *EnergyCost) IssueRefund(sim *Simulation, spell *Spell) {
spell.Unit.AddEnergy(sim, ec.Refund*spell.CurCast.Cost, ec.RefundMetrics)
}
}

func (spell *Spell) EnergyMetrics() *ResourceMetrics {
return spell.Cost.(*EnergyCost).ComboPointMetrics
}

func (spell *Spell) ComboPointMetrics() *ResourceMetrics {
return spell.Cost.(*EnergyCost).ComboPointMetrics
}
32 changes: 32 additions & 0 deletions sim/core/runic_power.go
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,12 @@ type RuneCostImpl struct {
RunicPowerCost float64
RunicPowerGain float64
Refundable bool

runicPowerMetrics *ResourceMetrics
bloodRuneMetrics *ResourceMetrics
frostRuneMetrics *ResourceMetrics
unholyRuneMetrics *ResourceMetrics
deathRuneMetrics *ResourceMetrics
}

func newRuneCost(spell *Spell, options RuneCostOptions) *RuneCostImpl {
Expand All @@ -1120,6 +1126,12 @@ func newRuneCost(spell *Spell, options RuneCostOptions) *RuneCostImpl {
RunicPowerCost: options.RunicPowerCost,
RunicPowerGain: options.RunicPowerGain,
Refundable: options.Refundable,

runicPowerMetrics: Ternary(options.RunicPowerCost > 0 || options.RunicPowerGain > 0, spell.Unit.NewRunicPowerMetrics(spell.ActionID), nil),
bloodRuneMetrics: Ternary(options.BloodRuneCost > 0, spell.Unit.NewBloodRuneMetrics(spell.ActionID), nil),
frostRuneMetrics: Ternary(options.FrostRuneCost > 0, spell.Unit.NewFrostRuneMetrics(spell.ActionID), nil),
unholyRuneMetrics: Ternary(options.UnholyRuneCost > 0, spell.Unit.NewUnholyRuneMetrics(spell.ActionID), nil),
deathRuneMetrics: spell.Unit.NewDeathRuneMetrics(spell.ActionID),
}
}

Expand Down Expand Up @@ -1225,3 +1237,23 @@ func (rc *RuneCostImpl) IssueRefund(sim *Simulation, spell *Spell) {
// Instead of issuing refunds we just don't charge the cost of spells which
// miss; this is better for perf since we'd have to cancel the regen actions.
}

func (spell *Spell) RunicPowerMetrics() *ResourceMetrics {
return spell.Cost.(*RuneCostImpl).runicPowerMetrics
}

func (spell *Spell) BloodRuneMetrics() *ResourceMetrics {
return spell.Cost.(*RuneCostImpl).bloodRuneMetrics
}

func (spell *Spell) FrostRuneMetrics() *ResourceMetrics {
return spell.Cost.(*RuneCostImpl).frostRuneMetrics
}

func (spell *Spell) UnholyRuneMetrics() *ResourceMetrics {
return spell.Cost.(*RuneCostImpl).unholyRuneMetrics
}

func (spell *Spell) DeathRuneMetrics() *ResourceMetrics {
return spell.Cost.(*RuneCostImpl).deathRuneMetrics
}
52 changes: 2 additions & 50 deletions sim/core/spell.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ type Spell struct {
// Example: https://wow.tools/dbc/?dbc=spellmisc&build=3.4.0.44996
MissileSpeed float64

ResourceMetrics *ResourceMetrics
comboPointMetrics *ResourceMetrics
runicPowerMetrics *ResourceMetrics
bloodRuneMetrics *ResourceMetrics
frostRuneMetrics *ResourceMetrics
unholyRuneMetrics *ResourceMetrics
deathRuneMetrics *ResourceMetrics
healthMetrics []*ResourceMetrics
ResourceMetrics *ResourceMetrics
healthMetrics []*ResourceMetrics

Cost SpellCost // Cost for the spell.
DefaultCast Cast // Default cast parameters with all static effects applied.
Expand Down Expand Up @@ -368,48 +362,6 @@ func (spell *Spell) doneIteration() {
}
}

func (spell *Spell) ComboPointMetrics() *ResourceMetrics {
if spell.comboPointMetrics == nil {
spell.comboPointMetrics = spell.Unit.NewComboPointMetrics(spell.ActionID)
}
return spell.comboPointMetrics
}

func (spell *Spell) RunicPowerMetrics() *ResourceMetrics {
if spell.runicPowerMetrics == nil {
spell.runicPowerMetrics = spell.Unit.NewRunicPowerMetrics(spell.ActionID)
}
return spell.runicPowerMetrics
}

func (spell *Spell) BloodRuneMetrics() *ResourceMetrics {
if spell.bloodRuneMetrics == nil {
spell.bloodRuneMetrics = spell.Unit.NewBloodRuneMetrics(spell.ActionID)
}
return spell.bloodRuneMetrics
}

func (spell *Spell) FrostRuneMetrics() *ResourceMetrics {
if spell.frostRuneMetrics == nil {
spell.frostRuneMetrics = spell.Unit.NewFrostRuneMetrics(spell.ActionID)
}
return spell.frostRuneMetrics
}

func (spell *Spell) UnholyRuneMetrics() *ResourceMetrics {
if spell.unholyRuneMetrics == nil {
spell.unholyRuneMetrics = spell.Unit.NewUnholyRuneMetrics(spell.ActionID)
}
return spell.unholyRuneMetrics
}

func (spell *Spell) DeathRuneMetrics() *ResourceMetrics {
if spell.deathRuneMetrics == nil {
spell.deathRuneMetrics = spell.Unit.NewDeathRuneMetrics(spell.ActionID)
}
return spell.deathRuneMetrics
}

func (spell *Spell) HealthMetrics(target *Unit) *ResourceMetrics {
if spell.healthMetrics == nil {
spell.healthMetrics = make([]*ResourceMetrics, len(spell.Unit.AttackTables))
Expand Down
3 changes: 2 additions & 1 deletion sim/deathknight/blood_tap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func (dk *Deathknight) registerBloodTapSpell() {
cdTimer := dk.NewTimer()
cd := time.Minute * 1

rpMetrics := dk.NewRunicPowerMetrics(actionID)
dk.BloodTapAura = dk.RegisterAura(core.Aura{
Label: "Blood Tap",
ActionID: actionID,
Expand All @@ -23,7 +24,7 @@ func (dk *Deathknight) registerBloodTapSpell() {

// Gain at the end, to take into account previous effects for callback
amountOfRunicPower := 10.0
dk.AddRunicPower(sim, amountOfRunicPower, dk.BloodTap.RunicPowerMetrics())
dk.AddRunicPower(sim, amountOfRunicPower, rpMetrics)
},
OnExpire: func(aura *core.Aura, sim *core.Simulation) {
dk.CancelBloodTap(sim)
Expand Down
3 changes: 2 additions & 1 deletion sim/deathknight/empower_rune_weapon.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func (dk *Deathknight) registerEmpowerRuneWeaponSpell() {
cdTimer := dk.NewTimer()
cd := time.Minute * 5

rpMetrics := dk.NewRunicPowerMetrics(actionID)
dk.EmpowerRuneWeapon = dk.RegisterSpell(core.SpellConfig{
ActionID: actionID,
Flags: core.SpellFlagNoOnCastComplete,
Expand All @@ -22,7 +23,7 @@ func (dk *Deathknight) registerEmpowerRuneWeaponSpell() {
},
ApplyEffects: func(sim *core.Simulation, target *core.Unit, spell *core.Spell) {
dk.RegenAllRunes(sim)
dk.AddRunicPower(sim, 25, dk.EmpowerRuneWeapon.RunicPowerMetrics())
dk.AddRunicPower(sim, 25, rpMetrics)
},
})
}
3 changes: 2 additions & 1 deletion sim/deathknight/horn_of_winter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
func (dk *Deathknight) registerHornOfWinterSpell() {
actionID := core.ActionID{SpellID: 57623}
duration := time.Minute * time.Duration((2.0 + core.TernaryFloat64(dk.HasMinorGlyph(proto.DeathknightMinorGlyph_GlyphOfHornOfWinter), 1.0, 0.0)))
rpMetrics := dk.NewRunicPowerMetrics(actionID)

bonusStats := stats.Stats{stats.Strength: 155.0, stats.Agility: 155.0}
negativeStats := bonusStats.Multiply(-1)
Expand Down Expand Up @@ -53,7 +54,7 @@ func (dk *Deathknight) registerHornOfWinterSpell() {
if dk.Inputs.RefreshHornOfWinter {
dk.HornOfWinterAura.Activate(sim)
}
dk.AddRunicPower(sim, 10, dk.HornOfWinter.RunicPowerMetrics())
dk.AddRunicPower(sim, 10, rpMetrics)
},
})
}
Expand Down

0 comments on commit 06c70cf

Please sign in to comment.