From 960409a9082d0b46832052f9bc1b331d52c65835 Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Sat, 14 Feb 2015 14:33:46 -0600 Subject: [PATCH 1/2] Squashed 'ZombieDice/' content from commit 2fe4703 git-subtree-dir: ZombieDice git-subtree-split: 2fe4703cbccae10fe005208e6d4caf7827f7b30a --- ZombieDice.js | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 14 +++++++++ 2 files changed, 95 insertions(+) create mode 100644 ZombieDice.js create mode 100644 package.json diff --git a/ZombieDice.js b/ZombieDice.js new file mode 100644 index 0000000000..a917aa9a26 --- /dev/null +++ b/ZombieDice.js @@ -0,0 +1,81 @@ +// Github: https://github.com/shdwjk/Roll20API/blob/master/ZombieDice/ZombieDice.js +// By: The Aaron, Arcane Scriptomancer +// Contact: https://app.roll20.net/users/104025/the-aaron + +var ZombieDice = ZombieDice || (function() { + 'use strict'; + + var version = 0.1, + + handleInput = function(msg) { + var args, + w=false, + t, + p,pp, + n,np, + s + ; + + if (msg.type !== "api") { + return; + } + + args = msg.content.split(/\s+/); + switch(args[0]) { + case '!wzd': + w=true; + /* break; */ // Intentional drop through + case '!zd': + t = parseInt(args[1],10); + p = ( msg.inlinerolls + && msg.inlinerolls[0] + && msg.inlinerolls[0].results + && msg.inlinerolls[0].results.rolls[0] + && msg.inlinerolls[0].results.rolls[0].results + && _.map(msg.inlinerolls[0].results.rolls[0].results,function(r){ + return r.v; + }).sort() ) || []; + n = ( msg.inlinerolls + && msg.inlinerolls[1] + && msg.inlinerolls[1].results + && msg.inlinerolls[1].results.rolls[0] + && msg.inlinerolls[1].results.rolls[0].results + && _.map(msg.inlinerolls[1].results.rolls[0].results,function(r){ + return r.v; + }).sort() ) || []; + pp = _.difference(p,n); + np = _.difference(n,p); + s = _.filter(pp,function(v){ + return v<=t; + }); + + sendChat( 'ZombieDice', (w ? '/w gm ' : '/direct ') + +'
' + +'
Positive['+p.length+']: '+pp.join(', ')+(p.length!==pp.length ? (', '+_.difference(p,pp).join(', ')+'') : '' )+'
' + + (n.length ? ('
Negative['+n.length+']: '+np.join(', ')+(n.length!==np.length ? (', '+_.difference(n,np).join(', ')+'') : '' )+'
') : '') + +'
' + +'
'+(s.length ? 'Success' : 'Failure')+'
' + +(np.length ? ('
'+np.length +' Stress
') : '') + +'
' + +'
' + +'
'); + + break; + } + }, + + registerEventHandlers = function() { + on('chat:message', handleInput); + }; + + return { + RegisterEventHandlers: registerEventHandlers + }; + +}()); + +on('ready',function() { + 'use strict'; + + ZombieDice.RegisterEventHandlers(); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000000..87bebb42d6 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "ZombieDice", + "version": "0.1", + "description": "Rolls canceling Zombie Dice", + "authors": "The Aaron", + "roll20userid": "104025", + "dependencies": { + "isGMModule": "0.x" + }, + "modifies": { + }, + "conflicts": [ + ] +} From 64a91d9d07e653bad802c60ed0ab2e634d2560fc Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Sat, 14 Feb 2015 18:31:38 -0600 Subject: [PATCH 2/2] Squashed 'ZombieDice/' changes from 2fe4703..3b7b460 3b7b460 prod-ZombieDice: Updated prod version of ZombieDice at version 0.2. git-subtree-dir: ZombieDice git-subtree-split: 3b7b4609d53a071dd43cf378adcc78d521087f5a --- ZombieDice.js | 85 ++++++++++++++++++++++++++++++++++++++------------- package.json | 2 +- 2 files changed, 65 insertions(+), 22 deletions(-) diff --git a/ZombieDice.js b/ZombieDice.js index a917aa9a26..b3995cad78 100644 --- a/ZombieDice.js +++ b/ZombieDice.js @@ -5,7 +5,28 @@ var ZombieDice = ZombieDice || (function() { 'use strict'; - var version = 0.1, + var version = 0.2, + + 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, @@ -13,6 +34,7 @@ var ZombieDice = ZombieDice || (function() { t, p,pp, n,np, + c={}, s ; @@ -26,33 +48,54 @@ var ZombieDice = ZombieDice || (function() { w=true; /* break; */ // Intentional drop through case '!zd': + t = parseInt(args[1],10); - p = ( msg.inlinerolls - && msg.inlinerolls[0] - && msg.inlinerolls[0].results - && msg.inlinerolls[0].results.rolls[0] - && msg.inlinerolls[0].results.rolls[0].results - && _.map(msg.inlinerolls[0].results.rolls[0].results,function(r){ - return r.v; - }).sort() ) || []; - n = ( msg.inlinerolls - && msg.inlinerolls[1] - && msg.inlinerolls[1].results - && msg.inlinerolls[1].results.rolls[0] - && msg.inlinerolls[1].results.rolls[0].results - && _.map(msg.inlinerolls[1].results.rolls[0].results,function(r){ - return r.v; - }).sort() ) || []; - pp = _.difference(p,n); - np = _.difference(n,p); + p = getDiceCounts(msg,0); + n = getDiceCounts(msg,1); + + pp = _.clone(p); + np = _.clone(n); + + _.reduce(np,function(m,r,k,l){ + var ps = m[k] || 0; + m[k] = Math.max(ps-r,0); + l[k] = Math.max(r-ps,0); + c[k] = ps-m[k]; + + if(!l[k]) { + delete l[k]; + } + if(!m[k]) { + delete m[k]; + } + if(!c[k]) { + delete c[k]; + } + return m; + },pp); + + p=getDiceArray(p); + n=getDiceArray(n); + pp=getDiceArray(pp); + np=getDiceArray(np); + c=getDiceArray(c); + s = _.filter(pp,function(v){ return v<=t; }); sendChat( 'ZombieDice', (w ? '/w gm ' : '/direct ') +'
' - +'
Positive['+p.length+']: '+pp.join(', ')+(p.length!==pp.length ? (', '+_.difference(p,pp).join(', ')+'') : '' )+'
' - + (n.length ? ('
Negative['+n.length+']: '+np.join(', ')+(n.length!==np.length ? (', '+_.difference(n,np).join(', ')+'') : '' )+'
') : '') + +'
Positive['+p.length+']: ' + +pp.join(', ') + +( (pp.length && c.length) ? ', ' : '') + +( c.length ? (''+c.join(', ')+'') : '' ) + +'
' + + (n.length ? ('
Negative['+n.length+']: ' + +np.join(', ') + +( (np.length && c.length) ? ', ' : '') + + (c.length ? (''+c.join(', ')+'') : '' ) + +'
') : '') +'
' +'
'+(s.length ? 'Success' : 'Failure')+'
' +(np.length ? ('
'+np.length +' Stress
') : '') diff --git a/package.json b/package.json index 87bebb42d6..f806581d0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ZombieDice", - "version": "0.1", + "version": "0.2", "description": "Rolls canceling Zombie Dice", "authors": "The Aaron", "roll20userid": "104025",