Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions sim/core/spell_mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"fmt"
"math"
"slices"
"strconv"
"time"
Expand All @@ -25,6 +26,7 @@ type SpellModConfig struct {
KeyValue string
ApplyCustom SpellModApply
RemoveCustom SpellModRemove
ResetCustom SpellModOnReset
}

type SpellMod struct {
Expand All @@ -41,13 +43,17 @@ type SpellMod struct {
Remove SpellModRemove
IsActive bool
AffectedSpells []*Spell
OnReset SpellModOnReset
}

type SpellModApply func(mod *SpellMod, spell *Spell)
type SpellModRemove func(mod *SpellMod, spell *Spell)
type SpellModOnReset func(mod *SpellMod)

type SpellModFunctions struct {
Apply SpellModApply
Remove SpellModRemove
Apply SpellModApply
Remove SpellModRemove
OnReset SpellModOnReset
}

func buildMod(unit *Unit, config SpellModConfig) *SpellMod {
Expand All @@ -58,6 +64,7 @@ func buildMod(unit *Unit, config SpellModConfig) *SpellMod {

var applyFn SpellModApply
var removeFn SpellModRemove
var resetFn SpellModOnReset

if config.Kind == SpellMod_Custom {
if (config.ApplyCustom == nil) || (config.RemoveCustom == nil) {
Expand All @@ -66,9 +73,12 @@ func buildMod(unit *Unit, config SpellModConfig) *SpellMod {

applyFn = config.ApplyCustom
removeFn = config.RemoveCustom
resetFn = config.ResetCustom

} else {
applyFn = functions.Apply
removeFn = functions.Remove
resetFn = functions.OnReset
}

if (config.ResourceType > 0) && !slices.Contains([]proto.ResourceType{proto.ResourceType_ResourceTypeMana, proto.ResourceType_ResourceTypeEnergy, proto.ResourceType_ResourceTypeRage, proto.ResourceType_ResourceTypeFocus}, config.ResourceType) {
Expand All @@ -88,6 +98,7 @@ func buildMod(unit *Unit, config SpellModConfig) *SpellMod {
Apply: applyFn,
Remove: removeFn,
IsActive: false,
OnReset: resetFn,
}

unit.OnSpellRegistered(func(spell *Spell) {
Expand All @@ -100,6 +111,12 @@ func buildMod(unit *Unit, config SpellModConfig) *SpellMod {
}
})

if mod.OnReset != nil {
unit.RegisterResetEffect(func(s *Simulation) {
mod.OnReset(mod)
})
}

return mod
}

Expand Down Expand Up @@ -313,8 +330,9 @@ var spellModMap = map[SpellModType]*SpellModFunctions{
},

SpellMod_DamageDone_Flat: {
Apply: applyDamageDoneAdd,
Remove: removeDamageDoneAdd,
Apply: applyDamageDoneAdd,
Remove: removeDamageDoneAdd,
OnReset: onResetDamageDoneAdd,
},

SpellMod_PowerCost_Pct: {
Expand Down Expand Up @@ -432,6 +450,14 @@ func removeDamageDoneAdd(mod *SpellMod, spell *Spell) {
spell.DamageMultiplierAdditive -= mod.floatValue
}

// Required to round floating point errors that might leak between iterations
// Edge case if many addtions / substractions with different float numbers are done in random order
func onResetDamageDoneAdd(mod *SpellMod) {
for _, spell := range mod.AffectedSpells {
spell.DamageMultiplierAdditive = math.Round(spell.DamageMultiplierAdditive*10000) / 10000
}
}

func applyPowerCostPercent(mod *SpellMod, spell *Spell) {
if spell.Cost != nil {
spell.Cost.PercentModifier += mod.intValue
Expand Down
2 changes: 1 addition & 1 deletion sim/priest/shadow/_shadow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestShadow(t *testing.T) {

SpecOptions: core.SpecOptionsCombo{Label: "Basic", SpecOptions: PlayerOptionsBasic},

Rotation: core.GetAplRotation("../../../ui/priest/shadow/apls", "default"),
Rotation: core.GetAplRotation("../../../ui/priest/shadow/apls", "p4"),
OtherRotations: []core.RotationCombo{
core.GetAplRotation("../../../ui/priest/shadow/apls", "default"),
},
Expand Down
Loading