From b5cffacc9f0bfc8974cac58ac6a2339187908933 Mon Sep 17 00:00:00 2001 From: lithl Date: Fri, 9 Jan 2015 00:55:55 -0600 Subject: [PATCH] Add script Marking Conditions --- Marking Conditions/Marking Conditions.js | 208 +++++++++++++++++++++++ Marking Conditions/README.md | 20 +++ Marking Conditions/package.json | 17 ++ 3 files changed, 245 insertions(+) create mode 100644 Marking Conditions/Marking Conditions.js create mode 100644 Marking Conditions/README.md create mode 100644 Marking Conditions/package.json diff --git a/Marking Conditions/Marking Conditions.js b/Marking Conditions/Marking Conditions.js new file mode 100644 index 0000000000..16fb8f775d --- /dev/null +++ b/Marking Conditions/Marking Conditions.js @@ -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(); +}); \ No newline at end of file diff --git a/Marking Conditions/README.md b/Marking Conditions/README.md new file mode 100644 index 0000000000..48e8334e2f --- /dev/null +++ b/Marking Conditions/README.md @@ -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. \ No newline at end of file diff --git a/Marking Conditions/package.json b/Marking Conditions/package.json new file mode 100644 index 0000000000..76ab16431c --- /dev/null +++ b/Marking Conditions/package.json @@ -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" + ] +}