From fa5f6db68cee5fc2e7729e1b2420c91b252d0150 Mon Sep 17 00:00:00 2001 From: NathaTerrien Date: Mon, 20 Apr 2015 09:54:13 +0200 Subject: [PATCH 1/2] 4.2: stat rolls from macro and assets handling 4.2: stat rolls can be called by macros and a selected character token. See the !nathanum-macroroll chat command below. Plus added assets handling to stat roll. --- Numenera_Natha/Help.txt | 42 ++++++++++++++--- Numenera_Natha/Numenera_Natha.js | 79 ++++++++++++++++++++++++-------- Numenera_Natha/package.json | 2 +- 3 files changed, 95 insertions(+), 28 deletions(-) diff --git a/Numenera_Natha/Help.txt b/Numenera_Natha/Help.txt index faaa6ffd1e..349fafc0b6 100644 --- a/Numenera_Natha/Help.txt +++ b/Numenera_Natha/Help.txt @@ -10,17 +10,42 @@ Sheet must be in version 4+ : chat outputs and error messages are managed throug ****************************************************** **** RELEASE ****************************************************** -Version: 4.0 -Date: March 2015 +Version: 4.2 +Date: 2015-04-20 Authors: Natha (75857) +4.2: By popular demand (of one, Hi Marturin!), stat rolls can be called by macros and a selected character token. See the !nathanum-macroroll chat command below. +Plus added assets handling to stat roll. + +4.1: Bug correction on the NPC damage function. + +4.0: Refactoring and adaptation to the 4+ version of the character sheets and the new template feature of Roll20. +Functions are now called by the buttons on the sheet, no need for macros. + ****************************************************** **** Chat commands ****************************************************** +!nathanum-macroroll token_or_character_id|stat name| + New! Stat roll that can be called easier by macros. + Calls statRoll(character-objet,name-of-the-attibute,who-rolled, difficulty, Stat-expense,Assets,Effort-on-Roll,Effort-on-damage,Bonus-to-roll). + (see the comments of the function below for details). + + MIGHT ROLL MACRO EXAMPLE: + !nathanum-macroroll @{selected|token_id}|might|?{Difficulty|0}|?{Cost|0}|?{Assets|0}|?{Effort on Roll|0}|?{Effort on Damage|0}|?{Bonus|0} + + SPEED ROLL MACRO EXAMPLE: + !nathanum-macroroll @{selected|token_id}|speed|?{Difficulty|0}|?{Cost|0}|?{Assets|0}|?{Effort on Roll|0}|?{Effort on Damage|0}|?{Bonus|0} + + INTELLECT ROLL MACRO EXAMPLE: + !nathanum-macroroll @{selected|token_id}|intellect|?{Difficulty|0}|?{Cost|0}|?{Assets|0}|?{Effort on Roll|0}|?{Effort on Damage|0}|?{Bonus|0} +|----------------------------------------------------- !nathanum-numeneroll character_id|attribute - Stat roll. - Example: !nathanum-numeneroll @{character_id}|speed - Calls statRoll(character-objet,name-of-the-attibute,who-rolled). + Stat roll (called from the sheet mainly, as it requires a character id). + Example: + !nathanum-numeneroll @{character_id}|might + !nathanum-numeneroll @{character_id}|speed + !nathanum-numeneroll @{character_id}|intellect + Calls statRollFromSheet(character-objet,name-of-the-attibute,who-rolled). (see the comments of the function below for details). |----------------------------------------------------- !nathanum-recoveryroll character_id @@ -82,9 +107,12 @@ initRoll(character-object): Damage track and token state are checked/updated by calling checkCharStates(). Chat output uses the "nathaNumInit" roll template. |----------------------------------------------------- -statRoll(character-objet,name-of-the-attibute,who-rolled): +statRollFromSheet(character-objet,name-of-the-attibute,who-rolled): + Gets the necessary parameters for this function as attributes from the character sheet (except the stat name). + And then calls statRoll(character-objet,name-of-the-attibute,who-rolled, difficulty, Stat-expense,Assets,Effort-on-Roll,Effort-on-damage,Bonus-to-roll). +|----------------------------------------------------- +statRoll(character-objet,name-of-the-attibute,who-rolled, difficulty, Stat-expense,Assets,Effort-on-Roll,Effort-on-damage,Bonus-to-roll). Might/speed/intellect roll (with eventual roll effort, additionnal cost, damage effort and bonus) against a difficulty (optional). - Every necessary parameters for this function are attributes of the character sheet (except the stat name). Difficulty is the level of difficulty, not the target number. The target number is calculated by the function. If difficulty is 0, the roll still happens, but is not confronted to any difficulty: instead of calculating success, it calculates the highest difficulty beaten. diff --git a/Numenera_Natha/Numenera_Natha.js b/Numenera_Natha/Numenera_Natha.js index ebf40bc936..ea2c924abb 100644 --- a/Numenera_Natha/Numenera_Natha.js +++ b/Numenera_Natha/Numenera_Natha.js @@ -1,9 +1,9 @@ /* read Help.txt */ var NathaNumenera = NathaNumenera || (function () { 'use strict'; - var version = 4.1, - releasedate= "2015-04-17", - schemaversion = 1.0, + var version = 4.2, + releasedate= "2015-04-20", + schemaversion = 1.0, author="Natha (roll20userid:75857)", warning = "Sheet must be in version 4+ : chat outputs and error messages are managed through the sheet's templates.", //----------------------------------------------------------------------------- @@ -282,8 +282,18 @@ var NathaNumenera = NathaNumenera || (function () { if(totalCost>0) tmplt+=" {{totalCost="+totalCost+"}} {{attrPool="+speedPool+"}} {{attrPoolInit="+speedPoolInit+"}}"; sendChat("character|"+charId, ""+tmplt); }, + //----------------------------------------------------------------------------- + statRollFromSheet= function (characterObj, statName,whoRolled) { + var difficulty=parseInt(getAttrByName(characterObj.id, "rollVarDiff", "current")) || 0; + var assets=parseInt(getAttrByName(characterObj.id, "rollVarAsset", "current")) || 0; + var statexp=parseInt(getAttrByName(characterObj.id, "rollVarCost", "current")) || 0; + var effortsOnRoll=parseInt(getAttrByName(characterObj.id, "rollVarRollEff", "current")) || 0; + var effortsOnDmg=parseInt(getAttrByName(characterObj.id, "rollVarRollDmg", "current")) || 0; + var rollBonus=parseInt(getAttrByName(characterObj.id, "rollVarBonus", "current")) || 0; + statRoll(characterObj,statName,whoRolled,difficulty,statexp,assets,effortsOnRoll,effortsOnDmg,rollBonus); + }, //----------------------------------------------------------------------------- - statRoll = function (characterObj,statName,whoRolled) { + statRoll = function (characterObj,statName,whoRolled,difficulty,statexp,assets,effortsOnRoll,effortsOnDmg,rollBonus) { /* Might/speed/intellect roll with eventual roll effort(s), additionnal cost, damage effort(s), bonus to the roll (<3), against a difficulty (optional). @@ -310,11 +320,6 @@ var NathaNumenera = NathaNumenera || (function () { sendChat("character|"+charId, "&{template:nathaNumMsg} {{nathaNumeneRoll=1}} {{pcDying=1}}"); return; }; - var difficulty=parseInt(getAttrByName(characterObj.id, "rollVarDiff", "current")) || 0; - var statexp=parseInt(getAttrByName(characterObj.id, "rollVarCost", "current")) || 0; - var effortsOnRoll=parseInt(getAttrByName(characterObj.id, "rollVarRollEff", "current")) || 0; - var effortsOnDmg=parseInt(getAttrByName(characterObj.id, "rollVarRollDmg", "current")) || 0; - var rollBonus=parseInt(getAttrByName(characterObj.id, "rollVarBonus", "current")) || 0; // checking the stat var attributeName = ""; @@ -391,18 +396,19 @@ var NathaNumenera = NathaNumenera || (function () { // beginning output calculation var tmplt="&{template:nathaNumRoll} {{"+attributeName+"="+attributeName+"}} {{attrEdge="+attrEdge+"}} {{finalRoll="+finalRoll+"}} {{diceRoll="+diceRoll+"}}"; if (bonusToRoll>0) tmplt += " {{bonusToRoll="+bonusToRoll+"}}"; + var assetsUsed = parseInt(0 || assets); + if (assetsUsed>0) tmplt += " {{assets="+assetsUsed+"}}"; //computing target task - var targetRoll = 0; - var target = 0; - var finalDiff=0; - if (parseInt(difficulty) > 0) { - target = (parseInt(difficulty))*3; - targetRoll = (parseInt(difficulty)-effortRoll)*3; - finalDiff= difficulty-effortRoll; - tmplt += "{{difficulty=" + difficulty + "}} {{target="+target+"}} {{finalDiff="+finalDiff+"}} {{targetRoll="+targetRoll+"}}"; + var initDiff=parseInt(0 || difficulty); + if (initDiff > 0) { + var target = initDiff*3; + var finalDiff= Math.max(0, initDiff-effortRoll-assetsUsed); + var targetRoll = finalDiff*3; + tmplt += "{{difficulty=" + initDiff + "}} {{target="+target+"}} {{finalDiff="+finalDiff+"}} {{targetRoll="+targetRoll+"}}"; } else { - tmplt += " {{rollBeats="+(Math.floor(finalRoll/3)+effortRoll)+"}}"; + var rollBeats=Math.floor(finalRoll/3)+effortRoll+assetsUsed; + tmplt += " {{rollBeats="+rollBeats+" ("+(rollBeats*3)+")"+"}}"; }; // Checking result @@ -424,7 +430,7 @@ var NathaNumenera = NathaNumenera || (function () { tmplt += " {{bonusToRoll=" + bonusToRoll + "}}"; }; // If not an automatic success or a known difficulty - if (difficulty > 0) { + if (initDiff > 0) { if( finalRoll >= targetRoll) { tmplt += " {{boolOK=1}}"; } @@ -627,7 +633,40 @@ var NathaNumenera = NathaNumenera || (function () { sendChat("GM", "&{template:nathaNumMsg} {{chatmessage=nathanum-numeneroll}} {{wtfAttribute="+msg.content+"}}"); return false; }; - statRoll(obj,paramArray[1],msg.who); + statRollFromSheet(obj,paramArray[1],msg.who); + break; + case '!nathanum-macroroll': + // macroroll can be called with a token_id or character_id + if(!obj) { + //not a character_id + obj = findObjs({ + _pageid: Campaign().get("playerpageid"), + _type: "graphic", + layer:"objects", + _id: paramArray[0] + })[0]; + }; + if (!obj) { + //not a token either + sendChat("GM", "&{template:nathaNumMsg} {{chatmessage=nathanum-macroroll}} {{noTokNoChar= "+msg.content+"}}"); + return false; + } else { + if(obj.get("type")=="graphic") { + // it's a token but does it represents a character ? + obj = getObj("character", obj.get("represents")); + if (!obj) { + //not a token either + sendChat("GM", "&{template:nathaNumMsg} {{chatmessage=nathanum-macroroll}} {{noTokNoChar= "+msg.content+"}}"); + return false; + }; + }; + }; + if (paramArray.length != 8) { + //this function requires more parameters + sendChat("GM", "&{template:nathaNumMsg} {{chatmessage=nathanum-macroroll}} {{genericMsg=Requires 8 paramaters : token|stat name|difficulty|assets|Cost|Effort on Roll|Effort on Damage|Roll Bonus}}"); + return false; + }; + statRoll(obj,paramArray[1],msg.who,paramArray[2],paramArray[3],paramArray[4],paramArray[5],paramArray[6],paramArray[7]) break; case '!nathanum-recoveryroll': if (!obj) { diff --git a/Numenera_Natha/package.json b/Numenera_Natha/package.json index 4e31775bb0..66bc2a44f6 100644 --- a/Numenera_Natha/package.json +++ b/Numenera_Natha/package.json @@ -1,6 +1,6 @@ { "name": "Natha's Numenera", - "version": "4.1", + "version": "4.2", "description": "Enables the use of advance rolls and functions in Natha's Numenera character sheets (both english and french) version 4+. See Help.txt", "authors": "Natha", "roll20userid": "75857", From 421c4aff3c83711217f8d423b8cdd46cc0054107 Mon Sep 17 00:00:00 2001 From: NathaTerrien Date: Mon, 20 Apr 2015 10:22:35 +0200 Subject: [PATCH 2/2] 4.2: stat rolls from macro and assets handling 4.2: stat rolls can be called by macros and a selected character token. See the !nathanum-macroroll chat command below. Plus added assets handling to stat roll. --- Numenera_Natha/Help.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Numenera_Natha/Help.txt b/Numenera_Natha/Help.txt index 349fafc0b6..611a730d80 100644 --- a/Numenera_Natha/Help.txt +++ b/Numenera_Natha/Help.txt @@ -25,7 +25,7 @@ Functions are now called by the buttons on the sheet, no need for macros. ****************************************************** **** Chat commands ****************************************************** -!nathanum-macroroll token_or_character_id|stat name| +!nathanum-macroroll token_or_character_id|stat name|Difficulty|Cost|Assets|Effort on Roll|Effort on Damage|Bonus New! Stat roll that can be called easier by macros. Calls statRoll(character-objet,name-of-the-attibute,who-rolled, difficulty, Stat-expense,Assets,Effort-on-Roll,Effort-on-damage,Bonus-to-roll). (see the comments of the function below for details).