-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfighting.js
157 lines (121 loc) · 6.22 KB
/
fighting.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
module.exports.createCommands = (world) => {
return [
new world.Command({
name: `kill`,
positions: [world.constants().positions.STANDING, world.constants().positions.FIGHTING],
execute: async (world, user, buffer, args) => {
/** Parse name and count of argument */
const [name, count] = world.parseName(user, args, 0);
/** Create array of users in room with name matching argument */
const users = user.room().users().filter(x => x.name().toLowerCase().startsWith(name));
/** Create array of mobiles in room with name matching argument */
const mobiles = user.room().mobiles().filter(x => x.names().some(y => y.toLowerCase().startsWith(name)));
/** Create array of users and mobiles combined */
const characters = users.concat(mobiles);
/** If the number of characters is less than the count, send error and return */
if ( characters.length < count )
return user.send(`There is no being here by that name.\r\n`);
/** Create variable for target */
const target = characters[count - 1];
/** If target is affected by 'safe', they can't be attacked, send error and return */
if ( target.affects().includes(world.constants().AFFECT_SAFE) )
return user.send(`That being cannot be attacked right now.\r\n`);
/** Send action to user */
user.send(`You attack ${target.name()}!\r\n`);
/** Send action to target */
target.send(`You are being attacked by ${user.name()}!\r\n`);
/** Send action to user's room */
user.room().send(`${user.name()} starts attacking ${target.name()}!\r\n`, [user, target]);
/** Update character's positions to fighting */
user.position(world.constants().positions.FIGHTING);
target.position(world.constants().positions.FIGHTING);
/** Set user and target as fighting each other */
user.fighting(target);
target.fighting(user);
},
priority: 999
})
];
};
module.exports.updateFighting = (world, character) => {
/** If character is not fighting, skip them */
if ( !character.fighting() )
return;
/** If character is no longer in same room as target... */
if ( character.room() != character.fighting().room() ) {
/** Update character's position */
character.fighting().position(world.constants().positions.STANDING);
character.position(world.constants().positions.STANDING);
/** Stop character's from fighting */
character.fighting().fighting(null);
character.fighting(null);
}
/** Otherwise, if target is now safe, stop fighting */
else if ( character.affects().includes(world.constants().AFFECT_SAFE) ) {
/** Send error to fighting character */
character.send(`That being cannot be attacked right now.\r\n`);
/** Update character's position */
character.fighting().position(world.constants().positions.STANDING);
character.position(world.constants().positions.STANDING);
/** Stop character's from fighting */
character.fighting().fighting(null);
character.fighting(null);
}
/** Otherwise... */
else {
/** Calculate the roll for this round of damage */
const roll = Math.floor(Math.random() * 100) + 1;
/** If the roll is less than dodge chance... */
if ( roll < character.fighting().dodge() ) {
/** Send miss to fighting character */
character.send(`You miss ${character.fighting().name()}.\r\n`);
/** Send miss to character being fought */
character.fighting().send(`${character.name()} misses you.\r\n`);
/** Send miss to character's room */
character.room().send(`${character.name()} misses ${character.fighting().name()}\r\n`, [character, character.fighting()]);
}
/** Otherwise... */
else {
/** Calculate damage for this hit */
const damage = Math.floor(Math.random() * 10) + 1;
/** Send hit to fighting character */
character.send(`You hit ${character.fighting().name()} for ${damage} damage!\r\n`);
/* * Send hit to character being fought */
character.fighting().send(`${character.name()} hits you for ${damage} damage!\r\n`);
/** Send hit to character's room */
character.room().send(`${character.name()} hits ${character.fighting().name()}!\r\n`, [character, character.fighting()]);
/** Deal damage to character being fought */
character.fighting().health(character.fighting().health() - damage);
}
/** If character being fought is defeated... */
if ( character.fighting().health() < 0 ) {
/** Send defeat to character */
character.send(`You have knocked ${character.fighting().name()} unconscious!\r\n`);
/** Send defeat to character being fought */
character.fighting().send(`You have been knocked unconscious!\r\n`);
/** Send defeat to character's room */
character.room().send(`${character.name()} has knocked ${character.fighting().name()} unconscious!\r\n`, [character, character.fighting()]);
/** Update character's positions */
character.fighting().position(world.constants().positions.INCAPACITATED);
character.position(world.constants().positions.STANDING);
/** Stop character's from fighting */
character.fighting().fighting(null);
character.fighting(null);
}
/** Otherwise, if fighting character is defeated... */
else if ( character.health() < 0 ) {
/** Send defeat to character */
character.send(`You have been knocked unconscious!\r\n`);
/** Send defeat to character being fought */
character.fighting().send(`You have knocked ${character.name()} unconscious!\r\n`);
/** Send defeat to character's room */
character.room().send(`${character.fighting().name()} has knocked ${character.name()} unconscious!\r\n`, [character, character.fighting()]);
/** Update character's positions */
character.fighting().position(world.constants().positions.STANDING);
character.position(world.constants().positions.INCAPACITATED);
/** Stop character's from fighting */
character.fighting().fighting(null);
character.fighting(null);
}
}
};