/
action_buttons.go
50 lines (40 loc) · 1.05 KB
/
action_buttons.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
package realm
import (
"github.com/Gophercraft/core/packet/spell"
"github.com/Gophercraft/core/realm/wdb/models"
"github.com/Gophercraft/log"
)
func (s *Session) SendActionButtons() {
var ab []models.ActionButton
if err := s.DB().Where("player = ?", s.PlayerID()).Find(&ab); err != nil {
panic(err)
}
nab := spell.NumActionButtons(s.Build())
if len(ab) > nab {
ab = ab[:nab]
}
data := &spell.ActionButtons{}
data.Buttons = make([]spell.ActionButton, nab)
for _, button := range ab {
if int(button.Button) > len(data.Buttons) {
continue
}
data.Buttons[int(button.Button)] = spell.ActionButton{
Action: button.Action,
Type: button.Type,
}
}
s.Send(data)
}
func (s *Session) HandleSetActionButton(sab *spell.SetActionButton) {
log.Dump("Set action button", sab)
s.DB().Where("player = ?", s.PlayerID()).Where("button = ?", sab.Slot).Delete(new(models.ActionButton))
if sab.Action != 0 {
s.DB().Insert(&models.ActionButton{
Player: s.PlayerID(),
Button: uint8(sab.Slot),
Action: sab.Action,
Type: sab.Type,
})
}
}