-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hit.js
77 lines (72 loc) · 2.04 KB
/
Hit.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
"use strict";
const DamageType = require("./DamageType");
const Table = require("cli-table");
module.exports = function () {
let currentType = 0;
let logTimeout = null;
const table = new Table({
head: [
"Damage Taken",
"Maximum Damage",
"Reduced By",
"Type",
"Zone",
"Resistance Breakdown",
"Capped",
],
colWidths: [14, 16, 17, 12, 9, 60, 14],
});
function closeType() {
if (currentType) {
// console.log("log: writing to table");
currentType.summarise(table);
currentType = 0;
} else if (table.length > 0) {
// console.log("table still has data");
} else {
// console.log("Nothing written to table");
}
}
function log() {
// console.log("log");
closeType();
if (table.length > 0) {
console.log(table.toString());
// console.log("table written");
}
}
return {
registerType: function (typeName, damage, zone) {
currentType = new DamageType(typeName, damage, zone);
},
setTimeout: function () {
// console.log("Setting Timeout");
logTimeout = setTimeout(() => {
// console.log("log timeout running");
log();
}, 2500);
},
reduceType: function (
reductionSource,
damageAfterReduction,
totalPercentage
) {
if (!currentType) return;
currentType.registerReduction(
reductionSource,
damageAfterReduction,
totalPercentage
);
},
capType: function (resistCap) {
if (!currentType) return;
currentType.setCap(resistCap);
},
closeType: closeType,
close: function () {
// console.log("clear timeout");
clearTimeout(logTimeout);
log();
},
};
};