Skip to content

Commit

Permalink
[core] APL now queries Spell.CastTime() instead of ApplyCastSpeedForS…
Browse files Browse the repository at this point in the history
…pell(), so dynamic overrides don't affect the core spell cast anymore

[hunter] use this facility for Steady Shot instead, and also add it to Multi Shot
  • Loading branch information
vigo2 committed Oct 9, 2023
1 parent d11e232 commit 8aadef4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
12 changes: 6 additions & 6 deletions sim/core/apl_values_spell.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (rot *APLRotation) newValueSpellCastTime(config *proto.APLValueSpellCastTim
func (value *APLValueSpellCastTime) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueSpellCastTime) GetDuration(sim *Simulation) time.Duration {
return value.spell.Unit.ApplyCastSpeedForSpell(value.spell.DefaultCast.CastTime, value.spell)
func (value *APLValueSpellCastTime) GetDuration(_ *Simulation) time.Duration {
return value.spell.CastTime()
}
func (value *APLValueSpellCastTime) String() string {
return fmt.Sprintf("Cast Time(%s)", value.spell.ActionID)
Expand All @@ -120,7 +120,7 @@ func (rot *APLRotation) newValueSpellChannelTime(config *proto.APLValueSpellChan
func (value *APLValueSpellChannelTime) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueSpellChannelTime) GetDuration(sim *Simulation) time.Duration {
func (value *APLValueSpellChannelTime) GetDuration(_ *Simulation) time.Duration {
return value.spell.Unit.ApplyCastSpeedForSpell(value.spell.DefaultCast.ChannelTime, value.spell)
}
func (value *APLValueSpellChannelTime) String() string {
Expand All @@ -144,7 +144,7 @@ func (rot *APLRotation) newValueSpellTravelTime(config *proto.APLValueSpellTrave
func (value *APLValueSpellTravelTime) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueSpellTravelTime) GetDuration(sim *Simulation) time.Duration {
func (value *APLValueSpellTravelTime) GetDuration(_ *Simulation) time.Duration {
return value.spell.TravelTime()
}
func (value *APLValueSpellTravelTime) String() string {
Expand Down Expand Up @@ -192,7 +192,7 @@ func (rot *APLRotation) newValueSpellIsChanneling(config *proto.APLValueSpellIsC
func (value *APLValueSpellIsChanneling) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeBool
}
func (value *APLValueSpellIsChanneling) GetBool(sim *Simulation) bool {
func (value *APLValueSpellIsChanneling) GetBool(_ *Simulation) bool {
return value.spell.Unit.ChanneledDot != nil && value.spell.Unit.ChanneledDot.Spell == value.spell
}
func (value *APLValueSpellIsChanneling) String() string {
Expand All @@ -216,7 +216,7 @@ func (rot *APLRotation) newValueSpellChanneledTicks(config *proto.APLValueSpellC
func (value *APLValueSpellChanneledTicks) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeInt
}
func (value *APLValueSpellChanneledTicks) GetInt(sim *Simulation) int32 {
func (value *APLValueSpellChanneledTicks) GetInt(_ *Simulation) int32 {
channeledDot := value.spell.Unit.ChanneledDot
if channeledDot == nil {
return 0
Expand Down
6 changes: 1 addition & 5 deletions sim/core/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type CastConfig struct {
CD Cooldown
SharedCD Cooldown

GetCastTime func(spell *Spell) time.Duration
CastTime func(spell *Spell) time.Duration
}

type Cast struct {
Expand Down Expand Up @@ -110,10 +110,6 @@ func (spell *Spell) makeCastFunc(config CastConfig) CastSuccessFunc {
spell.CurCast.ChannelTime = spell.Unit.ApplyCastSpeedForSpell(spell.CurCast.ChannelTime, spell)
}

if spell.GetCastTime != nil {
spell.CurCast.CastTime = spell.GetCastTime(spell)
}

if config.CD.Timer != nil {
// By panicking if spell is on CD, we force each sim to properly check for their own CDs.
if !spell.CD.IsReady(sim) {
Expand Down
15 changes: 11 additions & 4 deletions sim/core/spell.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type Spell struct {
SharedCD Cooldown
ExtraCastCondition CanCastCondition

castTimeFn func(spell *Spell) time.Duration // allows to override CastTime()

// Performs a cast of this spell.
castFn CastSuccessFunc

Expand Down Expand Up @@ -141,8 +143,6 @@ type Spell struct {

// Per-target auras that are related to this spell, usually buffs or debuffs applied by the spell.
RelatedAuras []AuraArray

GetCastTime func(spell *Spell) time.Duration
}

func (unit *Unit) OnSpellRegistered(handler SpellRegisteredHandler) {
Expand Down Expand Up @@ -185,6 +185,12 @@ func (unit *Unit) RegisterSpell(config SpellConfig) *Spell {
panic("Cast.SharedCD w/o Duration specified for spell " + config.ActionID.String())
}

if config.Cast.CastTime == nil {
config.Cast.CastTime = func(spell *Spell) time.Duration {
return spell.Unit.ApplyCastSpeedForSpell(spell.DefaultCast.CastTime, spell)
}
}

spell := &Spell{
ActionID: config.ActionID,
Unit: unit,
Expand All @@ -198,6 +204,8 @@ func (unit *Unit) RegisterSpell(config SpellConfig) *Spell {
SharedCD: config.Cast.SharedCD,
ExtraCastCondition: config.ExtraCastCondition,

castTimeFn: config.Cast.CastTime,

ApplyEffects: config.ApplyEffects,

expectedInitialDamageInternal: config.ExpectedInitialDamage,
Expand All @@ -220,7 +228,6 @@ func (unit *Unit) RegisterSpell(config SpellConfig) *Spell {
splitSpellMetrics: make([][]SpellMetrics, max(1, config.MetricSplits)),

RelatedAuras: config.RelatedAuras,
GetCastTime: config.Cast.GetCastTime,
}

switch {
Expand Down Expand Up @@ -573,7 +580,7 @@ func (spell *Spell) EffectiveCastTime() time.Duration {

// Time until the cast is finished (ignoring GCD)
func (spell *Spell) CastTime() time.Duration {
return spell.Unit.ApplyCastSpeedForSpell(spell.DefaultCast.CastTime, spell)
return spell.castTimeFn(spell)
}

func (spell *Spell) TravelTime() time.Duration {
Expand Down
3 changes: 0 additions & 3 deletions sim/core/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,6 @@ func (unit *Unit) ApplyCastSpeed(dur time.Duration) time.Duration {
return time.Duration(float64(dur) * unit.CastSpeed)
}
func (unit *Unit) ApplyCastSpeedForSpell(dur time.Duration, spell *Spell) time.Duration {
if spell.GetCastTime != nil {
return spell.GetCastTime(spell)
}
return time.Duration(float64(dur) * unit.CastSpeed * spell.CastTimeMultiplier)
}

Expand Down
13 changes: 6 additions & 7 deletions sim/hunter/multi_shot.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ func (hunter *Hunter) registerMultiShotSpell(timer *core.Timer) {
Cast: core.CastConfig{
DefaultCast: core.Cast{
GCD: core.GCDDefault,
CastTime: 1, // Dummy value so core doesn't optimize the cast away
CastTime: time.Millisecond * 500,
},
ModifyCast: func(_ *core.Simulation, _ *core.Spell, cast *core.Cast) {
cast.CastTime = hunter.MultiShotCastTime()
ModifyCast: func(_ *core.Simulation, spell *core.Spell, cast *core.Cast) {
cast.CastTime = spell.CastTime()
},
IgnoreHaste: true, // Hunter GCD is locked at 1.5s
CD: core.Cooldown{
Timer: timer,
Duration: time.Second*10 - core.TernaryDuration(hunter.HasMajorGlyph(proto.HunterMajorGlyph_GlyphOfMultiShot), time.Second*1, 0),
},
CastTime: func(spell *core.Spell) time.Duration {
return time.Duration(float64(spell.DefaultCast.CastTime) / hunter.RangedSwingSpeed())
},
},

BonusCritRating: 0 +
Expand Down Expand Up @@ -60,7 +63,3 @@ func (hunter *Hunter) registerMultiShotSpell(timer *core.Timer) {
},
})
}

func (hunter *Hunter) MultiShotCastTime() time.Duration {
return time.Duration(float64(time.Millisecond*500) / hunter.RangedSwingSpeed())
}
8 changes: 6 additions & 2 deletions sim/hunter/steady_shot.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ func (hunter *Hunter) registerSteadyShotSpell() {
Cast: core.CastConfig{
DefaultCast: core.Cast{
GCD: core.GCDDefault,
CastTime: time.Millisecond * 2000,
CastTime: time.Second * 2,
},
IgnoreHaste: true, // Hunter GCD is locked at 1.5s
GetCastTime: func(spell *core.Spell) time.Duration {
ModifyCast: func(_ *core.Simulation, spell *core.Spell, cast *core.Cast) {
cast.CastTime = spell.CastTime()
},

CastTime: func(spell *core.Spell) time.Duration {
return time.Duration(float64(spell.DefaultCast.CastTime) / hunter.RangedSwingSpeed())
},
},
Expand Down

0 comments on commit 8aadef4

Please sign in to comment.