-
Notifications
You must be signed in to change notification settings - Fork 2
/
book.go
104 lines (88 loc) · 1.99 KB
/
book.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
package spell
import (
"github.com/Gophercraft/core/packet"
"github.com/Gophercraft/core/vsn"
)
type Page struct {
Spell uint32
Flag uint16
Slot uint16
}
type Cooldown struct {
Spell uint32
Item uint32
Category uint16
RecoveryTime uint32
CategoryRecoveryTime uint32
}
func (c *Cooldown) Encode(build vsn.Build, out *packet.WorldPacket) error {
switch {
case build < 9767:
out.WriteUint16(uint16(c.Spell))
default:
out.WriteUint32(uint32(c.Spell))
}
switch {
case build < 14545:
out.WriteUint16(uint16(c.Item))
default:
out.WriteUint32(uint32(c.Item))
}
out.WriteUint16(c.Category)
out.WriteUint32(c.RecoveryTime)
out.WriteUint32(c.CategoryRecoveryTime)
return nil
}
type Book struct {
TalentSpec uint8
Spells []Page
Cooldown []Cooldown
}
func (p *Page) Encode(build vsn.Build, out *packet.WorldPacket) error {
if build == vsn.Alpha {
out.WriteUint16(uint16(p.Spell))
out.WriteUint16(uint16(p.Slot))
return nil
}
out.WriteUint32(p.Spell)
if build.AddedIn(vsn.V3_0_2) {
out.WriteUint16(p.Flag)
}
return nil
}
func (p *Page) Decode(build vsn.Build, in *packet.WorldPacket) error {
if build == vsn.Alpha {
p.Spell = uint32(in.ReadUint16())
p.Slot = in.ReadUint16()
return nil
}
p.Spell = in.ReadUint32()
if build.AddedIn(vsn.V3_0_2) {
p.Flag = in.ReadUint16()
}
return nil
}
func (l *Book) Encode(build vsn.Build, out *packet.WorldPacket) error {
out.Type = packet.SMSG_INITIAL_SPELLS
out.WriteByte(l.TalentSpec)
out.WriteUint16(uint16(len(l.Spells)))
for _, spell := range l.Spells {
if err := spell.Encode(build, out); err != nil {
return err
}
}
out.WriteUint16(uint16(len(l.Cooldown)))
for _, cooldown := range l.Cooldown {
if err := cooldown.Encode(build, out); err != nil {
return err
}
}
return nil
}
type Learned struct {
Page
}
func (l *Learned) Encode(build vsn.Build, out *packet.WorldPacket) error {
out.Type = packet.SMSG_LEARNED_SPELL
return l.Page.Encode(build, out)
}