-
Notifications
You must be signed in to change notification settings - Fork 1
/
dignityMission.js
51 lines (44 loc) · 1.98 KB
/
dignityMission.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
function DignityMission() {
DignityObject.call(this);
this.desc = "";
this.actionStart = new DignityAction; //execute action when start mission
this.actionStartName = ""; //method name for action start
this.actionEnd = new DignityAction; //execute action when end mission
this.actionEndName = ""; //method name for action end
this.actionTime = new DignityAction; //execute action when timing mission
this.actionTimeName = ""; //method name for action time
this.finishTime = 0; //run end action for after finishTime
this.time = 0; //time milisecond for actionTime
this.continuous = false; //if true actionTime works continuously, execute each time interval
this.async = false; //actions start same time
this.end = false; //learn for mission end to execute actionEnd
};
DignityMission.prototype = Object.create(DignityObject.prototype);
DignityMission.prototype.constructor = DignityMission;
DignityMission.prototype.executeAction = function(_dignityObject, _name) {
_dignityObject[_name]();
};
DignityMission.prototype.executeEndAction = function() {
if(this.actionEndName !== "")
this.actionEnd[this.actionEndName]();
};
DignityMission.prototype.execute = function() {
if(this.finishTime > 0) {
this.executeAction(this.actionStart, this.actionStartName);
window.setTimeout(this.executeAction, this.finishTime, this.actionEnd, this.actionEndName);
} else if(this.time <= 0) {
if(this.end) {
this.executeAction(this.actionEnd, this.actionEndName);
}
else {
this.executeAction(this.actionStart, this.actionStartName);
}
}
if(this.time > 0) {
if(this.continuous) {
window.setInterval(this.executeAction, this.time, this.actionTime, this.actionTimeName); //run every time seconds
} else {
window.setTimeout(this.executeAction, this.time, this.actionTime, this.actionTimeName); //run once after time seconds
}
}
};