-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlvl2.js
107 lines (106 loc) · 2.59 KB
/
lvl2.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
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
function sleep(ms) {
return new Promise(function(resolve) {setTimeout(resolve, ms)});
}
exports.is_forked = function(hud, PObject, actions) {
return function(objectName) {
return hud.GetInteractable(objectName).getLeft() != "";
}
}
exports.walk = function(hud, PObject, actions) {
return function(objectName) {
async function x() {
var object = hud.GetInteractable(objectName);
if (object) {
if (PObject.Near(object.startOfRiver())) {
object.VisitStart();
destination = object.endOfRiver();
var seconds = PObject.TurnTo(destination);
await sleep(seconds);
seconds = PObject.WalkTo(destination, 500);
await sleep(seconds);
} else {
throw "Too far from start of river"
}
} else {
throw "Invalid Name"
}
return new Promise(function(resolve) {
resolve();
});
}
actions.list[actions.list.length] = x;
}
}
exports.retrace = function(hud, PObject, actions) {
return function(objectName) {
async function x() {
var object = hud.GetInteractable(objectName);
if (object) {
if (PObject.Near(object.endOfRiver())) {
object.VisitEnd();
destination = object.startOfRiver();
var seconds = PObject.TurnTo(destination);
await sleep(seconds);
seconds = PObject.WalkTo(destination, 500);
await sleep(seconds);
} else {
throw "Too far from end of river"
}
} else {
throw "Invalid Name"
}
return new Promise(function(resolve) {
resolve();
});
}
actions.list[actions.list.length] = x;
}
}
exports.get_left = function(hud, PObject, actions) {
return function(objectName) {
return hud.GetInteractable(objectName).getLeft();
}
}
exports.get_right = function(hud, PObject, actions) {
return function(objectName) {
return hud.GetInteractable(objectName).getRight();
}
}
exports._advance = function(hud, PObject, actions) {
return function() {
async function x() {
hud.nextLevel();
return new Promise(function(resolve) {
resolve();
});
}
actions.list[actions.list.length] = x;
}
}
exports._remove = function(hud, PObject, actions) {
async function exec(resolve) {
if (actions.list.length === 0) {
actions.running = false;
resolve();
} else {
actions.running = true;
try {
await (actions.list.shift(1))();
exec(resolve);
} catch (e) {
hud.Output(e + "");
actions.running = false;
actions.list = [];
resolve();
}
}
}
function init() {
return new Promise(
function(resolve){
exec(resolve);
}
);
}
return init;
}