Skip to content

Commit

Permalink
Adjust item swap PPM handling
Browse files Browse the repository at this point in the history
  • Loading branch information
1337LutZ committed Dec 21, 2024
1 parent 1b36516 commit 2158a2b
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 231 deletions.
4 changes: 3 additions & 1 deletion sim/common/cata/damage_procs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func init() {
MaxDmg: 8750,
Flags: core.SpellFlagNoSpellMods | core.SpellFlagIgnoreModifiers | core.SpellFlagNoOnDamageDealt,
Outcome: shared.OutcomeMeleeNoBlockDodgeParryCrit,
Slots: []proto.ItemSlot{proto.ItemSlot_ItemSlotTrinket1, proto.ItemSlot_ItemSlotTrinket2},
Trigger: core.ProcTrigger{
Name: "Darkmoon Card: Hurricane",
ProcMask: core.ProcMaskMeleeOrRanged,
Expand All @@ -32,8 +33,9 @@ func init() {
School: core.SpellSchoolNature,
MinDmg: 5250,
MaxDmg: 8750,
Outcome: shared.OutcomeMeleeNoBlockDodgeParryCrit,
Flags: core.SpellFlagNoSpellMods | core.SpellFlagIgnoreModifiers | core.SpellFlagNoOnDamageDealt,
Outcome: shared.OutcomeMeleeNoBlockDodgeParryCrit,
Slots: []proto.ItemSlot{proto.ItemSlot_ItemSlotTrinket1, proto.ItemSlot_ItemSlotTrinket2},
Trigger: core.ProcTrigger{
Name: "Darkmoon Card: Hurricane",
ProcMask: core.ProcMaskMeleeOrRanged,
Expand Down
8 changes: 4 additions & 4 deletions sim/common/cata/enchant_effects.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func init() {
},
}))

character.ItemSwap.RegisterPPMEffect(4067, ppm, &ppmm, aura)
character.ItemSwap.RegisterPPMEffect(4067, ppm, &ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

// Enchant: 4074, Spell: 74211 - Enchant Weapon - Elemental Slayer
Expand Down Expand Up @@ -153,7 +153,7 @@ func init() {
},
})

character.ItemSwap.RegisterPPMEffect(4074, ppm, aura.Ppmm, aura)
character.ItemSwap.RegisterPPMEffect(4074, ppm, aura.Ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

// Enchant: 4083, Spell: 74223 - Enchant Weapon - Hurricane
Expand Down Expand Up @@ -238,7 +238,7 @@ func init() {
},
}))

character.ItemSwap.RegisterPPMEffect(4083, ppm, &ppmm, aura)
character.ItemSwap.RegisterPPMEffect(4083, ppm, &ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

// Enchant: 4084, Spell: 74225 - Enchant Weapon - Heartsong
Expand Down Expand Up @@ -328,7 +328,7 @@ func init() {
},
})

character.ItemSwap.RegisterPPMEffect(4099, ppm, aura.Ppmm, aura)
character.ItemSwap.RegisterPPMEffect(4099, ppm, aura.Ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

// Enchant: 4115, Spell: 75172 - Lightweave Embroidery
Expand Down
11 changes: 9 additions & 2 deletions sim/common/shared/shared_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func factory_EnchantStatBonusEffect(config EnchantProcStatBonusEffect, extraSpel
}

if config.PPM != 0 {
character.ItemSwap.RegisterPPMEffect(config.EnchantID, config.PPM, triggerAura.Ppmm, triggerAura)
character.ItemSwap.RegisterPPMEffect(config.EnchantID, config.PPM, triggerAura.Ppmm, triggerAura, config.Slots)
} else {
character.ItemSwap.RegisterEnchantProc(config.EnchantID, triggerAura, config.Slots)
}
Expand Down Expand Up @@ -535,6 +535,7 @@ const (
type ProcDamageEffect struct {
ItemID int32
SpellID int32
Slots []proto.ItemSlot
Trigger core.ProcTrigger

School core.SpellSchool
Expand Down Expand Up @@ -596,7 +597,13 @@ func NewProcDamageEffect(config ProcDamageEffect) {
triggerConfig.Handler = func(sim *core.Simulation, _ *core.Spell, _ *core.SpellResult) {
damageSpell.Cast(sim, character.CurrentTarget)
}
core.MakeProcTriggerAura(&character.Unit, triggerConfig)
triggerAura := core.MakeProcTriggerAura(&character.Unit, triggerConfig)

if config.Trigger.PPM != 0 {
character.ItemSwap.RegisterPPMItem(config.ItemID, config.Trigger.PPM, triggerAura.Ppmm, triggerAura, config.Slots)
} else {
character.ItemSwap.RegisterEnchantProc(config.ItemID, triggerAura, config.Slots)
}
})
}

Expand Down
11 changes: 6 additions & 5 deletions sim/common/tbc/enchant_effects.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func init() {
},
})

