Last active
January 2, 2016 19:49
-
-
Save sturtus/8353030 to your computer and use it in GitHub Desktop.
Cleric spell script for Dungeon Crawl Classics in Roll20.
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
/* | |
Cleric spell script for Dungeon Crawl Classics in Roll20. Calculates the target for the spell check, checks for disapproval, and increments the disapproval attribute by 1 if failure. If disapproval happens, it rolls the disapproval. | |
Requires my Roll20 Library script. https://gist.github.com/sturtus/8352577 | |
To use, the character must have the attributes defined in the config portion of the script. | |
- ActionDie: the die to roll for the spell check, as a d20 or d16 or whatever. | |
- Disapproval: the attribute that tracks the cleric's current disapproval, starts at 1. | |
- List of attributes to possibly affect the roll, expressed as bonuses such as +1 or -1 or 0. In my campaign we use 3 letter abbreviations for these like STR, AGI, PER, LCK, and INT. Change the array to match your campaign. | |
To call the script do this: | |
!clericSpell Spell Name|Level of spell|list of attributes or bonuses separated by commas | |
for example: | |
!clericSpell Blessing|1|PER,+1 | |
*/ | |
function clericSpell(characterObj, attributeObjArray, spellName, spellLevel, spellModArray) { | |
//finally assign the variables for output. | |
var characterName = characterObj.get("name"); | |
var actionDieValue = attributeObjArray[0].get("current"); | |
var disapprovalObj = attributeObjArray[1]; | |
var disapprovalAtt = attributeObjArray[1].get("name")//attributeArray[1]; | |
var disapprovalValue = Number(attributeObjArray[1].get("current")); | |
var luckValue = Number(attributeObjArray[4].get("current")); | |
var spellTarget = 10+(2*Number(spellLevel)); | |
// get the action die max value and die roll, as expressed as 1d20 or d5 or whatever in the current value of the attribute. | |
var d = actionDieValue.indexOf("d")+1; | |
var actionDieMax = parseInt(actionDieValue.slice(d)); | |
var actionDieResult = randomInteger(actionDieMax); | |
var spellRoll = Number(actionDieResult); | |
//get the values in spellModArray, return current numbers if attributes and numbers if numbers | |
var spellMods = spellModArray; | |
for (var i = 2; i < attributeObjArray.length; i++) { | |
for (var j = 0; j < spellModArray.length; j++) { | |
if (attributeObjArray[i].get("name") == spellModArray[j]) { | |
spellMods[j] = attributeObjArray[i].get("current"); | |
}; | |
}; | |
}; | |
//clean up any + symbols | |
spellMods = removePlus(spellMods); | |
luckValue = removePlus(luckValue); | |
disapprovalValue = removePlus(disapprovalValue); | |
//build results and send to chat | |
var spellChatString = spellName + ": [[" + actionDieResult; | |
if (spellModArray[0] != "None") { | |
for (var i = 0; i < spellMods.length; i++) { | |
if (spellMods[i].indexOf("+") !== -1) { | |
var p = spellMods[i].indexOf("+")+1; | |
spellMods[i] = parseInt(spellMods[i].slice(p)); | |
} | |
spellChatString = spellChatString.concat(" +", spellMods[i]); | |
spellRoll = spellRoll+Number(spellMods[i]); | |
}; | |
}; | |
spellChatString = spellChatString.concat(" ]]"); | |
sendChat(characterName,spellChatString); | |
// spell fails if spellRoll is < (10 + (2*spellLevel)) | |
// disapproval chance goes up by 1 if the spell fails no matter the spell level | |
// disapproval happens if the result is <= dissapproval value, even if above spellTarget | |
if ((spellRoll < spellTarget) && (actionDieResult > disapprovalValue)) { | |
sendChat(characterName, "" + spellName + " has failed. Chance of disapproval has increased by 1."); | |
newDisapproval = disapprovalValue+1; | |
newDisapprovalString = newDisapproval.toString(); | |
disapprovalObj.set("current", newDisapprovalString); | |
}; | |
if (actionDieResult <= disapprovalValue) { | |
sendChat(characterName, "" + spellName + " has failed with a natural roll of " + actionDieResult + ". Disapproval [[" + actionDieResult + "d4+" + (Number(luckValue)*-1) + "]]!"); | |
}; | |
}; | |
on("chat:message", function(msg) { | |
if (msg.type == "api" && msg.content.indexOf("!clericSpell ") !== -1) { | |
//parse the input into two variables, oAttrib and newValue | |
var selected = msg.selected; | |
var attributeArray = ["ActionDie", "Disapproval", "CasterLevel", "PER", "LCK"]; | |
var param = msg.content.split("!clericSpell ")[1]; | |
var spellName = param.split("|")[0]; | |
var spellLevel = param.split("|")[1]; | |
var spellMod = param.split("|")[2]; | |
var spellModArray = spellMod.split(","); | |
if(!selected) { | |
sendChat("", "/desc Select token and try again."); | |
return; //quit if nothing selected | |
}; | |
//loop through selected tokens | |
_.each(selected, function(obj) { | |
var characterObj = getCharacterObj(obj); | |
if (characterObj == false) return; | |
var attributeObjArray = getAttributeObjects(characterObj, attributeArray); | |
if (attributeObjArray == false) return; | |
clericSpell(characterObj, attributeObjArray, spellName, spellLevel, spellModArray); | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment