-
Notifications
You must be signed in to change notification settings - Fork 0
/
shadowrun5eInit
56 lines (51 loc) · 1.65 KB
/
shadowrun5eInit
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
var iniobj = {
to: [],
check: '',
idx: 0
};
var inicheck = function() {
iniobj.po = iniobj.to;
iniobj.to = JSON.parse(Campaign().get('turnorder'));
iniobj.check = _.find(iniobj.to, function(obj) { return obj.custom == 'Initiative Pass'});
iniobj.idx = iniobj.to.indexOf(iniobj.check);
};
var addini = function(oTurnOrder) {
oTurnOrder.unshift({
id: '-1',
pr: '1',
custom: 'Initiative Pass'
});
Campaign().set("turnorder", JSON.stringify(oTurnOrder));
};
on('chat:message', function(msg) {
// Check for "!ini" command
if(msg.type == 'api' && msg.content.indexOf('ini') !== -1) {
//Open Tracker if not open
if(Campaign().get('initiativepage') === false) {
Campaign().set('initiativepage', true);
};
//Setup iniobj
inicheck();
//Create "Initiative Pass" if it doesn't exist
if(iniobj.check === undefined){
addini(iniobj.to);
}
//Otherwise start a new turn
else{
iniobj.to.splice(iniobj.idx, 1);
addini(iniobj.to);
};
};
});
//Check for iniobj to make it to top of tracker
on('change:campaign:turnorder', function() {
inicheck();
if(iniobj.idx === 0 && (_.isArray(iniobj.to) && _.isArray(iniobj.po) && !_.isEqual(iniobj.to[0],iniobj.po[0]) ) || (_.isArray(iniobj.to) && ! _.isArray(iniobj.po))){
iniobj.to[0].pr++;
for (var i = 1; i < iniobj.to.length; i++) {
iniobj.to[i].pr-=10;
iniobj.to[i].pr = iniobj.to[i].pr < 0 ? 0 : iniobj.to[i].pr;
};
Campaign().set("turnorder", JSON.stringify(iniobj.to));
};
});