-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoDL Calendar
534 lines (483 loc) · 21.2 KB
/
SoDL Calendar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
// API Commands:
// !cal - for the GM displays the menu in the chat window, for a player displays date, weather, moon and down days
var Calendar = Calendar || (function() {
'use strict';
var colour = '#7E2D40';
const blue = '#063e62', gold = '#b49e67', red = `#8f1313`;
const divstyle = 'style="color: #eee;width: 90%; border: 1px solid black; background-color: #131415; padding: 5px;"';
const astyle1 = `style="text-align:center; border: 1px solid black; margin: 1px; padding: 2px; background-color: ${blue}; border-radius: 4px; box-shadow: 1px 1px 1px #707070; width: 100px;`;
const astyle2 = `style="text-align:center; border: 1px solid black; margin: 3px; padding: 2px; background-color: ${blue}; border-radius: 4px; box-shadow: 1px 1px 1px #707070; width: 150px;"`;
const arrowstyle = `style="border: none; border-top: 3px solid transparent; border-bottom: 3px solid transparent; border-left: 195px solid ${gold}; margin: 5px 0px;"`;
const headstyle = `style="color: #fff; font-size: 18px; text-align: left; font-constiant: small-caps; font-family: Times, serif; margin-bottom: 2px;"`;
const substyle = 'style="font-size: 0.8em; line-height: 13px; margin-top: -2px; font-style: italic;"';
const breaks = `style="border-color:${gold}; margin: 5px 2px;"`;
const label = `style="color: #c9c9c9; display:inline-block; width: 50%"`;
const label2 = `style="color: #c9c9c9; display:inline-block; width: 32%"`;
const centered = `style="text-align:center;"`;
const tdstyle = 'style="padding: 2px; padding-left: 5px; border: none;"';
const version = '1.0';
const setDefaults = () => {
state.Calendar = {
now: {
version: "1.0",
world: 1,
ordinal: 1,
year: 888,
weather: "It is a cool but sunny day.",
startdate: "1,Hammer,1486"
},
};
},
checkDefaults = function() {
if( ! state.Calendar.now.version){state.Calendar.now.version = "3.0.0"};
if( ! state.Calendar.now.world){state.Calendar.now.world = 1};
if( ! state.Calendar.now.ordinal){state.Calendar.now.ordinal = 1};
if( ! state.Calendar.now.year){state.Calendar.now.year = 888};
if( ! state.Calendar.now.weather){state.Calendar.now.weather = "It is a cool but sunny day."};
if( ! state.Calendar.now.startdate){state.Calendar.now.startdate = "1,Hammer,1486"};
},
handleInput = function(msg) {
const args = msg.content.split(",");
const apiOptions = args[0].split(" --");
if (msg.type !== "api") { return; }
if (playerIsGM(msg.playerid) && apiOptions[0] === "!cal"){
switch(apiOptions[1]) {
case 'settings':
calSettings();
break;
case 'setworld':
state.Calendar.now.world=args[1];
calView();
break;
case 'startdate':
state.Calendar.now.startdate=args[1]+','+args[2]+','+args[3];
calView();
break;
case 'setday':
getModernOrdinal(msg);
weather();
calView();
break;
case 'setmonth':
getModernOrdinal(msg);
weather();
calView();
break;
case 'setyear':
state.Calendar.now.year=args[1];
calView();
break;
case 'setordinal':
state.Calendar.now.ordinal=args[1];
calView();
break;
case 'addday':
addday(args[1]);
weather();
calView();
break;
case 'weather':
if(args[1]=='Roll}'){
weather();
}else{
var string = args[1];
for (var i = 2; i < args.length; i++) {
string = string + ", " + args[i];
}
state.Calendar.now.weather = string;
}
calView();
break;
case 'playercal':
showcal(msg);
break;
default:
calView();
break;
}
};
},
calSettings = function() {
var world = getworld();
var moMenu = getMoMenu();
var ordinal = state.Calendar.now.ordinal;
var nowdate = getModernDate(ordinal).split(',');
var month = nowdate[0];
var day = nowdate[1];
var moon = getGreyhawkMoon();
var start = state.Calendar.now.startdate.split(',');
var startdate = start[0]+getsuffix(start[0])+' '+start[1]+', '+start[2];
sendChat('Calendar', `/w gm <div ${divstyle}>` + //--
`<div ${headstyle}>Calendar</div>` + //--
`<div ${substyle}>Menu</div>` + //--
`<div ${arrowstyle}></div>` + //--
'<table>' + //--
`<tr><td>Start Date: </td><td><a ${astyle1}" href="!cal --startdate,?{Day},?{Month},?{Year|888}">${startdate}</a></td></tr>` + //--
`<tr><td>Day: </td><td><a ${astyle1} " href="!cal --setday,?{Day?|1}, ${month}">${day}</a></td></tr>` + //--
`<tr><td>Month: </td><td><a ${astyle1}" href="!cal --setmonth,${day}${moMenu}${month}</a></td></tr>` + //--
'<tr><td>Year: </td><td><a ' + astyle1 + '" href="!cal --setyear,?{Year?|888}">' + state.Calendar.now.year + '</a></td></tr>' + //--
'<tr><td>Ordinal: </td><td><a ' + astyle1 + '" href="!cal --setordinal,?{Ordinal?|1}">' + state.Calendar.now.ordinal + '</a></td></tr>' + //--
'</table>' + //--
'<br>Weather: ' + state.Calendar.now.weather + //--
'<br><br>' + moon + //--
'<br><br><div style="text-align:center;"><a ' + astyle2 + '" href="!cal --addday,?{Days to add?|1}">Advance the Date</a></div>' + //--
'<div style="text-align:center;"><a ' + astyle2 + '" href="!cal --weather,?{Weather|Roll|Edit,?{Edit Weather}}">Change Weather</a></div>' + //--
'<div style="text-align:center;"><a ' + astyle2 + '" href="!cal --playercal">Show to Players</a></div>' + //--
'</div>'
);
},
calView = () => {
const moon = getGreyhawkMoon();
const ordinal = state.Calendar.now.ordinal;
const nowdate = getModernDate(ordinal).split(',');
var month = nowdate[0];
var day = nowdate[1];
var suffix = getsuffix(day);
var start = state.Calendar.now.startdate.split(',');
var startdate = start[0]+getsuffix(start[0])+' '+start[1]+', '+start[2];
sendChat('Calendar', `/w gm <div ${divstyle}>` + //--
`<div ${headstyle}>Calendar</div>` + //--
'<div ' + substyle + '>Menu (v.' + state.Calendar.now.version + ')</div>' + //--
`<div ${arrowstyle}></div>` + //--
`<table ${centered}>` + //--
'<tr><td ' + tdstyle + '>Date: </td><td ' + tdstyle + '>' + day + suffix + ' day of ' + month + ', ' + state.Calendar.now.year + '</td></tr>' + //--
'<tr><td ' + tdstyle + '>Moon: </td><td ' + tdstyle + '>' + moon + //--
'</table>' + //--
'Weather: ' + state.Calendar.now.weather + //--
'<br><br><div style="text-align:center;"><a ' + astyle2 + '" href="!cal --addday,?{Days to add?|1}">Advance the Date</a></div>' + //--
'<div style="text-align:center;"><a ' + astyle2 + '" href="!cal --weather,?{Weather|Roll|Edit,?{Edit Weather}}">Change Weather</a></div>' + //--
'<div style="text-align:center;"><a ' + astyle2 + '" href="!cal --playercal">Show to Players</a></div>' + //--
'<div style="text-align:center;"><a ' + astyle2 + '" href="!cal --settings">Settings</a></div>' + //--
'</div>'
);
},
showcal = function(msg) {
var ordinal = state.Calendar.now.ordinal;
var nowdate = getModernDate(ordinal).split(',');
var month = nowdate[0];
var day = nowdate[1];
var suffix = getsuffix(day);
var world = getworld();
var moon = getGreyhawkMoon();
sendChat(msg.who, '<div ' + divstyle + '>' + //--
`<div ${headstyle}>Calendar</div>` + //--
`<div ${arrowstyle}></div>` + //--
day + suffix + ' day of ' + month + ', ' + state.Calendar.now.year + //--
'<br><br>Today\'s weather:<br>' + state.Calendar.now.weather + //--
`<br><br>${moon}`
);
},
getworld = function() {
var num = Number(state.Calendar.now.world);
var world = 'Modern';
return world;
},
getMoMenu = function() {
var world = Number(state.Calendar.now.world);
var moMenu = ',?{Month|1st Month|2nd Month|3rd Month|4th Month|5th Month|6th Month|7th Month|8th Month|9th Month|10th Month|11th Month|12th Month}">';
return moMenu;
},
getModernDate = function(options){
var day = Number(options);
var date;
var month;
if(day>0 && day<=28){
month="1st Month";
date=day;
}else if(day<= 56){
month="2nd Month";
date=day-28;
}else if(day<=84){
month="3rd Month";
date=day-56;
}else if(day<=112){
month="4th Month";
date=day-84;
}else if(day<=140){
month="5th Month";
date=day-112;
}else if(day<=168){
month="6th Month";
date=day-140;
}else if(day<=196){
month="7th Month";
date=day-168;
}else if(day<=224){
month="8th Month";
date=day-196;
}else if(day<=252){
month="9th Month";
date=day-224;
}else if(day<=280){
month="10th Month";
date=day-252;
}else if(day<=308){
month="11th Month"
date=day-280;
}else if(day<=336){
month="12th Month";
date=day-308;
}else{
month="1st Month";
date='1';
}
var array=month+','+String(date);
return array;
},
getModernOrdinal = function(options){
var args = options.content.split(",");
var date = Number(args[1]);
var month = args[2];
var ordinal = state.Calendar.now.ordinal;
switch(month) {
case '1st Month':
ordinal = date;
break;
case '2nd Month':
ordinal = 28+date;
break;
case '3rd Month':
ordinal = (28*2)+date;
break;
case '4th Month':
ordinal = (28*3)+date;
break;
case '5th Month':
ordinal = (28*4)+date;
break;
case '6th Month':
ordinal = (28*5)+date;
break;
case '7th Month':
ordinal = (28*6)+date;
break;
case '8th Mont':
ordinal = (28*7)+date;
break;
case '9th Month':
ordinal = (28*8)+date;
break;
case '10th Month':
ordinal = (28*9)+date;
break;
case '11th Month':
ordinal = (28*10)+date;
break;
case '12th Month':
ordinal = (28*11)+date;
break;
}
state.Calendar.now.ordinal = ordinal;
},
addday = function(no){
var days = Number(no);
let ordinal = Number(state.Calendar.now.ordinal);
ordinal = ordinal+days;
if (ordinal > 336) {
ordinal=ordinal-336;
state.Calendar.now.year = Number(state.Calendar.now.year)+1;
}
state.Calendar.now.ordinal = ordinal;
},
getsuffix = function(day) {
var date = Number(day);
var suffix = (date == 1 || date == 21 ) ? 'st' : (date == 2 || date == 22) ? 'nd' : (date == 3 || date == 23) ? 'rd' : 'th';
return suffix;
},
weather = function() {
var roll;
var temperature;
var wind;
var precipitation;
var season;
var ordinal = state.Calendar.now.ordinal;
if (ordinal > 308 || ordinal <= 28) {
season = 'Winter'
} else if (ordinal > 28 && ordinal <= 140) {
season = 'Spring'
} else if (ordinal > 140 && ordinal <= 224) {
season = 'Summer'
} else {
season = 'Fall'
}
roll = Math.floor(Math.random()*(20-1+1)+1);
if(roll>=15 && roll<=17){
switch(season) {
case 'Winter':
temperature = 'It is a bitterly cold winter day. ';
break;
case 'Spring':
temperature = 'It is a cold spring day. ';
break;
case 'Summer':
temperature = 'It is a cool summer day. ';
break;
case 'Fall':
temperature = 'It is a cold fall day. ';
break;
}
}else if(roll>=18 && roll<=20){
switch(season) {
case 'Winter':
temperature = 'It is a warm winter day. ';
break;
case 'Spring':
temperature = 'It is a hot spring day. ';
break;
case 'Summer':
temperature = 'It is a blisteringly hot summer day. ';
break;
case 'Fall':
temperature = 'It is a hot fall day. ';
break;
}
}else{
switch(season) {
case 'Winter':
temperature = 'It is a cold winter day. ';
break;
case 'Spring':
temperature = 'It is a mild spring day. ';
break;
case 'Summer':
temperature = 'It is a hot summer day. ';
break;
case 'Fall':
temperature = 'It is a mild fall day. ';
break;
}
}
roll = Math.floor(Math.random()*(20-1+1)+1);
if(roll>=15 && roll<=17){
wind='There is a light breeze and ';
}else if(roll>=18 && roll<=20){
wind='There is a howling wind and ';
}else{
wind='The air is still and ';
}
roll = Math.floor(Math.random()*(20-1+1)+1);
if(roll>=15 && roll<=17){
precipitation="Light rain or snow.";
if(season=='Winter'){
precipitation = 'snow falls softly on the ground.';
}else{
precipitation = 'a light rain falls from the sky.';
}
}else if(roll>=18 && roll<=20){
if(season=='Winter'){
precipitation = 'snow falls thick and fast from the sky.';
}else{
precipitation = 'a torrential rain begins to fall.';
}
}else{
roll = Math.floor(Math.random()*(2-1+1)+1);
if(roll=1){
precipitation = 'the sky is overcast.';
}else{
precipitation = 'the sky is clear.';
}
}
var forecast=temperature+wind+precipitation;
state.Calendar.now.weather = forecast;
},
getGreyhawkMoon = function() {
var ordinal = Number(state.Calendar.now.ordinal);
var lunaArray = '0,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7,7,8,8,9,10,10,11,12,12,13,13,14,14,15,15,16,16,1,2,2,3,4,4,5,5,6,6,7';
var lunaNO = lunaArray.split(",");
var lunaImg = lunaNO[ordinal];
var Luna = getMoon(lunaImg);
var moon = '<img src="'+Luna+'" style="width:40px;height:40px;"></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';
break;
case '2':
// moon = 'Waning Gibbous';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Twemoji_1f316.svg/512px-Twemoji_1f316.svg.png';
break;
case '3':
// moon = 'Waning Gibbous';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Twemoji_1f316.svg/512px-Twemoji_1f316.svg.png';
break;
case '4':
// moon = 'Waning Gibbous';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Twemoji_1f316.svg/512px-Twemoji_1f316.svg.png';
break;
case '5':
// moon = 'Last Quarter';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/67/Twemoji_1f317.svg/512px-Twemoji_1f317.svg.png';
break;
case '6':
// moon = 'Waning Crescent';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Twemoji_1f318.svg/512px-Twemoji_1f318.svg.png';
break;
case '7':
// moon = 'Waning Crescent';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Twemoji_1f318.svg/512px-Twemoji_1f318.svg.png';
break;
case '8':
// moon = 'Waning Crescent';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Twemoji_1f318.svg/512px-Twemoji_1f318.svg.png';
break;
case '9':
// moon = 'New Moon';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Twemoji_1f311.svg/512px-Twemoji_1f311.svg.png';
break;
case '10':
// moon = 'Waxing Crescent';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Twemoji_1f312.svg/512px-Twemoji_1f312.svg.png';
break;
case '11':
// moon = 'Waxing Crescent';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Twemoji_1f312.svg/512px-Twemoji_1f312.svg.png';
break;
case '12':
// moon = 'Waxing Crescent';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Twemoji_1f312.svg/512px-Twemoji_1f312.svg.png';
break;
case '13':
// moon = 'First Quarter';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Twemoji_1f313.svg/512px-Twemoji_1f313.svg.png';
break;
case '14':
// moon = 'Waxing Gibbous';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Twemoji_1f314.svg/512px-Twemoji_1f314.svg.png';
break;
case '15':
// moon = 'Waxing Gibbous';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Twemoji_1f314.svg/512px-Twemoji_1f314.svg.png';
break;
case '16':
// moon = 'Waxing Gibbous';
moon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Twemoji_1f314.svg/512px-Twemoji_1f314.svg.png';
break;
}
return moon;
},
checkInstall = function() {
if( ! state.Calendar.now.version ) {
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();
});