-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopMove.go
74 lines (63 loc) · 1.8 KB
/
opMove.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
package main
import (
"strconv"
"time"
"github.com/vikebot/vbgs/vbge"
)
type moveObj struct {
Direction *string `json:"direction"`
}
type movePacket struct {
Type string `json:"type"`
Obj moveObj `json:"obj"`
}
func opMove(c *ntcpclient, packet movePacket) {
//c.Player.Rl.Move.Take()
time.Sleep(1000 * time.Millisecond)
if packet.Obj.Direction == nil {
c.Respond("Invalid packet. '.obj.direction' missing")
return
}
dir := *packet.Obj.Direction
if !vbge.IsDir(dir) {
c.RespondFmt("Invalid packet. '%s' is not a valid value for '.obj.direction'", *packet.Obj.Direction)
return
}
ngl, err := c.Player.Move(dir)
if err != nil {
c.Respond(err.Error())
return
}
// Move is successfully finished for client -> return nil
c.RespondNil()
// get new line for player
newLine := vbge.GetNewLineMapentity(vbge.RenderWidth, c.Player.UserID, battle, dir)
// create generic player response packet
playerResp := vbge.PlayerResp{
GRID: c.Player.GRenderID,
Health: c.Player.Health.HealthSynced(),
CharacterType: c.Player.CharacterType,
WatchDir: c.Player.WatchDir,
}
// loop over all player's in the notifygroup and send an update
for _, entity := range ngl {
// set the relative posititon for the current opponent
playerResp.Location = entity.ARLoc
dist.GetClient(strconv.Itoa(entity.Player.UserID)).Push("game",
struct {
GRID string `json:"grid"`
Type string `json:"type"`
Direction string `json:"direction"`
PlayerInfo vbge.PlayerResp `json:"playerinfo"`
Loc *vbge.ARLocation `json:"loc"`
NewLine *vbge.ViewableMapentity `json:"newline"`
}{
c.Player.GRenderID,
"move",
dir,
playerResp,
entity.ARLoc,
newLine},
c.Log)
}
}