-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HPRollsky.js
63 lines (53 loc) · 2.16 KB
/
HPRollsky.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
var RollHP = RollHP || (function () {
'use strict';
var barNumber = 1,
attrName = 'npc_hpformula',
setupManualAttribute = function (token) {
const attr = findObjs({type: 'attribute', characterid: token.get('represents'), name: attrName})[0];
if (attr) {
sendChat('', `[[${attr.get('current')}]]`, (results) => {
if (results && results.length === 1) {
if (!results[0].inlinerolls || !results[0].inlinerolls[0]) {
log('HP roll didn\'t have the expected structure. This is what we got back: ' + results[0]);
}
else {
const hp = results[0].inlinerolls[0].results.total;
token.set(`bar${barNumber}_value`, hp);
token.set(`bar${barNumber}_max`, hp);
}
}
});
}
},
handleInput = function (msg) {
var args;
if (msg.type !== "api") {
return;
}
args = msg.content.split(/\s+/);
switch (args.shift()) {
case '!roll-hp':
_.chain(msg.selected)
.map(function (o) {
return getObj('graphic', o._id);
})
.reject(_.isUndefined)
.reject(function (t) {
return undefined === t.get('represents');
})
.each(setupManualAttribute)
;
break;
}
},
registerEventHandlers = function () {
on('chat:message', handleInput);
};
return {
RegisterEventHandlers: registerEventHandlers
};
}());
on('ready', function () {
'use strict';
RollHP.RegisterEventHandlers();
});