-
Notifications
You must be signed in to change notification settings - Fork 2
/
senses.js
415 lines (334 loc) · 19 KB
/
senses.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
module.exports.createCommands = (world) => {
return [
new world.Command({
name: `look`,
positions: world.constants().positionsAwake,
execute: async (world, user, buffer, args) => {
if ( typeof args[0] == `string` ) {
/** If the first argument is 'in'... */
if ( `in`.startsWith(args[0]) ) {
/** If no second argument was provided, send error and return */
if ( typeof args[1] != `string` ) {
user.send(`Look in what?\r\n`);
return;
}
/** Parse container name and count from second argument */
const [name, count] = world.parseName(user, args, 1);
/** Create array of all items in user's inventory with name matching second argument */
let items = user.inventory().filter(x => x.names().some(y => y.toLowerCase().startsWith(name)));
/** Concatenate with all items in user's equipment with name matching second argument */
items = items.concat(user.room().items().filter(x => x.names().some(y => y.toLowerCase().startsWith(name))));
/** If number of items is less than count, send error */
if ( items.length < count ) {
user.send(`You can't find that item anywhere.\r\n`);
}
/** Otherwise, if item is not a container, send error */
else if ( !items[count - 1].flags().includes(world.constants().itemFlags.CONTAINER) ) {
user.send(`That item is not a container.\r\n`);
}
/** Otherwise... */
else {
/** Send header for container contents */
user.send(`Contents of ${items[count - 1].name()}:\r\n`);
/** Keep track of items already included in item counts */
const itemsIncluded = [];
/** Loop through each item in container */
items[count - 1].contents().forEach((content) => {
/** If item is already included, skip it */
if ( itemsIncluded.includes(content.name()) )
return;
/** Count number of items of the same name in the container */
const numItems = items[count - 1].contents().filter(x => x.name() == content.name()).length;
/** If the number of items is greater than, send quantity and name */
if ( numItems > 1 )
user.send(` (${numItems}) ${content.name()}\r\n`);
/** Otherwise, just send name */
else
user.send(` ${content.name()}\r\n`);
/** Add item to items included */
itemsIncluded.push(content.name());
});
/** If there are no items in the container, send none */
if ( items[count - 1].contents().length == 0 )
user.send(` None\r\n`);
}
}
/** Otherwise... */
else {
/** Parse container name and count from argument */
const [name, count] = world.parseName(user, args, 0);
/** Create array of users with name matching the arugment */
const users = user.room().users().filter(x => x.name().toLowerCase().startsWith(name) || ( name == `self` && x == user ) );
/** Create array of mobiles with name matching the arugment */
const mobiles = user.room().mobiles().filter(x => x.names().some(y => y.toLowerCase().startsWith(name)));
/** Create array of items in user's inventory with name matching the arugment */
const inventory = user.inventory().filter(x => x.names().some(y => y.toLowerCase().startsWith(name)));
/** Create array of items in user's equipemnt with name matching the arugment */
const equipment = user.equipment().filter(x => x.names().some(y => y.toLowerCase().startsWith(name)));
/** Create array of items in user's room with name matching the arugment */
const items = user.room().items().filter(x => x.names().some(y => y.toLowerCase().startsWith(name)));
/** Create array of all characters and items with name matching the argument combined */
const targets = users.concat(mobiles.concat(inventory.concat(equipment.concat(items))));
/** If number of targets is less than count, send error and return */
if ( targets.length < count )
return user.send(`You can't find that anywhere.\r\n`);
/** Define target */
const target = targets[count - 1];
/** If the target is a user... */
if ( target instanceof world.User ) {
/** Send target user's name */
user.send(`${target.name()} is standing here.\r\n\r\n`);
/** Send target user's equipment */
world.sendUserEquipment(user, target);
}
/** Otherwise, if target is a mobile... */
else if ( target instanceof world.MobileInstance ) {
/** Send target mobile's description */
user.send(`${world.terminalWrap(world.colorize(target.name()))}\r\n`);
user.send(`${world.terminalWrap(world.colorize(target.description()))}\r\n\r\n`);
/** Send target mobile's equipment */
world.sendUserEquipment(user, target);
}
/** Otherwise, if there is a second argument */
else if ( typeof args[1] == `string` ) {
/** If the detail name is not valid, send error */
if ( !args[1].match(/^[a-z0-9]+$/i) )
return user.send(`You can't find that anywhere.\r\n`);
/** Parse detail name and count */
const [detailName, detailCount] = world.parseName(user, args, 1);
/** Attempt to find detail on target */
const detail = Object.keys(target.details()).filter(x => x.startsWith(detailName))[detailCount - 1];
/** If detail doesn't exist, send error */
if ( !detail )
return user.send(`You can't find that anywhere.\r\n`);
/** Send detail description */
user.send(`${world.terminalWrap(world.colorize(target.details()[detail]))}\r\n`);
}
/** Otherwise... */
else {
/** Send item description */
user.send(`${world.terminalWrap(world.colorize(target.description()))}\r\n`);
/** Define array of stats */
const stats = [target.accuracy(), target.air(), target.armor(), target.deflection(), target.dodge(),
target.earth(), target.fire(), target.life(), target.power(), target.speed(), target.water()];
if ( stats.some(x => x > 0) )
user.send(`\r\n`);
/** If the target is an item... */
if ( target instanceof world.ItemInstance ) {
/** If the item has accuracy, show it */
if ( target.accuracy() > 0 )
user.send(world.colorize(` #OAccuracy#n +${target.accuracy()}\r\n`));
/** If the item has air, show it */
if ( target.air() > 0 )
user.send(world.colorize(` Air +${target.air()}\r\n`));
/** If the item has armor, show it */
if ( target.armor() > 0 )
user.send(world.colorize(` #KArmor#n +${target.armor()}\r\n`));
/** If the item has deflection, show it */
if ( target.deflection() > 0 )
user.send(world.colorize(` #PDeflection#n +${target.deflection()}\r\n`));
/** If the item has dodge, show it */
if ( target.dodge() > 0 )
user.send(world.colorize(` #cDodge#n +${target.dodge()}\r\n`));
/** If the item has earth, show it */
if ( target.earth() > 0 )
user.send(world.colorize(` #yEarth#n +${target.earth()}\r\n`));
/** If the item has fire, show it */
if ( target.fire() > 0 )
user.send(world.colorize(` #RFire#n +${target.fire()}\r\n`));
/** If the item has life, show it */
if ( target.life() > 0 )
user.send(world.colorize(` #gLife#n +${target.life()}\r\n`));
/** If the item has power, show it */
if ( target.power() > 0 )
user.send(world.colorize(` #oPower#n +${target.power()}\r\n`));
/** If the item has speed, show it */
if ( target.speed() > 0 )
user.send(world.colorize(` #YSpeed#n +${target.speed()}\r\n`));
/** If the item has water, show it */
if ( target.water() > 0 )
user.send(world.colorize(` #BWater#n +${target.water()}\r\n`));
}
/** Create array of detail keys */
const keys = Object.keys(target.details());
/** If there are details, output heading */
if ( keys.length > 0 )
user.send(`\r\nDetails: `);
/** Loop through each detail key and output */
keys.forEach((key, index) => {
user.send(`${key} `);
/** Output new line after every fifth key */
if ( (index + 1) % 6 == 0 && index != keys.length - 1 )
user.send(`\r\n`);
});
/** If we output some detail keys, send new line */
if ( keys.length > 0 )
user.send(`\r\n`);
}
}
} else {
/** Send room name */
user.send(`${user.room().name()}\r\n`);
/** Start exits */
let exits = `#G[Exits:`;
/** Loop through exits in user's room */
user.room().exits().forEach((exit) => {
/** Append exit names separated by spaces */
exits += ` ${world.constants().directionNames[exit.direction()]}`;
});
/** If there are no exits, append none */
if ( user.room().exits().length == 0 )
exits += ` None`;
/** Finish exits */
exits += `]\r\n`;
/** Colorize and send exits */
user.send(world.colorize(exits));
/** Send room description */
user.send(world.terminalWrap(world.colorize(`#w${user.room().description()}\r\n`)));
/** Keep track of items already included in item counts */
const itemsIncluded = [];
/** Loop through each item in the user's room */
user.room().items().forEach((item) => {
/** If item is already included, skip it */
if ( itemsIncluded.includes(item.roomDescription()) )
return;
/** Count number of items of the same name in the room */
const count = user.room().items().filter(x => x.roomDescription() == item.roomDescription()).length;
/** If the number of items is greater than, send quantity and room description */
if ( count > 1 )
user.send(` (${count}) ${item.roomDescription()}\r\n`);
/** Otherwise, just send room description */
else
user.send(` ${item.roomDescription()}\r\n`);
/** Add item to items included */
itemsIncluded.push(item.roomDescription());
});
/** Loop through each mobile in user's room... */
user.room().mobiles().forEach((mobile) => {
/** Send description based on mobile's position and who they're fighting */
if ( mobile.position() == world.constants().positions.INCAPACITATED )
user.send(` ${mobile.name()} is lying here incapacitated!\r\n`);
else if ( mobile.position() == world.constants().positions.SLEEPING )
user.send(` ${mobile.name()} is lying here sleeping\r\n`);
else if ( mobile.position() == world.constants().positions.MEDITATING )
user.send(` ${mobile.name()} is meditating here\r\n`);
else if ( mobile.position() == world.constants().positions.LYING_DOWN )
user.send(` ${mobile.name()} is lying down here\r\n`);
else if ( mobile.position() == world.constants().positions.KNEELING )
user.send(` ${mobile.name()} is kneeling here\r\n`);
else if ( mobile.position() == world.constants().positions.SITTING )
user.send(` ${mobile.name()} is sitting here\r\n`);
else if ( mobile.fighting() && mobile.fighting() == user )
user.send(` ${mobile.name()} is here fighting YOU!\r\n`);
else if ( mobile.fighting() )
user.send(` ${mobile.name()} is here fighting ${mobile.fighting().name()}!\r\n`);
else
user.send(` ${mobile.roomDescription()}\r\n`);
});
/** Loop through each other user in the user's room... */
user.room().users().forEach((other) => {
/** If user in room is not the looking user... */
if ( user != other ) {
/** Send description based on user's position and who they're fighting */
if ( other.position() == world.constants().positions.INCAPACITATED )
user.send(` ${other.name()} is lying here incapacitated!\r\n`);
else if ( other.position() == world.constants().positions.SLEEPING )
user.send(` ${other.name()} is lying here sleeping\r\n`);
else if ( other.position() == world.constants().positions.MEDITATING )
user.send(` ${other.name()} is meditating here\r\n`);
else if ( other.position() == world.constants().positions.LYING_DOWN )
user.send(` ${other.name()} is lying down here\r\n`);
else if ( other.position() == world.constants().positions.KNEELING )
user.send(` ${other.name()} is kneeling here\r\n`);
else if ( other.position() == world.constants().positions.SITTING )
user.send(` ${other.name()} is sitting here\r\n`);
else if ( other.position() == world.constants().positions.FIGHTING && other.fighting() == user )
user.send(` ${other.name()} is here fighting YOU!\r\n`);
else if ( other.position() == world.constants().positions.FIGHTING && other.fighting() && other.fighting() != user )
user.send(` ${other.name()} is here fighting ${other.fighting().name()}!\r\n`);
else if ( other.position() == world.constants().positions.STANDING )
user.send(` ${other.name()} is standing here\r\n`);
}
});
}
},
priority: 999
}),
new world.Command({
name: `equipment`,
positions: world.constants().positionsAwake,
execute: async (world, user, buffer) => {
/** Send user's equipment */
world.sendUserEquipment(user, user);
},
priority: 998
}),
new world.Command({
name: `inventory`,
positions: world.constants().positionsAwake,
execute: async (world, user, buffer) => {
/** Send inventory header */
user.send(`Inventory:\r\n`);
/** Keep track of items already included in item counts */
const itemsIncluded = [];
/** Loop through each item in the user's inventory */
user.inventory().forEach((item) => {
/** If item is already included, skip it */
if ( itemsIncluded.includes(item.name()) )
return;
/** Count number of items of the same name in the user's inventory */
const count = user.inventory().filter(x => x.name() == item.name()).length;
/** If the number of items is greater than one, send quantity and name */
if ( count > 1 )
user.send(` (${count}) ${item.name()}\r\n`);
/** Otherwise, just send name */
else
user.send(` ${item.name()}\r\n`);
/** Add item to items included */
itemsIncluded.push(item.name());
});
/** If there are no items in the user's inventory, send nothing */
if ( user.inventory().length == 0 )
user.send(` nothing\r\n`);
},
priority: 999
}),
new world.Command({
name: `who`,
execute: async (world, user, buffer) => {
/** Send top border */
user.send(world.colorize(`#r~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\n`));
/** Keep track of the number of visible other users */
let count = 0;
/** Loop through each other user in the world... */
world.users().forEach((other) => {
/** If the other user is not the user looking and the other user is cloaked, return */
if ( other != user && other.affects().includes(world.constants().AFFECT_CLOAKED))
return;
/** If the other user is named xodin, send who entry with title 'The Designer' */
if ( other.name().toLowerCase() == `xodin` )
user.send(world.colorize(` #y[The Designer ] #W${other.name()} #w${other.title()}`.padEnd(86) + `\r\n`));
/** Otherwise, send who entry with title 'Honored Guest' */
else
user.send(world.colorize(` #y[Honored Guest] #W${other.name()} #w${other.title()}`.padEnd(86) + `\r\n`));
/** Increment visible user count by one */
count++;
});
/** Send first bottom border */
user.send(world.colorize(`\r\n#r~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n`));
/** If visible user count is equal to one, send only visible user */
if ( count == 1 )
user.send(world.colorize(`#wYou are the only Avatar that you can sense in this world.\r\n`));
/** If visible user count is equal to two, send only one other visible user */
else if ( count == 2 )
user.send(world.colorize(`#wYou can sense one other Avatar in this world.\r\n`));
/** Otherwise, send visible user count */
else
user.send(world.colorize(`#wYou can sense ${count - 1} other Avatars in this world.\r\n`));
/** Send second bottom border */
user.send(world.colorize(`#r~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n`));
},
priority: 0
})
];
};