-
Notifications
You must be signed in to change notification settings - Fork 4
/
dom.js
8530 lines (7699 loc) · 348 KB
/
dom.js
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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
// go to class select if the user's class has not been selected yet for this session
// playerClass is set in savedata
if (playerClass === null) {
window.location.replace("./selection/index.html");
}
window.onfocus = function () {
Dom.focus = true;
}
window.onblur = function () {
Dom.focus = false;
}
let Dom = {
focus: true,
elements: {
acceptOn: document.getElementById("acceptOn"),
achievement: document.getElementById("achievement"),
achievementDescription: document.getElementById("achievementDescription"),
achievementImg: document.getElementById("achievementImg"),
achievementName: document.getElementById("achievementName"),
achievementPoints: document.getElementById("achievementPoints"),
activeAbility: document.getElementById("activeAbility"),
activeQuestBox: document.getElementById("activeQuestBox"),
adventurePage: document.getElementById("adventurePage"),
adventureWrapper: document.getElementById("adventureWrapper"),
aggroOn: document.getElementById("aggroOn"),
bag: document.getElementById("bag"),
bagText: document.getElementById("bagText"),
bankPage: document.getElementById("bankPage"),
bankPageInventory: document.getElementById("bankPageInventory"),
bookmarks: document.getElementById("bookmarks"),
boots: document.getElementById("boots"),
buyer: document.getElementById("buyer"),
buyerPage: document.getElementById("buyerPage"),
buyerPageChat: document.getElementById("buyerPageChat"),
buyerPageInventory: document.getElementById("buyerPageInventory"),
canvasChatInput: document.getElementById("canvasChatInput"),
canvasSend: document.getElementById("canvasSend"),
chance: document.getElementById("chance"),
chanceImage: document.getElementById("chanceImage"),
changeSpellbook: document.getElementById("changeSpellbook"),
changeChat: document.getElementById("changeChat"),
changeInventory: document.getElementById("changeInventory"),
changeQuests: document.getElementById("changeQuests"),
changeAdventure: document.getElementById("changeAdventure"),
changeSettings: document.getElementById("changeSettings"),
charges: document.getElementById("charges"),
chat: document.getElementById("chat"),
chatInput: document.getElementById("chatInput"),
chatPage: document.getElementById("chatPage"),
chatText: document.getElementById("chatText"),
chest: document.getElementById("chest"),
choosePage: document.getElementById("choosePage"),
choosePageAchievementPoints: document.getElementById("choosePageAchievementPoints"),
choosePageBoots: document.getElementById("choosePageBoots"),
choosePageChest: document.getElementById("choosePageChest"),
choosePageContent: document.getElementById("choosePageContent"),
choosePageGreaves: document.getElementById("choosePageGreaves"),
choosePageHelm: document.getElementById("choosePageHelm"),
choosePagePlayer: document.getElementById("choosePagePlayer"),
choosePageWeapon: document.getElementById("choosePageWeapon"),
chooseStats: document.getElementById("chooseStats"),
close: document.getElementById("close"),
closeDriver: document.getElementById("closeDriver"),
closeReputation: document.getElementById("closeReputation"),
completedQuestBox: document.getElementById("completedQuestBox"),
conditionalChooseStats: document.getElementById("conditionalChooseStats"),
conditionalStats: document.getElementById("conditionalStats"),
cooldown: document.getElementById("cooldown"),
coordsOn: document.getElementById("coordsOn"),
creditsPage: document.getElementById("creditsPage"),
darkOn: document.getElementById("darkOn"),
dayNight: document.getElementById("dayNight"),
driverPage: document.getElementById("driverPage"),
driverPageBuy: document.getElementById("driverPageBuy"),
driverPageMain: document.getElementById("driverPageMain"),
durability: document.getElementById("durability"),
food: document.getElementById("food"),
fpsOn: document.getElementById("fpsOn"),
fullscreenOff: document.getElementById("fullscreenOff"),
fullscreenOn: document.getElementById("fullscreenOn"),
functionText: document.getElementById("functionText"),
game: document.getElementById("game"),
greaves: document.getElementById("greaves"),
gridOn: document.getElementById("gridOn"),
helm: document.getElementById("helm"),
hitboxesOn: document.getElementById("hitboxesOn"),
hotbar: document.getElementById("hotbar"),
identifiedPage: document.getElementById("identifiedPage"),
identifiedPageBack: document.getElementById("identifiedPageBack"),
identifiedPageChat: document.getElementById("identifiedPageChat"),
identifiedPageOption: document.getElementById("identifiedPageOption"),
identifierPage: document.getElementById("identifierPage"),
identifierPageBuy: document.getElementById("identifierPageBuy"),
identifierPageChat: document.getElementById("identifierPageChat"),
identifierPageOption: document.getElementById("identifierPageOption"),
idtriangle: document.getElementById("idtriangle"),
information: document.getElementById("information"),
innerStats: document.getElementById("innerStats"),
innerStatus: document.getElementById("innerStatus"),
interact: document.getElementById("interact"),
inventoryGoldXP: document.getElementById("inventoryGoldXP"),
inventoryPage: document.getElementById("inventoryPage"),
itemDescriptionText: document.getElementById("itemDescriptionText"),
itemTier: document.getElementById("itemTier"),
itemIdentification: document.getElementById("itemIdentification"),
itemInventory: document.getElementById("itemInventory"),
leaderboardPage: document.getElementById("leaderboardPage"),
leaderboardPageDescription: document.getElementById("leaderboardPageDescription"),
leaderboardPageList: document.getElementById("leaderboardPageList"),
leaderboardPageList: document.getElementById("leaderboardPageList"),
leaderboardPageTitle: document.getElementById("leaderboardPageTitle"),
leftArrow: document.getElementById("leftArrow"),
level: document.getElementById("level"),
light: document.getElementById("light"),
loot: document.getElementById("loot"),
lootAll: document.getElementById("lootAll"),
lootingPageClose: document.getElementById("lootingPageClose"),
lootingPageTitle: document.getElementById("lootingPageTitle"),
lootPage: document.getElementById("lootPage"),
lore: document.getElementById("lore"),
mailPage: document.getElementById("mailPage"),
merchantPage: document.getElementById("merchantPage"),
merchantPageBuy: document.getElementById("merchantPageBuy"),
merchantPageChat: document.getElementById("merchantPageChat"),
merchantPageOptions: document.getElementById("merchantPageOptions"),
merchantPageTitle: document.getElementById("merchantPageTitle"),
infoBar: document.getElementById("infoBar"),
minigamesOn: document.getElementById("minigamesOn"),
mountSlotLocked: document.getElementById("mountSlotLocked"),
mountSlotUnlocked: document.getElementById("mountSlotUnlocked"),
musicOn: document.getElementById("musicOn"),
name: document.getElementById("name"),
notifsOn: document.getElementById("notifsOn"),
npcChatBanner1: document.getElementById("npcChatBanner1"),
npcChatBannerText1: document.getElementById("npcChatBannerText1"),
npcChatBannerHeader1: document.getElementById("npcChatBannerHeader1"),
npcChatImage: document.getElementById("npcChatImage"),
npcChatNext: document.getElementById("npcChatNext"),
npcChatOptions: document.getElementById("chatBannerOptions"),
npcChatOptionList: document.getElementById("chatBannerOptionList"),
otherQuestBox: document.getElementById("otherQuestBox"),
outIdtriangle: document.getElementById("outIdtriangle"),
outTriangle: document.getElementById("outTriangle"),
particlesOff: document.getElementById("particlesOff"),
particlesOn: document.getElementById("particlesOn"),
players: document.getElementById("players"),
playersInfo: document.getElementById("playersInfo"),
possibleQuestBox: document.getElementById("possibleQuestBox"),
quest: document.getElementById("quest"),
questFinish: document.getElementById("questFinish"),
questFinishItems: document.getElementById("questFinishItems"),
questFinishObjectivesHeading: document.getElementById("questFinishObjectivesHeading"),
questFinishObjectives: document.getElementById("questFinishObjectives"),
questFinishQuest: document.getElementById("questFinishQuest"),
questFinishRewardsTitle: document.getElementById("questFinishRewardsTitle"),
//questFinishStartItems: document.getElementById("questFinishStartItems"),
questFinishXP: document.getElementById("questFinishXP"),
questsPage: document.getElementById("questsPage"),
questStart: document.getElementById("questStart"),
questStartChat: document.getElementById("questStartChat"),
questStartChatWrapper: document.getElementById("questStartChatWrapper"),
questStartItems: document.getElementById("questStartItems"),
questStartName: document.getElementById("questStartName"),
questStartObjectives: document.getElementById("questStartObjectives"),
questStartQuest: document.getElementById("questStartQuest"),
questStartRewardsTitle: document.getElementById("questStartRewardsTitle"),
questStartStartItems: document.getElementById("questStartStartItems"),
questStartStartRewardsTitle: document.getElementById("questStartStartRewardsTitle"),
questStartXP: document.getElementById("questStartXP"),
reputationPage: document.getElementById("reputationPage"),
reputationWrapper: document.getElementById("reputationWrapper"),
rightArrow: document.getElementById("rightArrow"),
scoreboard: document.getElementById("scoreboard"),
secondary: document.getElementById("secondary"),
set: document.getElementById("set"),
settingAcceptHolder: document.getElementById("settingAcceptHolder"),
settingDelete: document.getElementById("settingDelete"),
settingLogout: document.getElementById("settingLogout"),
settingsPage: document.getElementById("settingsPage"),
settingNotifsHolder: document.getElementById("settingNotifsHolder"),
settingsTwoPage: document.getElementById("settingsTwoPage"),
settingTutorialHolder: document.getElementById("settingTutorialHolder"),
speedOn: document.getElementById("speedOn"),
spellArsenal: document.getElementById("spellArsenal"),
spellsEquipped: document.getElementById("spellsEquipped"),
stats: document.getElementById("stats"),
textPage: document.getElementById("textPage"),
them: document.getElementById("them"),
tradePage: document.getElementById("tradePage"),
tradePageInventory: document.getElementById("tradePageInventory"),
tradePageOther: document.getElementById("tradePageOther"),
transparencyOn: document.getElementById("transparencyOn"),
triangle: document.getElementById("triangle"),
trinketSlot1: document.getElementById("trinketSlot1"),
trinketSlot2: document.getElementById("trinketSlot2"),
trinketSlot3: document.getElementById("trinketSlot3"),
tutorialOff: document.getElementById("tutorialOff"),
tutorialOn: document.getElementById("tutorialOn"),
weapon: document.getElementById("weapon"),
weatherOff: document.getElementById("weatherOff"),
weatherOn: document.getElementById("weatherOn"),
nametagOff: document.getElementById("nametagOff"),
nametagOn: document.getElementById("nametagOn"),
},
canvas: {},
chat: {},
inventory: {
slotKeys: { // lookup for inventory DOM slot keyname in Dom.elements based on item type
weapon: "weapon",
helm: "helm",
chest: "chest",
greaves: "greaves",
boots: "boots",
staff: "weapon",
bow: "weapon",
sword: "weapon",
tool: "weapon",
rod: "weapon",
mount: "mountSlotUnlocked",
bag: "bag",
// aaaaaaaaaaaaa tbd trinkets
},
},
hotbar: {},
quests: {},
adventure: {},
reputation: {},
settings: {},
instructions: {},
quest: {},
merchant: {},
identifier: {},
loot: {},
buyer: {},
mail: {},
driver: {},
bank: {},
trade: {},
leaderboard: {},
choose: {},
text: {},
alert: {},
infoBar: {},
achievements: {},
spellChoice: {},
spellbook: {},
};
//
// Alerts
//
Dom.alert.array = []; // number of alerts that have appeared (used to give ids)
// start a dom alert
// text = what the alert says
// type = number of buttons or text or input
// type = 3 makes the button just "ok"
// values (type 3 or text) = array of what buttons will say
// values (input) = "name" if you want name validation
// page = what page it came from (what it appears over); undefined = canvas
// target = an object containing target, ev, targetNo, evNo
// target is the function that is called by confirming the alert
// targetNo is the function that is called by clicking no
// ev is an array of parameters that is passed in to target
// evNo is an array of parameters that is passed in to targetNo
// if type = 3 then the last parameter after all of ev is set to true on clicking second button
Dom.alert.page = function (text, type, values, page, target) { // can't pass in target and ev because chooseStats are called by an innerHTML
// if there are no alerts already open on the same page
if (Dom.alert.array.find(alert => alert.page === page) === undefined || page === undefined) {
if (target === undefined) {
target = {};
}
let id = Dom.alert.array.length;
if (target !== undefined) {
Dom.alert.array.push(Object.assign(target, {id: id, page: page, text: text}));
}
let alert = document.createElement("div");
alert.classList.add("alert");
alert.id = "alert"+id;
if (page !== undefined) {
alert.style.left = document.getElementById(page).offsetLeft+document.getElementById(page).offsetWidth/2-175+"px";
}
else {
alert.style.left = Dom.canvas.width/2-175+"px";
}
// text only (e.g. chooseStats)
if (type === "text") {
alert.innerHTML = `<p class="alertText" id="alertText${id}">${text}</p>
<div class="alertOptions" id="alertOptions${id}" onclick="Game.inventoryUpdate()">${values}</div>`;
}
// text input (e.g. name tag)
else if (type === "input") {
alert.innerHTML = `<p class="alertText" id="alertText${id}">${text}</p>
<input type="text" class="alertInput" id="alertInput${id}"></input>
<div class="alertYes" id="alertYes${id}" onclick="Game.inventoryUpdate()">OK</div>
<div class="alertNo" id="alertNo${id}" style="left: 15px; bottom: 20px;">Cancel</div>`;
}
// 3 buttons
else if (type === 3) {
alert.innerHTML = `<p class="alertText" id="alertText${id}">${text}</p>
<div class="alertYes" id="alertYes${id}" onclick="Game.inventoryUpdate()">${values !== undefined ? values[0] : "One"}</div>
<div class="alertDispose" id="alertDispose${id}" onclick="Game.inventoryUpdate()">${values !== undefined ? values[1] : "All"}</div>
<div class="alertNo" id="alertNo${id}" style="left: 0px; bottom: 5px;">Cancel</div>`;
}
// 2 buttons
else if (type === 2) {
alert.innerHTML = `<p class="alertText" id="alertText${id}">${text}</p>
<div class="alertYes" id="alertYes${id}" onclick="Game.inventoryUpdate()">Yes</div>
<div class="alertNo" id="alertNo${id}" style="left: 15px; bottom: 20px;">No</div>`;
}
// 1 button
else {
alert.innerHTML = `<p class="alertText" id="alertText${id}">${text}</p>
<div class="alertNo" id="alertNo${id}" style="left: 0px; bottom: 20px;">OK</div>`;
}
document.body.appendChild(alert);
// set the functions
if (type === 3 || type === 2) {
document.getElementById("alertYes"+id).onclick = function () {
// close alert and call function with parameter
if (target.ev !== undefined) {
target.target(...target.ev);
}
else {
target.target();
}
document.body.removeChild(alert);
Dom.alert.array.splice(Dom.alert.array.findIndex(index => index.id === target.id, 1));
}
}
if (type === "input") {
document.getElementById("alertYes"+id).onclick = function () {
// close alert and call function with parameter
let value = alert.getElementsByTagName("INPUT")[0].value;
if (target.ev === undefined) {
target.ev = [];
}
let newValue = target.ev.unshift(value); // add player input to the beginning of the parameter array
target.target(...newValue);
document.body.removeChild(alert);
Dom.alert.array.splice(Dom.alert.array.findIndex(index => index.id === target.id, 1));
}
Dom.alert.array[id].value = "";
if (values === "name") {
document.getElementById("alertInput"+id).onkeydown = function () {
setTimeout(function () {
if (ValidateName(document.getElementById("alertInput"+id).value)) {
Dom.alert.array[id].value = document.getElementById("alertInput"+id).value;
}
else {
document.getElementById("alertInput"+id).value = Dom.alert.array[id].value;
}
}, 1);
}
}
}
if (type !== "text") {
document.getElementById("alertNo"+id).onclick = function () {
// close alert only - and potentially call a function
if (target.targetNo !== undefined) {
if (target.evNo !== undefined) {
target.targetNo(...target.evNo);
}
else {
target.targetNo();
}
}
document.body.removeChild(alert);
Dom.alert.array.splice(Dom.alert.array.findIndex(index => index.id === target.id, 1));
}
}
if (type === 3) {
document.getElementById("alertDispose"+id).onclick = function () {
// close alert and call function with parameter and (true)
if (target.ev !== undefined) {
target.target(...target.ev, true);
}
else {
target.target(true);
}
document.body.removeChild(alert);
Dom.alert.array.splice(Dom.alert.array.findIndex(index => index.id === target.id, 1));
}
}
if (type === "text") {
alert.onclick = function () {
document.body.removeChild(alert);
Dom.alert.array.splice(Dom.alert.array.findIndex(index => index.id === target.id, 1));
}
}
}
}
// close the alert from Dom.alert.array with a particular id
Dom.alert.close = function (id) {
document.body.removeChild(document.getElementById("alert"+id));
Dom.alert.array.splice(Dom.alert.array.findIndex(index => index.id === id, 1));
}
// close all open alerts
Dom.alert.closeAll = function () {
for (let i = 0; i < Dom.alert.array.length; i++) {
let id = Dom.alert.array[i].id;
document.body.removeChild(document.getElementById("alert"+id));
Dom.alert.array.splice(0, 1);
i--;
}
}
// Make the save, logout, delete buttons at the top of the settings page
Dom.elements.settingLogout.innerHTML = "You are logged in as "+Player.name+"<div id='settingSave' onclick='Game.saveProgress()'>Save</div><div id='settingLogoutInner' onclick='Game.saveProgress(\"logout\")'>Logout</div><div id='settingDelete' onclick='Dom.settings.delete()'>Delete</div><br><br><br><div id='settingControls' onclick='Dom.settings.page(\"settingsTwoPage\")'>Controls</div>";
Dom.settings.delete = function () {
Dom.alert.page("Are you sure you want to delete your progress for this class? It will be lost forever!", 2, undefined, "settingsPage", {
target: function () {
Dom.settings.deleted = true;
localStorage.removeItem(Player.class);
window.location.replace("./selection/index.html");
}
});
}
// DO NOT ADD CODE ABOVE THIS POINT
Dom.achievements.page = function (i) {
if (!Dom.achievements.wait) {
Dom.achievements.wait = true;
Dom.elements.achievementImg.style = 'background-image: url("'+Achievements[i].image.substring(1)+'")';
Dom.elements.achievementName.innerHTML = '<strong>'+Achievements[i].name+'</strong>';
Dom.elements.achievementDescription.innerHTML = 'Achievement Unlocked';
Dom.elements.achievementPoints.innerHTML = Achievements[i].points;
setTimeout(function () {
Dom.elements.achievementDescription.style.marginRight = 15 + Dom.elements.achievementPoints.offsetWidth+"px";
},1);
if (Achievements[i].position !== undefined) {
Dom.elements.achievementImg.style.backgroundPosition = Achievements[i].position.x+"%"+Achievements[i].position.y+"%";
}
if (Achievements[i].color !== undefined) {
Dom.elements.achievementImg.style.backgroundColor = Achievements[i].color;
}
Dom.elements.achievement.hidden = false;
setTimeout(function () {
Dom.elements.achievementDescription.innerHTML = Achievements[i].description;
}, 3000);
setTimeout(function () {
Dom.elements.achievement.hidden = true;
Dom.achievements.wait = false;
}, 5000);
}else {
setTimeout(function () {
Dom.achievements.page(i);
}, 6000);
}
}
Dom.achievements.update = function () {
for (let i = 0; i < Achievements.length; i++) {
if (!Object.keys(User.achievements).includes(ToCamelCase(Achievements[i].name)) && Achievements[i].isCompleted !== undefined && Achievements[i].isCompleted()) {
User.achievements[ToCamelCase(Achievements[i].name)] = GetFullDateDisplay();
User.achievementPoints.total += Achievements[i].points;
User.achievementPoints.unclaimed += Achievements[i].points;
Dom.achievements.page(i);
// send websocket information if websocket is open
if (ws !== false && ws.readyState === 1) {
ws.send(JSON.stringify({
type: "achievementEarnt",
achievementPoints: User.achievementPoints.total,
achievement: Achievements[i].name
}));
}
}
}
}
// called to update all player quest etc. progress
Dom.checkProgress = function () {
Dom.achievements.update();
Dom.quests.active();
Dom.quests.possible();
}
// called when the player has walked further than its domRange away from the npc that it is talking to (saved in Dom.currentNPC)
Dom.closeNPCPages = function () {
if (this.elements.bankPage.hidden === false) {
Dom.closePage("inventoryPage");
//Dom.bank.active = false;
}
if (Dom.trade.requested) {
Dom.chat.insert("Your trade request with " + Dom.currentlyDisplayed + " has been cancelled because one of you walked away.");
Dom.chat.notification(Dom.currentlyDisplayed + " has cancelled the trade request.");
Dom.trade.requested = false;
}
else if (Dom.trade.received) {
let alert = Dom.alert.array.find(alert => alert.data === "tradeReceived");
if (alert !== undefined) { // showing the function to join the game still (so the wrong one isn't closed by accident)
Dom.alert.close(alert.id);
//document.getElementById("alertNo"+alert.id).onclick();
}
Dom.chat.insert("Your trade request from " + Dom.currentlyDisplayed + " has been cancelled because one of you walked away.");
Dom.chat.notification(Dom.currentlyDisplayed + " has cancelled the trade request.");
Dom.trade.received = false;
}
if (this.elements.tradePage.hidden === false) {
Dom.trade.close(true);
//Dom.closePage("inventoryPage");
//Dom.trade.active = false;
}
this.elements.questStart.hidden = true;
this.elements.questFinish.hidden = true;
this.elements.merchantPage.hidden = true;
this.elements.identifierPage.hidden = true;
this.elements.identifiedPage.hidden = true;
this.elements.lootPage.hidden = true;
this.elements.buyerPage.hidden = true;
this.elements.mailPage.hidden = true;
this.elements.driverPage.hidden = true;
//this.elements.bankPage.hidden = true;
//this.elements.tradePage.hidden = true;
this.elements.leaderboardPage.hidden = true;
this.elements.choosePage.hidden = true;
this.elements.textPage.hidden = true;
this.elements.npcChatBanner1.hidden = true;
Dom.elements.npcChatOptions.hidden = true;
Dom.currentlyDisplayed = "";
Dom.currentNPC = {};
}
// these pages can be displayed even if an NPC page is also being shown (i.e. currentlyDisplayed isn't "")
// therefore these pages won't set currentlyDisplayed or currentNPC
const displayExceptionPages = ["leaderboardPage"];
// notClose is set to true if currentlyDisplayed and currentNPC shoudl not be changed when the page is closed
// i.e. if the NPC is still being spoken to (i.e. another page is opened/still open) after this one is closed
Dom.closePage = function (page, notClose) {
if (page === "chatPage" || page === "inventoryPage" || page === "questsPage" || page === "adventurePage" || page === "spellbookPage" || page === "settingsPage" || page === "settingsTwoPage" || page === "creditsPage") {
let tab = page
if (page === "settingsTwoPage" || page === "creditsPage") {
tab = "settingsPage";
}
document.getElementById("change"+tab.substring(0,1).toUpperCase()+tab.substring(1,tab.length-4)).style.opacity = 0.7;
//document.getElementById("change"+tab.substring(0,1).toUpperCase()+tab.substring(1,tab.length-4)).style.bottom = "-12px";
document.getElementById("change"+tab.substring(0,1).toUpperCase()+tab.substring(1,tab.length-4)).style.marginTop = "12px";
}
else if (!notClose && !displayExceptionPages.includes(page)) {
Dom.currentlyDisplayed = "";
Dom.currentNPC = {};
}
if (page === "inventoryPage" && Dom.bank.active) {
Dom.closePage("bankPage");
Dom.bank.active = false;
}
if (page === "inventoryPage" && !Dom.elements.tradePage.hidden) {
Dom.closePage("tradePage");
if (Dom.trade.active) {
Dom.trade.close();
}
}
document.getElementById(page).hidden = true;
Dom.checkProgress();
}
// open a page, dealing with the positioning of the page on the screen, and whether the page is actually allowed to be shown on the screen (per Dom.currentlyDisplayed)
// returns true if the page was hidden and will now be shown
// openClose means the page is closed if it is already open
// npc is used to set currentNPC if one exists
Dom.changeBook = function (page, npc, openClose) {
let bookmark = false;
let tab = page
let settingsOpen = false;
if (page === "settingsTwoPage" || page === "creditsPage") {
tab = "settingsPage";
}
else if (page === "settingsPage") {
page = Dom.settings.current;
}
if (document.getElementById(page).hidden && !settingsOpen) {
// check if page is a "bookmarked" one
if (page === "chatPage" || page === "inventoryPage" || page === "questsPage" || page === "adventurePage" || page === "spellbookPage" || page === "settingsPage" || page === "settingsTwoPage" || page === "creditsPage") {
bookmark = true;
document.getElementById("change"+tab.substring(0,1).toUpperCase()+tab.substring(1,tab.length-4)).style.opacity = 1;
//document.getElementById("change"+tab.substring(0,1).toUpperCase()+tab.substring(1,tab.length-4)).style.bottom = "0px";
document.getElementById("change"+tab.substring(0,1).toUpperCase()+tab.substring(1,tab.length-4)).style.marginTop = "0px";
}
if (!bookmark && Dom.currentlyDisplayed !== "" && !displayExceptionPages.includes(page)) {
// a page is already displayed
return false;
}
document.getElementById(page).hidden = false;
if (!bookmark && !displayExceptionPages.includes(page)) {
Dom.currentlyDisplayed = page;
if (typeof npc !== "undefined" && typeof npc.type !== "undefined") {
Dom.currentNPC = npc;
}
}
for (let x = 0; x < document.getElementsByClassName("DOM").length; x++) {
if (parseInt(document.getElementsByClassName("DOM")[x].style.zIndex) >= parseInt(document.getElementById(page).style.zIndex)) {
document.getElementsByClassName("DOM")[x].style.zIndex--;
}
}
document.getElementById(page).style.zIndex = 6+document.getElementsByClassName("DOM").length-1;
let left = 530;
let right = 0;
let next = 30;
//let top = 0;
for (let i = 0; i < document.getElementsByClassName("DOM").length; i++) {
if (document.getElementsByClassName("DOM")[i].hidden === false && document.getElementsByClassName("DOM")[i] !== document.getElementById(page)) {
if (document.getElementsByClassName("DOM")[i].offsetLeft < left) {
left = document.getElementsByClassName("DOM")[i].offsetLeft;
//top = document.getElementsByClassName("DOM")[i].offsetTop;
}
if (document.getElementsByClassName("DOM")[i].offsetLeft > right) {
right = document.getElementsByClassName("DOM")[i].offsetLeft;
}
if (document.getElementsByClassName("DOM")[i].style.left === next+"px" && document.getElementsByClassName("DOM")[i].style.top === next+"px") {
next += 22;
}
}
}
// All NPC DOMs have the same position
if (!bookmark) {
document.getElementById(page).style.left = Dom.canvas.npcLeft;
document.getElementById(page).style.top = Dom.canvas.npcTop;
}
if (left < 530) {
if (right < Dom.canvas.width-1060) {
document.getElementById(page).style.left = Dom.canvas.width-530+"px";
}
else {
document.getElementById(page).style.left = next+"px";
document.getElementById(page).style.top = next+"px";
}
}
// All NPC DOMs have the same position
if (!bookmark) {
Dom.canvas.npcLeft = document.getElementById(page).style.left;
Dom.canvas.npcTop = document.getElementById(page).style.top;
}
/*if (page === "chatPage") {
Dom.chat.page();
}*/
// preparation of pages
if (page === "reputationPage") {
Dom.reputation.update();
}
if (page === "chatPage") {
if (Dom.elements.chatText.offsetHeight === 390) {
Dom.elements.chatText.style.overflowY = "auto";
Dom.elements.chatText.scrollTop = Dom.elements.chatText.scrollHeight;
}
}
return true;
}
else if (openClose) {
Dom.closePage(page);
}
}
// called when player connection status changes
Dom.chat.showPlayersOnline = function (type) {
if (type === "hide") {
Dom.elements.players.hidden = true;
Dom.elements.playersInfo.hidden = true;
}
else if (type === "show") {
Dom.chat.overridePlayers = false;
Dom.elements.players.innerHTML = Dom.players.length;
Dom.elements.players.hidden = false;
}
else if (type === "reconnecting") {
Dom.chat.overridePlayers = true;
Dom.elements.players.innerHTML = "Reconnecting...";
Dom.elements.players.hidden = false;
Dom.elements.playersInfo.hidden = true;
}
}
Dom.hotbar.update = function () {
for (let i = 0; i < 6; i++) {
Dom.elements.hotbar.getElementsByTagName("td")[i].innerHTML = Dom.elements.itemInventory.getElementsByTagName("td")[i].innerHTML;
if (Dom.elements.hotbar.getElementsByTagName("td")[i].getElementsByTagName("img").length > 0) {
Dom.elements.hotbar.getElementsByTagName("td")[i].getElementsByTagName("img")[0].setAttribute('draggable', false);
Dom.elements.hotbar.getElementsByTagName("td")[i].getElementsByTagName("img")[0].setAttribute('ondragstart', "return false;");
if (Player.inventory.items[i].onClick !== undefined) {
Dom.elements.hotbar.getElementsByTagName("td")[i].getElementsByTagName("img")[0].setAttribute('onclick', "Player.inventory.items["+i+"].onClick("+i+", true)");
}
}
}
}
//
// Instructions
//
// calls Tutorial in adventuredata.js
Dom.instructions.page = function (chapter) {
if (!Player.skipTutorial && !Player.tipsSeen.includes(chapter) && (Player.tutorialProgress === undefined || Player.tutorialProgress < chapter)) {
// player still wants to see tutorial
if (!Tutorial[chapter].branch) {
// in the main tutorial path
// changes your tutorialProgress chapter
Player.tutorialProgress = chapter;
}
Player.tipsSeen.push(chapter); // array of all chapters seen
Dom.alert.closeAll(); // close all other open tutorial messages
if (chapter === 0 && User.notFirst) {
// instructions for second+ time playing
Tutorial[0].altFunc();
}
else {
Tutorial[chapter].func();
}
}
Dom.quests.possible();
}
Dom.instructions.unlockTab = function (tab, skip) {
if (!Player.unlockedTabs.includes(tab)) {
Player.unlockedTabs.push(tab);
document.getElementById("change"+tab[0].toUpperCase()+tab.substring(1)).style.display = "block";
document.getElementById("change"+tab[0].toUpperCase()+tab.substring(1)).style.bottom = "-12px";
document.getElementById("change"+tab[0].toUpperCase()+tab.substring(1)).style.top = Dom.canvas.height-87+12+"px";
if (skip) {
Player.skippedTabs.push(tab);
}
}
else if (!skip) {
Player.skippedTabs.shift();
}
}
Dom.elements.tutorialOn.onclick = function () {
Dom.instructions.unlockTab("quests", true);
Dom.instructions.unlockTab("chat", true);
Dom.instructions.unlockTab("inventory", true);
Dom.instructions.unlockTab("adventure", true);
Player.skipTutorial = true;
}
Dom.elements.tutorialOff.onclick = function () {
Player.skipTutorial = false;
for (let i = 0; i < Player.skippedTabs.length; i++) {
for (let x = 0; x < Player.unlockedTabs.length; x++) {
if (Player.unlockedTabs[x] === Player.skippedTabs[i]) {
Player.unlockedTabs.splice(x, 1);
}
}
document.getElementById("change"+Player.skippedTabs[i][0].toUpperCase()+Player.skippedTabs[i].substring(1)).style.display = "none";
}
Player.skippedTabs = [];
}
//
// Chat
//
// if message is an array of objects with parameters text and condition
// returns the first message where condition is true or undefined
Dom.chat.decideMessage = function (message) {
// if message is an array of objects
if (message.constructor === Array && typeof message[0] === "object") {
for (let i = 0; i < message.length; i++) {
// if that condition is true or undefined
if (message[i].condition === undefined || message[i].condition()) {
// return that message
return message[i].text;
}
}
}
else {
// if the message is not in this format then return it without editing
return message;
}
}
// format a message for chat, under the format of "name: message"
// name is emboldened via <strong> tags
// if message begins with "/me " (including space), the format changes to "this.name message"
// if message is an array of objects with parameters text and condition, the message is decided from these (first object that satisfies)
Dom.chat.say = function (name, message, language) {
if (message !== undefined) {
// update message for special chat cases
// pick a message based on conditions for messages (if there are no conditions the message is returned normally)
// conditions in message can be done by making message an array of objects, with properties text and conition
message = this.decideMessage(message);
if (message.constructor === Array) {
// pick a random message from the array
message = message[Random(0, message.length - 1)];
}
if (language === "giblish") {
message = Dom.chat.toGiblish(message);
}
if (typeof name === "undefined") {
// no name for NPC, post without a name
}
else if (message.substring(0, 4) === "/me ") {
// reflexive message
message = "<strong>" + name + "</strong> " + message.substr(4, message.length);
}
else {
// normal message (includes NPC name)
message = "<strong>" + name + "</strong>: " + message;
}
return message;
}
else {
console.warn("undefined chat message for " + name);
}
}
// text - array of strings
// values - array of integers which are times in milliseconds between messages (OR a single value, time waited between each message)
// end - function called when sequence is done
// endParameters - array of parameters passed in to end function
// cutscene true means no other npcs can be spoken to whilst this is running
Dom.chat.insertSequence = function (text, values, end, endParameters, cutscene) {
if (values === undefined) {
values = [];
values.length = text.length+1; // should be text.length ??
}
else if (!Array.isArray(values)) {
// single integer value
let x = values;
values = [];
for (let i = 0; i < text.length; i++) {
values.push(x);
}
}
values.push(0);
let time = values[0] || 0;
for (let i = 0; i < text.length; i++) {
if (values[i+1] === undefined) {
values[i+1] = text[i].split(" ").length/200*60000;
}
Dom.chat.insert(text[i], time, values[i+1]);
time += values[i+1];
}
if (cutscene) {
Dom.cutscene(time);
}
if (end !== undefined) {
setTimeout (function () {
end(endParameters);
}, time);
}
}
// input to chat via chat page or bottom right of screen
Dom.chat.input = function (id) {
Dom.chat.playerMessage(Dom.elements[id].value);
Dom.elements[id].value = "";
Dom.elements[id].select();
Dom.elements[id].focus();
}
// player sending a message to chat
Dom.chat.playerMessage = function (message) {
if (message !== "") {
if (message === "/help") {
Dom.chat.insert(Dom.chat.say("The Mighty Zararanath",
`Hello, ${Player.name}. Here is a list of commands that you can type in chat:
<br><br>/me [message] - refer to yourself in the third person.
<br>/msg [player name] [message] - send a message to only one player.
<br>/r [message] - respond to the person who most recently messaged you through /msg.
<br>/ping - see your connection speed with server.
<br><br>If you require help with the game, click your yellow bookmark with a compass on.`));
}
// message intended to be sent to other players
else if (ws === false || ws.readyState !== 1) {
// server off
Dom.chat.insert(Dom.chat.say(Player.name, message));
if (message === "/creative") {
Game.toggleCreativeMode();
}
else if (message.substring(0, 7) === "/image ") {
Game.setCreativeItem(message.substr(7));
}
}
else {
// server on
if (message === "/ping") {
let message = {
type: "ping",
content: Date.now(),
}
let jsonMessage = JSON.stringify(message);
ws.send(jsonMessage);
}
else if (message.substring(0, 5) === "/msg ") {
let array = message.split(" ");
if (array.length > 2 && Dom.players.findIndex(player => player.name === array[1]) !== -1) {
let string = array[2];
for (let i = 3; i < array.length; i++) {
string += " " + array[i];
}
Dom.chat.insert(Dom.chat.say(Player.name + " ➔ " + array[1], string));
let messageObj = {
type: "msg",
name: array[1],
content: string,
}
let jsonMessage = JSON.stringify(messageObj);
ws.send(jsonMessage);
}
else if (array.length <= 2) {
Dom.chat.insert("Incorrect usage of /msg. Should be /msg [player name] [message].");
}
else {
Dom.chat.insert("Player "+array[1]+" cannot be found.");
}
}
else if (message.substring(0, 3) === "/r ") {
if (Dom.chat.replyTo !== undefined) {
Dom.chat.insert(Dom.chat.say(Player.name + " ➔ " + Dom.chat.replyTo, message.substring(3)));
let messageObj = {
type: "msg",
name: Dom.chat.replyTo,
content: message.substring(3),
}
let jsonMessage = JSON.stringify(messageObj);
ws.send(jsonMessage);
}
else {
Dom.chat.insert("You cannot return a message until someone has messaged you first.");
}
}
// send message which is thus broadcasted to all others (no KAO)
else {
let messageObj = {
type: "chat",
name: Player.name,
content: message,