-
Notifications
You must be signed in to change notification settings - Fork 32
/
weaponprocs.go
112 lines (95 loc) · 4 KB
/
weaponprocs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package itemhelpers
import (
"fmt"
"github.com/wowsims/sod/sim/core"
)
// Create a simple weapon proc that deals damage.
func CreateWeaponProcDamage(itemId int32, itemName string, ppm float64, spellId int32, school core.SpellSchool,
dmgMin float64, dmgRange float64, bonusCoef float64, defType core.DefenseType) {
core.NewItemEffect(itemId, func(agent core.Agent) {
character := agent.GetCharacter()
sc := core.SpellConfig{
ActionID: core.ActionID{SpellID: spellId},
SpellSchool: school,
DefenseType: defType,
ProcMask: core.ProcMaskEmpty,
DamageMultiplier: 1,
ThreatMultiplier: 1,
BonusCoefficient: bonusCoef,
}
switch defType {
case core.DefenseTypeNone:
sc.ApplyEffects = func(sim *core.Simulation, target *core.Unit, spell *core.Spell) {
dmg := dmgMin + core.TernaryFloat64(dmgRange > 0, sim.RandomFloat(itemName)*dmgRange, 0)
spell.CalcAndDealDamage(sim, target, dmg, spell.OutcomeAlwaysHit)
}
case core.DefenseTypeMagic:
sc.ApplyEffects = func(sim *core.Simulation, target *core.Unit, spell *core.Spell) {
dmg := dmgMin + core.TernaryFloat64(dmgRange > 0, sim.RandomFloat(itemName)*dmgRange, 0)
spell.CalcAndDealDamage(sim, target, dmg, spell.OutcomeMagicHitAndCrit)
}
case core.DefenseTypeMelee:
sc.ApplyEffects = func(sim *core.Simulation, target *core.Unit, spell *core.Spell) {
dmg := dmgMin + core.TernaryFloat64(dmgRange > 0, sim.RandomFloat(itemName)*dmgRange, 0)
spell.CalcAndDealDamage(sim, target, dmg, spell.OutcomeMeleeSpecialHitAndCrit)
}
case core.DefenseTypeRanged:
sc.ApplyEffects = func(sim *core.Simulation, target *core.Unit, spell *core.Spell) {
dmg := dmgMin + core.TernaryFloat64(dmgRange > 0, sim.RandomFloat(itemName)*dmgRange, 0)
spell.CalcAndDealDamage(sim, target, dmg, spell.OutcomeRangedHitAndCrit)
}
}
procSpell := character.RegisterSpell(sc)
procMask := character.GetProcMaskForItem(itemId)
ppmm := character.AutoAttacks.NewPPMManager(ppm, procMask)
character.GetOrRegisterAura(core.Aura{
Label: fmt.Sprintf("%s Proc Aura", itemName),
Duration: core.NeverExpires,
OnReset: func(aura *core.Aura, sim *core.Simulation) {
aura.Activate(sim)
},
OnSpellHitDealt: func(aura *core.Aura, sim *core.Simulation, spell *core.Spell, result *core.SpellResult) {
if result.Landed() && ppmm.Proc(sim, spell.ProcMask, aura.Label) {
procSpell.Cast(sim, result.Target)
}
},
})
})
}
// Create a weapon proc using a custom spell.
func CreateWeaponProcSpell(itemId int32, itemName string, ppm float64, procSpellGenerator func(character *core.Character) *core.Spell) {
core.NewItemEffect(itemId, func(agent core.Agent) {
character := agent.GetCharacter()
procSpell := procSpellGenerator(character)
procMask := character.GetProcMaskForItem(itemId)
ppmm := character.AutoAttacks.NewPPMManager(ppm, procMask)
procLabel := itemName + " Proc"
core.MakePermanent(character.GetOrRegisterAura(core.Aura{
Label: itemName + " Proc Aura",
OnSpellHitDealt: func(aura *core.Aura, sim *core.Simulation, spell *core.Spell, result *core.SpellResult) {
if result.Landed() && ppmm.Proc(sim, spell.ProcMask, procLabel) {
procSpell.Cast(sim, result.Target)
}
},
}))
})
}
// Create a weapon proc for a custom aura.
func CreateWeaponProcAura(itemId int32, itemName string, ppm float64, procAuraGenerator func(character *core.Character) *core.Aura) {
core.NewItemEffect(itemId, func(agent core.Agent) {
character := agent.GetCharacter()
procAura := procAuraGenerator(character)
procMask := character.GetProcMaskForItem(itemId)
ppmm := character.AutoAttacks.NewPPMManager(ppm, procMask)
procLabel := itemName + " Proc"
core.MakePermanent(character.GetOrRegisterAura(core.Aura{
Label: itemName + " Proc Aura",
Duration: core.NeverExpires,
OnSpellHitDealt: func(aura *core.Aura, sim *core.Simulation, spell *core.Spell, result *core.SpellResult) {
if result.Landed() && ppmm.Proc(sim, spell.ProcMask, procLabel) {
procAura.Activate(sim)
}
},
}))
})
}