-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathparse.js
More file actions
40 lines (33 loc) · 1.13 KB
/
Copy pathparse.js
File metadata and controls
40 lines (33 loc) · 1.13 KB
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
// an occurrence of damage from the logs
function Damage(time, damage, doer, taker) {
this.time = time;
this.damage = damage;
this.doer = doer;
this.taker = taker;
}
var directHit = {
"regex": /^\[(.*)\] (.*) (?:hit|slash|bash|crush|pierce|kick|bite|maul|backstab|claw|strike)(?:s|es)? (.*) for (\d+) points of(?: non-melee)? damage.*/,
"toDamage": function(split) {
return new Damage(new Date(split[1]), parseInt(split[4]), split[2], split[3]);
}
};
var indirect = {
"regex": /^\[(.*)\] (.*) ha(?:ve|s) taken (\d+) damage from (?:your.*|.* by (.*)).*/,
"toDamage": function(split) {
// a falsy split[4] means the character is the damager doer
var doer = !split[4] ? "You" : split[4];
return new Damage(new Date(split[1]), parseInt(split[3]), doer, split[2]);
}
};
var exprs = [directHit, indirect];
// parse a raw line of log output
function parseLine(line) {
for (var i=0; i < exprs.length; i++) {
var split = exprs[i].regex.exec(line);
if (split) {
return exprs[i].toDamage(split);
}
}
return null;
}
exports.parseLine = parseLine;