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
208 changes: 208 additions & 0 deletions Marking Conditions/Marking Conditions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/**
* Mark a token with !mark @{target|token_id} status type
* Unmark a token with !unmark @{target|token_id} status type
* Clear all statusmarkers on a token with !clearmark @{target|token_id}
*
* `status` can be a statusmarker name or a D&D 4e condition. `type` can be a
* D&D 4e damage type. `type` is only necessary when `status` is "ongling",
* "damage", or "dam". If `type` is omitted for these statuses, an "untyped
* damage" icon will be used.
*/
var bshields = bshields || {};
bshields.conditions = (function() {
'use strict';

var version = 3.0,
commands = {
mark: function(args, msg) {
var tok = getTokenMark(args[0], args[1], args[2]);

if (tok) {
tok.target.set('status_' + tok.marker, true);
}
},
clearmark: function(args, msg) {
var target = getObj('graphic', args[0]);

if (!target) {
sendChat('ERROR', '/w ' + msg.who + ' Please specify a token to mark with @{target|token_id} or @{selected|token_id}.');
return;
}

target.set('statusmarkers', '');
},
unmark: function(args, msg) {
var tok = getTokenMark(args[0], args[1], args[2]);

if (tok) {
tok.target.set('status_' + tok.marker, false);
}
}
};

function handleInput(msg) {
var isApi = msg.type === 'api',
args = msg.content.trim().splitArgs(),
command, args0, isHelp;

if (!list[msg.playerid]) {
list[msg.playerid] = { cmds: [], delay: 500 };
}

if (isApi) {
command = args.shift().substring(1).toLowerCase();
arg0 = args.shift();
isHelp = arg0.toLowerCase() === 'help' || arg0.toLowerCase() === 'h';

if (!isHelp) {
if (arg0 && arg0.length > 0) {
args.unshift(arg0);
}

if (_.isFunction(commands[command])) {
commands[command](args, msg);
}
} else if (_.isFunction(commands.help)) {
commands.help(command, args, msg);
}
} else if (_.isFunction(commands['msg_' + msg.type])) {
commands['msg_' + msg.type](args, msg);
}
}

function registerEventHandlers() {
on('chat:message', handleInput);
}

function getTokenMark(tokenid, status, damageType) {
var marker = 'purple',
target = getObj('graphic', tokenid);

if (!target) {
sendChat('ERROR', '/w ' + msg.who + ' Please specify a token to mark with @{target|token_id} or @{selected|token_id}.');
return;
}

if (status) {
status = status.toLowerCase();
switch (status) {
case 'blinded':
case 'blind':
marker = 'bleeding-eye';
break;
case 'dazed':
case 'daze':
marker = 'pummeled';
break;
case 'deafened':
case 'deaf':
marker = 'screaming';
break;
case 'dominated':
case 'dominate':
marker = 'chained-heart';
break;
case 'immobilized':
case 'immobile':
case 'immob':
marker = 'fishing-net';
break;
case 'marked':
case 'mark':
marker = 'purple';
break;
case 'petrified':
case 'petrify':
case 'stone':
marker = 'white-tower';
break;
case 'prone':
marker = 'back-pain';
break;
case 'restrained':
marker = 'aura';
break;
case 'slowed':
case 'slow':
marker = 'snail';
break;
case 'stunned':
case 'stun':
marker = 'lightning-helix';
break;
case 'weakened':
case 'weak':
marker = 'broken-heart';
break;
case 'ongoing':
case 'damage':
case 'dam':
if (damageType) {
damageType = damageType.toLowerCase();
switch (damageType) {
case 'acid':
marker = 'chemical-bolt';
break;
case 'cold':
marker = 'frozen-orb';
break;
case 'fire':
marker = 'half-haze';
break;
case 'force':
marker = 'blue';
break;
case 'lightning':
marker = 'edge-crack';
break;
case 'necrotic':
marker = 'death-zone';
break;
case 'poison':
marker = 'skull';
break;
case 'psychic':
marker = 'pink';
break;
case 'radiant':
marker = 'angel-outfit';
break;
case 'thunder':
marker = 'yellow';
break;
default:
sendChat('System', '/w ' + msg.who + ' No damage type called ' + damageType +
'. If the damage has no type, do not include a type.');
return;
}
} else {
marker = 'all-for-one';
}
break;
case 'dying':
case 'helpless':
case 'unconscious':
case 'insubstantial':
case 'surprised':
sendChat('ERROR', '/w ' + msg.who + ' The ' + status +
' status is not implemented for the !mark command.');
return;
default:
marker = status;
break;
}
}

return { marker: marker, target: target };
}

return {
registerEventHandlers: registerEventHandlers,
};
}());

on('ready', function() {
'use strict';

bshields.conditions.registerEventHandlers();
});
20 changes: 20 additions & 0 deletions Marking Conditions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Marking Conditions

Allows marking targeted or selected tokens with statusmarkers either directly by name (if known), or by a number of aliases based on D&D 4e statuses.

Statusmarkers can be set with `!mark tokenid [status [type]]` or removed with `!unmark tokenid [status [type]]`, where _tokenid_ is a token object's id (obtained with `@{target|token_id}` or `@{selected|token_id}`), _status_ is the status to set (defaults to `purple` if ommitted), and _type_ is a D&D 4e damage type (only used if _status_ is "ongoing", "damage", or "dam").

The D&D 4e damage types are:

* acid
* cold
* fire
* force
* lightning
* necrotic
* poison
* psychic
* radiant
* thunder

If _status_ is a value that requires a damage type parameter and none is provided, an icon for "untyped" damage will be used.
17 changes: 17 additions & 0 deletions Marking Conditions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Marking Conditions",
"version": "3.0",
"description": "Sets and removes statusmarkers on tokens.",
"authors": "Brian Shields",
"roll20userid": "235259",
"dependencies": {
"splitArgs": "1.0"
},
"modifies": {
"message": "read",
"graphic": "write"
},
"conflicts": [
"none"
]
}