Created
September 4, 2019 01:48
-
-
Save Bastlifa/e3b9f1d670cf24c8c7b17a06b2f2c50b to your computer and use it in GitHub Desktop.
Combat Maneuver Batch Adder for Roll20 PF1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add other maneuvers as desired. | |
// Select PC tokens tokens, hit !CombatManeuverBatch | |
var generateUUID = (function() { | |
"use strict"; | |
var a = 0, b = []; | |
return function() { | |
var c = (new Date()).getTime() + 0, d = c === a; | |
a = c; | |
for (var e = new Array(8), f = 7; 0 <= f; f--) { | |
e[f] = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".charAt(c % 64); | |
c = Math.floor(c / 64); | |
} | |
c = e.join(""); | |
if (d) { | |
for (f = 11; 0 <= f && 63 === b[f]; f--) { | |
b[f] = 0; | |
} | |
b[f]++; | |
} else { | |
for (f = 0; 12 > f; f++) { | |
b[f] = Math.floor(64 * Math.random()); | |
} | |
} | |
for (f = 0; 12 > f; f++){ | |
c += "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".charAt(b[f]); | |
} | |
return c; | |
}; | |
}()), | |
generateRowID = function () { | |
"use strict"; | |
return generateUUID().replace(/_/g, "Z"); | |
}; | |
on("ready", function() { | |
on("chat:message", function (msg) { | |
if (msg.type === "api" && playerIsGM(msg.playerid) && msg.content === "!CombatManeuverBatch") | |
{ | |
combatManeuverAdd(msg); | |
} | |
}); | |
}); | |
const sc = str => sendChat("", `${str}`) | |
const combatManeuverAdd = msg => | |
{ | |
if(!msg.selected) | |
{ | |
sc("Please select one or more representative tokens before the api command") | |
return | |
} | |
msg.selected.forEach((token, index) => | |
{ | |
if(!getObj(msg.selected[index]._type,msg.selected[index]._id).get('represents')) | |
{ | |
sc(`${getObj(msg.selected[index]._type,msg.selected[index]._id).get('name')} is not representative`) | |
return | |
} | |
else | |
{ | |
let reps = getObj(msg.selected[index]._type,msg.selected[index]._id).get('represents') | |
generateManeuvers(reps) | |
} | |
}) | |
} | |
const generateManeuvers = reps => | |
{ | |
maneuvers.forEach(man => | |
{ | |
const data = {}; | |
const repString = `repeating_attacks_${generateRowID()}`; | |
Object.keys(man).forEach(field => { | |
log(`field: ${field}`) | |
data[`${repString}_${field}`] = man[field]; | |
}); | |
// set attributes | |
setAttrs(reps, data); | |
}) | |
} | |
const maneuvers = | |
[ | |
{ | |
atkname: "Bull Rush", | |
atktype: "cmb", | |
atkvs: "cmd", | |
dmgflag: "unchecked", | |
atkrange: "5 ft", | |
category: "Combat Maneuver", | |
descflag: "checked", | |
atkdesc: "You snort and stamp your feet before goring someone with your horns.\n I didn't want to put the text in, for copyright concerns. I know it's OGL, but not sure exactly what that means." | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment