/
movement.go
216 lines (177 loc) · 5.11 KB
/
movement.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package realm
import (
"github.com/Gophercraft/core/guid"
"github.com/Gophercraft/core/packet"
"github.com/Gophercraft/core/packet/update"
"github.com/Gophercraft/core/tempest"
"github.com/Gophercraft/core/vsn"
"github.com/Gophercraft/log"
)
func (s *Session) SetFly(on bool) {
s.Flying = on
if s.Build().RemovedIn(vsn.V2_4_3) {
// Hacky bullshit.
// Flying wasn't actually implemented until version 2.0.
// You can only move laterally and it's buggy as hell
mask := update.MoveFlagCanFly | update.MoveFlagFlying
if on {
s.MovementInfo.Flags |= mask
} else {
s.MovementInfo.Flags &= ^mask
}
s.Send(&update.MovementPacket{
Type: packet.MSG_MOVE_START_SWIM,
Server: true,
GUID: s.GUID(),
Info: s.MovementInfo,
})
} else {
s.Send(&update.FlyState{
GUID: s.GUID(),
On: on,
})
}
}
// Important TODO: validate position
func (s *Session) HandleUpdateMovement(mpacket *update.MovementPacket) {
if mpacket.GUID == guid.Nil {
mpacket.GUID = s.GUID()
}
if s.Moves != nil {
s.Moves <- mpacket
}
// log.Dump("movement update", mpacket)
// TODO: validate flags
// s.UpdatePosition(s.MovementInfo.Position)
// s.Map().PlayersInSightOfObject(s, s.Map().VisibilityDistance()).Iter(func(s *Session) {
// s.Send(&update.MovementPacket{
// Type: mpacket.Type,
// Server: true,
// // Todo: allow player to control other GUIDs
// GUID: s.GUID(),
// Info: mpacket.Info,
// })
// })
}
// func (s *Session) UpdateCameraPosition(syncSelf bool, pos tempest.C4Vector) {
// visRange := s.Server.FloatVar("Sync.VisibilityRange")
// s.GuardTrackedGUIDs.Lock()
// defer s.GuardTrackedGUIDs.Unlock()
// tGuids := s.TrackedGUIDs[:0]
// // TODO: time out object synchronization if the player only moved a little bit, or has moved very recently
// // Remove GUIDs if too far away
// for _, g := range s.TrackedGUIDs {
// active := s.Map().GetObject(g)
// if active == nil {
// s.SendObjectDelete(g)
// } else {
// if active.Movement().Position.C3().Distance(s.Position().C3()) > visRange {
// s.SendObjectDelete(g)
// if syncSelf {
// if activeSession, ok := (active).(*Session); ok {
// activeSession.RemoveTrackedGUID(s.GUID())
// activeSession.SendObjectDelete(s.GUID())
// }
// }
// } else {
// tGuids = append(tGuids, g)
// }
// }
// }
// s.TrackedGUIDs = tGuids
// // Add new GUIDs if not found yet
// for _, nearObject := range s.Map().VisibleObjectsInRange(s, visRange) {
// if !s.IsTrackedGUID(nearObject.GUID()) {
// s.TrackedGUIDs = append(s.TrackedGUIDs, nearObject.GUID())
// s.SendObjectCreate(nearObject)
// if syncSelf {
// // TODO: it may be more efficient to send these creates as multiple blocks in a SMSG_COMPRESSED_OBJECT_UPDATE
// // We may be appearing to a new player. Notify them of us.
// if nearSession, ok := (nearObject).(*Session); ok {
// nearSession.SendObjectCreate(s)
// }
// }
// }
// }
// }
func (s *Session) HandleMoves(moves *update.MovementPacket) {
s.HandleUpdateMovement(moves)
}
func (s *Session) Movement() *update.MovementBlock {
s.MovementInfo.Time = s.Server.UptimeMS()
mData := &update.MovementBlock{
Speeds: s.MoveSpeeds,
Position: s.MovementInfo.Position,
Info: s.MovementInfo,
}
mData.UpdateFlags |= update.UpdateFlagLiving
mData.UpdateFlags |= update.UpdateFlagHasPosition
mData.UpdateFlags |= update.UpdateFlagAll
mData.UpdateFlags |= update.UpdateFlagHighGUID
mData.All = 0x1 // 5875 only
mData.HighGUID = 0x1
return mData
}
func (s *Session) Position() tempest.C4Vector {
return s.MovementInfo.Position
}
func (s *Session) Speeds() update.Speeds {
return s.MoveSpeeds
}
func (m *Map) UpdateSpeed(g guid.GUID, st update.SpeedType) {
obj := m.GetObject(g)
if obj == nil {
return
}
speeds := obj.Movement().Speeds
if g.HighType() == guid.Player {
if sess, ok := obj.(*Session); ok {
sess.Send(&update.ForceSpeedChange{
Type: st,
ID: g,
NewSpeed: speeds[st],
})
}
}
// pkt := packet.NewWorldPacket(pair.Spline)
// g.EncodePacked(m.Phase.Server.Build(), pkt)
// pkt.WriteFloat32(speeds[st])
m.VisibleObjects(obj).Sessions().Iter(func(s *Session) {
s.Send(&update.SplineSpeedChange{
Type: st,
ID: g,
NewSpeed: speeds[st],
})
})
}
func (s *Session) SyncSpeeds() {
list := update.GetSpeedList(s.Build())
for _, speed := range list {
s.Map().UpdateSpeed(s.GUID(), speed)
}
// var sl update.Speed
// vsn.QueryDescriptors(s.Build())
// for k, v := range update.SpeedLists {
// if k.Contains(s.Build()) {
// for _, speed := range v {
// s.Map().UpdateSpeed(s.GUID(), speed)
// }
// break
// }
// }
s.SyncTime()
}
func (s *Session) HandleSetActiveMover(sam *update.SetActiveMover) {
log.Println(s, "set active mover", sam.ID)
}
func (s *Session) SetPosition(c4 tempest.C4Vector) {
s.Camera.Position = c4
s.MovementInfo.Position = c4
s.Char.X = s.MovementInfo.Position.X
s.Char.Y = s.MovementInfo.Position.Y
s.Char.Z = s.MovementInfo.Position.Z
s.Char.O = s.MovementInfo.Position.W
}
func (s *Session) UpdatePosition() {
s.Map().UpdateMapPosition(s.GUID())
}