Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Reliable Talent test for future Token Action Maker update
- // type !rtTest to run the script - if the selected character has any levels
- // in Rogue, it should create the RT version of the Ability Check drop-down.
- // Only one 3d die will be thrown when using the RT version.
- const tokenActionUpdate = (() => { // eslint-disable-line no-unused-vars
- const handleInput = (msg) => {
- if (msg.type === 'api' && msg.content.match(/^!rtTest/i)) {
- let chars = getSelectedCharacters(msg.selected);
- if (!chars || chars.length < 1) return sendChat('','Nothing selected!');
- let c = chars[0];
- let reliableTalent = isRogue(c.id);
- let npcFlag = isNpc(c.id);
- createAbility('AbilityCheck', createDropDown('ability', reliableTalent, npcFlag), c.id);
- createAbility('SavingThrow', createDropDown('save', reliableTalent, npcFlag), c.id);
- if (reliableTalent) {
- createAttribute('rtypeRT', '@{rtype}0]]}} {{r2=[[@{d20RT}', '', c.id);
- createAttribute('d20RT', '{[[1d20]]', '', c.id);
- }
- sendChat('', `Ability created on ${c.get('name')}. Character has Rogue levels?? **${reliableTalent}.**`)
- }
- }
- const getSelectedCharacters = function(selected) {
- return _.chain(selected)
- .map(function(s) {
- return getObj(s._type, s._id);
- })
- .reject(_.isUndefined)
- .map(function(c) {
- return getObj('character', c.get('represents'));
- })
- .filter(_.identity)
- .value();
- }
- const isNpc = function(id) {
- var checkNpc = findObjs({
- _type: 'attribute',
- _characterid: id,
- name: 'npc'
- });
- if (_.isUndefined(checkNpc[0])) {
- return false;
- } else {
- return checkNpc[0].get('current');
- }
- }
- const createAbility = function(name, pattern, id, isTokenAction = true) {
- var checkAbility = findObjs({
- _type: 'ability',
- _characterid: id,
- name: name
- });
- if (checkAbility[0]) {
- checkAbility[0].set({
- action: pattern
- });
- } else {
- createObj('ability', {
- name: name,
- action: pattern,
- characterid: id,
- istokenaction: isTokenAction
- });
- }
- }
- const isRogue = (charId) => {
- let classes = [];
- classes = findObjs({type: 'attribute', characterid: charId})
- .filter((attr) => (attr.get('name').match(/multiclass\d\b/i) || attr.get('name').match(/^class\b/i)))
- .map((attr) => attr.get('current'));
- if (classes.some((attr) => attr.match(/rogue/i))) return true;
- else return false;
- }
- const createAttribute = (attrName, attrCurrent = '', attrMax = '', charId) => {
- let attr = findObjs({characterid: charId, name: attrName});
- if (attr.length > 0) {
- attr[0].set({current: attrCurrent, max: attrMax});
- } else {
- createObj('attribute', {characterid: charId, name: attrName, current: attrCurrent, max: attrMax});
- log(`Attribute ${attrName} created on ${charId} . Current value: ${attrCurrent}}`);
- }
- }
- const createDropDown = (checkType, reliableTalent = false, npc = false) => {
- const skillLabels = ['Acrobatics','Animal Handling','Arcana','Athletics','Deception','History','Insight','Intimidation','Investigation','Medicine','Nature','Perception','Performance','Persuasion','Religion','Sleight Of Hand','Stealth','Survival'];
- const skillArray = skillLabels.map(a => a.replace(/\s/g,'_'))
- const abilityArray = ['Strength','Dexterity','Constitution','Intelligence','Wisdom','Charisma'];
- const npcSaveArray = abilityArray.map((ab) => ab.slice(0,3).toUpperCase());
- let skillMacroArray = [], abilityMacroArray = [], saveMacroArray = [];
- let rtype = (reliableTalent) ? 'rtypeRT' : 'rtype'; // Reliable Talent variables
- let d20 = (reliableTalent) ? 'd20RT' : 'd20'; //
- let template = (npc) ? 'npc' : 'simple'; // NPC variables
- let npcPrefix = (npc) ? 'npc_' : ''; //
- let pcSuffix = (npc) ? '' : '_bonus'; //
- let npcName = (npc) ? '@{selected|npc_name_flag}' : ''; //
- let saveArray = (npc) ? npcSaveArray : abilityArray; //
- if (checkType === 'ability') { // Skills
- for (let i=0; i < skillArray.length; i++) {
- let RTkh1 = (reliableTalent) ? `,[[@{selected|reliable_talent}*ceil(@{selected|${skillArray[i]}_prof}/100)]][RT]}k1` : ''; // Reliable talent calculation
- skillMacroArray.push(`|${skillLabels[i]},${RTkh1}+@{selected|${npcPrefix}${skillArray[i]}${pcSuffix}}@{selected|pbd_safe}[${(skillLabels[i]+' ').slice(0,skillLabels[i].indexOf(' '))}]]]}} {{rname=${skillLabels[i]}}} {{mod=@{selected|${npcPrefix}${skillArray[i]}${pcSuffix}}}} {{r1=[[@{selected|${d20}}${RTkh1} + @{selected|${npcPrefix}${skillArray[i]}${pcSuffix}}@{selected|pbd_safe}[${(skillLabels[i]+' ').slice(0,skillLabels[i].indexOf(' '))}]]]`)
- }
- for (let i=0; i < abilityArray.length; i++) { // Abilities w JOAT and Globals
- let RTAbilityFudge = (reliableTalent) ? ',0}k1' : ''; // Reliable Talent fix
- abilityMacroArray.push(`|${abilityArray[i]},${RTAbilityFudge}+@{selected|${abilityArray[i]}_mod}@{selected|jack_attr}[${npcSaveArray[i]}]]]}} {{rname=${abilityArray[i]}}} {{mod=@{selected|${abilityArray[i]}_mod}@{selected|jack_bonus}}} {{r1=[[ @{selected|d20} + @{selected|${abilityArray[i]}_mod}@{selected|jack_attr}[${npcSaveArray[i]}]]]`);
- }
- let AbilityMacro = `@{selected|wtype}&{template:${template}} ${npcName} @{selected|${rtype}}?{Ability${skillMacroArray.join('')}${abilityMacroArray.join('')}}}} {{global=@{selected|global_skill_mod}}} {{type=Check}} {{typec=Check}} @{selected|charname_output}`;
- return AbilityMacro;
- }
- if (checkType === 'save') { // Saves
- for (let i=0; i < abilityArray.length; i++) {
- saveMacroArray.push(`|${abilityArray[i]}, +@{selected|${npcPrefix}${saveArray[i]}_save${pcSuffix}}@{selected|pbd_safe}[${npcSaveArray[i]} SAVE]]]}} {{rname=${abilityArray[i]} Save}} {{mod=@{selected|${abilityArray[i]}_save_bonus}}} {{r1=[[@{selected|d20}+@{selected|${npcPrefix}${saveArray[i]}_save${pcSuffix}}@{selected|pbd_safe}[${npcSaveArray[i]} SAVE]]]`);
- }
- let SaveMacro = `@{selected|wtype}&{template:${template}} ${npcName} @{selected|rtype}?{Saving Throw${saveMacroArray.join('')}}}} {{global=@{selected|global_save_mod}}} {{type=Save}} {{typec=Save}} @{selected|charname_output}`;
- return SaveMacro;
- }
- }
- const registerEventHandlers = () => {
- on('chat:message', handleInput);
- }
- on('ready', () => {
- //checkInstall();
- registerEventHandlers();
- });
- return;
- })();
Add Comment
Please, Sign In to add comment