From 8ab5e9d0da27591da317fa659dfc190ec8eeb47c Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Sat, 20 Jun 2015 01:58:40 -0500 Subject: [PATCH 1/5] Squashed 'CthulhuTechDice/' content from commit a723430 git-subtree-dir: CthulhuTechDice git-subtree-split: a723430370ff1cd0095a3cf724a54865a2e4c2fc --- CthulhuTechDice.js | 245 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 14 +++ 2 files changed, 259 insertions(+) create mode 100644 CthulhuTechDice.js create mode 100644 package.json diff --git a/CthulhuTechDice.js b/CthulhuTechDice.js new file mode 100644 index 0000000000..660371fa68 --- /dev/null +++ b/CthulhuTechDice.js @@ -0,0 +1,245 @@ +// Github: https://github.com/shdwjk/Roll20API/blob/master/CthulhuTechDice/CthulhuTechDice.js +// By: The Aaron, Arcane Scriptomancer +// Contact: https://app.roll20.net/users/104025/the-aaron + +var CthulhuTechDice = CthulhuTechDice || (function() { + 'use strict'; + + var version = '0.1.1', + lastUpdate = 1434783356, + schemaVersion = 0.1, + + checkInstall = function() { + log('-=> CthulhuTechDice v'+version+' <=- ['+(new Date(lastUpdate*1000))+']'); + + if( ! _.has(state,'CthulhuTechDice') || state.CthulhuTechDice.version !== schemaVersion) { + log(' > Updating Schema to v'+schemaVersion+' <'); + state.CthulhuTechDice = { + version: schemaVersion + }; + } + }, + + getDiceCounts = function(msg,idx) { + return ( msg.inlinerolls + && msg.inlinerolls[idx] + && msg.inlinerolls[idx].results + && msg.inlinerolls[idx].results.rolls[0] + && msg.inlinerolls[idx].results.rolls[0].results + && (_.reduce(_.map(msg.inlinerolls[idx].results.rolls[0].results, function(r){ + return r.v; + }).sort() || [], function(m,r){ + m[r]=(m[r]||0)+1; + return m; + },{}))); + }, + + getDiceArray = function(c) { + return _.reduce(c,function(m,v,k){ + _.times(v,function(){m.push(k);}); + return m; + },[]); + }, + + + + handleInput = function(msg) { + var args, + diceCounts, + maxSingle=0, + maxMultiple=0, + maxRun=0, + diceArray, + result, + w=false; + + if (msg.type !== "api") { + return; + } + + args = msg.content.split(/\s+/); + switch(args.shift()) { + case '!wct': + w=true; + /* break; */ // Intentional drop through + case '!ct': + + diceCounts=getDiceCounts(msg,0); + if(!diceCounts){ + return; + } + diceArray=getDiceArray(diceCounts); + + maxMultiple=_.chain(diceCounts) + .map(function(c,r){ + return { + label: 'Best Set', + roll: r, + count: c, + total: (r*c) + }; + }) + .sortBy('total') + .reverse() + .first() + .value(); + + maxRun=_.chain(_.keys(diceCounts)) + .map(function(r){ + return parseInt(r,10); + }) + .tap(function(s){ + var m=_.max(s); + maxSingle={ + label: 'High Roll', + roll: m, + count: 1, + total: m + }; + }) + .reduce(function(m,r){ + if(0 === _.last(m).length) { + _.last(m).push(r); + } else if( r === _.last(_.last(m))+1) { + _.last(m).push(r); + } else { + m.push([r]); + } + return m; + },[[]]) + .map(function(r){ + return { + label: 'Best Run', + run: r, + total: _.reduce(r,function(m,v){return m+v;},0) + }; + }) + .sortBy('total') + .reverse() + .first() + .value(); + + result=_.reduce([maxMultiple,maxRun],function(m,e){ + return ( (e && m && e.total>m.total ) ? e : m); + },maxSingle); + + + sendChat( msg.who, (w ? '/w gm ' : '/direct ')+ + '
'+ + '
'+ + '
'+ + '
'+ + 'Result'+ + '
'+ + '
'+ + result.total+ + '
'+ + '
'+ + '
'+ + '
'+ + _.map(diceArray,function(r){ + return ''+r+''; + }).join('') + + '
'+ + '
'+ + ''+ + result.label+ + ' :: '+ + ''+ + + _.map( + ( _.has(result,'count') + ? (function(r,c){ + var d={}; + d[r]=c; + return getDiceArray(d); + }(result.roll,result.count)) + : result.run + ) ,function(r){ + return ''+r+''; + }).join('') + + '
'+ + '
'+ + '
'+ + '
'+ + '
' + ); + + break; + } + }, + + registerEventHandlers = function() { + on('chat:message', handleInput); + }; + + return { + CheckInstall: checkInstall, + RegisterEventHandlers: registerEventHandlers + }; + +}()); + +on('ready',function() { + 'use strict'; + + CthulhuTechDice.CheckInstall(); + CthulhuTechDice.RegisterEventHandlers(); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000000..1d76aa033a --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "CthulhuTechDice", + "version": "0.1.1", + "description": "", + "authors": "The Aaron", + "roll20userid": "104025", + "dependencies": { + }, + "modifies": { + "state.CthulhutechDice": "read,write" + }, + "conflicts": [ + ] +} From 0c0ac9e72af664dd5645b1db37ea433f68ce99de Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Sat, 20 Jun 2015 10:15:01 -0500 Subject: [PATCH 2/5] Squashed 'CthulhuTechDice/' changes from a723430..a6d9651 a6d9651 prod-CthulhuTechDice: Updated prod version of CthulhuTechDice at version 0.1.2. git-subtree-dir: CthulhuTechDice git-subtree-split: a6d96512df6f34def3c8155bcebcfd9921d078a3 --- CthulhuTechDice.js | 44 +++++++++++++++++++++++++++++++++++++++++--- package.json | 2 +- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/CthulhuTechDice.js b/CthulhuTechDice.js index 660371fa68..2b74486201 100644 --- a/CthulhuTechDice.js +++ b/CthulhuTechDice.js @@ -5,8 +5,8 @@ var CthulhuTechDice = CthulhuTechDice || (function() { 'use strict'; - var version = '0.1.1', - lastUpdate = 1434783356, + var version = '0.1.2', + lastUpdate = 1434813095, schemaVersion = 0.1, checkInstall = function() { @@ -50,6 +50,7 @@ var CthulhuTechDice = CthulhuTechDice || (function() { maxMultiple=0, maxRun=0, diceArray, + bonus, result, w=false; @@ -64,6 +65,10 @@ var CthulhuTechDice = CthulhuTechDice || (function() { /* break; */ // Intentional drop through case '!ct': + if(args.length>1){ + bonus = parseInt(args[1],10) || undefined; + } + diceCounts=getDiceCounts(msg,0); if(!diceCounts){ return; @@ -114,6 +119,9 @@ var CthulhuTechDice = CthulhuTechDice || (function() { total: _.reduce(r,function(m,v){return m+v;},0) }; }) + .filter(function(o){ + return o.run.length>2; + }) .sortBy('total') .reverse() .first() @@ -160,9 +168,39 @@ var CthulhuTechDice = CthulhuTechDice || (function() { 'font-size: 2em;'+ 'font-weight: bold;'+ 'margin-top: 8px;'+ + 'margin-bottom: 12px;'+ '">'+ - result.total+ + (result.total+(bonus||0))+ ''+ + (!_.isUndefined(bonus) + ? ( + ''+ + ''+ + result.total+ + ''+ + ' + '+ + ''+ + bonus+ + ''+ + '' + ) + : '' + )+ ''+ '
Date: Sat, 20 Jun 2015 10:24:09 -0500 Subject: [PATCH 3/5] Squashed 'CthulhuTechDice/' changes from a6d9651..f621a6e f621a6e prod-CthulhuTechDice: Updated prod version of CthulhuTechDice at version 0.1.2. git-subtree-dir: CthulhuTechDice git-subtree-split: f621a6e0cfbeacf70641c05271ba20d120f7f65f --- CthulhuTechDice.js | 19 ++++++++++++++++--- package.json | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CthulhuTechDice.js b/CthulhuTechDice.js index 2b74486201..5e49c52f30 100644 --- a/CthulhuTechDice.js +++ b/CthulhuTechDice.js @@ -6,7 +6,7 @@ var CthulhuTechDice = CthulhuTechDice || (function() { 'use strict'; var version = '0.1.2', - lastUpdate = 1434813095, + lastUpdate = 1434813726, schemaVersion = 0.1, checkInstall = function() { @@ -43,8 +43,9 @@ var CthulhuTechDice = CthulhuTechDice || (function() { - handleInput = function(msg) { - var args, + handleInput = function(msg_orig) { + var msg = _.clone(msg_orig), + args, diceCounts, maxSingle=0, maxMultiple=0, @@ -58,6 +59,18 @@ var CthulhuTechDice = CthulhuTechDice || (function() { return; } + if(_.has(msg,'inlinerolls')){ + msg.content = _.chain(msg.inlinerolls) + .reduce(function(m,v,k){ + m['$[['+k+']]']=v.results.total || 0; + return m; + },{}) + .reduce(function(m,v,k){ + return m.replace(k,v); + },msg.content) + .value(); + } + args = msg.content.split(/\s+/); switch(args.shift()) { case '!wct': diff --git a/package.json b/package.json index 2378e58be7..dc7fb43fda 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "CthulhuTechDice", - "version": "0.1.2", + "version": "0.1.3", "description": "", "authors": "The Aaron", "roll20userid": "104025", From 477cd61925970b29f0267f97c340fc094ea0a18d Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Sat, 20 Jun 2015 10:39:14 -0500 Subject: [PATCH 4/5] CthulhuTechDice: Fixed 0 bonus to display 0 instead of being ignored. --- CthulhuTechDice/CthulhuTechDice.js | 7 ++++--- CthulhuTechDice/package.json | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CthulhuTechDice/CthulhuTechDice.js b/CthulhuTechDice/CthulhuTechDice.js index 5e49c52f30..9e65bdd9fa 100644 --- a/CthulhuTechDice/CthulhuTechDice.js +++ b/CthulhuTechDice/CthulhuTechDice.js @@ -5,8 +5,8 @@ var CthulhuTechDice = CthulhuTechDice || (function() { 'use strict'; - var version = '0.1.2', - lastUpdate = 1434813726, + var version = '0.1.4', + lastUpdate = 1434814696, schemaVersion = 0.1, checkInstall = function() { @@ -79,7 +79,8 @@ var CthulhuTechDice = CthulhuTechDice || (function() { case '!ct': if(args.length>1){ - bonus = parseInt(args[1],10) || undefined; + bonus = parseInt(args[1],10); + bonus = _.isNaN(bonus) ? undefined : bonus; } diceCounts=getDiceCounts(msg,0); diff --git a/CthulhuTechDice/package.json b/CthulhuTechDice/package.json index dc7fb43fda..23a3f1719a 100644 --- a/CthulhuTechDice/package.json +++ b/CthulhuTechDice/package.json @@ -1,6 +1,6 @@ { "name": "CthulhuTechDice", - "version": "0.1.3", + "version": "0.1.4", "description": "", "authors": "The Aaron", "roll20userid": "104025", From 9dbc09b91769685f553af96f36b10601be0111a4 Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Sat, 20 Jun 2015 10:45:15 -0500 Subject: [PATCH 5/5] Squashed 'CthulhuTechDice/' changes from f621a6e..8ea4c61 8ea4c61 prod-CthulhuTechDice: Updated prod version of CthulhuTechDice at version 0.1.6. git-subtree-dir: CthulhuTechDice git-subtree-split: 8ea4c613aa6ca057cc0e79601f4d4b1c003cbaf7 --- CthulhuTechDice.js | 7 ++++--- package.json | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CthulhuTechDice.js b/CthulhuTechDice.js index 5e49c52f30..1616d45ff7 100644 --- a/CthulhuTechDice.js +++ b/CthulhuTechDice.js @@ -5,8 +5,8 @@ var CthulhuTechDice = CthulhuTechDice || (function() { 'use strict'; - var version = '0.1.2', - lastUpdate = 1434813726, + var version = '0.1.6', + lastUpdate = 1434814969, schemaVersion = 0.1, checkInstall = function() { @@ -79,7 +79,8 @@ var CthulhuTechDice = CthulhuTechDice || (function() { case '!ct': if(args.length>1){ - bonus = parseInt(args[1],10) || undefined; + bonus = parseInt(args[1],10); + bonus = _.isNaN(bonus) ? undefined : bonus; } diceCounts=getDiceCounts(msg,0); diff --git a/package.json b/package.json index dc7fb43fda..9df2c71a7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "CthulhuTechDice", - "version": "0.1.3", + "version": "0.1.6", "description": "", "authors": "The Aaron", "roll20userid": "104025",