/
walk.js
77 lines (77 loc) · 2.55 KB
/
walk.js
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
(function (app) {
let walk = Include("include/walk.js")
let Move = Include("core/move/move.js")
var backward = Include("include/backward.js")
let Walk = function (mode, target, onFinish, options) {
Move.call(this, mode, target, onFinish, options)
this.Move = function () {
if (this.Context.Path.Length() == 0) {
this.Stop()
world.Note("到达目的地")
app.ExecuteCallback(this.onFinish, this.Data)
return
}
let step
while (true) {
step = this.Context.Move()
if (step == null) {
break
}
if (!backward[step.Command]) {
break
}
if (this.Context.Current() && !backward[this.Context.Current().Command]) {
break
}
if (this.Context.Moving.length >= app.GetNumberParam("walkstep")) {
break
}
}
this.Context.Moving.forEach(function (step) {
app.Send(step.Command)
})
}
this.OnStart = function () {
if (!app.Data.Room.ID) {
this.Stop()
app.Raise("MoveLost")
return
}
if (app.Data.Room.ID==this.Target){
this.Stop()
world.Note("到达目的地")
app.ExecuteCallback(this.onFinish, this.Data)
return
}
var target = this.Target
if (typeof (target) == "string") {
target = [target]
}
var path = App.API.GetPath(app.Data.Room.ID, target)
if (path == null) {
this.Stop()
world.Note("无法找到从[" + app.Data.Room.ID + "]到[" + target.join(",") + "]的路径")
app.Raise("MoveNopath")
return
}
this.Context = new walk(path.Path)
this.Move()
}
this.Resume = function () {
if (this.Paused) {
this.Paused = false
}
this.Move()
}
this.OnRoomObjEnd = function () {
this.Context.Arrive()
if (!this.Paused && this.OnStep) {
app.ExecuteCallback(this.OnStep, this.StepData)
}
if (!this.Paused && this.Context.Moving.length == 0) {
this.Move()
}
}
}
return Walk;
})(App)