character.ItemSwap.RegisterPPMEffect(1900, 1.0, &ppmm, aura)
character.ItemSwap.RegisterPPMEffect(1900, 1.0, &ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

core.NewEnchantEffect(2929, func(agent core.Agent) {
Expand Down Expand Up @@ -130,7 +130,7 @@ func init() {
},
})

character.ItemSwap.RegisterPPMEffect(2673, 0.73, &ppmm, aura)
character.ItemSwap.RegisterPPMEffect(2673, 0.73, &ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

core.AddWeaponEffect(2723, func(agent core.Agent, _ proto.ItemSlot) {
Expand Down Expand Up @@ -173,7 +173,7 @@ func init() {
},
})

character.ItemSwap.RegisterPPMEffect(3225, 1.0, &ppmm, aura)
character.ItemSwap.RegisterPPMEffect(3225, 1.0, &ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

// https://web.archive.org/web/20100702102132/http://elitistjerks.com/f15/t27347-deathfrost_its_mechanics/p2/#post789470
Expand All @@ -189,7 +189,8 @@ func init() {
} else {
label += "OH"
}
ppmm := character.AutoAttacks.NewPPMManager(2.15, core.ProcMaskMelee)
procMask := core.ProcMaskMelee
ppmm := character.AutoAttacks.NewPPMManager(2.15, procMask)

aura := character.GetOrRegisterAura(core.Aura{
Label: label,
Expand All @@ -215,7 +216,7 @@ func init() {
},
})

character.ItemSwap.RegisterPPMEffect(3273, 2.15, &ppmm, aura)
character.ItemSwap.RegisterPPMEffect(3273, 2.15, &ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
}
core.NewEnchantEffect(3273, func(agent core.Agent) {
character := agent.GetCharacter()
Expand Down
8 changes: 4 additions & 4 deletions sim/common/wotlk/enchant_effects.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func init() {
},
})

character.ItemSwap.RegisterPPMEffect(3251, 4.0, &ppmm, aura)
character.ItemSwap.RegisterPPMEffect(3251, 4.0, &ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

// Enchant: 3239, Spell: 44525 - Icebreaker
Expand Down Expand Up @@ -95,7 +95,7 @@ func init() {
},
})

character.ItemSwap.RegisterPPMEffect(3239, 4.0, &ppmm, aura)
character.ItemSwap.RegisterPPMEffect(3239, 4.0, &ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

// Enchant: 3607, Spell: 55076, Item: 41146 - Sun Scope
Expand Down Expand Up @@ -184,7 +184,7 @@ func init() {
},
})

character.ItemSwap.RegisterPPMEffect(3789, 1.0, &ppmm, aura)
character.ItemSwap.RegisterPPMEffect(3789, 1.0, &ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

// TODO: These are stand-in values without any real reference.
Expand Down Expand Up @@ -213,7 +213,7 @@ func init() {
},
})

