-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.js
67 lines (54 loc) · 2.29 KB
/
update.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
/** Require local modules */
const fighting = require(`./fighting`);
let tick = 1;
module.exports = (world) => {
/** Loop through each area in the world */
world.areas().forEach((area) => {
/** Loop through each room in the area */
area.rooms().forEach((room) => {
/** Create array of all characters in room */
const characters = room.users().concat(room.mobiles());
/** Loop through each character in room who is fighting */
characters.forEach((character) => {
/** On every fouorth tick, update fighting for character */
if ( tick % 4 == 0 ) {
/** Update any fighting the character is engaged in */
fighting.updateFighting(world, character);
/** Update health, mana, and energy */
character.health(Math.min(character.maxHealth(), character.health() + 1));
character.mana(Math.min(character.maxMana(), character.mana() + 1));
character.energy(Math.min(character.maxEnergy(), character.energy() + 1));
/** Update position if necessary */
if ( character.position() == world.constants().positions.INCAPACITATED && character.health() > 0 ) {
character.send(`You come to your senses and slowly stumble to your feet.\r\n`);
character.position(world.constants().positions.STANDING);
}
}
});
});
});
/** Loop through each user in the world */
world.users().forEach((user) => {
/** If the user is connected and has text waiting in the output buffer... */
if ( user.state() != world.constants().states.DISCONNECTED && user.socket() && user.outBuffer().length > 0 ) {
/** If user is connected, send prompt */
if ( user.state() == world.constants().states.CONNECTED )
user.prompt(world);
if ( !user.command() )
user.socket().write(`\r\n`);
/** Send output buffer */
user.socket().write(user.outBuffer());
/** Clear output buffer */
user.outBuffer(``);
/** Unset user's command boolean */
user.command(false);
}
});
/** Increment tick by one */
tick++;
/** If tick exceeds 256, reset to 1 */
if ( tick > 256 )
tick = 1;
/** Update fights every 250 ms */
setTimeout(module.exports, 250, world);
};