Skip to content

Commit

Permalink
Undo MultiplyCastSpeed requiring sim context
Browse files Browse the repository at this point in the history
  • Loading branch information
1337LutZ committed Jan 31, 2025
1 parent 0e7b516 commit f4e8c2a
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 73 deletions.
12 changes: 6 additions & 6 deletions sim/core/buffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ func DarkIntentAura(unit *Unit, isWarlock bool) *Aura {
Label: "Dark Intent",
ActionID: ActionID{SpellID: 85767},
OnGain: func(aura *Aura, sim *Simulation) {
aura.Unit.MultiplyCastSpeed(sim, 1.03)
aura.Unit.MultiplyCastSpeed(1.03)
aura.Unit.MultiplyAttackSpeed(sim, 1.03)
},
OnExpire: func(aura *Aura, sim *Simulation) {
aura.Unit.MultiplyCastSpeed(sim, 1/1.03)
aura.Unit.MultiplyCastSpeed(1 / 1.03)
aura.Unit.MultiplyAttackSpeed(sim, 1/1.03)
},
// OnPeriodicDamageDealt: periodicHandler,
Expand Down Expand Up @@ -823,10 +823,10 @@ func registerExclusiveSpellHaste(aura *Aura, spellHastePercent float64) {
aura.NewExclusiveEffect("SpellHaste%Buff", false, ExclusiveEffect{
Priority: spellHastePercent,
OnGain: func(ee *ExclusiveEffect, sim *Simulation) {
ee.Aura.Unit.MultiplyCastSpeed(sim, 1+ee.Priority)
ee.Aura.Unit.MultiplyCastSpeed(1 + ee.Priority)
},
OnExpire: func(ee *ExclusiveEffect, sim *Simulation) {
ee.Aura.Unit.MultiplyCastSpeed(sim, 1/(1+ee.Priority))
ee.Aura.Unit.MultiplyCastSpeed(1 / (1 + ee.Priority))
},
})
}
Expand Down Expand Up @@ -1298,10 +1298,10 @@ func multiplyCastSpeedEffect(aura *Aura, multiplier float64) *ExclusiveEffect {
return aura.NewExclusiveEffect("MultiplyCastSpeed", false, ExclusiveEffect{
Priority: multiplier,
OnGain: func(ee *ExclusiveEffect, sim *Simulation) {
ee.Aura.Unit.MultiplyCastSpeed(sim, multiplier)
ee.Aura.Unit.MultiplyCastSpeed(multiplier)
},
OnExpire: func(ee *ExclusiveEffect, sim *Simulation) {
ee.Aura.Unit.MultiplyCastSpeed(sim, 1/multiplier)
ee.Aura.Unit.MultiplyCastSpeed(1 / multiplier)
},
})
}
Expand Down
4 changes: 2 additions & 2 deletions sim/core/racials.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ func applyRaceEffects(agent Agent) {
ActionID: actionID,
Duration: time.Second * 10,
OnGain: func(aura *Aura, sim *Simulation) {
character.MultiplyCastSpeed(sim, 1.2)
character.MultiplyCastSpeed(1.2)
character.MultiplyAttackSpeed(sim, 1.2)
character.MultiplyResourceRegenSpeed(sim, 1.2)
},
OnExpire: func(aura *Aura, sim *Simulation) {
character.MultiplyCastSpeed(sim, 1/1.2)
character.MultiplyCastSpeed(1 / 1.2)
character.MultiplyAttackSpeed(sim, 1/1.2)
character.MultiplyResourceRegenSpeed(sim, 1/1.2)
},
Expand Down
13 changes: 6 additions & 7 deletions sim/core/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type UnitType int
type SpellRegisteredHandler func(spell *Spell)
type OnMasteryStatChanged func(sim *Simulation, oldMasteryRating float64, newMasteryRating float64)
type OnCastSpeedChanged func(sim *Simulation, oldSpeed float64, newSpeed float64)
type OnCastSpeedChanged func(oldSpeed float64, newSpeed float64)
type OnTemporaryStatsChange func(sim *Simulation, buffAura *Aura, statsChangeWithoutDeps stats.Stats)

const (
Expand Down Expand Up @@ -327,7 +327,7 @@ func (unit *Unit) processDynamicBonus(sim *Simulation, bonus stats.Stats) {
unit.runicPowerBar.updateRegenTimes(sim)
unit.energyBar.processDynamicHasteRatingChange(sim)
unit.focusBar.processDynamicHasteRatingChange(sim)
unit.updateCastSpeed(sim)
unit.updateCastSpeed()
}
if bonus[stats.MasteryRating] != 0 {
newMasteryRating := unit.stats[stats.MasteryRating]
Expand Down Expand Up @@ -414,18 +414,18 @@ func (unit *Unit) TotalSpellHasteMultiplier() float64 {
return unit.PseudoStats.CastSpeedMultiplier * (1 + unit.stats[stats.HasteRating]/(HasteRatingPerHastePercent*100))
}

func (unit *Unit) updateCastSpeed(sim *Simulation) {
func (unit *Unit) updateCastSpeed() {
oldCastSpeed := unit.CastSpeed
unit.CastSpeed = 1 / unit.TotalSpellHasteMultiplier()
newCastSpeed := unit.CastSpeed

for i := range unit.OnCastSpeedChanged {
unit.OnCastSpeedChanged[i](sim, oldCastSpeed, newCastSpeed)
unit.OnCastSpeedChanged[i](oldCastSpeed, newCastSpeed)
}
}
func (unit *Unit) MultiplyCastSpeed(sim *Simulation, amount float64) {
func (unit *Unit) MultiplyCastSpeed(amount float64) {
unit.PseudoStats.CastSpeedMultiplier *= amount
unit.updateCastSpeed(sim)
unit.updateCastSpeed()
}

func (unit *Unit) ApplyCastSpeed(dur time.Duration) time.Duration {
Expand Down Expand Up @@ -536,7 +536,6 @@ func (unit *Unit) finalize() {

unit.defaultTarget = unit.CurrentTarget
unit.applyParryHaste()
unit.updateCastSpeed(nil)
unit.initMovement()

// All stats added up to this point are part of the 'initial' stats.
Expand Down
2 changes: 1 addition & 1 deletion sim/death_knight/summon_gargoyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (dk *DeathKnight) NewGargoyle() *GargoylePet {

gargoyle.OnPetEnable = func(sim *core.Simulation) {
gargoyle.PseudoStats.CastSpeedMultiplier = 1 // guardians are not affected by raid buffs
gargoyle.MultiplyCastSpeed(sim, dk.PseudoStats.MeleeSpeedMultiplier)
gargoyle.MultiplyCastSpeed(dk.PseudoStats.MeleeSpeedMultiplier)

// No longer updates dynamically
// gargoyle.EnableDynamicMeleeSpeed(func(amount float64) {
Expand Down
4 changes: 2 additions & 2 deletions sim/druid/talents.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ func (druid *Druid) applyNaturesGrace() {
ActionID: core.ActionID{SpellID: ngAuraSpellId},
Duration: time.Second * 15,
OnGain: func(aura *core.Aura, sim *core.Simulation) {
druid.MultiplyCastSpeed(sim, 1+ngAuraSpellHastePct)
druid.MultiplyCastSpeed(1 + ngAuraSpellHastePct)
},
OnExpire: func(aura *core.Aura, sim *core.Simulation) {
druid.MultiplyCastSpeed(sim, 1/(1+ngAuraSpellHastePct))
druid.MultiplyCastSpeed(1 / (1 + ngAuraSpellHastePct))
},
})

Expand Down
4 changes: 2 additions & 2 deletions sim/encounters/_ulduar/hodir_ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ func (ai *HodirAI) registerBuffsDebuffs(target *core.Target) {
Duration: time.Second * 30,
OnGain: func(aura *core.Aura, sim *core.Simulation) {
character.MultiplyAttackSpeed(sim, 1.5)
character.MultiplyCastSpeed(sim, 1.5)
character.MultiplyCastSpeed(1.5)
},
OnExpire: func(aura *core.Aura, sim *core.Simulation) {
character.MultiplyAttackSpeed(sim, 1/1.5)
character.MultiplyCastSpeed(sim, 1/1.5)
character.MultiplyCastSpeed(1 / 1.5)
},
})

Expand Down
13 changes: 11 additions & 2 deletions sim/mage/apl_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func (mage *Mage) NewAPLValue(rot *core.APLRotation, config *proto.APLValue) cor

type APLValueMageCurrentCombustionDotEstimate struct {
core.DefaultAPLValueImpl
mage *Mage
mage *Mage
combustionDotEstimate int32
}

func (mage *Mage) newValueCurrentCombustionDotEstimate(_ *proto.APLValueMageCurrentCombustionDotEstimate, _ *proto.UUID) core.APLValue {
Expand All @@ -34,7 +35,15 @@ func (value *APLValueMageCurrentCombustionDotEstimate) Type() proto.APLValueType
}

func (value *APLValueMageCurrentCombustionDotEstimate) GetInt(sim *core.Simulation) int32 {
return value.mage.combustionDotEstimate

if value.mage.combustionDotEstimate != value.combustionDotEstimate {
value.combustionDotEstimate = value.mage.combustionDotEstimate
if sim.Log != nil {
value.mage.Log(sim, "Combustion Dot Estimate: %d", value.combustionDotEstimate)
}
}

return value.combustionDotEstimate
}

func (value *APLValueMageCurrentCombustionDotEstimate) String() string {
Expand Down
28 changes: 8 additions & 20 deletions sim/mage/combustion.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,19 @@ func (mage *Mage) registerCombustionSpell() {
combustionTickDamage = mage.Combustion.RelatedDotSpell.ExpectedTickDamage(sim, mage.CurrentTarget)
}

updateCombustionTotalDamageEstimate := func(sim *core.Simulation) int32 {
updateCombustionTotalDamageEstimate := func() {
combustionDotDamage := int32(float64(combustionTickCount) * combustionTickDamage)

if combustionDotDamage != mage.combustionDotEstimate {
mage.combustionDotEstimate = combustionDotDamage
if sim.Log != nil {
mage.Log(sim, "Combustion Dot Estimate: %d - %d Ticks ", combustionDotDamage, combustionTickCount)
}
}

return combustionDotDamage
mage.combustionDotEstimate = combustionDotDamage
}

mage.AddOnCastSpeedChanged(func(sim *core.Simulation, old float64, new float64) {
if sim != nil {
updateCombustionTickCountEstimate()
updateCombustionTotalDamageEstimate(sim)
}
mage.AddOnCastSpeedChanged(func(old float64, new float64) {
updateCombustionTickCountEstimate()
updateCombustionTotalDamageEstimate()
})

mage.AddOnTemporaryStatsChange(func(sim *core.Simulation, _ *core.Aura, stats stats.Stats) {
if sim != nil {
updateCombustionTickDamageEstimate(sim)
updateCombustionTotalDamageEstimate(sim)
}
updateCombustionTickDamageEstimate(sim)
updateCombustionTotalDamageEstimate()
})

core.MakeProcTriggerAura(&mage.Unit, core.ProcTrigger{
Expand All @@ -157,7 +145,7 @@ func (mage *Mage) registerCombustionSpell() {
Callback: core.CallbackOnCastComplete | core.CallbackOnPeriodicDamageDealt,
Handler: func(sim *core.Simulation, spell *core.Spell, _ *core.SpellResult) {
updateCombustionTickDamageEstimate(sim)
updateCombustionTotalDamageEstimate(sim)
updateCombustionTotalDamageEstimate()
},
})
}
4 changes: 2 additions & 2 deletions sim/mage/talents_fire.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ func (mage *Mage) applyPyromaniac() {
ActionID: core.ActionID{SpellID: 83582},
Duration: core.NeverExpires,
OnGain: func(aura *core.Aura, sim *core.Simulation) {
mage.MultiplyCastSpeed(sim, hasteBonus)
mage.MultiplyCastSpeed(hasteBonus)
},
OnExpire: func(aura *core.Aura, sim *core.Simulation) {
mage.MultiplyCastSpeed(sim, 1/hasteBonus)
mage.MultiplyCastSpeed(1 / hasteBonus)
},
})

Expand Down
4 changes: 2 additions & 2 deletions sim/paladin/seal_of_truth.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func (paladin *Paladin) registerSealOfTruth() {
paladin.JudgementsOfThePureAura.IsActive()

if undoJotpForInitialTick {
paladin.MultiplyCastSpeed(sim, 1/hasteMultiplier)
paladin.MultiplyCastSpeed(1 / hasteMultiplier)
}

dot.Apply(sim)
dot.AddStack(sim)

if undoJotpForInitialTick {
paladin.MultiplyCastSpeed(sim, hasteMultiplier)
paladin.MultiplyCastSpeed(hasteMultiplier)
}
},
})
Expand Down
4 changes: 2 additions & 2 deletions sim/paladin/talents_holy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ func (paladin *Paladin) applyJudgementsOfThePure() {
ActionID: actionId,
Duration: 60 * time.Second,
OnGain: func(aura *core.Aura, sim *core.Simulation) {
paladin.MultiplyCastSpeed(sim, hasteMultiplier)
paladin.MultiplyCastSpeed(hasteMultiplier)
paladin.MultiplyMeleeSpeed(sim, hasteMultiplier)
paladin.PseudoStats.SpiritRegenRateCombat += spiritRegenAmount
},
OnExpire: func(aura *core.Aura, sim *core.Simulation) {
paladin.MultiplyCastSpeed(sim, 1/hasteMultiplier)
paladin.MultiplyCastSpeed(1 / hasteMultiplier)
paladin.MultiplyMeleeSpeed(sim, 1/hasteMultiplier)
paladin.PseudoStats.SpiritRegenRateCombat -= spiritRegenAmount
},
Expand Down
6 changes: 1 addition & 5 deletions sim/paladin/talents_retribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,13 @@ func (paladin *Paladin) applySanctityOfBattle() {
spenderCooldownMod.UpdateTimeValue(-(time.Millisecond * time.Duration(baseSpenderCooldown-baseSpenderCooldown*castSpeed)))
}

paladin.AddOnCastSpeedChanged(func(_ *core.Simulation, _ float64, castSpeed float64) {
paladin.AddOnCastSpeedChanged(func(_ float64, castSpeed float64) {
updateTimeValue(castSpeed)
})

core.MakePermanent(paladin.GetOrRegisterAura(core.Aura{
Label: "Sanctity of Battle",
ActionID: core.ActionID{SpellID: 25956},
OnInit: func(aura *core.Aura, sim *core.Simulation) {

},

OnGain: func(aura *core.Aura, sim *core.Simulation) {
updateTimeValue(paladin.CastSpeed)
spenderCooldownMod.Activate()
Expand Down
4 changes: 2 additions & 2 deletions sim/priest/talents.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,10 +803,10 @@ func (priest *Priest) applyShadowyApparition() {
// ActionID: core.ActionID{SpellID: 52800},
// Duration: time.Second * 6,
// OnGain: func(aura *core.Aura, sim *core.Simulation) {
// priest.MultiplyCastSpeed(sim, multiplier)
// priest.MultiplyCastSpeed(multiplier)
// },
// OnExpire: func(aura *core.Aura, sim *core.Simulation) {
// priest.MultiplyCastSpeed(sim, 1 / multiplier)
// priest.MultiplyCastSpeed(1 / multiplier)
// },
// })

Expand Down
4 changes: 2 additions & 2 deletions sim/shaman/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ var ItemSetSpiritwalkersVestments = core.NewItemSet(core.ItemSet{
ActionID: core.ActionID{SpellID: 105876},
Duration: shaman.spiritwalkersGraceBaseDuration(),
OnGain: func(aura *core.Aura, sim *core.Simulation) {
shaman.MultiplyCastSpeed(sim, hasteMulti)
shaman.MultiplyCastSpeed(hasteMulti)
shaman.MultiplyAttackSpeed(sim, hasteMulti)
},
OnExpire: func(aura *core.Aura, sim *core.Simulation) {
shaman.MultiplyCastSpeed(sim, 1/hasteMulti)
shaman.MultiplyCastSpeed(1 / hasteMulti)
shaman.MultiplyAttackSpeed(sim, 1/hasteMulti)
},
})
Expand Down
4 changes: 2 additions & 2 deletions sim/shaman/talents.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ func (shaman *Shaman) registerElementalMasteryCD() {
ActionID: core.ActionID{SpellID: 64701},
Duration: time.Second * 15,
OnGain: func(aura *core.Aura, sim *core.Simulation) {
shaman.MultiplyCastSpeed(sim, 1.20)
shaman.MultiplyCastSpeed(1.20)
damageMod.Activate()
},
OnExpire: func(aura *core.Aura, sim *core.Simulation) {
shaman.MultiplyCastSpeed(sim, 1/1.20)
shaman.MultiplyCastSpeed(1 / 1.20)
damageMod.Deactivate()
},
})
Expand Down
4 changes: 2 additions & 2 deletions sim/warlock/affliction/affliction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ func checkTicks(t *testing.T, dot *core.Dot, msg string, expected int32) {
func TestCorruptionHasteCap(t *testing.T) {
sim := setupFakeSim(defStats, afflictionTalents, &proto.Glyphs{})
lock := sim.Raid.Parties[0].Players[0].(*AfflictionWarlock)
lock.Unit.MultiplyCastSpeed(sim, 1+0.05) // 5% haste buff
lock.Unit.MultiplyCastSpeed(sim, 1+0.03) // dark intent
lock.Unit.MultiplyCastSpeed(1 + 0.05) // 5% haste buff
lock.Unit.MultiplyCastSpeed(1 + 0.03) // dark intent
lock.AddStatsDynamic(sim, stats.Stats{
stats.HasteRating: 2588,
})
Expand Down
4 changes: 2 additions & 2 deletions sim/warlock/demon_soul.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func (warlock *Warlock) registerDemonSoul() {
ActionID: core.ActionID{SpellID: 79462},
Duration: 20 * time.Second,
OnGain: func(aura *core.Aura, sim *core.Simulation) {
warlock.MultiplyCastSpeed(sim, felguardHasteMulti)
warlock.MultiplyCastSpeed(felguardHasteMulti)
warlock.MultiplyAttackSpeed(sim, felguardHasteMulti)
felguardDamageMod.Activate()
},
OnExpire: func(aura *core.Aura, sim *core.Simulation) {
warlock.MultiplyCastSpeed(sim, 1/felguardHasteMulti)
warlock.MultiplyCastSpeed(1 / felguardHasteMulti)
warlock.MultiplyAttackSpeed(sim, 1/felguardHasteMulti)
felguardDamageMod.Deactivate()
},
Expand Down
12 changes: 6 additions & 6 deletions sim/warlock/demonology/demonology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ func TestFelFlameExtension(t *testing.T) {
func TestShadowflameHasteCap(t *testing.T) {
sim := setupFakeSim(defStats, &proto.Glyphs{}, 10)
lock := sim.Raid.Parties[0].Players[0].(*DemonologyWarlock)
lock.Unit.MultiplyCastSpeed(sim, 1+0.05) // 5% haste buff
lock.Unit.MultiplyCastSpeed(sim, 1+0.03) // dark intent
lock.Unit.MultiplyCastSpeed(1 + 0.05) // 5% haste buff
lock.Unit.MultiplyCastSpeed(1 + 0.03) // dark intent
lock.AddStatsDynamic(sim, stats.Stats{
stats.HasteRating: 1006,
})
Expand All @@ -359,8 +359,8 @@ func TestShadowflameHasteCap(t *testing.T) {
func TestImmolateHasteCap(t *testing.T) {
sim := setupFakeSim(defStats, &proto.Glyphs{}, 10)
lock := sim.Raid.Parties[0].Players[0].(*DemonologyWarlock)
lock.Unit.MultiplyCastSpeed(sim, 1+0.05) // 5% haste buff
lock.Unit.MultiplyCastSpeed(sim, 1+0.03) // dark intent
lock.Unit.MultiplyCastSpeed(1 + 0.05) // 5% haste buff
lock.Unit.MultiplyCastSpeed(1 + 0.03) // dark intent
lock.AddStatsDynamic(sim, stats.Stats{
stats.HasteRating: 1572,
})
Expand All @@ -381,8 +381,8 @@ func TestImmolateHasteCap(t *testing.T) {
func TestCorruptionHasteCap(t *testing.T) {
sim := setupFakeSim(defStats, &proto.Glyphs{}, 10)
lock := sim.Raid.Parties[0].Players[0].(*DemonologyWarlock)
lock.Unit.MultiplyCastSpeed(sim, 1+0.05) // 5% haste buff
lock.Unit.MultiplyCastSpeed(sim, 1+0.03) // dark intent
lock.Unit.MultiplyCastSpeed(1 + 0.05) // 5% haste buff
lock.Unit.MultiplyCastSpeed(1 + 0.03) // dark intent
lock.AddStatsDynamic(sim, stats.Stats{
stats.HasteRating: 1992,
})
Expand Down
4 changes: 2 additions & 2 deletions sim/warlock/destruction/destruction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ func checkTicks(t *testing.T, dot *core.Dot, msg string, expected int32) {
func TestImmolateHasteCap(t *testing.T) {
sim := setupFakeSim(defStats, destroTalents, &immoGlyph)
lock := sim.Raid.Parties[0].Players[0].(*DestructionWarlock)
lock.Unit.MultiplyCastSpeed(sim, 1+0.05) // 5% haste buff
lock.Unit.MultiplyCastSpeed(sim, 1+0.03) // dark intent
lock.Unit.MultiplyCastSpeed(1 + 0.05) // 5% haste buff
lock.Unit.MultiplyCastSpeed(1 + 0.03) // dark intent
lock.AddStatsDynamic(sim, stats.Stats{
stats.HasteRating: 2588,
})
Expand Down
Loading

0 comments on commit f4e8c2a

Please sign in to comment.