character.ItemSwap.RegisterPPMEffect(3241, 3.0, &ppmm, aura)
character.ItemSwap.RegisterPPMEffect(3241, 3.0, &ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

// Enchant: 3790, Spell: 59630 - Black Magic
Expand Down
74 changes: 58 additions & 16 deletions sim/core/item_swaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,61 @@ func (character *Character) RegisterItemSwapCallback(slots []proto.ItemSlot, cal
}

// Helper for handling Effects that use PPMManager to toggle the aura on/off
func (swap *ItemSwap) RegisterPPMEffect(effectID int32, ppm float64, ppmm *PPMManager, aura *Aura) {
func (swap *ItemSwap) RegisterPPMEffect(effectID int32, ppm float64, ppmm *PPMManager, aura *Aura, slots []proto.ItemSlot) {
swap.registerPPMInternal(0, effectID, ppm, ppmm, aura, slots)
}

// Helper for handling Effects that use PPMManager to toggle the aura on/off
func (swap *ItemSwap) RegisterPPMItem(itemID int32, ppm float64, ppmm *PPMManager, aura *Aura, slots []proto.ItemSlot) {
swap.registerPPMInternal(itemID, 0, ppm, ppmm, aura, slots)
}

func (swap *ItemSwap) registerPPMInternal(itemID int32, effectID int32, ppm float64, ppmm *PPMManager, aura *Aura, slots []proto.ItemSlot) {
character := swap.character
if character == nil || !character.ItemSwap.IsEnabled() {
return
}
character.RegisterItemSwapCallback([]proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand}, func(sim *Simulation, slot proto.ItemSlot) {
procMask := character.GetProcMaskForEnchant(effectID)
*ppmm = character.AutoAttacks.NewPPMManager(ppm, procMask)
character.RegisterItemSwapCallback(slots, func(sim *Simulation, slot proto.ItemSlot) {
item := swap.GetEquippedItemBySlot(slot)

var hasItemEquipped bool
var procMask ProcMask
var isItemSlotMatch = false

isItemPPM := itemID != 0
isEffectPPM := effectID != 0

if isItemPPM {
hasItemEquipped = item.ID == itemID
isItemSlotMatch = swap.GetItemFromPossibleSlotsByItemID(itemID, slots) == slot
procMask = character.GetProcMaskForItem(itemID)
} else if isEffectPPM {
hasItemEquipped = item.Enchant.EffectID == effectID || item.TempEnchant == effectID
isItemSlotMatch = swap.GetItemFromPossibleSlotsByEffectID(effectID, slots) == slot
procMask = character.GetProcMaskForEnchant(effectID)
}
if !isItemSlotMatch {
return
}

if ppmm.Chance(procMask) == 0 {
aura.Deactivate(sim)
} else {
if hasItemEquipped {
aura.Activate(sim)
} else {
aura.Deactivate(sim)
}

*ppmm = character.AutoAttacks.NewPPMManager(ppm, procMask)
})

}

// Helper for handling procs that use PPMManager to toggle the aura on/off
func (swap *ItemSwap) RegisterPPMEffectWithCustomProcMask(procMask ProcMask, ppm float64, ppmm *PPMManager) {
func (swap *ItemSwap) RegisterPPMEffectWithCustomProcMask(procMask ProcMask, ppm float64, ppmm *PPMManager, slots []proto.ItemSlot) {
character := swap.character
if character == nil || !character.ItemSwap.IsEnabled() {
return
}
character.RegisterItemSwapCallback([]proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand}, func(sim *Simulation, slot proto.ItemSlot) {
character.RegisterItemSwapCallback(slots, func(sim *Simulation, slot proto.ItemSlot) {
*ppmm = character.AutoAttacks.NewPPMManager(ppm, procMask)
})
}
Expand Down Expand Up @@ -147,12 +178,12 @@ func (swap *ItemSwap) RegisterEnchantProc(effectID int32, aura *Aura, slots []pr
return
}
character.RegisterItemSwapCallback(slots, func(sim *Simulation, slot proto.ItemSlot) {
procMask := character.GetProcMaskForEnchant(effectID)

if procMask == ProcMaskUnknown {
aura.Deactivate(sim)
} else {
item := swap.GetEquippedItemBySlot(slot)
hasEffectID := item.Enchant.EffectID == effectID
if hasEffectID {
aura.Activate(sim)
} else {
aura.Deactivate(sim)
}
})
}
Expand All @@ -169,7 +200,7 @@ func (swap *ItemSwap) RegisterActive(itemID int32, slots []proto.ItemSlot) {
return
}
hasItemEquipped := swap.HasItemEquipped(itemID)
itemSlot := swap.GetItemFromPossibleSlots(itemID, slots)
itemSlot := swap.GetItemFromPossibleSlotsByItemID(itemID, slots)
if itemSlot == -1 {
return
}
Expand Down Expand Up @@ -232,7 +263,7 @@ func (swap *ItemSwap) GetUnequippedItemBySlot(slot proto.ItemSlot) *Item {
return &swap.unEquippedItems[slot]
}

func (swap *ItemSwap) GetItemFromPossibleSlots(itemID int32, possibleSlots []proto.ItemSlot) proto.ItemSlot {
func (swap *ItemSwap) GetItemFromPossibleSlotsByItemID(itemID int32, possibleSlots []proto.ItemSlot) proto.ItemSlot {
for _, slot := range possibleSlots {
if swap.swapEquip[slot].ID == itemID {
return slot
Expand All @@ -243,6 +274,17 @@ func (swap *ItemSwap) GetItemFromPossibleSlots(itemID int32, possibleSlots []pro
return -1
}

func (swap *ItemSwap) GetItemFromPossibleSlotsByEffectID(effectID int32, possibleSlots []proto.ItemSlot) proto.ItemSlot {
for _, slot := range possibleSlots {
if swap.swapEquip[slot].Enchant.EffectID == effectID {
return slot
} else if swap.originalEquip[slot].Enchant.EffectID == effectID {
return slot
}
}
return -1
}

func (swap *ItemSwap) ItemExistsInSwapSet(itemID int32) bool {
for _, item := range swap.swapEquip {
if item.ID == itemID {
Expand Down
8 changes: 5 additions & 3 deletions sim/death_knight/runeforging.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func init() {
},
})

character.ItemSwap.RegisterPPMEffect(3368, 2.0, aura.Ppmm, aura)
character.ItemSwap.RegisterPPMEffect(3368, 2.0, aura.Ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

// Rune of Cinderglacier
Expand All @@ -120,6 +120,8 @@ func init() {
School: core.SpellSchoolShadow | core.SpellSchoolFrost,
})

procMask := character.GetProcMaskForEnchant(3369)

cinderAura := character.GetOrRegisterAura(core.Aura{
ActionID: core.ActionID{SpellID: 53386},
Label: "Cinderglacier",
Expand Down Expand Up @@ -154,15 +156,15 @@ func init() {
Name: "Rune of Cinderglacier",
Callback: core.CallbackOnSpellHitDealt,
Outcome: core.OutcomeLanded,
ProcMask: character.GetProcMaskForEnchant(3369),
ProcMask: procMask,
PPM: 1.0,
Handler: func(sim *core.Simulation, spell *core.Spell, result *core.SpellResult) {
cinderAura.Activate(sim)
cinderAura.SetStacks(sim, cinderAura.MaxStacks)
},
})

character.ItemSwap.RegisterPPMEffect(3369, 1.0, aura.Ppmm, aura)
character.ItemSwap.RegisterPPMEffect(3369, 1.0, aura.Ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
})

// Rune of Razorice
Expand Down
2 changes: 1 addition & 1 deletion sim/death_knight/talents_frost.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (dk *DeathKnight) applyKillingMachine() {
},
})

dk.ItemSwap.RegisterPPMEffectWithCustomProcMask(core.ProcMaskMeleeMH, ppm, triggerAura.Ppmm)
dk.ItemSwap.RegisterPPMEffectWithCustomProcMask(core.ProcMaskMeleeMH, ppm, triggerAura.Ppmm, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
}

func (dk *DeathKnight) applyMightOfTheFrozenWastes() {
Expand Down
3 changes: 2 additions & 1 deletion sim/death_knight/talents_unholy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

"github.com/wowsims/cata/sim/core"
"github.com/wowsims/cata/sim/core/proto"
"github.com/wowsims/cata/sim/core/stats"
)

Expand Down Expand Up @@ -325,7 +326,7 @@ func (dk *DeathKnight) applySuddenDoom() {
},
})

dk.ItemSwap.RegisterPPMEffectWithCustomProcMask(core.ProcMaskMeleeMH, ppm, triggerAura.Ppmm)
dk.ItemSwap.RegisterPPMEffectWithCustomProcMask(core.ProcMaskMeleeMH, ppm, triggerAura.Ppmm, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
}

func (dk *DeathKnight) applyShadowInfusion() *core.Aura {
Expand Down
2 changes: 1 addition & 1 deletion sim/shaman/weapon_imbues.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (shaman *Shaman) RegisterFrostbrandImbue(procMask core.ProcMask) {
},
})

shaman.ItemSwap.RegisterPPMEffect(2, 9.0, &ppmm, aura)
shaman.ItemSwap.RegisterPPMEffect(2, 9.0, &ppmm, aura, []proto.ItemSlot{proto.ItemSlot_ItemSlotMainHand, proto.ItemSlot_ItemSlotOffHand})
}

func (shaman *Shaman) newEarthlivingImbueSpell() *core.Spell {
Expand Down
Loading

0 comments on commit 2158a2b

Please sign in to comment.