/
speed_change.go
72 lines (60 loc) · 1.85 KB
/
speed_change.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
package update
import (
"fmt"
"github.com/Gophercraft/core/guid"
"github.com/Gophercraft/core/packet"
"github.com/Gophercraft/core/vsn"
)
type SpeedOpcodePair struct {
Force packet.WorldType
Spline packet.WorldType
}
var (
SpeedCodes = map[SpeedType]SpeedOpcodePair{
Walk: {packet.SMSG_FORCE_WALK_SPEED_CHANGE, packet.SMSG_SPLINE_SET_WALK_SPEED},
Run: {packet.SMSG_FORCE_RUN_SPEED_CHANGE, packet.SMSG_SPLINE_SET_RUN_SPEED},
RunBackward: {packet.SMSG_FORCE_RUN_BACK_SPEED_CHANGE, packet.SMSG_SPLINE_SET_RUN_BACK_SPEED},
Swim: {packet.SMSG_FORCE_SWIM_SPEED_CHANGE, packet.SMSG_SPLINE_SET_SWIM_SPEED},
SwimBackward: {packet.SMSG_FORCE_SWIM_BACK_SPEED_CHANGE, packet.SMSG_SPLINE_SET_SWIM_BACK_SPEED},
Turn: {packet.SMSG_FORCE_TURN_RATE_CHANGE, packet.SMSG_SPLINE_SET_TURN_RATE},
Flight: {packet.SMSG_FORCE_FLIGHT_SPEED_CHANGE, packet.SMSG_SPLINE_SET_FLIGHT_SPEED},
FlightBackward: {packet.SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE, packet.SMSG_SPLINE_SET_FLIGHT_BACK_SPEED},
}
)
type ForceSpeedChange struct {
Type SpeedType
ID guid.GUID
Counter uint32
NewSpeed float32
}
func (fs *ForceSpeedChange) Encode(build vsn.Build, out *packet.WorldPacket) (err error) {
code, ok := SpeedCodes[fs.Type]
if !ok {
err = fmt.Errorf("%d", fs.Type)
return
}
out.Type = code.Force
fs.ID.EncodePacked(build, out)
out.WriteUint32(fs.Counter)
if fs.Type == Run {
out.WriteByte(0)
}
out.WriteFloat32(fs.NewSpeed)
return nil
}
type SplineSpeedChange struct {
Type SpeedType
ID guid.GUID
NewSpeed float32
}
func (ss *SplineSpeedChange) Encode(build vsn.Build, out *packet.WorldPacket) (err error) {
code, ok := SpeedCodes[ss.Type]
if !ok {
err = fmt.Errorf("%d", ss.Type)
return
}
out.Type = code.Spline
ss.ID.EncodePacked(build, out)
out.WriteFloat32(ss.NewSpeed)
return nil
}