-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
5eOGL-statblock.js
312 lines (287 loc) · 18.8 KB
/
5eOGL-statblock.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
function getCharacterObj(obj) {
"use strict";
//send any object and returns the associated character object
//returns character object for attribute, token/graphic, and ability, and... character
var objType = obj._type,
att, characterObj, tok;
if ((objType !== "attribute") && (objType !== "graphic") && (objType !== "character")) {
sendChat("API"," cannot be associated with a character.");
return;
}
if ((objType === "attribute") || (objType === "ability")) {
att = getObj(objType, obj._id);
if (att.get("_characterid") !== "") {
characterObj = getObj("character", att.get("_characterid"));
}
}
if (objType === "graphic") {
tok = getObj("graphic", obj._id);
if (tok.get("represents") !== "") {
characterObj = getObj("character", tok.get("represents"));
} else {
sendChat("API"," Selected token does not represent a character.");
return;
}
}
if (objType === "character") {
characterObj = getObj("character", obj._id);
}
return characterObj;
}
on("chat:message", function(msg) {
"use strict";
var msg,
selected,
Parameters,
statusName,
aName,
ids,
attributeName,
newValue,
characterObj,
attributeObjArray,
tok;
if (msg.type === "api" && msg.content.indexOf("!statblock") !== -1 )
{
selected = msg.selected;
var spellClass = -1;
//loop through selected tokens
_.each(selected, function(obj) {
tok = getObj("graphic", obj._id);
// Get the character token represents
characterObj = getCharacterObj(obj);
if ( ! characterObj) {
return;
}
var characterName = characterObj.get("name");
var rowIDs = new Array(); // Create array for repeating spell attribute names
var attackIds = new Array(); // Create array for repeating spell attribute names
var npcActionIds = new Array(); // Create array for repeating spell attribute names
var npcReactionIds = new Array(); // Create array for repeating spell attribute names
var npcTraitIds = new Array(); // Create array for repeating spell attribute names
var legendaryActionIds = new Array(); // Create array for repeating spell attribute names
getAllObjs().forEach(function(obj) {
// Filter down to just attribute objects belonging to the character, whose name indicates it's a spell
if (obj.get("type") !== "attribute")
return;
if (obj.get("_characterid") !== characterObj.get("_id"))
return;
if (obj.get("name").indexOf("repeating_spell-") === -1 &&
obj.get("name").indexOf("repeating_attack") === -1 &&
obj.get("name").indexOf("repeating_npcaction") === -1 &&
obj.get("name").indexOf("repeating_npcreaction") === -1 &&
obj.get("name").indexOf("repeating_npctrait") === -1)
return;
// If this is a name attribute, use that to add the base repeating attribute name to the array
if (obj.get("name").indexOf("_spellname") !== -1){
rowIDs.push(obj.get("name").substr(0,obj.get("name").indexOf("_spellname")));
}
if (obj.get("name").indexOf("_atkname") !== -1){
attackIds.push(obj.get("name").substr(0,obj.get("name").indexOf("_atkname")));
}
if (obj.get("name").indexOf("npcaction_") !== -1 && obj.get("name").indexOf("_name") !== -1){
npcActionIds.push(obj.get("name").substr(0,obj.get("name").indexOf("_name")));
}
if (obj.get("name").indexOf("npcreaction_") !== -1 && obj.get("name").indexOf("_name") !== -1){
npcReactionIds.push(obj.get("name").substr(0,obj.get("name").indexOf("_name")));
}
if (obj.get("name").indexOf("npctrait_") !== -1 && obj.get("name").indexOf("_name") !== -1){
npcTraitIds.push(obj.get("name").substr(0,obj.get("name").indexOf("_name")));
}
if (obj.get("name").indexOf("npcaction-l_") !== -1 && obj.get("name").indexOf("_name") !== -1){
legendaryActionIds.push(obj.get("name").substr(0,obj.get("name").indexOf("_name")));
}
});
// Create arrays for individual spell levels
var lvl0 = new Array();
var lvl1 = new Array();
var lvl2 = new Array();
var lvl3 = new Array();
var lvl4 = new Array();
var lvl5 = new Array();
var lvl6 = new Array();
var lvl7 = new Array();
var lvl8 = new Array();
var lvl9 = new Array();
var npc = new Array();
// Sort rowIDs into spell levels
rowIDs.forEach(function(entry){
// Grab the spell level from attribute name repeating_spell-1
var lvl = entry.substr(16,1);
if(entry.indexOf("cantrip") >= 0){
lvl = "cantrip";
}
if(entry.indexOf("npc") >= 0){
lvl = "npc";
}
// Put spell into the correct spell level
switch (lvl) {
case "cantrip":
lvl0.push(entry);
break;
case "1":
lvl1.push(entry);
break;
case "2":
lvl2.push(entry);
break;
case "3":
lvl3.push(entry);
break;
case "4":
lvl4.push(entry);
break;
case "5":
lvl5.push(entry);
break;
case "6":
lvl6.push(entry);
break;
case "7":
lvl7.push(entry);
break;
case "8":
lvl8.push(entry);
break;
case "9":
lvl9.push(entry);
break;
case "npc":
npc.push(entry);
break;
}
});
var macroText = "/w "+characterName+" <div style='background-color:white;border: 1px solid rgb(126, 45, 64);padding: 5px;'><h3>@{"+characterName+"|character_name}</h3>";//@{selected|wtype}&{template:atk} {{rname=Spell List}} {{desc=SPELL LIST:<br><br>"; // Base macro text
var linkStyle = 'style="background-color: transparent;color:blue;padding:0;border:none;"';
var cellStyle = 'style="border-left: solid black 1px; border-right: solid black 1px; padding: 0 2px"';
var divider = '<hr style="border-top: solid #afafaf 1px; border-bottom: solid #8a8a8a 1px;margin: 6px;">'
// Add spells to macro by spell level
var addButtons = function(actionlist, name_suffix, action_suffix, title){
if (actionlist.length > 0)
{
var lvlText = "";
actionlist.forEach(function(entry) {
// Check for spell name attribute; was having orphaned row_id attributes creating buttons for repeating rows that didn't actually exist
if (_.isUndefined(getAttrByName(characterObj.get("_id"), entry + name_suffix)))
return;
if(lvlText){
lvlText += ", ";
}
lvlText = lvlText + "<a "+linkStyle+" href='~"+characterName+"|"+entry+action_suffix+"'>@{"+characterName+"|"+entry+name_suffix+"}</a>";
});
if (lvlText !== "")
macroText = macroText+title+": <br>"+ lvlText+"<br><br>";
}
}
macroText += divider;
if(getAttrByName(characterObj.get("_id"), "npc") == 1){
macroText += "<small style='color:black'>";
macroText += "<b>AC</b>: @{"+characterName+"|npc_ac} (@{"+characterName+"|npc_actype})<br>";
macroText += "<b>HP</b>: @{"+characterName+"|hp|max} (@{"+characterName+"|npc_hpformula})<br>";
macroText += "<b>Speed</b>: @{"+characterName+"|npc_speed}<br>";
macroText += "<b>Senses</b>: @{"+characterName+"|npc_senses}<br>";
macroText += "<b>Languages</b>: @{"+characterName+"|npc_languages}<br>";
macroText += "<b>CR</b>: @{"+characterName+"|npc_challenge} (@{"+characterName+"|npc_xp} XP)<br>";
macroText += "</small>"+divider;
macroText += "<table style='text-align:center;border-collapse: collapse;'><tr>";
macroText += "<td "+cellStyle+"><b>STR</b><br>@{"+characterName+"|strength} (@{"+characterName+"|strength_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|npc_str'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|npc_str_save'>Save</a> </small></td>";
macroText += "<td "+cellStyle+"><b>DEX</b><br>@{"+characterName+"|dexterity} (@{"+characterName+"|dexterity_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|npc_dex'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|npc_dex_save'>Save</a> </small></td>";
macroText += "<td "+cellStyle+"><b>CON</b><br>@{"+characterName+"|constitution} (@{"+characterName+"|constitution_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|npc_con'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|npc_con_save'>Save</a> </small></td>";
macroText += "<td "+cellStyle+"><b>WIS</b><br>@{"+characterName+"|wisdom} (@{"+characterName+"|wisdom_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|npc_wis'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|npc_wis_save'>Save</a> </small></td>";
macroText += "<td "+cellStyle+"><b>INT</b><br>@{"+characterName+"|intelligence} (@{"+characterName+"|intelligence_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|npc_int'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|npc_int_save'>Save</a> </small></td>";
macroText += "<td "+cellStyle+"><b>CHA</b><br>@{"+characterName+"|charisma} (@{"+characterName+"|charisma_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|npc_cha'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|npc_cha_save'>Save</a> </small></td></tr></table>";
macroText += divider+"<small>"
macroText += "<a "+linkStyle+" href='~"+characterName+"|npc_Acrobatics'>Acrobatics</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Animal_Handling'>Animal Handling</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Arcana'>Arcana</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Athletics'>Athletics</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Deception'>Deception</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_History'>History</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Insight'>Insight</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Intimidation'>Intimidation</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Investigation'>Investigation</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Medicine'>Medicine</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Nature'>Nature</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Perception'>Perception</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Performance'>Performance</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Persuasion'>Persuasion</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Religion'>Religion</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Sleight_of_Hand'>Sleight of Hand</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Stealth'>Stealth</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|npc_Survival'>Survival</a> </small>";
} else {
macroText += "<td "+cellStyle+"><b>STR</b><br>@{"+characterName+"|strength} (@{"+characterName+"|strength_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|strength'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|strength_save'>Save</a> </small></td>";
macroText += "<td "+cellStyle+"><b>DEX</b><br>@{"+characterName+"|dexterity} (@{"+characterName+"|dexterity_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|dexterity'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|dexterity_save'>Save</a> </small></td>";
macroText += "<td "+cellStyle+"><b>CON</b><br>@{"+characterName+"|constitution} (@{"+characterName+"|constitution_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|constitution'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|constitution_save'>Save</a> </small></td>";
macroText += "<td "+cellStyle+"><b>WIS</b><br>@{"+characterName+"|wisdom} (@{"+characterName+"|wisdom_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|wisdom'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|wisdom_save'>Save</a> </small></td>";
macroText += "<td "+cellStyle+"><b>INT</b><br>@{"+characterName+"|intelligence} (@{"+characterName+"|intelligence_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|intelligence'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|intelligence_save'>Save</a> </small></td>";
macroText += "<td "+cellStyle+"><b>CHA</b><br>@{"+characterName+"|charisma} (@{"+characterName+"|charisma_mod})<br>"
macroText += "<small><a "+linkStyle+" href='~"+characterName+"|charisma'>Check</a><br><a "+linkStyle+" href='~"+characterName+"|charisma_save'>Save</a> </small></td></tr></table>";
macroText += divider+"<small><a "+linkStyle+" href='~"+characterName+"|Acrobatics'>Acrobatics</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Animal_Handling'>Animal Handling</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Arcana'>Arcana</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Athletics'>Athletics</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Deception'>Deception</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|History'>History</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Insight'>Insight</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Intimidation'>Intimidation</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Investigation'>Investigation</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Medicine'>Medicine</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Nature'>Nature</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Perception'>Perception</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Performance'>Performance</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Persuasion'>Persuasion</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Religion'>Religion</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Sleight_of_Hand'>Sleight of Hand</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Stealth'>Stealth</a> ";
macroText += ", <a "+linkStyle+" href='~"+characterName+"|Survival'>Survival</a> </small>";
}
macroText += divider+"<h4>Spells</h4>";
addButtons(lvl0, "_spellname", "_spell", "Cantrips");
addButtons(lvl1, "_spellname", "_spell", "Level 1");
addButtons(lvl2, "_spellname", "_spell", "Level 2");
addButtons(lvl3, "_spellname", "_spell", "Level 3");
addButtons(lvl4, "_spellname", "_spell", "Level 4");
addButtons(lvl5, "_spellname", "_spell", "Level 5");
addButtons(lvl6, "_spellname", "_spell", "Level 6");
addButtons(lvl7, "_spellname", "_spell", "Level 7");
addButtons(lvl8, "_spellname", "_spell", "Level 8");
addButtons(lvl9, "_spellname", "_spell", "Level 9");
addButtons(npc, "_spellname", "_spell", "NPC");
macroText += divider+"<h4>Traits</h4>";
if (npcTraitIds.length > 0)
{
var text = "";
npcTraitIds.forEach(function(entry) {
// Check for spell name attribute; was having orphaned row_id attributes creating buttons for repeating rows that didn't actually exist
if (_.isUndefined(getAttrByName(characterObj.get("_id"), entry+"_name")))
return;
if(text){
text += ", ";
}
text = text + "<small style='color:black'><b>@{"+characterName+"|"+entry+"_name}:</b> "+"@{"+characterName+"|"+entry+"_desc}</small>";
});
if (text !== "")
macroText = macroText+ text+"<br>";
}
macroText += divider+"<h4>Actions</h4>";
addButtons(attackIds, "_atkname", "_attack", "Attacks");
addButtons(npcActionIds, "_name", "_npc_action", "NPC Actions");
addButtons(npcReactionIds, "_name", "_npc_action", "NPC Reactions");
addButtons(legendaryActionIds, "_name", "_npc_action", "Legendary Actions");
macroText += "</div>"
sendChat("Statblock",macroText, null, {noarchive:true});
});
}
});