diff --git a/MonsterHitDice5e/AaronDebug/.AaronDebug.js.swp b/MonsterHitDice5e/AaronDebug/.AaronDebug.js.swp new file mode 100644 index 0000000000..b4bdbc45a2 Binary files /dev/null and b/MonsterHitDice5e/AaronDebug/.AaronDebug.js.swp differ diff --git a/MonsterHitDice5e/CharMod/.inlineparser.js.swp b/MonsterHitDice5e/CharMod/.inlineparser.js.swp new file mode 100644 index 0000000000..8908d49eba Binary files /dev/null and b/MonsterHitDice5e/CharMod/.inlineparser.js.swp differ diff --git a/MonsterHitDice5e/MonsterHitDice5e.js b/MonsterHitDice5e/MonsterHitDice5e.js index 51498c94bb..feac24735b 100644 --- a/MonsterHitDice5e/MonsterHitDice5e.js +++ b/MonsterHitDice5e/MonsterHitDice5e.js @@ -2,30 +2,48 @@ // By: The Aaron, Arcane Scriptomancer // Contact: https://app.roll20.net/users/104025/the-aaron -on('ready', function(){ - on('add:graphic',function(obj){ - if( - 'graphic' == obj.get('type') - && 'token' == obj.get('subtype') - && '' != obj.get('represents') - ) - { +// TODO: Add rerolls on copy. + +on('ready', function() { + "use strict"; + + var bar = 'bar3', + hdAttr = 'npc_HP_hit_dice', + conAttr = 'npc_constitution'; + + + on('add:graphic',function(obj) { + var sets = {}; + + if( 'graphic' === obj.get('type') + && 'token' === obj.get('subtype') + && '' !== obj.get('represents')) { + setTimeout(_.bind(function(id){ - var obj=getObj('graphic',id) + var obj=getObj('graphic',id), + hdAttrib, conAttrib, bonus = 0; - if( - undefined != obj - && '' == obj.get('bar2_link') - ) - { - var attrib = findObjs({ + if( obj && '' === obj.get(bar+'_link') ) { + hdAttrib = findObjs({ + _type: 'attribute', + _characterid:obj.get('represents'), + name: hdAttr + })[0]; + conAttrib = findObjs({ _type: 'attribute', _characterid:obj.get('represents'), - name: 'npc_HP_hit_dice' - }) - if( attrib.length ) - { - sendChat('','/r '+attrib[0].get('current'),function(r){ + name: conAttr + })[0]; + + if( hdAttrib ) { + if( conAttrib ) { + bonus = _.reduce(hdAttrib.get('current').match(/(\d+)d\d+/g),function(m,die){ + m+=parseInt(die.match(/(\d+)d\d+/)[1],10); + return m; + },0)*((conAttrib.get('current')-10)/2); + } + + sendChat('','/r '+hdAttrib.get('current')+'+'+bonus,function(r){ var hp=0; _.each(r,function(subr){ var val=JSON.parse(subr.content); @@ -34,10 +52,9 @@ on('ready', function(){ hp+=val.total; } }); - obj.set({ - bar2_value: hp, - bar2_max: hp - }) + sets[bar+"_value"] = hp; + sets[bar+"_max"] = hp; + obj.set(sets); }); } } diff --git a/MonsterHitDice5e/TokenMod/.foo.js.swp b/MonsterHitDice5e/TokenMod/.foo.js.swp new file mode 100644 index 0000000000..0d9efaa66c Binary files /dev/null and b/MonsterHitDice5e/TokenMod/.foo.js.swp differ diff --git a/MonsterHitDice5e/_Others/HBPowerCards/.PowerCards.js.swp b/MonsterHitDice5e/_Others/HBPowerCards/.PowerCards.js.swp new file mode 100644 index 0000000000..c25cfac7f9 Binary files /dev/null and b/MonsterHitDice5e/_Others/HBPowerCards/.PowerCards.js.swp differ diff --git a/MonsterHitDice5e/package.json b/MonsterHitDice5e/package.json index a4ea51e550..4d2da0544f 100644 --- a/MonsterHitDice5e/package.json +++ b/MonsterHitDice5e/package.json @@ -1,23 +1,21 @@ { - "name": "MonsterHitDice5e", - "version": "0.2", - "description": "Set Monster hit dice on add, usually via drag from journal. Configured for Dungeons and Dragons 5e Character Sheet", - "authors": "The Aaron", - "roll20userid": "104025", - "dependencies": { - }, - "modifies": { - "attribute.current": "read", - "attribute.name": "read", - "attribute.type": "read", - "character.represents": "read", - "graphic.bar2_link": "read", - "graphic.bar2_max": "write", - "graphic.bar2_value": "write", - "graphic.represents": "read", - "graphic.subtype": "read", - "graphic.type": "read" - }, - "conflicts": [ - ] + "name": "MonsterHitDice5e", + "version": "0.2.1", + "description": "Set Monster hit dice on add, usually via drag from journal. Configured for Dungeons and Dragons 5e Character Sheet", + "authors": "The Aaron", + "roll20userid": "104025", + "dependencies": [], + "modifies": { + "attribute.current": "read", + "attribute.name": "read", + "attribute.type": "read", + "character.represents": "read", + "graphic.bar2_link": "read", + "graphic.bar2_max": "write", + "graphic.bar2_value": "write", + "graphic.represents": "read", + "graphic.subtype": "read", + "graphic.type": "read" + }, + "conflicts": [] }