Created
August 29, 2017 16:11
-
-
Save Bastlifa/a910903e96fdc25ee7cc8a9bedad3869 to your computer and use it in GitHub Desktop.
Roll20 Script for Moon Tracking. Needs GM work to function.
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
/****************Dragonlance Moon Tracker***************** | |
A script to track the moon phases in a Dragonlance Game. | |
You'll need the accompanying images for the moon phases. | |
Put them in a table as specified. Create a character | |
named "MoonTracker", optionally, change the GM whisper | |
for Nuitari to whisper your black robed mages. Only they | |
can see Nuitari. | |
*********************************************************/ | |
on("ready", function() { | |
"use strict"; | |
//gets an image for use in creating graphics (tokens and map objects) | |
let getCleanImgsrc = function (imgsrc) { | |
let parts = imgsrc.match(/(.*\/images\/.*)(thumb|med|original|max)([^\?]*)(\?[^?]+)?$/); | |
if(parts) { | |
return parts[1]+'thumb'+parts[3]+(parts[4]?parts[4]:`?${Math.round(Math.random()*9999999)}`); | |
} | |
return; | |
}; | |
const SolImgTableID = (findObjs({type: 'rollabletable', name: 'SolinariPhases'}, {caseInsensitive: true})||{id:'doesnotexist'})[0].id; | |
const SolPhaseArray = findObjs({type: 'tableitem', _rollabletableid: SolImgTableID}) | |
.map((ti)=>getCleanImgsrc(ti.get('avatar'))) | |
.filter((i)=>!_.isUndefined(i)); | |
const SolPhaseArrayNames = findObjs({type: 'tableitem', _rollabletableid: SolImgTableID}) | |
.map((ti)=>ti.get('name')) | |
.filter((i)=>!_.isUndefined(i)); | |
const LunImgTableID = (findObjs({type: 'rollabletable', name: 'LunitariPhases'}, {caseInsensitive: true})||{id:'doesnotexist'})[0].id; | |
const LunPhaseArray = findObjs({type: 'tableitem', _rollabletableid: LunImgTableID}) | |
.map((ti)=>getCleanImgsrc(ti.get('avatar'))) | |
.filter((i)=>!_.isUndefined(i)); | |
const LunPhaseArrayNames = findObjs({type: 'tableitem', _rollabletableid: LunImgTableID}) | |
.map((ti)=>ti.get('name')) | |
.filter((i)=>!_.isUndefined(i)); | |
const NuiImgTableID = (findObjs({type: 'rollabletable', name: 'NuitariPhases'}, {caseInsensitive: true})||{id:'doesnotexist'})[0].id; | |
const NuiPhaseArray = findObjs({type: 'tableitem', _rollabletableid: NuiImgTableID}) | |
.map((ti)=>getCleanImgsrc(ti.get('avatar'))) | |
.filter((i)=>!_.isUndefined(i)); | |
const NuiPhaseArrayNames = findObjs({type: 'tableitem', _rollabletableid: NuiImgTableID}) | |
.map((ti)=>ti.get('name')) | |
.filter((i)=>!_.isUndefined(i)); | |
let MoonTracker = findObjs({type: 'character', name: "MoonTracker"})[0]; | |
let NuitariPhaseAttr = findObjs({type: 'attribute', characterid: MoonTracker.id, name: 'Nuitari'})[0]; | |
let SolinariPhaseAttr = findObjs({type: 'attribute', characterid: MoonTracker.id, name: 'Solinari'})[0]; | |
let LunitariPhaseAttr = findObjs({type: 'attribute', characterid: MoonTracker.id, name: 'Lunitari'})[0]; | |
let NuitariPhase = getAttrByName(MoonTracker.id, 'Nuitari'); | |
let SolinariPhase = getAttrByName(MoonTracker.id, 'Solinari'); | |
let LunitariPhase = getAttrByName(MoonTracker.id, 'Lunitari'); | |
function Report() | |
{ | |
NuitariPhase = getAttrByName(MoonTracker.id, 'Nuitari'); | |
SolinariPhase = getAttrByName(MoonTracker.id, 'Solinari'); | |
LunitariPhase = getAttrByName(MoonTracker.id, 'Lunitari'); | |
var SolPhaseNames = ["HS-XG", "HS-XG", "HS-XG", "HS-FM", "HS-FM", "HS-FM", "HS-NG", "HS-NG", "HS-NG", "WN-NG", "WN-NG", "WN-NG", "WN-LQ", "WN-LQ", "WN-LQ", | |
"WN-NC", "WN-NC", "WN-NC", "LS-NC", "LS-NC", "LS-NC", "LS-NM", "LS-NM", "LS-NM", "LS-XC", "LS-XC", "LS-XC", "WX-XC", "WX-XC", "WX-XC", "WX-1Q", "WX-1Q", "WX-1Q", | |
"WX-XG", "WX-XG", "WX-XG"]; | |
var LunPhaseNames = ["HS-XG", "HS-XG", "HS-FM", "HS-FM", "HS-FM", "HS-NG", "HS-NG", "WN-NG", "WN-NG", "WN-LQ", "WN-LQ", "WN-LQ", "WN-NC", "WN-NC", | |
"LS-NC", "LS-NC", "LS-NM", "LS-NM", "LS-NM", "LS-XC", "LS-XC", "WX-XC", "WX-XC", "WX-1Q", "WX-1Q", "WX-1Q", "WX-XG", "WX-XG"]; | |
var NuiPhaseNames = ["HS-FM", "HS-NG", "WN-LQ", "WN-NC", "LS-NM", "LS-XC", "WX-1Q", "WX-XG"]; | |
sendChat("", "&{template:default} {{name=Moon Phase Report}} {{Solinari}} {{" + SolPhaseNames[SolinariPhase] +"=" + | |
'<div> <img src = ' + SolPhaseArray[SolPhaseArrayNames.indexOf(SolPhaseNames[SolinariPhase].split("-")[1])] + '> </div>}} ') | |
sendChat("", "&{template:default} {{name=Moon Phase Report}} {{Lunitari}} {{" + LunPhaseNames[LunitariPhase] +"=" + | |
'<div> <img src = ' + LunPhaseArray[LunPhaseArrayNames.indexOf(LunPhaseNames[LunitariPhase].split("-")[1])] + '> </div>}} ') | |
sendChat("", "/w gm &{template:default} {{name=Nuitari Phase Report}} {{" + NuiPhaseNames[NuitariPhase] +"=" + | |
'<div> <img src = ' + NuiPhaseArray[NuiPhaseArrayNames.indexOf(NuiPhaseNames[NuitariPhase].split("-")[1])] + '> </div>}} ') | |
} | |
function Advance(days = 1) | |
{ | |
NuitariPhaseAttr.set("current", (NuitariPhaseAttr.get("current") + days)%8); | |
LunitariPhaseAttr.set("current", (LunitariPhaseAttr.get("current") + days)%28); | |
SolinariPhaseAttr.set("current", (SolinariPhaseAttr.get("current") + days)%36); | |
Report(); | |
} | |
// receive message to make the thing happen. | |
on("chat:message", function (msg) { | |
if ('api'===msg.type && playerIsGM(msg.playerid)){ | |
let player = getObj('player',msg.playerid); | |
var args = msg.content.split(/\s+/); | |
if (msg.content === "!DLMoonReport") | |
{ | |
Report(); | |
} | |
if (args[0] === "!DLMoonAdvance") | |
{ | |
//if they advaned x days, else advance 1 day | |
if(args[1]) {Advance(parseInt(args[1]));} | |
else {Advance()} | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment