-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1873 from richranallo/velvet-generation-support
initial commit of Velvet Generation support script
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "VelvetGeneration", | ||
"script": "vg.js", | ||
"version": "0.1", | ||
"description": "This is a set of API helpers for Velvet Generation.\n* It automatically sets all d6 dice dragged from chat onto the table to be controlled by all players.\n* It enables the `!amped` command, which rerolls all 1s in a selection\n* It enables the `onFire|*` command, which sets all 1s in a selection to the number indicated by *.", | ||
"authors": "Rich Ranallo", | ||
"roll20userid": "104025", | ||
"patreon": "https://www.patreon.com/shdwjk", | ||
"useroptions": [ | ||
{ | ||
"name": "Players can use --ids", | ||
"type": "checkbox", | ||
"description": "Select this option to allow players to use the `--ids` parameter to specify tokens they don't control to be modified.", | ||
"value": "playersCanIDs" | ||
} | ||
], | ||
"dependencies": [], | ||
"modifies": {}, | ||
"conflicts": [], | ||
"previousversions": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
on('ready',()=>{ | ||
// applies a given effect to a single token | ||
function dieEffect(dieToken, effect) { | ||
let dieProps = { | ||
left: dieToken.get('left'), | ||
top: dieToken.get('top') | ||
} | ||
spawnFx(dieProps.left, dieProps.top, effect); | ||
} | ||
|
||
// sets a die token to a given value | ||
function setDieValue(dieToken, value) { | ||
const boundedVal = Math.min(Math.max(value,0),5) | ||
const sides = dieToken.get('sides').replaceAll('%3A', ':').replaceAll('%3F', '?').split('|') | ||
const sideImg = sides[boundedVal] | ||
dieToken.set({ | ||
imgsrc: sideImg, | ||
currentSide: boundedVal | ||
}) | ||
} | ||
|
||
// regex statements used to match commands | ||
const ampedRegex = new RegExp(/^!amped/) | ||
const onFireRegex = new RegExp(/^!onFire\|/) | ||
const digitRegex = new RegExp(/(?<=\|)\d/) | ||
|
||
//images used for sides of a d6 | ||
const d6Sides = [ | ||
'images/779533', | ||
'images/779535', | ||
'images/779534', | ||
'images/779531', | ||
'images/779532', | ||
'images/779536' | ||
] | ||
// recognizes d6s dragged from the chat window onto the tabletop and sets them to be controlled by all players | ||
on('add:token', tok=>{ | ||
log(tok) | ||
if(_.every(d6Sides, side => { | ||
log(side) | ||
log(tok.get('sides')) | ||
return tok.get('sides').includes(side) | ||
})) { | ||
tok.set('controlledby', 'all') | ||
} | ||
}) | ||
|
||
//powers !amped and !onFire|* statements. | ||
//!amped rerolls all 1s in the selected dice | ||
//!onFire|* sets all 1s in the selection to the value inidcated by * | ||
//both apply a visual effect to the dice | ||
on("chat:message", msg => { | ||
if(msg.type === 'api' && msg.selected){ | ||
msg.selected.forEach(die =>{ | ||
if (die._type === 'graphic') { | ||
let dieToken = getObj('graphic', die._id) | ||
if(dieToken.get('currentSide')===0){ | ||
if(msg.content.match(ampedRegex)){ | ||
dieEffect(dieToken, 'explode-charm') | ||
const newValue = Math.floor(Math.random() * 6) | ||
setDieValue(dieToken, newValue) | ||
} | ||
if(msg.content.match(onFireRegex)){ | ||
const requestedValue = msg.content.match(digitRegex) | ||
if(requestedValue && requestedValue[0]) { | ||
setDieValue(dieToken, parseInt(requestedValue)-1) | ||
dieEffect(dieToken, 'burst-fire') | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
}) | ||
|
||
}) |