Skip to content

Instantly share code, notes, and snippets.

@Heilemann
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Heilemann/11390377 to your computer and use it in GitHub Desktop.
Save Heilemann/11390377 to your computer and use it in GitHub Desktop.
Roll20 Wearynator for The One Ring
/*
The One Ring weary-state setter for Roll20 API
By Michael Heilemann (michael.heilemann@me.com)
Checks to see if a character's endurance drops below her fatigue, and
automatically sets the `weary` attribute to `weary` or `normal`, depending.
This is very useful particularly if you're using the TOR roll tables, as you
can then read the weary attribute of the selected token in a macro and roll
on the appropriate success die table automatically:
/r 1t[feat] + @{travel}t[@{weary}]
It requires that the character have `endurance`, `travel_fatigue`,
`encumbrance_fatigue` and `weary` attributes.
For information on how to setup rollable tables for The One Ring:
https://wiki.roll20.net/The_One_Ring
For more of my The One Ring shenanigans:
https://ringen.squarespace.com/loremasters-journal/
*/
on('ready', function() {
var characters = findObjs({
_type: 'character'
});
characters.forEach(checkWeary, this);
});
on('change:attribute', function(obj, prev) {
var characterid = obj.get('_characterid');
var character = getObj("character", characterid);
checkWeary(character);
});
var checkWeary = function (character) {
var characterid = character.get('_id');
var encumbrance_fatigue = findObjs({
_characterid: characterid,
_type: 'attribute',
name: 'encumbrance_fatigue'
})[0];
var travel_fatigue = findObjs({
_characterid: characterid,
_type: 'attribute',
name: 'travel_fatigue'
})[0];
var endurance = findObjs({
_characterid: characterid,
_type: 'attribute',
name: 'endurance'
})[0];
var weary = findObjs({
_characterid: characterid,
_type: 'attribute',
name: 'weary'
})[0];
var tokens = findObjs({
_type: 'graphic',
represents: characterid
});
if (!travel_fatigue || !encumbrance_fatigue || !endurance || !weary) {
return;
}
var fatigue = encumbrance_fatigue.get('current') + travel_fatigue.get('current');
if (endurance.get('current') < fatigue) {
weary.set('current', 'weary');
tokens.forEach(function(token) {
token.set('status_yellow', '');
}, this);
} else {
weary.set('current', 'normal');
tokens.forEach(function(token) {
token.set('status_yellow', false);
}, this);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment