/
reload.js
140 lines (114 loc) · 3.49 KB
/
reload.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
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
module.exports = new Class({
Extends: Command,
init: function() {
//Epic multiple syntaxes with different handlers action!
this.add_syntax('<object>', 'reload_item');
this.add_syntax('<living>', 'reload_living');
this.add_syntax('<string>', 'reload_something');
this.add_syntax('', 'reload_room');
},
reload_item: function(object) {
//We need to know if this object is in the room or in an inventory.
var holder = object.getContainer(),
//Attempt to get a new item to replace it.
error = false,
replacement = this.world.reloadItem(object, {
onFailure: function(e) { holder.sendError(e); }
}),
//We'll store some text here to append to the destruction message.
andThen;
//Take the item away.
object.getContainer().removeItem(object);
if (replacement) {
andThen = "A new "+replacement.get('short')+
" erupts within a flash of fire to take its place.";
holder.addItem(replacement);
} else {
andThen = "A spark ignites in its place for a moment before "+
"fading away with a disappointing fizz.";
}
this.emit("%You wave%s %your hands about in an arcane manner.");
if (holder instanceof Living) {
holder.emit("%Your "+ object.get('definite') +" disappears in a "+
"cloud of smoke. "+andThen);
} else {
holder.emit(object.get('definite')+" disappears in a cloud of "+
"smoke. "+andThen);
}
if (error) {
if (holder.send) {
holder.send("The object couldn't be reloaded. "+
"Please check for errors.");
holder.send(error);
}
}
},
reload_room: function() {
var player = this,
success = this.world.reloadRoom(this.get('room'), {
onFailure: function(e) { player.sendError(e); }
}),
andThen;
if (success) {
andThen = "The world shimmers around you and seems to take on a "+
"new life.";
} else {
andThen = "Nothing seems to happen.";
}
this.emit("%You snap%s %your fingers. "+andThen);
},
reload_living: function(l) {
this.emit(
"%You chant%s something under %your breath while peering at "+
l.get('definite')
);
if (l.player && l.name == this.name) {
this.send("You reload yourself.");
}
if (l.player) {
this.send(
l.get('definite')+" is a human, what would you reload?"
);
return false;
}
var player = this,
replacement = this.world.reloadNPC(l, {
onFailure: function(e) { player.sendError(e); }
});
if (replacement) {
replacement.emit(
"%You look%s startled as %you disappears into thin air for "+
"a moment."
);
} else {
l.emit("%You cock%s %his at %them, confused.", this);
this.send(
"Failed to reload "+l.get('definite')+". Check for bugs!"
);
}
},
reload_something: function(words) {
var player = this,
andThen = "Nothing happens.",
success = false,
opts = {
onFailure: function(e) { player.sendError(e); }
};
if (this.world.reloadEngineModule(words, opts)) {
andThen = "The core mechanics of the universe seem to be "+
"different somehow.";
success = true;
} else if (this.world.reloadCommand(words, opts)) {
andThen = "The rules of '"+words+"' seem to have changed.";
this.send(andThen);
success = true;
}
this.emit("%You hop%s about mysteriously. "+andThen);
if (!success) {
this.send(
"Sorry, the "+words+" command either can't be found or "+
"isn't working. Try checking for bugs."
);
}
}
});