Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added MonsterHitDice5e/AaronDebug/.AaronDebug.js.swp
Binary file not shown.
Binary file added MonsterHitDice5e/CharMod/.inlineparser.js.swp
Binary file not shown.
65 changes: 41 additions & 24 deletions MonsterHitDice5e/MonsterHitDice5e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});
}
}
Expand Down
Binary file added MonsterHitDice5e/TokenMod/.foo.js.swp
Binary file not shown.
Binary file not shown.
40 changes: 19 additions & 21 deletions MonsterHitDice5e/package.json
Original file line number Diff line number Diff line change
@@ -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": []
}