-
Notifications
You must be signed in to change notification settings - Fork 130
/
shield.go
89 lines (70 loc) · 2.11 KB
/
shield.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
package core
import "strconv"
type ShieldConfig struct {
SelfOnly bool // Set to true to only create the self-shield.
Spell *Spell
Aura
}
// Rerpresents an absorption effect, e.g. Power Word: Shield.
type Shield struct {
Spell *Spell
// Embed Aura so we can use IsActive/Refresh/etc directly.
*Aura
}
func (shield *Shield) Apply(sim *Simulation, shieldAmount float64) {
caster := shield.Spell.Unit
target := shield.Aura.Unit
//attackTable := caster.AttackTables[target.UnitIndex]
// Shields are not affected by healing pseudostats the same way heals are.
// So we only apply the spell-specific multiplier.
shieldAmount *= shield.Spell.DamageMultiplier
shield.Aura.Deactivate(sim)
shield.Aura.Activate(sim)
threat := 0.0 // TODO
shield.Spell.SpellMetrics[target.UnitIndex].TotalThreat += threat
shield.Spell.SpellMetrics[target.UnitIndex].TotalShielding += shieldAmount
shield.Spell.SpellMetrics[target.UnitIndex].Hits++
if sim.Log != nil {
caster.Log(sim, "%s %s Hit for %0.3f shielding. (Threat: %0.3f)", target.LogLabel(), shield.Spell.ActionID, shieldAmount, threat)
}
}
func newShield(config Shield) *Shield {
shield := &Shield{}
*shield = config
return shield
}
type ShieldArray []*Shield
func (shields ShieldArray) Get(target *Unit) *Shield {
return shields[target.UnitIndex]
}
func (spell *Spell) createShields(config ShieldConfig) {
if config.Aura.Label == "" {
return
}
if config.Spell == nil {
config.Spell = spell
}
shield := Shield{
Spell: config.Spell,
}
auraConfig := config.Aura
if auraConfig.ActionID.IsEmptyAction() {
auraConfig.ActionID = shield.Spell.ActionID
}
caster := shield.Spell.Unit
if config.SelfOnly {
shield.Aura = caster.GetOrRegisterAura(auraConfig)
spell.selfShield = newShield(shield)
} else {
auraConfig.Label += "-" + strconv.Itoa(int(caster.UnitIndex))
if spell.shields == nil {
spell.shields = make([]*Shield, len(caster.Env.AllUnits))
}
for _, target := range caster.Env.AllUnits {
if !caster.IsOpponent(target) {
shield.Aura = target.GetOrRegisterAura(auraConfig)
spell.shields[target.UnitIndex] = newShield(shield)
}
}
}
}