Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shdwjk/fb796a7de28215923bd017cd86887c81 to your computer and use it in GitHub Desktop.
Save shdwjk/fb796a7de28215923bd017cd86887c81 to your computer and use it in GitHub Desktop.
/*
Calendar for Mundana
Created by Kirsty (https://app.roll20.net/users/1165285/kirsty)
and sabotaged to an extreme extent by dancodan, also cramed in some swedish here and there..
Many thanks to Aaron (https://app.roll20.net/users/104025/the-aaron) for his NoteLog script, parts of which I "borrowed"
API Commands:
!cal (as Player) - Shows world, date, time, moon, weather and counted days
!cal (as GM) - Same as player but includes options to advance the date/time, alter the weather, add a note or view the settings menu.
!calSet (GM only) - Allows the GM to change the world, date, time display, show/hide days until full moon, adjust day counter or set the start date
Red Colour: #7E2D40
*/
var Calendar = Calendar || (function() {
'use strict';
var version = '1.0',
handoutName = 'Events Log',
setDefaults = function() {
state.Calendar = {
now: {
version: '1.0',
ordinal: 1,
year: 2945,
weather: "It is a cool but sunny day.",
startdate: "1,Mörkerviste,2945",
events: ""
},
};
},
checkDefaults = function() {
if( state.Calendar.now.version != version ){
state.Calendar.now.version = version;
}
if( ! state.Calendar.now.ordinal){state.Calendar.now.ordinal = 1};
if( ! state.Calendar.now.year){state.Calendar.now.year = 2945};
if( ! state.Calendar.now.weather){state.Calendar.now.weather = "It is a cool but sunny day."};
if( ! state.Calendar.now.timetype){state.Calendar.now.timetype = "OFF"};
if( ! state.Calendar.now.startdate){state.Calendar.now.startdate = "1,Mörkerviste,2945"};
if( ! state.Calendar.now.startdate){state.Calendar.now.events = ""};
},
handleInput = function(msg) {
var args = msg.content.split(",");
if (msg.type !== "api") {return;}
if(playerIsGM(msg.playerid)){
switch(args[0]) {
case '!cal':
calmain();
break;
case '!settings':
calmenu();
break;
case '!setworld':
state.Calendar.now.world=args[1];
calmenu();
break;
case '!startdate':
state.Calendar.now.startdate=args[1]+','+args[2]+','+args[3];
calmenu();
break;
case '!setday':
getOrdinal(msg);
weather();
calmenu();
break;
case '!setmonth':
getOrdinal(msg);
weather();
calmenu();
break;
case '!setyear':
state.Calendar.now.year=args[1];
calmenu();
break;
case '!setordinal':
state.Calendar.now.ordinal=args[1];
calmenu();
break;
case '!addday':
addday(args[1]);
checkWeather();
calmain();
break;
case '!weather':
if(args[1]=='Roll}'){
checkWeather();
}else{
var string = args[1];
for (var i = 2; i < args.length; i++) {
string = string + ", " + args[i];
}
state.Calendar.now.weather = string;
}
calmain();
break;
case '!log':
log(msg);
break;
case '!playercal':
showcal(msg);
break;
}
}else if(args[0]=='!cal'){
showcal(msg);
}
},
calstyle = function() {
var colour = '#7E2D40';
var divstyle = 'style="width: 189px; border: 1px solid black; background-color: #ffffff; padding: 5px; font-size: 12px;"'
var astyle1 = 'style="text-align:center; border: 1px solid black; margin: 1px; padding: 2px; background-color: ' + colour + '; border-radius: 4px; box-shadow: 1px 1px 1px #707070; width: 100px;';
var astyle2 = 'style="text-align:center; border: 1px solid black; margin: 1px; padding: 2px; background-color: ' + colour + '; border-radius: 4px; box-shadow: 1px 1px 1px #707070; width: 150px;';
var tablestyle = '';
var arrowstyle = 'style="border: none; border-top: 3px solid transparent; border-bottom: 3px solid transparent; border-left: 195px solid ' + colour + '; margin-bottom: 2px; margin-top: 2px;"';
var headstyle = 'style="color: ' + colour + '; font-size: 18px; text-align: left; font-variant: small-caps; font-family: Times, serif;"';
var substyle = 'style="font-size: 11px; line-height: 13px; margin-top: -3px; font-style: italic;"';
var styles = colour + '|' + divstyle + '|' + astyle1 + '|' + astyle2 + '|' + tablestyle + '|' + arrowstyle + '|' + headstyle + '|' + substyle;
return styles;
},
calmain = function() {
var styles = calstyle().split("|");
var colour = styles[0];
var divstyle = styles[1];
var astyle1 = styles[2];
var astyle2 = styles[3];
var tablestyle = styles[4];
var arrowstyle = styles[5];
var headstyle = styles[6];
var substyle = styles[7];
var world = "Mundana";
var moMenu = getMoMenu();
var ordinal = state.Calendar.now.ordinal;
var nowdate = getDate(ordinal).split(',');
var month = nowdate[0];
var day = nowdate[1];
var moon = getMundanaMoon();
var start = state.Calendar.now.startdate.split(',');
var startdate = start[1]+' '+start[0]+', '+start[2];
sendChat('Kalender', '/w gm <div ' + divstyle + '>' + //--
'<div ' + headstyle + '>Kalender</div>' + //--
'<div ' + substyle + '>Menu (v.' + state.Calendar.now.version + ')</div>' + //--
'<div ' + arrowstyle + '></div>' + //--
'<table ' + tablestyle + '>' + //--
'<tr><td>World: </td><td>' + world + '</td></tr>' + //--
'<tr><td>Date: </td><td>'+ month + ' ' + day + ', ' + state.Calendar.now.year + '</td></tr>' + //--
moon + //--
'</table>' + //--
'<br>Weather: ' + state.Calendar.now.weather + //--
'<br><br><div style="text-align:center;"><a ' + astyle2 + '" href="!addday,?{Days to add?|1}">Advance the Date</a></div>' + //--
'<div style="text-align:center;"><a ' + astyle2 + '" href="!weather,?{Weather|Roll|Edit,?{Edit Weather}}">Change Weather</a></div>' + //--
'<div style="text-align:center;"><a ' + astyle2 + '" href="!log,?{Notes}">Log Day</a></div>' + //--
'<div style="text-align:center;"><a ' + astyle2 + '" href="!playercal">Show to Players</a></div>' + //--
'<div style="text-align:center;"><a ' + astyle2 + '" href="!settings">Settings</a></div>' + //--
'</div>'
);
},
calmenu = function() {
var styles = calstyle().split("|");
var colour = styles[0];
var divstyle = styles[1];
var astyle1 = styles[2];
var astyle2 = styles[3];
var tablestyle = styles[4];
var arrowstyle = styles[5];
var headstyle = styles[6];
var substyle = styles[7];
var world = "Mundana";
var moMenu = getMoMenu();
var ordinal = state.Calendar.now.ordinal;
var nowdate = getDate(ordinal).split(',');
var month = nowdate[0];
var day = nowdate[1];
var start = state.Calendar.now.startdate.split(',');
var startdate = start[1]+' '+start[0]+', '+start[2];
sendChat('Kalender', '/w gm <div ' + divstyle + '>' + //--
'<div ' + headstyle + '>Kalender</div>' + //--
'<div ' + substyle + '>Menu (v.' + state.Calendar.now.version + ')</div>' + //--
'<div ' + arrowstyle + '></div>' + //--
'<table>' + //--
'<tr><td>World: </td><td>' + world + '</a></td></tr>' + //--
'<tr><td>Start Date: </td><td><a ' + astyle1 + '" href="!startdate,?{Day},?{Month},?{Year}">' + startdate + '</a></td></tr>' + //--
'<tr><td>Day: </td><td><a ' + astyle1 + '" href="!setday,?{Day?|1},' + month +'">' + day + '</a></td></tr>' + //--
'<tr><td>Month: </td><td><a ' + astyle1 + '" href="!setmonth,' + day + moMenu + month + '</a></td></tr>' + //--
'<tr><td>Year: </td><td><a ' + astyle1 + '" href="!setyear,?{Year?|2945}">' + state.Calendar.now.year + '</a></td></tr>' + //--
//'<tr><td>Ordinal: </td><td><a ' + astyle1 + '" href="!setordinal,?{Ordinal?|1}">' + ordinal + '</a></td></tr>' + //-
'</table>' + //--
'<div style="text-align:center;"><a ' + astyle2 + '" href="!cal">Main Menu</a></div>' + //--
'</div>'
);
},
showcal = function(msg) {
var ordinal = state.Calendar.now.ordinal;
var nowdate = getDate(ordinal).split(',');
var month = nowdate[0];
var day = nowdate[1];
var world = "Mundana";
var colour = '#7E2D40';
var divstyle = 'style="width: 189px; border: 1px solid black; background-color: #ffffff; padding: 5px;"'
var tablestyle = 'style="text-align:center; table-layout: auto; width: 170px;"';
var arrowstyle = 'style="border: none; border-top: 3px solid transparent; border-bottom: 3px solid transparent; border-left: 195px solid ' + colour + '; margin-bottom: 2px; margin-top: 2px;"';
var headstyle = 'style="color: ' + colour + '; font-size: 18px; text-align: left; font-variant: small-caps; font-family: Times, serif;"';
var substyle = 'style="font-size: 11px; line-height: 13px; margin-top: -3px; font-style: italic;"';
var moon = '<table '+tablestyle+'>'+getMundanaMoon()+'</table>';
sendChat(msg.who, '<div ' + divstyle + '>' + //--
'<div ' + headstyle + '>Kalender</div>' + //--
'<div ' + substyle + '>' + world + '</div>' + //--
'<div ' + arrowstyle + '></div>' + //--
month + ' ' + day + ', ' + state.Calendar.now.year + //--
moon + //--
'<br>Today\'s weather:<br>' + state.Calendar.now.weather
);
},
getMoMenu = function() {
var moMenu = ',?{Month|Mörkerviste|Långsnö|Frostfall|Vårkomstdagen|Vattensvall|Blomsterkomst|Gröngräs|Midsommardagen|Högsol|Skördevärv|Sommaränd|Lövfäll|Bittervind|Vinterkomstdagen|Midvinter}">';
return moMenu;
},
getDate = function(options){
var day = Number(options);
var date;
var month;
if(day>0 && day<=31){
month="Mörkerviste";
date=day;
}else if(day>31 && day<=59){
month="Långsnö";
date=day-31;
}else if(day>59 && day<=90){
month="Frostfall";
date=day-59;
}else if(day==91){
month="Vårkomstdagen";
date='festival';
}else if(day>91 && day<=121){
month="Vattensvall";
date=day-91;
}else if(day>121 && day<=152){
month="Blomsterkomst";
date=day-121;
}else if(day>152 && day<=182){
month="Gröngräs";
date=day-152;
}else if(day==183){
month="Midsommardagen";
date='festival';
}else if(day>183 && day<=214){
month="Högsol"
date=day-183;
}else if(day>214 && day<=245){
month="Skördevärv";
date=day-214;
}else if(day>245 && day<=275){
month="Sommaränd";
date=day-245;
}else if(day>275 && day<=306){
month="Lövfäll";
date=day-275;
}else if(day>306 && day<=336){
month="Bittervind";
date=day-306;
}else if(day==337){
month="Vinterkomstdagen";
date='festival';
}else if(day>337 && day<=368){
month="Midvinter";
date=day-337;
}else{
month="Mörkerviste";
date='1';
}
var array=month+','+String(date);
return array;
},
getOrdinal = function(options){
var args = options.content.split(",");
var date = args[1];
var month = args[2];
var ordinal = state.Calendar.now.ordinal;
if(date == 'festival'){
date = 1;
}else{
date = Number(args[1]);
}
switch(month) {
case 'Mörkerviste':
ordinal = date;
break;
case 'Långsnö':
ordinal = 31+date;
break;
case 'Frostfall':
ordinal = 59+date;
break;
case 'Vårkomstdagen':
ordinal = 91;
break;
case 'Vattensvall':
ordinal = 91+date;
break;
case 'Blomsterkomst':
ordinal = 121+date;
break;
case 'Gröngräs':
ordinal = 152+date;
break;
case 'Midsommardagen':
ordinal = 183;
break;
case 'Högsol':
ordinal = 183+date;
break;
case 'Skördevärv':
ordinal = 214+date;
break;
case 'Sommaränd':
ordinal = 245+date;
break;
case 'Lövfäll':
ordinal = 275+date;
break;
case 'Bittervind':
ordinal = 306+date;
break;
case 'Vinterkomstdagen':
ordinal = 337;
break;
case 'Midvinter':
ordinal = 337+date;
break;
}
state.Calendar.now.ordinal = ordinal;
},
addday = function(no){
var days = Number(no);
var ordinal = Number(state.Calendar.now.ordinal);
var newordinal = ordinal+days;
if(newordinal>368){
state.Calendar.now.ordinal=newordinal-368;
state.Calendar.now.year = Number(state.Calendar.now.year)+1;
}else{
state.Calendar.now.ordinal = newordinal;
}
},
getsuffix = function(day) {
var date = day;
var suffix;
if (date == 'festival'){
suffix = '';
}else if (date == 1 || date == 2 || date == 21 || date == 22 || date == 31 ){
suffix = ':a';
}else{
suffix = ':e';
}
return suffix;
},
checkWeather = function() {
var roll = randomInteger(100);
if(roll<=30){
weather();
}
},
weather = function() {
var roll;
var temperature;
var wind;
var precipitation;
var season;
var ordinal = state.Calendar.now.ordinal;
if(ordinal > 349 || ordinal <= 75){
season = 'Winter'
}else if(ordinal <= 166){
season = 'Spring'
}else if(ordinal <=257 ){
season = 'Summer'
}else if(ordinal <=349 ){
season = 'Fall'
}
//Lets roll 1d100 to determine the temperature
roll = Math.floor(Math.random()*(99));
//5% chance it will be a bitterly cold day
if(roll>=0 && roll<=4){
switch(season) {
case 'Winter':
temperature = `Det är en extremt kall vinterdag med en temperatur runt ${Math.floor(Math.random() * 10 - 40)} grader. `;
break;
case 'Spring':
temperature = `Det är en extremt kall vårdag med en temperatur runt ${Math.floor(Math.random() * 5 -3)} grader. `;
break;
case 'Summer':
temperature = `Det är en extremt kall sommardag med en temperatur runt ${Math.floor(Math.random() * 5 + 9)} grader. `;
break;
case 'Fall':
temperature =`Det är en extremt kall höstdag med en temperatur runt ${Math.floor(Math.random() * 5 - 3)} grader. `;
break;
}
}else if(roll>=5 && roll<=9){
//5% chance it will be a very cold day
switch(season) {
case 'Winter':
temperature = `Det är en väldigt kall vinterdag med en temperatur runt ${Math.floor(Math.random() * 5 - 30)} grader. `;
break;
case 'Spring':
temperature = `Det är en väldigt kall vårdag med en temperatur runt ${Math.floor(Math.random() * 5 + 1)} grader. `;
break;
case 'Summer':
temperature = `Det är en väldigt kall sommardag med en temperatur runt ${Math.floor(Math.random() * 5 + 12)} grader. `;
break;
case 'Fall':
temperature = `Det är en väldigt kall höstdag med en temperatur runt ${Math.floor(Math.random() * 5 + 0)} grader. `;
break;
}
}else if(roll>=10 && roll<=19){
//10% chance it will be a cold day
switch(season) {
case 'Winter':
temperature = `Det är en kall vinterdag med en temperatur runt ${Math.floor(Math.random() * 5 - 25)} grader. `;
break;
case 'Spring':
temperature = `Det är en kall vårdag med en temperatur runt ${Math.floor(Math.random() * 5 + 4)} grader. `;
break;
case 'Summer':
temperature = `Det är en kall sommardag med en temperatur runt ${Math.floor(Math.random() * 5 + 15)} grader. `;
break;
case 'Fall':
temperature = `Det är en kall höstdag med en temperatur runt ${Math.floor(Math.random() * 5 + 3)} grader. `;
break;
}
}else if(roll>=20 && roll<=79){
//60% chance of a mild and normal day
switch(season) {
case 'Winter':
temperature = `Det är en mild vinterdag med en temperatur runt ${Math.floor(Math.random() * 10 - 20)} grader.`;
break;
case 'Spring':
temperature = `Det är en mild vårdag med en temperatur runt ${Math.floor(Math.random() * 10 + 8)} grader. `;
break;
case 'Summer':
temperature = `Det är en mild sommardag med en temperatur runt ${Math.floor(Math.random() * 10 + 15)} grader. `;
break;
case 'Fall':
temperature = `Det är en mild höstdag med en temperatur runt ${Math.floor(Math.random() * 10 + 8)} grader. `;
break;
}
}else if(roll>=80 && roll<=89){
//10% chance of a warm day
switch(season) {
case 'Winter':
temperature = `Det är en varm vinterdag med en temperatur runt ${Math.floor(Math.random() * 10 - 15)} grader.`;
break;
case 'Spring':
temperature = `Det är en varm vårdag med en temperatur runt ${Math.floor(Math.random() * 10 + 10)} grader. `;
break;
case 'Summer':
temperature = `Det är en varm sommardag med en temperatur runt ${Math.floor(Math.random() * 10 + 20)} grader. `;
break;
case 'Fall':
temperature = `Det är en varm höstdag med en temperatur runt ${Math.floor(Math.random() * 10 + 10)} grader. `;
break;
}
}else if(roll>=90 && roll<=94){
//5% chance of a very warm day
switch(season) {
case 'Winter':
temperature = `Det är en väldigt varm vinterdag med en temperatur runt ${Math.floor(Math.random() * 10 - 10)} grader.`;
break;
case 'Spring':
temperature = `Det är en väldigt varm vårdag med en temperatur runt ${Math.floor(Math.random() * 10 + 13)} grader. `;
break;
case 'Summer':
temperature = `Det är en väldigt varm sommardag med en temperatur runt ${Math.floor(Math.random() * 10 + 25)} grader. `;
break;
case 'Fall':
temperature = `Det är en väldigt varm höstdag med en temperatur runt ${Math.floor(Math.random() * 10 + 13)} grader. `;
break;
}
}else{
//5% chance of an extremely hot day
switch(season) {
case 'Winter':
temperature = `Det är en extremnt varm vinterdag med en temperatur runt ${Math.floor(Math.random() * 10 - 5)} grader.`;
break;
case 'Spring':
temperature = `Det är en extremnt varm vårdag med en temperatur runt ${Math.floor(Math.random() * 10 + 15)} grader. `;
break;
case 'Summer':
temperature = `Det är en extremnt varm sommardag med en temperatur runt ${Math.floor(Math.random() * 10 + 30)} grader. `;
break;
case 'Fall':
temperature = `Det är en extremnt varm höstdag med en temperatur runt ${Math.floor(Math.random() * 10 + 15)} grader. `;
break;
}
}
//Ok lets do 1d100 for wind
roll = Math.floor(Math.random()*(99));
if(roll>=0 && roll<=9){
wind='Det är vindstilla och ';
}else if(roll>=10 && roll<=29){
wind='Vinden blåser med en svag bris och ';
}else if(roll>=30 && roll<=49){
wind='En bris blåser milt och ';
}else if(roll>=50 && roll<=69){
wind='En måttlig vind blåser och ';
}else if(roll>=70 && roll<=89){
wind='En frisk vind blåser och ';
}else if(roll>=90 && roll<=95){
wind='En hård vind blåser och ';
}else if(roll=96){
wind='Lokala stormbyar piskar lander och ';
}else if(roll=97){
wind='En storm blåser och ';
}else if(roll=98){
wind='En orkan blåser och ';
}else {
wind='Luften känns elektrisk, huvudet värker, en magistorm förstör allt i sin väg och ';
}
//Lets check if there is some precipitation
roll = Math.floor(Math.random()*(99));
if(roll>=0 && roll<=14){
precipitation="Light rain or snow.";
if(season=='Winter'){
precipitation = 'molnen lyser med sin frånvaro.';
}else{
precipitation = 'det är en klarblå himmel.';
}
}else if(roll>=15 && roll<=39){
if(season=='Winter'){
precipitation = 'på himmelen syns vita moln.';
}else{
precipitation = 'på himmelen syns vita moln.';
}
}else if(roll>=40 && roll<=54){
if(season=='Winter'){
precipitation = 'himmelen täcks av mörka moln som spricker upp emellanåt.';
}else{
precipitation = 'himmelen täcks av mörka moln som spricker upp emellanåt.';
}
}else if(roll>=55 && roll<=59){
if(season=='Winter'){
precipitation = 'enstaka snöflingor dalar sakta mot marken.';
}else{
precipitation = 'ett lätt duggregn faller sakta.';
}
}else if(roll>=60 && roll<=69){
if(season=='Winter'){
precipitation = 'små snöflingor virvlar i luften.';
}else{
precipitation = 'spridda regnskurar faller under några timmar.';
}
}else if(roll>=70 && roll<=79){
if(season=='Winter'){
precipitation = 'snön faller.';
}else{
precipitation = 'ett lätt regn strilar ner mot marken.';
}
}else if(roll>=80 && roll<=85){
if(season=='Winter'){
precipitation = 'ett snöväder täcker lander.';
}else{
precipitation = 'ett regnväder faller från en mörk himmel.';
}
}else if(roll>=86 && roll<=91){
if(season=='Winter'){
precipitation = 'ett snöväder faller tungt.';
}else{
precipitation = 'ett ösregn faller från en mörk himmel.';
}
}else if(roll>=92 && roll<=93){
if(season=='Winter'){
precipitation = 'snön faller tungt från tjocka moln på himmelen.';
}else{
precipitation = 'ett ösregn faller från en mörk himmel, på avstånd hörs en lätt åska.';
}
}else if(roll>=94 && roll<=95){
if(season=='Winter'){
precipitation = 'snön faller tungt från mörka, tunga moln på himmelen.';
}else{
precipitation = 'ett ösregn börjar falla från en mörk himmel, på avstånd hörs en rejäl åska.';
}
}else if(roll>=96 && roll<=97){
if(season=='Winter'){
precipitation = 'snön faller intensivt från himmelen. Begränsad sikt och framkomlighet.';
}else{
precipitation = 'ett skyfall faller från himmelen. Bäckar och floder har svämmat över. Begränsad framkomlighet.';
}
}else{
if(season=='Winter'){
precipitation = 'snön faller intensivt från himmelen. Begränsad sikt och framkomlighet.';
}else{
precipitation = 'ett skyfall faller från himmelen och en intensiv åska råder. Bäckar och floder har svämmat över. Begränsad framkomlighet.';
}
}
var forecast = temperature + '<br>' + wind + '<br>' + precipitation;
state.Calendar.now.weather = forecast;
},
getMundanaMoon = function() {
var ordinal = Number(state.Calendar.now.ordinal);
var tristianaArray = '0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16';
var izagardArray = '0,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16,1,2,3,3,4,5,5,6,7,7,8,9,10,11,11,12,13,13,14,15,15,16,16';
var tristianaNO = tristianaArray.split(",");
var tristianaImg = tristianaNO[ordinal];
var tristiana = getMoon(tristianaImg);
var izagardNO = izagardArray.split(",");
var izagardImg = izagardNO[ordinal];
var izagard = getMoon(izagardImg);
var moon = '<tr><td><img src="'+tristiana+'" style="width:40px;height:40px;"></td><td><img src="'+izagard+'" style="width:30px;height:30px;"></td></tr><tr><td>Tristiana</td><td>Izagard</td></tr>';
return moon;
},
getMoon = function(moonNo) {
var args = moonNo;
var moon;
switch(args) {
case '1':
// moon = 'Full Moon';
// moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/78/Twemoji_1f315.svg/512px-Twemoji_1f315.svg.png';
moon = 'https://upload.wikimedia.org/wikipedia/commons/7/79/Moon-waning-100.svg';
break;
case '2':
// moon = 'Waning Gibbous';
// moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Twemoji_1f316.svg/512px-Twemoji_1f316.svg.png';
moon = 'https://upload.wikimedia.org/wikipedia/commons/d/df/Moon-waning-086.svg';
break;
case '3':
// moon = 'Waning Gibbous';
// moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Twemoji_1f316.svg/512px-Twemoji_1f316.svg.png';
moon = 'https://upload.wikimedia.org/wikipedia/commons/b/b3/Moon-waning-075.svg';
break;
case '4':
// moon = 'Waning Gibbous';
// moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Twemoji_1f316.svg/512px-Twemoji_1f316.svg.png';
moon = 'https://upload.wikimedia.org/wikipedia/commons/1/14/Moon-waning-062.svg';
break;
case '5':
// moon = 'Last Quarter';
// moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/67/Twemoji_1f317.svg/512px-Twemoji_1f317.svg.png';
moon = 'https://upload.wikimedia.org/wikipedia/commons/c/c1/Moon-waning-050.svg';
break;
case '6':
// moon = 'Waning Crescent';
// moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Twemoji_1f318.svg/512px-Twemoji_1f318.svg.png';
moon = 'https://upload.wikimedia.org/wikipedia/commons/a/ab/Moon-waning-038.svg';
break;
case '7':
// moon = 'Waning Crescent';
// moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Twemoji_1f318.svg/512px-Twemoji_1f318.svg.png';
moon = 'https://upload.wikimedia.org/wikipedia/commons/4/40/Moon-waning-022.svg';
break;
case '8':
// moon = 'Waning Crescent';
// moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Twemoji_1f318.svg/512px-Twemoji_1f318.svg.png';
moon = 'https://upload.wikimedia.org/wikipedia/commons/a/ad/Moon-waning-014.svg';
break;
case '9':
// moon = 'New Moon';
//moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Twemoji_1f311.svg/512px-Twemoji_1f311.svg.png';
moon = 'https://upload.wikimedia.org/wikipedia/commons/e/e3/Moon-waning-000.svg';
break;
case '10':
// moon = 'Waxing Crescent';
// moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Twemoji_1f312.svg/512px-Twemoji_1f312.svg.png';
moon = 'https://upload.wikimedia.org/wikipedia/commons/2/27/Moon-waxing-014.svg';
break;
case '11':
// moon = 'Waxing Crescent';
// moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Twemoji_1f312.svg/512px-Twemoji_1f312.svg.png';
moon = 'https://upload.wikimedia.org/wikipedia/commons/e/e9/Moon-waxing-022.svg';
break;
case '12':
// moon = 'Waxing Crescent';
moon = 'https://upload.wikimedia.org/wikipedia/commons/b/b8/Moon-waxing-038.svg';
break;
case '13':
// moon = 'First Quarter';
moon = 'https://upload.wikimedia.org/wikipedia/commons/f/ff/Moon-waxing-050.svg';
break;
case '14':
// moon = 'Waxing Gibbous';
moon = 'https://upload.wikimedia.org/wikipedia/commons/4/4d/Moon-waxing-062.svg';
break;
case '15':
// moon = 'Waxing Gibbous';
moon = 'https://upload.wikimedia.org/wikipedia/commons/7/74/Moon-waxing-075.svg';
break;
case '16':
// moon = 'Waxing Gibbous';
moon = 'https://upload.wikimedia.org/wikipedia/commons/0/0c/Moon-waxing-086.svg';
break;
}
return moon;
},
createHandout = function() {
var handout = createObj('handout',{
name: handoutName
});
return handout;
},
getHandout = function() {
var handout = filterObjs(function(o){
return ( 'handout' === o.get('type') && handoutName === o.get('name') && false === o.get('archived'));
})[0];
if(handout) {
return handout;
}
return createHandout();
},
log = function(msg) {
var args = msg.content.split(",");
var text = args[1];
var handout = getHandout();
var ordinal = state.Calendar.now.ordinal;
var nowdate = getDate(ordinal).split(',');
var month = nowdate[0];
var day = nowdate[1];
var suffix = getsuffix(day);
var year = state.Calendar.now.year;
var date = day + suffix + " " + month + ", " + year;
handout.get('notes', function(nts) {
if(!_.isNull(nts)){
setTimeout(function(){
var newtext = nts + "<br>" + date + " - " + text;
handout.set('notes', newtext);
},0);
}
setTimeout(function(){},0);
});
sendChat('Calendar','/w gm A new note has been added to the Events Log handout.');
},
checkInstall = function() {
if(typeof state.Calendar == "undefined"){
setDefaults();
}
if ( state.Calendar.now.version != version ){
checkDefaults();
}
},
registerEventHandlers = function() {
on('chat:message', handleInput);
};
return {
CheckInstall: checkInstall,
RegisterEventHandlers: registerEventHandlers
};
}());
on("ready",function(){
'use strict';
Calendar.CheckInstall();
Calendar.RegisterEventHandlers();
});
// Ported from: https://github.com/josephg/noisejs
/*
Perlin.seed(134123);
let v1 = Perlin.perlin2(0.5,0.5);
*/
/*
* A speed-improved perlin and simplex noise algorithms for 2D.
*
* Based on example code by Stefan Gustavson ([email protected]).
* Optimisations by Peter Eastman ([email protected]).
* Better rank ordering method by Stefan Gustavson in 2012.
* Converted to Javascript by Joseph Gentle.
*
* Version 2012-03-09
*
* This code was placed in the public domain by its original author,
* Stefan Gustavson. You may use it as you see fit, but
* attribution is appreciated.
*
*/
const Noise = (function(){
function Grad(x, y, z) {
this.x = x; this.y = y; this.z = z;
}
Grad.prototype.dot2 = function(x, y) {
return this.x*x + this.y*y;
};
Grad.prototype.dot3 = function(x, y, z) {
return this.x*x + this.y*y + this.z*z;
};
var grad3 = [new Grad(1,1,0),new Grad(-1,1,0),new Grad(1,-1,0),new Grad(-1,-1,0),
new Grad(1,0,1),new Grad(-1,0,1),new Grad(1,0,-1),new Grad(-1,0,-1),
new Grad(0,1,1),new Grad(0,-1,1),new Grad(0,1,-1),new Grad(0,-1,-1)];
var p = [151,160,137,91,90,15,
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];
// To remove the need for index wrapping, double the permutation table length
var perm = new Array(512);
var gradP = new Array(512);
// This isn't a very good seeding function, but it works ok. It supports 2^16
// different seed values. Write something better if you need more seeds.
const seed = function(seed) {
if(seed > 0 && seed < 1) {
// Scale the seed out
seed *= 65536;
}
seed = Math.floor(seed);
if(seed < 256) {
seed |= seed << 8;
}
for(var i = 0; i < 256; i++) {
var v;
if (i & 1) {
v = p[i] ^ (seed & 255);
} else {
v = p[i] ^ ((seed>>8) & 255);
}
perm[i] = perm[i + 256] = v;
gradP[i] = gradP[i + 256] = grad3[v % 12];
}
};
seed(0);
/*
for(var i=0; i<256; i++) {
perm[i] = perm[i + 256] = p[i];
gradP[i] = gradP[i + 256] = grad3[perm[i] % 12];
}*/
// Skewing and unskewing factors for 2, 3, and 4 dimensions
var F2 = 0.5*(Math.sqrt(3)-1);
var G2 = (3-Math.sqrt(3))/6;
var F3 = 1/3;
var G3 = 1/6;
// 2D simplex noise
const simplex2 = function(xin, yin) {
var n0, n1, n2; // Noise contributions from the three corners
// Skew the input space to determine which simplex cell we're in
var s = (xin+yin)*F2; // Hairy factor for 2D
var i = Math.floor(xin+s);
var j = Math.floor(yin+s);
var t = (i+j)*G2;
var x0 = xin-i+t; // The x,y distances from the cell origin, unskewed.
var y0 = yin-j+t;
// For the 2D case, the simplex shape is an equilateral triangle.
// Determine which simplex we are in.
var i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
if(x0>y0) { // lower triangle, XY order: (0,0)->(1,0)->(1,1)
i1=1; j1=0;
} else { // upper triangle, YX order: (0,0)->(0,1)->(1,1)
i1=0; j1=1;
}
// A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
// a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
// c = (3-sqrt(3))/6
var x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
var y1 = y0 - j1 + G2;
var x2 = x0 - 1 + 2 * G2; // Offsets for last corner in (x,y) unskewed coords
var y2 = y0 - 1 + 2 * G2;
// Work out the hashed gradient indices of the three simplex corners
i &= 255;
j &= 255;
var gi0 = gradP[i+perm[j]];
var gi1 = gradP[i+i1+perm[j+j1]];
var gi2 = gradP[i+1+perm[j+1]];
// Calculate the contribution from the three corners
var t0 = 0.5 - x0*x0-y0*y0;
if(t0<0) {
n0 = 0;
} else {
t0 *= t0;
n0 = t0 * t0 * gi0.dot2(x0, y0); // (x,y) of grad3 used for 2D gradient
}
var t1 = 0.5 - x1*x1-y1*y1;
if(t1<0) {
n1 = 0;
} else {
t1 *= t1;
n1 = t1 * t1 * gi1.dot2(x1, y1);
}
var t2 = 0.5 - x2*x2-y2*y2;
if(t2<0) {
n2 = 0;
} else {
t2 *= t2;
n2 = t2 * t2 * gi2.dot2(x2, y2);
}
// Add contributions from each corner to get the final noise value.
// The result is scaled to return values in the interval [-1,1].
return 70 * (n0 + n1 + n2);
};
// 3D simplex noise
const simplex3 = function(xin, yin, zin) {
var n0, n1, n2, n3; // Noise contributions from the four corners
// Skew the input space to determine which simplex cell we're in
var s = (xin+yin+zin)*F3; // Hairy factor for 2D
var i = Math.floor(xin+s);
var j = Math.floor(yin+s);
var k = Math.floor(zin+s);
var t = (i+j+k)*G3;
var x0 = xin-i+t; // The x,y distances from the cell origin, unskewed.
var y0 = yin-j+t;
var z0 = zin-k+t;
// For the 3D case, the simplex shape is a slightly irregular tetrahedron.
// Determine which simplex we are in.
var i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
var i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
if(x0 >= y0) {
if(y0 >= z0) { i1=1; j1=0; k1=0; i2=1; j2=1; k2=0; }
else if(x0 >= z0) { i1=1; j1=0; k1=0; i2=1; j2=0; k2=1; }
else { i1=0; j1=0; k1=1; i2=1; j2=0; k2=1; }
} else {
if(y0 < z0) { i1=0; j1=0; k1=1; i2=0; j2=1; k2=1; }
else if(x0 < z0) { i1=0; j1=1; k1=0; i2=0; j2=1; k2=1; }
else { i1=0; j1=1; k1=0; i2=1; j2=1; k2=0; }
}
// A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
// a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
// a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
// c = 1/6.
var x1 = x0 - i1 + G3; // Offsets for second corner
var y1 = y0 - j1 + G3;
var z1 = z0 - k1 + G3;
var x2 = x0 - i2 + 2 * G3; // Offsets for third corner
var y2 = y0 - j2 + 2 * G3;
var z2 = z0 - k2 + 2 * G3;
var x3 = x0 - 1 + 3 * G3; // Offsets for fourth corner
var y3 = y0 - 1 + 3 * G3;
var z3 = z0 - 1 + 3 * G3;
// Work out the hashed gradient indices of the four simplex corners
i &= 255;
j &= 255;
k &= 255;
var gi0 = gradP[i+ perm[j+ perm[k ]]];
var gi1 = gradP[i+i1+perm[j+j1+perm[k+k1]]];
var gi2 = gradP[i+i2+perm[j+j2+perm[k+k2]]];
var gi3 = gradP[i+ 1+perm[j+ 1+perm[k+ 1]]];
// Calculate the contribution from the four corners
var t0 = 0.6 - x0*x0 - y0*y0 - z0*z0;
if(t0<0) {
n0 = 0;
} else {
t0 *= t0;
n0 = t0 * t0 * gi0.dot3(x0, y0, z0); // (x,y) of grad3 used for 2D gradient
}
var t1 = 0.6 - x1*x1 - y1*y1 - z1*z1;
if(t1<0) {
n1 = 0;
} else {
t1 *= t1;
n1 = t1 * t1 * gi1.dot3(x1, y1, z1);
}
var t2 = 0.6 - x2*x2 - y2*y2 - z2*z2;
if(t2<0) {
n2 = 0;
} else {
t2 *= t2;
n2 = t2 * t2 * gi2.dot3(x2, y2, z2);
}
var t3 = 0.6 - x3*x3 - y3*y3 - z3*z3;
if(t3<0) {
n3 = 0;
} else {
t3 *= t3;
n3 = t3 * t3 * gi3.dot3(x3, y3, z3);
}
// Add contributions from each corner to get the final noise value.
// The result is scaled to return values in the interval [-1,1].
return 32 * (n0 + n1 + n2 + n3);
};
// ##### Perlin noise stuff
function fade(t) {
return t*t*t*(t*(t*6-15)+10);
}
function lerp(a, b, t) {
return (1-t)*a + t*b;
}
// 2D Perlin Noise
const perlin2 = function(x, y) {
// Find unit grid cell containing point
var X = Math.floor(x), Y = Math.floor(y);
// Get relative xy coordinates of point within that cell
x = x - X; y = y - Y;
// Wrap the integer cells at 255 (smaller integer period can be introduced here)
X = X & 255; Y = Y & 255;
// Calculate noise contributions from each of the four corners
var n00 = gradP[X+perm[Y]].dot2(x, y);
var n01 = gradP[X+perm[Y+1]].dot2(x, y-1);
var n10 = gradP[X+1+perm[Y]].dot2(x-1, y);
var n11 = gradP[X+1+perm[Y+1]].dot2(x-1, y-1);
// Compute the fade curve value for x
var u = fade(x);
// Interpolate the four results
return lerp(
lerp(n00, n10, u),
lerp(n01, n11, u),
fade(y));
};
// 3D Perlin Noise
const perlin3 = function(x, y, z) {
// Find unit grid cell containing point
var X = Math.floor(x), Y = Math.floor(y), Z = Math.floor(z);
// Get relative xyz coordinates of point within that cell
x = x - X; y = y - Y; z = z - Z;
// Wrap the integer cells at 255 (smaller integer period can be introduced here)
X = X & 255; Y = Y & 255; Z = Z & 255;
// Calculate noise contributions from each of the eight corners
var n000 = gradP[X+ perm[Y+ perm[Z ]]].dot3(x, y, z);
var n001 = gradP[X+ perm[Y+ perm[Z+1]]].dot3(x, y, z-1);
var n010 = gradP[X+ perm[Y+1+perm[Z ]]].dot3(x, y-1, z);
var n011 = gradP[X+ perm[Y+1+perm[Z+1]]].dot3(x, y-1, z-1);
var n100 = gradP[X+1+perm[Y+ perm[Z ]]].dot3(x-1, y, z);
var n101 = gradP[X+1+perm[Y+ perm[Z+1]]].dot3(x-1, y, z-1);
var n110 = gradP[X+1+perm[Y+1+perm[Z ]]].dot3(x-1, y-1, z);
var n111 = gradP[X+1+perm[Y+1+perm[Z+1]]].dot3(x-1, y-1, z-1);
// Compute the fade curve value for x, y, z
var u = fade(x);
var v = fade(y);
var w = fade(z);
// Interpolate
return lerp(
lerp(
lerp(n000, n100, u),
lerp(n001, n101, u), w),
lerp(
lerp(n010, n110, u),
lerp(n011, n111, u), w),
v);
};
return {
seed,
simplex2,
simplex3,
perlin2,
perlin3
};
})();
on('ready',()=>{
//let simplex = new SimplexNoise();
//for( let i = 0; i <= 0.4; i += 0.01) {
//// let n1 = (simplex.noise2D(i,0)-simplex.noise2D(i*.3,0))*2;
// //let n2 = simplex.noise2D(1.0-i,0);
//
// /* eslint-disable no-console */
// console.log( `(${i.toFixed(2)}, 0.0) <-> ${n1.toFixed(4)}`);
// //console.log( `(${i.toFixed(2)}, 0.0) <-> ${n1.toFixed(4)} + ${n2.toFixed(4)} = ${(n1+n2/2).toFixed(4)}`);
//}
// Threshold
const getWind = (n) => {
if(n>1.07) {
return 'A magical storm is coming';
}
if(n>1.06) {
return 'A hurricane is blowing';
}
if(n>1.05) {
return 'A strong storm is blowing';
}
if(n>1.02) {
return 'A storm is blowing';
}
if(n>1.0) {
return 'An extremely strong wind is blowing';
}
if(n>0.95) {
return 'A very strong wind is blowing';
}
if(n>0.93) {
return 'A strong wind is blowing';
}
if(n>0.80) {
return 'A wind is blowing';
}
if(n>0.50) {
return 'A light wind is blowing';
}
if(n>0.40) {
return 'A breeze is blowing';
}
if(n>0.30) {
return 'A light breeze is blowing';
}
if(n>0.2) {
return 'A light breeze is blowing occationaly';
}
return 'The air is still';
};
Noise.seed(2);
let min=10000;
let max=-10000;
//let simplex = new SimplexNoise();
//const NF = (x,y) => (simplex.noise2D(x,y)+1)*.5;
//const NF = (x,y) => Math.max(0,Math.min(1,(Noise.simplex2(x,y)+.79)*.65));
const NF = (x,y) => Noise.perlin2(x,y)+.5;
let y = 0.5;
let dX = 0.05;
for( let i = 0; i <= 10; i += dX) {
y += (Math.random()*(2*dX)-dX);
let line = `(${i.toFixed(2)}, ${y.toFixed(2)}) :: `;
let n = NF(i,y);
min=Math.min(min,n);
max=Math.max(max,n);
let wind = getWind(n);
line += ` ${n.toFixed(2)} [${wind}]`;
/* eslint-disable no-console */
log( line );
}
log(`Min: ${min}, Max: ${max}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment