Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ItemSwap fixes #4106

Merged
merged 2 commits into from
Dec 23, 2023
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
6 changes: 3 additions & 3 deletions sim/core/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ func (unit *Unit) OnAutoAttack(_ *Simulation, _ *Spell) {}
func (aa *AutoAttacks) finalize() {
if aa.AutoSwingMelee {
aa.mh.spell = aa.mh.unit.GetOrRegisterSpell(aa.mh.config)
if aa.IsDualWielding {
aa.oh.spell = aa.oh.unit.GetOrRegisterSpell(aa.oh.config)
}

// Will keep keep the OH spell registered for Item swapping
aa.oh.spell = aa.oh.unit.GetOrRegisterSpell(aa.oh.config)
}
if aa.AutoSwingRanged {
aa.ranged.spell = aa.ranged.unit.GetOrRegisterSpell(aa.ranged.config)
Expand Down
1 change: 1 addition & 0 deletions sim/core/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ func (character *Character) AddPartyBuffs(partyBuffs *proto.PartyBuffs) {

func (character *Character) initialize(agent Agent) {
character.majorCooldownManager.initialize(character)
character.ItemSwap.initialize(character)

character.gcdAction = &PendingAction{
Priority: ActionPriorityGCD,
Expand Down
14 changes: 10 additions & 4 deletions sim/core/item_swaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (character *Character) enableItemSwap(itemSwap *proto.ItemSwap, mhCritMulti
}

character.ItemSwap = ItemSwap{
character: character,
mhCritMultiplier: mhCritMultiplier,
ohCritMultiplier: ohCritMultiplier,
rangedCritMultiplier: rangedCritMultiplier,
Expand All @@ -83,6 +82,10 @@ func (character *Character) enableItemSwap(itemSwap *proto.ItemSwap, mhCritMulti
}
}

func (swap *ItemSwap) initialize(character *Character) {
swap.character = character
}

func (character *Character) RegisterOnItemSwap(callback OnSwapItem) {
if character == nil || !character.ItemSwap.IsEnabled() {
return
Expand Down Expand Up @@ -136,7 +139,7 @@ func (swap *ItemSwap) RegisterOnSwapItemForEnchantEffect(effectID int32, aura *A
}

func (swap *ItemSwap) IsEnabled() bool {
return swap.character != nil
return swap.character != nil && len(swap.slots) > 0
}

func (swap *ItemSwap) IsSwapped() bool {
Expand Down Expand Up @@ -172,6 +175,7 @@ func (swap *ItemSwap) SwapItems(sim *Simulation, slots []proto.ItemSlot, useGCD
newStats := stats.Stats{}
has2H := swap.GetItem(proto.ItemSlot_ItemSlotMainHand).HandType == proto.HandType_HandTypeTwoHand
for _, slot := range slots {

//will swap both on the MainHand Slot for 2H.
if slot == proto.ItemSlot_ItemSlotOffHand && has2H {
continue
Expand Down Expand Up @@ -252,8 +256,10 @@ func (swap *ItemSwap) swapWeapon(slot proto.ItemSlot) {
}
case proto.ItemSlot_ItemSlotOffHand:
if character.AutoAttacks.AutoSwingMelee {
character.AutoAttacks.SetOH(character.WeaponFromOffHand(swap.ohCritMultiplier))
//Special case for when the OHAuto Spell was set up with a non weapon and does not have a crit multiplier.
weapon := character.WeaponFromOffHand(swap.ohCritMultiplier)
character.AutoAttacks.SetOH(weapon)

character.AutoAttacks.IsDualWielding = weapon.SwingSpeed != 0
character.PseudoStats.CanBlock = character.OffHand().WeaponType == proto.WeaponType_WeaponTypeShield
}
case proto.ItemSlot_ItemSlotRanged:
Expand Down
8 changes: 4 additions & 4 deletions sim/core/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ func (unit *Unit) AddDynamicDamageTakenModifier(ddtm DynamicDamageTakenModifier)
}

func (unit *Unit) AddStatsDynamic(sim *Simulation, bonus stats.Stats) {
if unit.Env == nil || !unit.Env.IsFinalized() {
if !unit.Env.MeasuringStats {
panic("Not finalized, use AddStats instead!")
}
if unit.Env == nil {
panic("Environment not constructed.")
} else if !unit.Env.IsFinalized() && !unit.Env.MeasuringStats {
panic("Not finalized, use AddStats instead!")
}

unit.statsWithoutDeps.AddInplace(&bonus)
Expand Down
Loading
Loading