Skip to content

Commit

Permalink
Merge pull request #4106 from Horatio27/itemswap_fixes
Browse files Browse the repository at this point in the history
ItemSwap fixes, added some additional support for ItemSwapping to enh spells, Stormstrike/Lavallash just to reduce the amount of error's that can happen.
  • Loading branch information
Horatio27 authored Dec 23, 2023
2 parents f8200b5 + 36e2c57 commit 339ba20
Show file tree
Hide file tree
Showing 9 changed files with 457 additions and 439 deletions.
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

0 comments on commit 339ba20

Please sign in to comment.