Last active
August 29, 2015 14:06
-
-
Save BaldarSilveraxe/38819267c88e611f28eb to your computer and use it in GitHub Desktop.
E Spell Management System
This file contains 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
var roll20API = roll20API || {}; | |
roll20API.AbjurationURL = "https://s3.amazonaws.com/files.d20.io/images/5586844/rcLDFgVjvGTtePvJ-681pg/thumb.png?1410738695"; | |
roll20API.ConjurationURL = "https://s3.amazonaws.com/files.d20.io/images/5586847/n156karksxGXY0nzUEyk9w/thumb.png?1410738696"; | |
roll20API.DivinationURL = "https://s3.amazonaws.com/files.d20.io/images/5586852/qSdZ682ZbKyjNxN2LjkSOw/thumb.png?1410738699"; | |
roll20API.EnchantmentURL = "https://s3.amazonaws.com/files.d20.io/images/5586853/JddRZXofOfQcliHENYbO4w/thumb.png?1410738699"; | |
roll20API.EvocationURL = "https://s3.amazonaws.com/files.d20.io/images/5586855/FWcn_55a8FUI5PL0uwyzDg/thumb.png?1410738700"; | |
roll20API.IllusionURL = "https://s3.amazonaws.com/files.d20.io/images/5586836/hPFiw2NZd_NBus7dp3gTNQ/thumb.png?1410738691"; | |
roll20API.NecromancyURL = "https://s3.amazonaws.com/files.d20.io/images/5586835/1ybbxZinU7bItV07K5nWUA/thumb.png?1410738691"; | |
roll20API.TransmutationURL = "https://s3.amazonaws.com/files.d20.io/images/5586840/vb2wuxATZKDCmBJ2GmTowA/thumb.png?1410738692"; | |
roll20API.UnkownURL = "https://s3.amazonaws.com/files.d20.io/images/5586843/3_UFc8afBl__yv0UyHRRXg/thumb.png?1410738695"; | |
roll20API.DeprecateURL = "https://s3.amazonaws.com/files.d20.io/images/5586850/VpJP6Gvz4RqEIpJCveqCrg/thumb.png?1410738698"; | |
roll20API.OnAbjurationURL = "https://s3.amazonaws.com/files.d20.io/images/5586846/RV-2F4b5tb5QGljb7Gcveg/thumb.png?1410738696"; | |
roll20API.OnConjurationURL = "https://s3.amazonaws.com/files.d20.io/images/5586848/o-BHG05ZR7nxI16aNvQerA/thumb.png?1410738696"; | |
roll20API.OnDivinationURL = "https://s3.amazonaws.com/files.d20.io/images/5586851/OqOsustmCvsfyvr16j1ueA/thumb.png?1410738698"; | |
roll20API.OnEnchantmentURL = "https://s3.amazonaws.com/files.d20.io/images/5586854/NIHto3av0SA2_8z8uyABYA/thumb.png?1410738700"; | |
roll20API.OnEvocationURL = "https://s3.amazonaws.com/files.d20.io/images/5586857/J93MU6POMATPBcgc-wEH8g/thumb.png?1410738702"; | |
roll20API.OnIllusionURL = "https://s3.amazonaws.com/files.d20.io/images/5586837/Euq27Q1V6pki3c4IqEWnyw/thumb.png?1410738692"; | |
roll20API.OnNecromancyURL = "https://s3.amazonaws.com/files.d20.io/images/5586839/I0elpvEphthLqLeOgJA2pQ/thumb.png?1410738692"; | |
roll20API.OnTransmutationURL = "https://s3.amazonaws.com/files.d20.io/images/5586838/y8_IF2-3rmo9ngqRuzarxg/thumb.png?1410738692"; | |
roll20API.OnUnkownURL = "https://s3.amazonaws.com/files.d20.io/images/5586845/hpQOic5OYyEwod3dhb3auw/thumb.png?1410738695"; | |
roll20API.spellbooks = [ | |
{Class: "Barbarian", Short: "BN", Name: "barbarian_level", SaveDC: "0", StatBonus:"0", Stat: "0", Gained: "Other Source"}, | |
{Class: "Bard", Short: "BD", Name: "bard_level", SaveDC: "bard_spell_dc", StatBonus:"charisma_mod", Stat: "charisma", Gained: "Bard"}, | |
{Class: "Cleric", Short: "CC", Name: "cleric_level", SaveDC: "cleric_spell_dc", StatBonus:"wisdom_mod", Stat: "wisdom", Gained: "Cleric"}, | |
{Class: "Druid", Short: "DD", Name: "druid_level", SaveDC: "druid_spell_dc", StatBonus:"wisdom_mod", Stat: "wisdom", Gained: "Druid"}, | |
{Class: "Fighter", Short: "FR", Name: "fighter_level", SaveDC: "eldritch_knight_spell_dc", StatBonus:"intelligence_mod", Stat: "intelligence", Gained: "Eldritch Knight"}, | |
{Class: "Monk", Short: "MK", Name: "monk_level", SaveDC: "0", StatBonus:"wisdom_mod", Stat: "wisdom", Gained: "Other Source"}, | |
{Class: "Paladin", Short: "PN", Name: "paladin_level", SaveDC: "paladin_spell_dc", StatBonus:"charisma_mod", Stat: "charisma", Gained: "Paladin"}, | |
{Class: "Ranger", Short: "RR", Name: "ranger_level", SaveDC: "ranger_spell_dc", StatBonus:"wisdom_mod", Stat: "wisdom", Gained: "Ranger"}, | |
{Class: "Rogue", Short: "RE", Name: "rogue_level", SaveDC: "arcane_trickster_spell_dc", StatBonus:"intelligence_mod", Stat: "intelligence", Gained: "Arcane Trickster"}, | |
{Class: "Sorcerer", Short: "SR", Name: "sorcerer_level", SaveDC: "sorcerer_spell_dc", StatBonus:"charisma_mod", Stat: "charisma", Gained: "Sorcerer"}, | |
{Class: "Warlock", Short: "WK", Name: "warlock_level", SaveDC: "warlock_spell_dc", StatBonus:"charisma_mod", Stat: "charisma", Gained: "Warlock"}, | |
{Class: "Wizard", Short: "WD", Name: "wizard_level", SaveDC: "wizard_spell_dc", StatBonus:"intelligence_mod", Stat: "intelligence", Gained: "Wizard"} | |
]; | |
var characters = []; | |
on("ready", function() { | |
on("chat:message", function (msg) { | |
// Exit if not an api command | |
if (msg.type != "api") return; | |
// Get the API Chat Command | |
msg.who = msg.who.replace(" (GM)", ""); | |
msg.content = msg.content.replace("(GM) ", ""); | |
var command = msg.content.split(" ", 1); | |
if(command == "!spellbooksY" || command == "!spellbooksy") { | |
spellbooks(); | |
}; | |
if(command == "!updatespellY" || command == "!updatespelly") { | |
updatespell(); | |
}; | |
if(command == "!updatelistY" || command == "!updatelisty") { | |
updateList(); | |
}; | |
if(command == "!getvalues" || command == "!getvalues") { | |
getvalues(); | |
}; | |
}); | |
}); | |
//--Utility Function | |
var fixNewObject = fixNewObject || function(obj){ | |
var p = obj.changed._fbpath; | |
var new_p = p.replace(/([^\/]*\/){4}/, "/"); | |
obj.fbpath = new_p; | |
return obj; | |
}; | |
roll20API.spelllist = [ | |
{ | |
Call:"acid_splash", | |
Name:"Acid Splash", | |
Class:"Sorcerer,Wizard", | |
SubClass:"", | |
Ritual:"N", | |
Concentration:"N", | |
Level:"0", | |
School:"Conjuration", | |
Component:"V,S", | |
Material:"", | |
Range:"60 feet", | |
CastingTime:"1 action", | |
Duration:"Instantaneous", | |
Description:"I hurl a bubble of acid. Choose one creature within range, or choose two creatures within range that are within 5 feet of each other. A target must succeed on a Dexterity saving throw or take 1d6 acid damage.", | |
HigherLevel:"This spell's damage increases by 1d6 when I reach 5th level (2d6), 11th level (3d6), and 17th level (4d6).", | |
Effect:"I target **@{target|t1|token_name}**, and **@{target|t2|token_name}** who is within 5 feet. --Make a DEX save|vs [[8+@{selected|spellcastingability}+@{selected|PB}]] --Failed Save|[[1d6+{floor((@{level})/5),1}kl1*1d6+{floor((@{level})/11),1}kl1*1d6+{floor((@{level})/17),1}kl1*1d6]] acid damage.", | |
PowerCard:"I hurl a bubble of acid. --text1|^*Choose one creature within range, or choose two creatures within range that are within 5 feet of each other. --text2|^*A target must succeed on a **Dexterity Saving Throw** or take **1d6 Acid Damage**." | |
}, | |
{ | |
Call:"blade_ward", | |
Name:"Blade Ward", | |
Class:"Bard,Sorcerer,Warlock,Wizard", | |
SubClass:"", | |
Ritual:"N", | |
Concentration:"N", | |
Level:"0", | |
School:"Abjuration", | |
Component:"V,S", | |
Material:"", | |
Range:"Self", | |
CastingTime:"1 action", | |
Duration:"1 round", | |
Description:"I extend my hand and trace a sigil of warding in the air. Until the end of my next turn, I have resistance against bludgeoning, piercing, and slashing damage dealt by weapon attacks.", | |
HigherLevel:"", | |
Effect:"", | |
PowerCard:"I extend my hand and trace a sigil of warding in the air. --text1|^*Until the end of my next turn, I have **Resistance** against Bludgeoning, Piercing, and Slashing damage dealt by weapon attacks." | |
}, | |
{ | |
Call:"chill_touch", | |
Name:"Chill Touch", | |
Class:"Sorcerer,Warlock,Wizard", | |
SubClass:"", | |
Ritual:"N", | |
Concentration:"N", | |
Level:"0", | |
School:"Necromancy", | |
Component:"V,S", | |
Material:"", | |
Range:"120 feet", | |
CastingTime:"1 action", | |
Duration:"1 round", | |
Description:"I create a ghostly, skeletal hand in the space of a creature within range. I make a ranged spell attack against the creature to assail it with the chill of the grave. On a hit, the target takes 1d8 necrotic damage, and it can't regain hit points until the start of my next turn. Until then, the hand clings to the target. If I hit an undead target, it also has disadvantage on attack rolls against me until the end of my next turn. ", | |
HigherLevel:"The spell’s damage increases by 1d8 when I reach 5th level (2d8), 11th level (3d8), and 17th level (4d8).", | |
Effect:"My conjured ghostly hand attacks **@{target|t1|token_name}**. --Ranged Attack|[[1d20+@{selected|spellcastingability}+@{selected|PB}]]|[[1d20+@{selected|spellcastingability}+@{selected|PB}]] vs. AC --On Hit|[[1d8+{floor((@{level})/5),1}kl1*1d8+{floor((@{level})/11),1}kl1*1d8+{floor((@{level})/17),1}kl1*1d8]] necrotic damage, and it can't regain hit points until the start of my next turn.", | |
PowerCard:"I create a ghostly, skeletal hand in the space of a creature within range. --text1|^*I make a **Ranged Spell Attack** against the creature to assail it with the chill of the grave. --text2|^*On a hit, the target takes **1d8 Necrotic Damage**, and it can't regain hit points until the start of my next turn. --text3|^*Until then, the hand clings to the target. If I hit an **Undead** target, it also has **Disadvantage** on attack rolls against me until the end of my next turn." | |
} | |
]; | |
spellbooks = function() { | |
//Find CharactersByGraphics on Spell Book page. | |
findCharacterByGraphics(); | |
//Checks for and Creates a Rollable Table as a Spell List | |
checkCreateSpellListTable(); | |
//Finds all the Classes a Character has and builds a spell list. | |
getCurrentSpellList(); | |
//builds all the spells as items on the tables | |
buildTableItems(); | |
//Deprecates extra spells | |
deprecateSpells(); | |
//Clean up the sort of the table | |
sortTable(); | |
}; | |
findCharacterByGraphics = function() { | |
characters = []; | |
var pageCheck = findObjs({type: "page", name: "Spell Book"}) | |
if(pageCheck.length != 1){ | |
var errorTxt = "/direct <hr>█▓▒░SETUP ERROR!░▒▓█ <br><small>" | |
if(pageCheck.length == 0){errorTxt += "Spell Book page does not exist.</small><hr>" | |
}else{errorTxt += "Multiple Spell Book pages exist.</small><hr>"}; | |
sendChat("API", errorTxt) | |
return | |
}; | |
var spellBookPageGraphics = findObjs({ | |
_pageid: findObjs({type: "page", name: "Spell Book"})[0].get("_id"), | |
_type: "graphic", | |
}); | |
var spellBookExists = false; | |
_.each(spellBookPageGraphics, function(indexSpellBookPageGraphics) { | |
var character = findObjs({type: "character", _id: indexSpellBookPageGraphics.get("represents")}); | |
if(character[0].get("name") == "Spell Book"){spellBookExists = true}; | |
if(character[0].get("name") != "Spell Book"){ | |
characters.push(character); | |
}; | |
}); | |
if(spellBookExists == false){ | |
sendChat("API", "/direct <hr>█▓▒░SETUP ERROR!░▒▓█ <br><small>Spell Book not found.</small><hr>") | |
return | |
}; | |
}; | |
checkCreateSpellListTable = function() { | |
var rollabletables = findObjs({type: "rollabletable"}); | |
_.each(characters, function(indexCharacters) { | |
var characterID = indexCharacters[0].get("_id"); | |
var characterName = indexCharacters[0].get("name").replace(/[^a-zA-Z ]/g, ""); | |
characterName = characterName.split(' ').join('-'); | |
var tableFound = false; | |
var tableID = ""; | |
_.each(rollabletables, function(indexrollabletables) { | |
if(tableFound == false){ | |
var rollabletableName = indexrollabletables.get("name"); | |
var start_pos = rollabletableName.indexOf("{") + 1; | |
var end_pos = rollabletableName.indexOf("}",start_pos); | |
var characterIDfound = rollabletableName.substring(start_pos,end_pos); | |
if(characterIDfound == characterID){tableFound = true; tableID = indexrollabletables.get("_id");}; | |
}; | |
}); | |
if(tableFound == false){ | |
var nameToUse = characterName+"{"+characterID+"}"; | |
createObj("rollabletable", {name: nameToUse, showplayers: false,}); | |
tableID = findObjs( {_type: "rollabletable", name: nameToUse})[0].get("_id"); | |
tableFound = true; | |
}; | |
}); | |
}; | |
getCurrentSpellList = function() { | |
var classString; | |
roll20API.spellListClass = ""; | |
roll20API.spellListClass = []; | |
_.each(characters, function(indexCharacters) { | |
var characterID = indexCharacters[0].get("_id"); | |
var characterName = indexCharacters[0].get("name").replace(/[^a-zA-Z ]/g, ""); | |
characterName = characterName.split(' ').join('-'); | |
classString = ""; | |
_.each(roll20API.spellbooks, function(indexBooks) { | |
var characterSheet = getObj("character", characterID); | |
var CurrentLevel = getAttrByName(characterSheet.id, indexBooks.Name) * 1; | |
if(CurrentLevel > 0){classString += indexBooks.Class + ","}; | |
}); | |
classString = classString.substring(0, classString.length - 1); | |
if(classString.length > 0){ | |
_.each(roll20API.spelllist, function(indexSpells) { | |
var spellFound = false; | |
var arr1 = indexSpells.Class.split(","); | |
var arr2 = classString.split(","); | |
for (var i = 0; i < arr1.length; i++) { | |
for (var j = 0; j < arr2.length; j++) { | |
if (arr1[i] === arr2[j]) { | |
if(spellFound == false){ | |
roll20API.spellListClass.push({ID: characterID, Level: indexSpells.Level, School: indexSpells.School, Call: indexSpells.Call}); | |
spellFound = true; | |
}; | |
}; | |
}; | |
}; | |
}); | |
}; | |
}); | |
}; | |
buildTableItems = function() { | |
var rollabletables = findObjs({type: "rollabletable"}); | |
_.each(characters, function(indexCharacters) { | |
var characterID = indexCharacters[0].get("_id"); | |
var characterName = indexCharacters[0].get("name").replace(/[^a-zA-Z ]/g, ""); | |
characterName = characterName.split(' ').join('-'); | |
_.each(rollabletables, function(indexrollabletables) { | |
var rollabletableName = indexrollabletables.get("name"); | |
var start_pos = rollabletableName.indexOf("{") + 1; | |
var end_pos = rollabletableName.indexOf("}",start_pos); | |
var characterIDfound = rollabletableName.substring(start_pos,end_pos); | |
if(characterIDfound == characterID){ | |
var tableItems = findObjs({ _type: "tableitem", _rollabletableid: indexrollabletables.get("_id")}); | |
if(tableItems.length != 0){ | |
_.each(roll20API.spellListClass, function(indexPlayerSpells) { | |
var spellFoundAsItem = false; | |
var itemName = indexPlayerSpells.Level + "_" + indexPlayerSpells.Call; | |
_.each(tableItems, function(indextListedSpells) { | |
if(indextListedSpells.get("name") == itemName){spellFoundAsItem = true}; | |
}); | |
if(spellFoundAsItem == false){ | |
var checkFor999 = false; | |
_.each(tableItems, function(indextListedSpells) { | |
if(checkFor999 == false && indextListedSpells.get("name").substring(0, 3) == "999"){ | |
checkFor999 = true; | |
spellFoundAsItem = true; | |
var itemID = indextListedSpells.get("_id") | |
var avatarURL = roll20API.UnkownURL; | |
if(indexPlayerSpells.School == "Abjuration"){avatarURL = roll20API.AbjurationURL}; | |
if(indexPlayerSpells.School == "Conjuration"){avatarURL = roll20API.ConjurationURL}; | |
if(indexPlayerSpells.School == "Divination"){avatarURL = roll20API.DivinationURL}; | |
if(indexPlayerSpells.School == "Enchantment"){avatarURL = roll20API.EnchantmentURL}; | |
if(indexPlayerSpells.School == "Evocation"){avatarURL = roll20API.EvocationURL}; | |
if(indexPlayerSpells.School == "Illusion"){avatarURL = roll20API.IllusionURL}; | |
if(indexPlayerSpells.School == "Necromancy"){avatarURL = roll20API.NecromancyURL}; | |
if(indexPlayerSpells.School == "Transmutation"){avatarURL = roll20API.TransmutationURL}; | |
var itemName = indexPlayerSpells.Level + "_" + indexPlayerSpells.Call; | |
findObjs({ _type: "tableitem", _id: itemID })[0].set({name: itemName}); | |
findObjs({ _type: "tableitem", _id: itemID })[0].set({avatar: avatarURL}) | |
findObjs({ _type: "tableitem", _id: itemID })[0].set({weight: 0}) | |
}; | |
}); | |
}; | |
if(spellFoundAsItem == false){ | |
var avatarURL = roll20API.UnkownURL; | |
if(indexPlayerSpells.School == "Abjuration"){avatarURL = roll20API.AbjurationURL}; | |
if(indexPlayerSpells.School == "Conjuration"){avatarURL = roll20API.ConjurationURL}; | |
if(indexPlayerSpells.School == "Divination"){avatarURL = roll20API.DivinationURL}; | |
if(indexPlayerSpells.School == "Enchantment"){avatarURL = roll20API.EnchantmentURL}; | |
if(indexPlayerSpells.School == "Evocation"){avatarURL = roll20API.EvocationURL}; | |
if(indexPlayerSpells.School == "Illusion"){avatarURL = roll20API.IllusionURL}; | |
if(indexPlayerSpells.School == "Necromancy"){avatarURL = roll20API.NecromancyURL}; | |
if(indexPlayerSpells.School == "Transmutation"){avatarURL = roll20API.TransmutationURL}; | |
var itemName = indexPlayerSpells.Level + "_" + indexPlayerSpells.Call; | |
if(characterID == indexPlayerSpells.ID){ | |
marker = createObj("tableitem", { | |
_rollabletableid: indexrollabletables.get("_id"), | |
name: itemName, | |
avatar: avatarURL, | |
weight: 0, | |
}); | |
marker=fixNewObject(marker); | |
}; | |
}; | |
}); | |
}else{ | |
_.each(roll20API.spellListClass, function(indexPlayerSpells) { | |
var avatarURL = roll20API.UnkownURL; | |
if(indexPlayerSpells.School == "Abjuration"){avatarURL = roll20API.AbjurationURL}; | |
if(indexPlayerSpells.School == "Conjuration"){avatarURL = roll20API.ConjurationURL}; | |
if(indexPlayerSpells.School == "Divination"){avatarURL = roll20API.DivinationURL}; | |
if(indexPlayerSpells.School == "Enchantment"){avatarURL = roll20API.EnchantmentURL}; | |
if(indexPlayerSpells.School == "Evocation"){avatarURL = roll20API.EvocationURL}; | |
if(indexPlayerSpells.School == "Illusion"){avatarURL = roll20API.IllusionURL}; | |
if(indexPlayerSpells.School == "Necromancy"){avatarURL = roll20API.NecromancyURL}; | |
if(indexPlayerSpells.School == "Transmutation"){avatarURL = roll20API.TransmutationURL}; | |
var itemName = indexPlayerSpells.Level + "_" + indexPlayerSpells.Call; | |
if(characterID == indexPlayerSpells.ID){ | |
marker = createObj("tableitem", { | |
_rollabletableid: indexrollabletables.get("_id"), | |
name: itemName, | |
avatar: avatarURL, | |
weight: 0, | |
}); | |
marker=fixNewObject(marker); | |
}; | |
}); | |
}; | |
}; | |
}); | |
}); | |
}; | |
deprecateSpells = function() { | |
var rollabletables = findObjs({type: "rollabletable"}); | |
_.each(characters, function(indexCharacters) { | |
var characterID = indexCharacters[0].get("_id"); | |
var characterName = indexCharacters[0].get("name").replace(/[^a-zA-Z ]/g, ""); | |
characterName = characterName.split(' ').join('-'); | |
_.each(rollabletables, function(indexrollabletables) { | |
var rollabletableName = indexrollabletables.get("name"); | |
var start_pos = rollabletableName.indexOf("{") + 1; | |
var end_pos = rollabletableName.indexOf("}",start_pos); | |
var characterIDfound = rollabletableName.substring(start_pos,end_pos); | |
if(characterIDfound == characterID){ | |
var tableItems = findObjs({ _type: "tableitem", _rollabletableid: indexrollabletables.get("_id")}); | |
if(tableItems.length != 0){ | |
_.each(tableItems, function(indextListedSpells) { | |
var validSpell = false; | |
_.each(roll20API.spellListClass, function(indexPlayerSpells) { | |
var itemName = indexPlayerSpells.Level + "_" + indexPlayerSpells.Call; | |
if(indextListedSpells.get("name") == itemName){validSpell = true}; | |
}); | |
if(validSpell == false){ | |
var itemID = indextListedSpells.get("_id") | |
findObjs({ _type: "tableitem", _id: itemID })[0].set({name: "999_deprecated"}); | |
findObjs({ _type: "tableitem", _id: itemID })[0].set({avatar: roll20API.DeprecateURL}); | |
findObjs({ _type: "tableitem", _id: itemID })[0].set({weight: -1}); | |
}; | |
}); | |
}; | |
}; | |
}); | |
}); | |
}; | |
sortTable = function() { | |
var rollabletables = findObjs({type: "rollabletable"}); | |
_.each(characters, function(indexCharacters) { | |
var characterID = indexCharacters[0].get("_id"); | |
var characterName = indexCharacters[0].get("name").replace(/[^a-zA-Z ]/g, ""); | |
characterName = characterName.split(' ').join('-'); | |
_.each(rollabletables, function(indexrollabletables) { | |
var rollabletableName = indexrollabletables.get("name"); | |
var start_pos = rollabletableName.indexOf("{") + 1; | |
var end_pos = rollabletableName.indexOf("}",start_pos); | |
var characterIDfound = rollabletableName.substring(start_pos,end_pos); | |
if(characterIDfound == characterID){ | |
var tableItems = findObjs({ _type: "tableitem", _rollabletableid: indexrollabletables.get("_id")}) | |
}; | |
roll20API.tobesorted = [] | |
_.each(tableItems, function(indextableItems) { | |
roll20API.tobesorted.push({ | |
name: indextableItems.get("name"), | |
avatar: indextableItems.get("avatar"), | |
weight: indextableItems.get("weight")}); | |
}); | |
sortedList = sortJSON(roll20API.tobesorted,"name"); | |
var j=0; | |
_.each(tableItems, function(indextableItems) { | |
var itemID = indextableItems.get("_id") | |
findObjs({ _type: "tableitem", _id: itemID })[0].set({name: roll20API.tobesorted[j].name}); | |
findObjs({ _type: "tableitem", _id: itemID })[0].set({avatar: roll20API.tobesorted[j].avatar}); | |
findObjs({ _type: "tableitem", _id: itemID })[0].set({weight: roll20API.tobesorted[j].weight}); | |
j++ | |
}); | |
}); | |
}); | |
}; | |
function sortJSON(data, key) { | |
return data.sort(function(a, b) { | |
var x = a[key]; var y = b[key]; | |
return ((x < y) ? -1 : ((x > y) ? 1 : 0)); | |
}); | |
}; | |
updatespell = function() { | |
//Find CharactersByGraphics on Spell Book page. | |
findCharacterByGraphics(); | |
//get Spell List From Table | |
getSpellListFromTable(); | |
}; | |
getSpellListFromTable = function() { | |
var rollabletables = findObjs({type: "rollabletable"}); | |
_.each(characters, function(indexCharacters) { | |
var characterID = indexCharacters[0].get("_id"); | |
var characterName = indexCharacters[0].get("name").replace(/[^a-zA-Z ]/g, ""); | |
characterName = characterName.split(' ').join('-'); | |
_.each(rollabletables, function(indexrollabletables) { | |
var rollabletableName = indexrollabletables.get("name"); | |
var start_pos = rollabletableName.indexOf("{") + 1; | |
var end_pos = rollabletableName.indexOf("}",start_pos); | |
var characterIDfound = rollabletableName.substring(start_pos,end_pos); | |
if(characterIDfound == characterID){ | |
var tableItems = findObjs({ _type: "tableitem", _rollabletableid: indexrollabletables.get("_id")}) | |
var j = -1; | |
var levelOfSpell = ""; | |
var lastLevel = ""; | |
_.each(tableItems, function(indextableItems) { | |
if(indextableItems.get("weight") > 0){ | |
levelOfSpell = indextableItems.get("name").substr(0, 1); | |
if(lastLevel != levelOfSpell){j = -1}; | |
j++ | |
var nameOfSpell = indextableItems.get("name").substr(2, indextableItems.get("name").length); | |
var countOfSpell = j; | |
lastLevel = levelOfSpell; | |
addSpellToSheet(levelOfSpell,nameOfSpell,countOfSpell,characterIDfound) | |
}; | |
}); | |
}; | |
}); | |
}); | |
}; | |
addSpellToSheet = function(levelOfSpell,nameOfSpell,countOfSpell,characterIDfound) { | |
var attributeName = ""; | |
if(levelOfSpell == 0){ | |
attributeNamePre = "repeating_spellbookcantrip_" + countOfSpell + "_"; | |
}else{ | |
attributeNamePre = "repeating_spellbooklevel" + levelOfSpell + "_" + countOfSpell + "_"; | |
}; | |
var spellData = _.findWhere(roll20API.spelllist, {Call: nameOfSpell}); | |
//Spell Information | |
var dataValue = spellData.Name; | |
var attributeName = attributeNamePre + "spellname"; | |
addSpellAttribute(dataValue,attributeName,characterIDfound); | |
var dataValue = spellData.School; | |
var attributeName = attributeNamePre + "spellschool"; | |
addSpellAttribute(dataValue,attributeName,characterIDfound); | |
var dataValue = spellData.CastingTime; | |
var attributeName = attributeNamePre + "spellcasttime"; | |
addSpellAttribute(dataValue,attributeName,characterIDfound); | |
var dataValue = spellData.Range; | |
var attributeName = attributeNamePre + "spellrange"; | |
addSpellAttribute(dataValue,attributeName,characterIDfound); | |
var dataValue = spellData.Component + spellData.Material; | |
var attributeName = attributeNamePre + "spellcomponents"; | |
addSpellAttribute(dataValue,attributeName,characterIDfound); | |
var dataValue = spellData.Duration; | |
var attributeName = attributeNamePre + "spellduration"; | |
addSpellAttribute(dataValue,attributeName,characterIDfound); | |
var dataValue = spellData.Description; | |
var attributeName = attributeNamePre + "spelldescription"; | |
addSpellAttribute(dataValue,attributeName,characterIDfound); | |
var dataValue = spellData.HigherLevel; | |
var attributeName = attributeNamePre + "spellhighersloteffect"; | |
addSpellAttribute(dataValue,attributeName,characterIDfound); | |
//Drop Downs | |
var dataValue = spellData.Ritual | |
if(dataValue == "N"){ | |
dataValue = ""; | |
}else{ | |
dataValue = "(Ritual)"; | |
}; | |
var attributeName = attributeNamePre + "spellritual"; | |
addSpellAttribute(dataValue,attributeName,characterIDfound); | |
var dataValue = spellData.Concentration | |
if(dataValue == "N"){ | |
dataValue = ""; | |
}else{ | |
dataValue = "(Concentration)"; | |
}; | |
var attributeName = attributeNamePre + "spellconcentration"; | |
addSpellAttribute(dataValue,attributeName,characterIDfound); | |
//Stat Bonus | |
var dataValue = spellData.Class | |
var attributeName = attributeNamePre + "healstatbonus"; | |
statBonus(dataValue,attributeName,characterIDfound); | |
var dataValue = spellData.Class | |
var attributeName = attributeNamePre + "attackstat"; | |
statBonus(dataValue,attributeName,characterIDfound); | |
var dataValue = spellData.Class | |
var attributeName = attributeNamePre + "damagestatbonus"; | |
statBonus(dataValue,attributeName,characterIDfound); | |
//Save DC | |
var dataValue = spellData.Class | |
var attributeName = attributeNamePre + "spellsavedc"; | |
saveDCfunction(dataValue,attributeName,characterIDfound); | |
//spell gained from | |
var dataValue = spellData.Class | |
var attributeName = attributeNamePre + "spellgainedfrom"; | |
gainfunction(dataValue,attributeName,characterIDfound); | |
//Token Action | |
var actionSpellName = spellData.Name.replace(/[^a-zA-Z ]/g, ""); | |
actionSpellName = actionSpellName.split(' ').join('-'); | |
var dataValue = "!power " + spellData.PowerCard; | |
var actionName = "[" + spellData.Level + "]-" + actionSpellName | |
addTokenAction(dataValue,actionName,characterIDfound) | |
}; | |
gainfunction = function(dataValue,attributeName,characterIDfound) { | |
var statArray = []; | |
_.each(roll20API.spellbooks, function(indexBooks) { | |
var CurrentLevel = getAttrByName(characterIDfound, indexBooks.Name) * 1; | |
if(CurrentLevel > 0){ | |
var givenStat = indexBooks.StatBonus; | |
var statValue = 0; | |
if(givenStat != "0"){ | |
var attributesExists = findObjs({type: "attribute", _characterid: characterIDfound, name: indexBooks.Stat}); | |
if(attributesExists.length > 0 ){ | |
statValue = attributesExists[0].get("current") * 1; | |
}; | |
}; | |
var classStatBouns = indexBooks.StatBonus; | |
statArray.push({ | |
Class: indexBooks.Class, | |
ClassLevel: indexBooks.Name, | |
Level: CurrentLevel, | |
StatBonus: classStatBouns, | |
Stat: indexBooks.Stat, | |
StatValue: statValue, | |
SaveDC: indexBooks.SaveDC, | |
SaveDCValue: 8 + (Math.round((5 + CurrentLevel) / 4)) + (Math.floor((statValue / 2) - 5)), | |
AttackMod: (Math.round((5 + CurrentLevel) / 4)) + (Math.floor((statValue / 2) - 5)), | |
Gained: indexBooks.Gained | |
}); | |
}; | |
}); | |
sortedStatArray = sortJSON(statArray,"AttackMod"); | |
var spellFoundByClass = false; | |
var SpellRecord = 0; | |
for (i = sortedStatArray.length - 1; i > -1; i = i - 1) { | |
if(spellFoundByClass == false){ | |
if(dataValue.indexOf(sortedStatArray[i].Class) > -1 ){ | |
spellFoundByClass = true | |
SpellRecord = i; | |
}; | |
}; | |
}; | |
dataValue = sortedStatArray[SpellRecord].Gained | |
var attributesExists = findObjs({type: "attribute", _characterid: characterIDfound, name: attributeName}); | |
if(attributesExists.length > 0 ){ | |
findObjs({ _type: "attribute", _id: attributesExists[0].get("_id") })[0].set({current: dataValue}); | |
}else{ | |
createObj("attribute", { | |
name: attributeName, | |
characterid: characterIDfound, | |
current: dataValue | |
}); | |
}; | |
}; | |
saveDCfunction = function(dataValue,attributeName,characterIDfound) { | |
var statArray = []; | |
_.each(roll20API.spellbooks, function(indexBooks) { | |
var CurrentLevel = getAttrByName(characterIDfound, indexBooks.Name) * 1; | |
if(CurrentLevel > 0){ | |
var givenStat = indexBooks.StatBonus; | |
var statValue = 0; | |
if(givenStat != "0"){ | |
var attributesExists = findObjs({type: "attribute", _characterid: characterIDfound, name: indexBooks.Stat}); | |
if(attributesExists.length > 0 ){ | |
statValue = attributesExists[0].get("current") * 1; | |
}; | |
}; | |
var classStatBouns = indexBooks.StatBonus; | |
statArray.push({ | |
Class: indexBooks.Class, | |
ClassLevel: indexBooks.Name, | |
Level: CurrentLevel, | |
StatBonus: classStatBouns, | |
Stat: indexBooks.Stat, | |
StatValue: statValue, | |
SaveDC: indexBooks.SaveDC, | |
SaveDCValue: 8 + (Math.round((5 + CurrentLevel) / 4)) + (Math.floor((statValue / 2) - 5)), | |
AttackMod: (Math.round((5 + CurrentLevel) / 4)) + (Math.floor((statValue / 2) - 5)), | |
Gained: indexBooks.Gained | |
}); | |
}; | |
}); | |
sortedStatArray = sortJSON(statArray,"AttackMod"); | |
var spellFoundByClass = false; | |
var SpellRecord = 0; | |
for (i = sortedStatArray.length - 1; i > -1; i = i - 1) { | |
if(spellFoundByClass == false){ | |
if(dataValue.indexOf(sortedStatArray[i].Class) > -1 ){ | |
spellFoundByClass = true | |
SpellRecord = i; | |
}; | |
}; | |
}; | |
dataValue = "@{" + sortedStatArray[SpellRecord].SaveDC + "}" | |
var attributesExists = findObjs({type: "attribute", _characterid: characterIDfound, name: attributeName}); | |
if(attributesExists.length > 0 ){ | |
findObjs({ _type: "attribute", _id: attributesExists[0].get("_id") })[0].set({current: dataValue}); | |
}else{ | |
createObj("attribute", { | |
name: attributeName, | |
characterid: characterIDfound, | |
current: dataValue | |
}); | |
}; | |
}; | |
statBonus = function(dataValue,attributeName,characterIDfound) { | |
var statArray = []; | |
_.each(roll20API.spellbooks, function(indexBooks) { | |
var CurrentLevel = getAttrByName(characterIDfound, indexBooks.Name) * 1; | |
if(CurrentLevel > 0){ | |
var givenStat = indexBooks.StatBonus; | |
var statValue = 0; | |
if(givenStat != "0"){ | |
var attributesExists = findObjs({type: "attribute", _characterid: characterIDfound, name: indexBooks.Stat}); | |
if(attributesExists.length > 0 ){ | |
statValue = attributesExists[0].get("current") * 1; | |
}; | |
}; | |
var classStatBouns = indexBooks.StatBonus; | |
statArray.push({ | |
Class: indexBooks.Class, | |
ClassLevel: indexBooks.Name, | |
Level: CurrentLevel, | |
StatBonus: classStatBouns, | |
Stat: indexBooks.Stat, | |
StatValue: statValue, | |
SaveDC: indexBooks.SaveDC, | |
SaveDCValue: 8 + (Math.round((5 + CurrentLevel) / 4)) + (Math.floor((statValue / 2) - 5)), | |
AttackMod: (Math.round((5 + CurrentLevel) / 4)) + (Math.floor((statValue / 2) - 5)), | |
Gained: indexBooks.Gained | |
}); | |
}; | |
}); | |
sortedStatArray = sortJSON(statArray,"AttackMod"); | |
var spellFoundByClass = false; | |
var SpellRecord = 0; | |
for (i = sortedStatArray.length - 1; i > -1; i = i - 1) { | |
if(spellFoundByClass == false){ | |
if(dataValue.indexOf(sortedStatArray[i].Class) > -1 ){ | |
spellFoundByClass = true | |
SpellRecord = i; | |
}; | |
}; | |
}; | |
dataValue = "@{" + sortedStatArray[SpellRecord].StatBonus + "}" | |
var attributesExists = findObjs({type: "attribute", _characterid: characterIDfound, name: attributeName}); | |
if(attributesExists.length > 0 ){ | |
findObjs({ _type: "attribute", _id: attributesExists[0].get("_id") })[0].set({current: dataValue}); | |
}else{ | |
createObj("attribute", { | |
name: attributeName, | |
characterid: characterIDfound, | |
current: dataValue | |
}); | |
}; | |
}; | |
addSpellAttribute = function(dataValue,attributeName,characterIDfound) { | |
var attributesExists = findObjs({type: "attribute", _characterid: characterIDfound, name: attributeName}); | |
if(attributesExists.length > 0 ){ | |
findObjs({ _type: "attribute", _id: attributesExists[0].get("_id") })[0].set({current: dataValue}); | |
}else{ | |
createObj("attribute", { | |
name: attributeName, | |
characterid: characterIDfound, | |
current: dataValue | |
}); | |
}; | |
}; | |
addTokenAction = function(dataValue,actionName,characterIDfound) { | |
var actionExists = findObjs({type: "ability", _characterid: characterIDfound, name: actionName}); | |
if(actionExists.length > 0 ){ | |
findObjs({ _type: "ability", _id: actionExists[0].get("_id") })[0].set({action: dataValue}); | |
}else{ | |
createObj("ability", { | |
name: actionName, | |
characterid: characterIDfound, | |
action: dataValue | |
}); | |
}; | |
}; | |
updateList = function() { | |
//Find CharactersByGraphics on Spell Book page. | |
findCharacterByGraphics(); | |
var rollabletables = findObjs({type: "rollabletable"}); | |
_.each(characters, function(indexCharacters) { | |
var characterID = indexCharacters[0].get("_id"); | |
var characterName = indexCharacters[0].get("name").replace(/[^a-zA-Z ]/g, ""); | |
characterName = characterName.split(' ').join('-'); | |
_.each(rollabletables, function(indexrollabletables) { | |
var rollabletableName = indexrollabletables.get("name"); | |
var start_pos = rollabletableName.indexOf("{") + 1; | |
var end_pos = rollabletableName.indexOf("}",start_pos); | |
var characterIDfound = rollabletableName.substring(start_pos,end_pos); | |
if(characterIDfound == characterID){ | |
var tableItems = findObjs({ _type: "tableitem", _rollabletableid: indexrollabletables.get("_id")}) | |
var j = -1; | |
var levelOfSpell = ""; | |
var lastLevel = ""; | |
_.each(tableItems, function(indextableItems) { | |
var newAvatar = indextableItems.get("avatar"); | |
if(indextableItems.get("name") != "999_deprecated"){ | |
if(indextableItems.get("weight") > 0){ | |
if(indextableItems.get("avatar") == roll20API.AbjurationURL){newAvatar = roll20API.OnAbjurationURL}; | |
if(indextableItems.get("avatar") == roll20API.ConjurationURL){newAvatar = roll20API.OnConjurationURL}; | |
if(indextableItems.get("avatar") == roll20API.DivinationURL){newAvatar = roll20API.OnDivinationURL}; | |
if(indextableItems.get("avatar") == roll20API.EnchantmentURL){newAvatar = roll20API.OnEnchantmentURL}; | |
if(indextableItems.get("avatar") == roll20API.EvocationURL){newAvatar = roll20API.OnEvocationURL }; | |
if(indextableItems.get("avatar") == roll20API.IllusionURL){newAvatar = roll20API.OnIllusionURL}; | |
if(indextableItems.get("avatar") == roll20API.NecromancyURL){newAvatar = roll20API.OnNecromancyURL}; | |
if(indextableItems.get("avatar") == roll20API.TransmutationURL){newAvatar = roll20API.OnTransmutationURL}; | |
if(indextableItems.get("avatar") == roll20API.UnkownURL){newAvatar = roll20API.OnUnkownURL}; | |
}else{ | |
if(indextableItems.get("avatar") == roll20API.OnAbjurationURL){newAvatar = roll20API.AbjurationURL}; | |
if(indextableItems.get("avatar") == roll20API.OnConjurationURL){newAvatar = roll20API.ConjurationURL}; | |
if(indextableItems.get("avatar") == roll20API.OnDivinationURL){newAvatar = roll20API.DivinationURL}; | |
if(indextableItems.get("avatar") == roll20API.OnEnchantmentURL){newAvatar = roll20API.EnchantmentURL}; | |
if(indextableItems.get("avatar") == roll20API.OnEvocationURL){newAvatar = roll20API.EvocationURL }; | |
if(indextableItems.get("avatar") == roll20API.OnIllusionURL){newAvatar = roll20API.IllusionURL}; | |
if(indextableItems.get("avatar") == roll20API.OnNecromancyURL){newAvatar = roll20API.NecromancyURL}; | |
if(indextableItems.get("avatar") == roll20API.OnTransmutationURL){newAvatar = roll20API.TransmutationURL}; | |
if(indextableItems.get("avatar") == roll20API.OnUnkownURL){newAvatar = roll20API.UnkownURL}; | |
}; | |
var itemID = indextableItems.get("_id") | |
findObjs({ _type: "tableitem", _id: itemID })[0].set({avatar: newAvatar}); | |
}; | |
}); | |
}; | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment