|
| 1 | +/** |
| 2 | + * Adds 3 commands related to lighting. A [GM] next to a command name means it is GM-only. |
| 3 | + * !light, to be used by players to set their token's light within defined boundaries |
| 4 | + * !flight [GM], to be used by GMs to change any token's light value arbitrarily |
| 5 | + * !todl [GM], to be used by GMs to move a token into the dynamic lighting layer so it |
| 6 | + * can still provide light but the token itself is invisible to players |
| 7 | + */ |
| 8 | +(function () { |
| 9 | + U.registerCommand('light', false, false, doLight); |
| 10 | + U.registerCommand('flight', true, true, doLight); |
| 11 | + |
| 12 | + U.registerCommand('todl', true, function (argv) { |
| 13 | + var selected = this.msg.selected, |
| 14 | + playerid = this.msg.playerid; |
| 15 | + |
| 16 | + _.each(selected, function(obj) { |
| 17 | + if (obj._type != 'graphic') return; // only move graphics |
| 18 | + var tok = getObj('graphic', obj._id); |
| 19 | + if (tok.get('subtype') != 'token') return; // don't try to move cards |
| 20 | + |
| 21 | + // move to DL layer and make it so that all players can see light |
| 22 | + // can manage light level with !flight |
| 23 | + tok.set('layer', 'walls'); |
| 24 | + tok.set('light_otherplayers', true); |
| 25 | + }); |
| 26 | + |
| 27 | + U.chat('!todl', playerid, 'Success'); |
| 28 | + }); |
| 29 | + |
| 30 | + function doLight(argv) { |
| 31 | + var selected = this.msg.selected, |
| 32 | + playerid = this.msg.playerid, |
| 33 | + cmd = this.cmd, |
| 34 | + override = this.data; |
| 35 | + |
| 36 | + var lightRadius = isNaN(Math.abs(argv[1])) ? false : Math.abs(argv[1]); |
| 37 | + var lightDimRad = isNaN(Math.abs(argv[2])) ? false : Math.abs(argv[2]); |
| 38 | + if (!selected || lightRadius === false) { |
| 39 | + U.chat(cmd, playerid, '<br><i>Usage: ' + cmd + |
| 40 | + ' &' + 'lt;light radius&' + 'gt; [start of dim light]</i><br>' + |
| 41 | + 'Use with the token you wish to modify selected'); |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + _.each(selected, function(obj) { |
| 46 | + var settings, tok, char; |
| 47 | + |
| 48 | + if (obj._type != 'graphic') return; // only light graphics |
| 49 | + |
| 50 | + tok = getObj('graphic', obj._id); |
| 51 | + if (tok.get('subtype') != 'token') return; // don't try to light cards |
| 52 | + |
| 53 | + if (tok.get('represents') != '') { |
| 54 | + char = getObj('character', tok.get('represents')); |
| 55 | + settings = U.extractJSON(char.get('gmnotes')) || {}; |
| 56 | + var owners = char.get('controlledby'); |
| 57 | + if (!U.isGM(playerid) && owners.indexOf(playerid) == -1) { |
| 58 | + return; // don't own this object |
| 59 | + } |
| 60 | + } else if (!override) { |
| 61 | + return; // players can't light non-character-tokens with this |
| 62 | + } |
| 63 | + |
| 64 | + // do limits if player (GM can do whatever) |
| 65 | + if (!override) { |
| 66 | + if (!settings.light_max && !settings.light_dim_max) { |
| 67 | + U.chat(cmd, playerid, 'You may not adjust light settings for this token'); |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + if (lightDimRad !== false) { |
| 72 | + if (lightDimRad > settings.light_max) { |
| 73 | + U.chat(cmd, playerid, 'You may not set the dim radius to above ' + settings.light_max); |
| 74 | + return; |
| 75 | + } |
| 76 | + |
| 77 | + if (lightRadius > settings.light_dim_max) { |
| 78 | + U.chat(cmd, playerid, 'You may not set the light radius to above ' + settings.light_dim_max); |
| 79 | + return; |
| 80 | + } |
| 81 | + } else { |
| 82 | + if (lightRadius > settings.light_max) { |
| 83 | + U.chat(cmd, playerid, |
| 84 | + 'You may not set the light radius to above ' + settings.light_max + |
| 85 | + ' if you do not specify a dim radius'); |
| 86 | + return; |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + tok.set('light_radius', lightRadius); |
| 92 | + |
| 93 | + if (lightDimRad !== false) { |
| 94 | + tok.set('light_dimradius', lightDimRad); |
| 95 | + } else { |
| 96 | + tok.set('light_dimradius', ''); |
| 97 | + } |
| 98 | + }); |
| 99 | + } |
| 100 | +})(); |
0 commit comments