-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
1729 lines (1634 loc) · 57.4 KB
/
game.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
const VERSION = 13;
var flashInterval;
var flashTimeout;
function flash(message, period, times) {
clearInterval(flashInterval);
clearTimeout(flashTimeout);
function callback() {
var banner = document.getElementsByClassName("thebanner")[0];
var contents = banner.innerHTML;
banner.innerHTML = (contents == message) ? " " : message;
}
flashInterval = setInterval(callback, period);
flashTimeout = setTimeout(function () {
var banner = document.getElementsByClassName("thebanner")[0];
banner.innerHTML = "";
clearInterval(flashInterval);
}, 2 * period * times);
}
// Thanks https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage
if (!window.localStorage) {
Object.defineProperty(window, "localStorage", new (function () {
var aKeys = [], oStorage = {};
Object.defineProperty(oStorage, "getItem", {
value: function (sKey) { return sKey ? this[sKey] : null; },
writable: false,
configurable: false,
enumerable: false
});
Object.defineProperty(oStorage, "key", {
value: function (nKeyId) { return aKeys[nKeyId]; },
writable: false,
configurable: false,
enumerable: false
});
Object.defineProperty(oStorage, "setItem", {
value: function (sKey, sValue) {
if(!sKey) { return; }
document.cookie = escape(sKey) + "=" + escape(sValue) + "; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/";
},
writable: false,
configurable: false,
enumerable: false
});
Object.defineProperty(oStorage, "length", {
get: function () { return aKeys.length; },
configurable: false,
enumerable: false
});
Object.defineProperty(oStorage, "removeItem", {
value: function (sKey) {
if(!sKey) { return; }
document.cookie = escape(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
},
writable: false,
configurable: false,
enumerable: false
});
this.get = function () {
var iThisIndx;
for (var sKey in oStorage) {
iThisIndx = aKeys.indexOf(sKey);
if (iThisIndx === -1) { oStorage.setItem(sKey, oStorage[sKey]); }
else { aKeys.splice(iThisIndx, 1); }
delete oStorage[sKey];
}
for (aKeys; aKeys.length > 0; aKeys.splice(0, 1)) { oStorage.removeItem(aKeys[0]); }
for (var aCouple, iKey, nIdx = 0, aCouples = document.cookie.split(/\s*;\s*/); nIdx < aCouples.length; nIdx++) {
aCouple = aCouples[nIdx].split(/\s*=\s*/);
if (aCouple.length > 1) {
oStorage[iKey = unescape(aCouple[0])] = unescape(aCouple[1]);
aKeys.push(iKey);
}
}
return oStorage;
};
this.configurable = false;
this.enumerable = true;
})());
}
// Note: the following two function are limited to native ints
// Thanks https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
// Returns a random number between min (inclusive) and max (exclusive)
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
// Returns a random integer between min (included) and max (excluded)
// Using Math.round() will give you a non-uniform distribution!
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
// Returns a random integer between min (included) and max (included)
// Using Math.round() will give you a non-uniform distribution!
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var game = {};
var iMsgLog = [];
var msgLog = [];
var needRefresh = false;
var lastWordsSaid = false;
var tooltipVisible = false;
const MAX_LOG_ENTRIES = 100;
function beautify(n) {
var ns = n.toString();
var len = ns.length;
var head = len % 3 || 3; // kek
var res = ns.slice(0, head);
for (var i = head; i < len; i += 3) {
res += "," + ns.slice(i, i + 3);
}
return res;
}
var words = [
"million", "billion", "trillion", "quadrillion",
"quintillion", "sextillion", "septillion", "octillion",
"nonillion", "decillion", "undecillion", "duodecillion",
"tredecillion", "quattuordecillion", "quindecillion",
"sedecillion", "septendecillion", "octodecillion",
"novemdecillion", "vigintillion"
];
var pcOfLast = words.length + 1;
function shorten(n) {
if (n === undefined) return "undefined";
if (n.valueOf() < 1000000) return beautify(n);
var ns = n.toString();
var power = ns.length - 1;
var cls = Math.floor(power / 3);
var residue = power % 3;
if (cls > pcOfLast) {
return shorten(ns.slice(0, ns.length - 3 * pcOfLast)) +
" " + words[words.length - 1];
} else {
var left = ns.slice(0, residue + 1);
var right = ns.slice(residue + 1, 6);
return left + "." + right + " " + words[cls - 2];
}
}
function S(n) {
return n == 1 ? "" : "s";
}
function beautifyTime(t) {
var s = [];
if (t >= 3600 * 20) {
var h = Math.floor(t / (3600 * 20));
s.push([h + " hour" + S(h)]);
t -= 3600 * 20 * h
}
if (t >= 60 * 20) {
var m = Math.floor(t / (60 * 20));
s.push([m + " minute" + S(m)]);
t -= 60 * 20 * m
}
s.push([(t / 20).toFixed(1) + " second" + S(t / 20)]);
return s.join(", ");
}
// Thanks http://stackoverflow.com/a/196991/3130218
function toTitleCase(str) {
if (str === undefined) return "uNDEFINED";
return str.replace(/\w\S*/g, function(txt){ return txt.charAt(0).toUpperCase() + txt.substr(1); });
}
function isVowelInitial(str) {
return str.match(/^[AEIOUaeiou]/) != null;
}
function attachA(str) {
return (isVowelInitial(str) ? "an " : "a ") + str;
}
function pluralize(str) {
return str + "s";
}
function attachNum(str, count) {
return count == 0 ? "no " + pluralize(str) :
count == 1 ? attachA(str) :
count + " " + pluralize(str);
}
function substSafe(obj) {
if (obj.xor) return { xor: obj.toString() };
if (typeof(obj) !== "object") return obj;
var upd = {};
for (var key in obj) {
var val = obj[key];
upd[key] = substSafe(val);
}
return upd;
}
function desubstSafe(obj) {
if (obj.xor) return bigInt(obj.xor);
if (typeof(obj) !== "object") return obj;
var upd = {};
for (var key in obj) {
var val = obj[key];
upd[key] = desubstSafe(val);
}
return upd;
}
function save() {
if (game.died) return;
var gameStr = JSON.stringify(substSafe(game));
localStorage.setItem("Clicker101SaveData", gameStr);
console.log("Saved: " + gameStr);
logMessage("Game saved.");
}
function merge(existingGame, newGame) {
for (var key in newGame) {
if (existingGame[key] == undefined)
existingGame[key] = newGame[key];
else if (typeof(existingGame[key]) === "object") {
merge(existingGame[key], newGame[key]);
}
}
}
function load() {
resetGame();
var newGame = game;
var gameStr = localStorage.getItem("Clicker101SaveData");
if (gameStr === null) {
resetGame();
return;
}
game = desubstSafe(JSON.parse(gameStr));
merge(game, newGame);
for (var key in game.staffPrice) {
var amt = game.staff[key];
game.staffPrice[key] = increase(baseStaffPrices[key], amt);
}
for (var upgrade in game.upgrades) {
addChildrenToAvailableList(upgrade);
}
game.version = VERSION;
console.log("Loaded: " + gameStr);
loadStaff();
loadUpgrades();
logMessage("Game loaded.");
if (game.died) onDeath();
else onLife();
}
function refreshAutoSaveMessage() {
var button = document.getElementById("autosave");
button.innerHTML = "Autosave " +
(game.autosave ? "ON" : "OFF");
}
function toggleAutoSave() {
game.autosave = !game.autosave;
}
function autoSave() {
if (game.autosave) save();
}
function logMessage(msg) {
iMsgLog.push(msg);
needRefresh = true;
}
function refreshLog() {
if (needRefresh) {
msgLog = iMsgLog.concat(msgLog);
iMsgLog = [];
if (msgLog.length >= 2 * MAX_LOG_ENTRIES) {
msgLog = msgLog.slice(0, MAX_LOG_ENTRIES);
}
var recentMessages = msgLog.slice(
0, Math.min(msgLog.length - 1, MAX_LOG_ENTRIES));
var box = document.getElementById("msglog");
box.innerHTML = recentMessages.join('<br>');
needRefresh = false;
if (game.died) lastWordsSaid = true;
}
}
function resetGame() {
game = {};
game.ver = 0;
game.resources = {
gold: bigInt.zero,
xp: bigInt.zero,
level: bigInt.one,
crowns: bigInt.zero,
activePlayers: bigInt("20000000"),
population: bigInt("7000000000"),
gear: bigInt.zero,
loot: bigInt.zero,
tickets: bigInt.zero,
wolf: bigInt.zero,
};
game.hres = {
gps: bigInt.zero,
agr: -30,
bagr: -30,
pgr: 12,
pp: 100,
fact: 0,
};
game.staff = {};
game.staffPrice = {};
game.upgrades = {};
game.died = false;
game.autosave = true;
game.cumulGold = 0;
game.cumulGear = 0;
game.timer = 0;
game.timer2 = {};
game.timer3 = {};
game.gps = bigInt.zero;
game.special = {};
game.version = VERSION;
var staffList = document.getElementById("staff");
staffList.innerHTML = "";
var upgradeList = document.getElementById("upgrades");
upgradeList.innerHTML = "";
var purchasedUpgradeList = document.getElementById("purchased-upgrades");
purchasedUpgradeList.innerHTML = "";
for (var upgrade in defaultUpgrades) {
availableUpgrades[upgrade] = defaultUpgrades[upgrade];
}
resourceNodesMade = {};
var resourcePanel = document.getElementsByClassName("mainResources")[0];
resourcePanel.innerHTML = "";
onLife();
}
function requestTimer(freq) {
if (game.timer2[freq] === undefined) {
game.timer2[freq] = 0;
game.timer3[freq] = Math.floor(game.timer / freq);
}
}
function updateTimers(d) {
for (var freq in game.timer2) {
if (game.timer2[freq] >= freq) {
game.timer2[freq] -= freq;
++game.timer3[freq];
}
game.timer2[freq] += d;
}
}
function timerRings(freq) {
requestTimer(freq);
return game.timer2[freq] >= freq;
}
function timerRingCount(freq) {
requestTimer(freq);
return game.timer3[freq];
}
var resourceNames = {
gold: "gold",
xp: "experience",
level: "level",
crowns: "Crowns",
loot: "loot",
gear: "awesome gear",
activePlayers: "active players",
population: "population",
tickets: "arena tickets",
wolf: "wolf points",
};
var resourceDescriptions = {
gold: "A common loot from mobs.",
xp: "Another common drop. Get enough of these to level up.",
level: "Higher levels mean more stuff for you.",
crowns: "Special wizard money for good wizards.",
loot: "Special loot from bosses.",
gear: "Special gear from bosses that will make your life easier when fighting.",
activePlayers: "The number of people playing the game regularly.",
population: "The number of people on Earth.",
tickets: "A reward from doing well in PvP.",
wolf: "Because you're diligent enough to work your butt off for money but too lazy to farm for game items.",
}
function resAmt(name, qty, inflation) {
if (!qty.xor) qty = bigInt(qty);
if (!inflation) inflation = 23;
return {
"type": name,
"qty": qty,
"inflation": inflation
};
}
function increase(price, units) {
return price.map(function (res) {
return {
"type": res.type,
"qty": res.qty.times(bigInt(res.inflation).pow(units)).divide(bigInt(20).pow(units)),
"inflation": res.inflation
};
})
}
function priceToString(price) {
return price.map(function (res) {
return shorten(res.qty) + " " + resourceNames[res.type];
}).join(", ");
}
function canAfford(price) {
return price.every(function (res) {
return game.resources[res.type] &&
game.resources[res.type].greaterOrEquals(res.qty)
});
}
function whatIsInsufficient(price) {
return price.filter(function (res) {
return !game.resources[res.type] ||
game.resources[res.type].lesser(res.qty)
}).map(function (res) { return res.type; });
}
function deductPrice(price) {
return price.map(function (res) {
game.resources[res.type] = game.resources[res.type].minus(res.qty);
});
}
function growthRatePrognostics(rate) {
if (rate < -500) return "might as well be dead";
if (rate < -250) return "is quickly dying";
if (rate < -100) return "is dying";
if (rate < -50) return "is diminishing";
if (rate < 0) return "is slowly diminishing";
if (rate < 30) return "is doing fairly";
if (rate < 100) return "is doing well";
if (rate < 200) return "is thriving";
return "is booming";
}
var resourceNodesMade = {};
function updateResourceNode(res) {
var node = document.getElementById("resamt-" + res);
var inner = beautify(game.resources[res]);
if (res == "xp")
inner += " / " + beautify(xpNeeded(game.resources.level));
node.innerHTML = inner;
}
function createResourceNode(panel, res) {
var inner = "<div><span class=\"resource\" onmouseover=\"startResourceTooltip('" +
res + "', event)\" " + "onmouseout=\"hideResourceTooltip()\">" +
toTitleCase(resourceNames[res]) + ": " +
"<span id=\"resamt-" + res + "\">";
inner += beautify(game.resources[res]);
if (res == "xp")
inner += " / " + beautify(xpNeeded(game.resources.level));
inner += "</span></span></div>";
panel.innerHTML += inner;
resourceNodesMade[res] = true;
}
function displayResources() {
if (game.died) return;
var resourcePanel = document.getElementsByClassName("mainResources")[0];
var prognosticPanel = document.getElementsByClassName("prognostics")[0];
var inner = "";
for (var res in game.resources) {
if (res == "gold" || res == "xp" ||
game.resources[res].valueOf() != 0 ||
resourceNodesMade[res] !== undefined) {
if (!resourceNodesMade[res]) createResourceNode(resourcePanel, res);
else updateResourceNode(res);
}
}
var rate = game.hres.agr;
prognosticPanel.innerHTML = "Your favorite game " + growthRatePrognostics(rate) + ".<br>";
}
var staffNames = {
novice: "novice wizard",
apprentice: "apprentice wizard",
initiate: "initiate wizard",
fanboy: "ardent fan",
journeyman: "journeyman wizard",
adept: "adept wizard",
magus: "magus wizard",
master: "master wizard",
grandmaster: "grandmaster wizard",
gearCrafter: "gear crafter",
legendary: "legendary wizard",
transcendent: "transcendent wizard",
pvpLord: "PvP warlord",
archmage: "archmage wizard",
promethean: "promethean wizard",
exalted: "exalted wizard",
overlord: "PvP overlord",
trivia: "trivia monkey",
prodigious: "prodigious wizard",
gun: "explosive bow",
champion: "champion wizard",
};
var staffDescriptions = {
novice: "A beginner to farm for you.",
apprentice: "Someone more experienced with magic.",
initiate: "This wizard now knows Rank-3 spells.",
fanboy: "A player who is engrossed in ***ard101.",
journeyman: "A wizard who has experience fighting in K***otopia. I hope.",
adept: "This wizard is now solving incidents in M********e.",
magus: "A hardened veteran in M*****.",
master: "Well-versed in magical combat, this player is ready to face the travails of D**********.",
grandmaster: "This wizard has survived the backbreaking effort to stop M********* D****, once and for all.",
gearCrafter: "Crafts high-level gear.",
legendary: "A level 60 wizard who is now leaving C******a and entering Z*****a.",
transcendent: "An even-higher level wizard to farm large amounts of gold.",
pvpLord: "A PvP master to attract even more players.",
archmage: "Best of luck to this wizard on A****a.",
promethean: "<b><i>OH NO WHAT HAPPENED TO A****A</i></b>",
exalted: "This wizard restored B****** and defeated M********, saving the spiral. Sizzle, young wizard, sizzle.",
overlord: "Why settle for 700 rank when you can go for 1000?",
trivia: "A NEET to complete trivias for you.",
prodigious: "The strongest in ***ard101, at least until M***** is released.",
gun: "These are also called guns.",
champion: "Let's be honest. These wizards are even <i>worse</i> than exalteds.",
};
var baseStaffPrices = {
novice: [resAmt("gold", 30)],
apprentice: [resAmt("gold", 200)],
initiate: [resAmt("gold", 550)],
fanboy: [resAmt("gold", 860)],
journeyman: [resAmt("gold", 2500)],
adept: [resAmt("gold", 8000)],
magus: [resAmt("gold", 17800)],
master: [resAmt("gold", 55000)],
grandmaster: [resAmt("gold", 160000)],
gearCrafter: [resAmt("gold", 200000)],
legendary: [resAmt("gold", 680000)],
transcendent: [resAmt("gold", 1890000)],
pvpLord: [resAmt("gold", 700000)],
archmage: [resAmt("gold", 5600000)],
promethean: [resAmt("gold", 27800000)],
exalted: [resAmt("gold", 345678901)],
overlord: [resAmt("gold", 456789012)],
trivia: [resAmt("gold", 10000000), resAmt("crowns", 50, 20)],
prodigious: [resAmt("gold", "88888888888")],
gun: [resAmt("crowns", 120000, 20)],
champion: [resAmt("gold", "999999999999")],
};
function staffCount(name) {
return game.staff[name] || 0;
}
function levelMinimum(l) {
return function() { return game.resources.level.greaterOrEquals(l) }
}
var wizardClasses = {
novice: true,
apprentice: true,
initiate: true,
journeyman: true,
adept: true,
magus: true,
master: true,
grandmaster: true,
legendary: true,
transcendent: true,
archmage: true,
promethean: true,
exalted: true,
prodigious: true,
champion: true,
};
var wizardClassesAsList = [];
for (var key in wizardClasses)
wizardClassesAsList.push(key);
function wizardCount() {
var c = 0;
for (var key in wizardClasses) {
c += game.staff[key] || 0;
}
return c;
}
function wizardMinimum(u) {
return function() {
var c = 0;
for (var key in wizardClasses) {
c += game.staff[key] || 0;
}
return c >= u;
}
}
function staffMinimum(name, count) {
return function() {
return staffCount(name) >= count;
}
}
var staffRequirements = {
novice: function () { return true; },
apprentice: levelMinimum(5),
initiate: levelMinimum(10),
fanboy: levelMinimum(12),
journeyman: levelMinimum(15),
adept: levelMinimum(20),
magus: levelMinimum(30),
master: levelMinimum(40),
grandmaster: levelMinimum(50),
gearCrafter: levelMinimum(56),
legendary: levelMinimum(60),
transcendent: levelMinimum(70),
pvpLord: function () {
return game.upgrades.arena && game.resources.level.greaterOrEquals(60);
},
archmage: levelMinimum(80),
promethean: levelMinimum(90),
exalted: levelMinimum(100),
overlord: function () {
return game.upgrades.arena3 && game.resources.level.greaterOrEquals(100);
},
trivia: function() {
return game.resources.crowns.greaterOrEquals(150);
},
prodigious: levelMinimum(110),
gun: levelMinimum(110),
champion: levelMinimum(120),
}
function updateStaffCount(name, amt) {
var staffQty = document.getElementById("staffQty-" + name);
var staffPrice = document.getElementById("staffPrice-" + name);
var oldAmt = game.staff[name];
var oldPrice = game.staffPrice[name];
var newPrice;
if (amt < oldAmt) {
newPrice = increase(baseStaffPrices[name], amt);
} else {
newPrice = increase(baseStaffPrices[name], amt);
}
game.staffPrice[name] = newPrice;
game.staff[name] = amt;
staffQty.innerHTML = amt;
staffPrice.innerHTML = priceToString(newPrice);
}
function buyOneStaff(name) {
var needed = whatIsInsufficient(game.staffPrice[name]);
if (needed.length != 0)
return needed;
deductPrice(game.staffPrice[name]);
updateStaffCount(name, game.staff[name] + 1);
return [];
}
function buyStaff(name, count) {
for (var i = 0; i < count; ++i) {
var needed = buyOneStaff(name);
if (needed.length != 0) return [i, needed];
}
return [count, []];
}
function neededToString(needed, and) {
if (!needed.length) return "NOTHING";
if (needed.length == 1)
return resourceNames[needed[0]];
if (needed.length == 2)
return resourceNames[needed[0]] + (and ? " and " : " or ") + resourceNames[needed[1]];
var realNames = needed.map(function (nm) { return resourceNames[nm]; });
return realNames.slice(0, needed.length - 1).join(", ") +
(and ? ", and " : ", or ") + resourceNames[needed[needed.length - 1]];
}
function buyStaffVerbose(name, count) {
count = count || 1;
var res = buyStaff(name, count);
var needed = res[1];
var bought = res[0];
var messages = [];
if (bought > 0)
messages.push("You successfully purchased " +
attachNum(staffNames[name], bought) + ".");
if (needed.length != 0)
messages.push(
(bought > 0 ? "But y" : "Y") + "ou don't have enough " +
neededToString(needed, false) +
(bought > 0 ? " for more." : ".")
);
if (messages.length != 0)
logMessage(messages.join(" "));
}
function staffHTML(staffName) {
var qty = (game.staff[staffName] || 0);
var html = "<tr><td class=\"staffEntry\" id=\"staff-" + staffName + "\">";
html += "<b>" + toTitleCase(staffNames[staffName]) + "</b><br>";
html += staffDescriptions[staffName] + "<br>";
html += "Quantity: <span class=\"staffPrice\" id=\"staffQty-" +
staffName + "\">" + qty + "</span><br>";
html += "Price: <span class=\"staffPrice\" id=\"staffPrice-" +
staffName + "\">" +
priceToString(qty > 0 ? game.staffPrice[staffName] : baseStaffPrices[staffName]) +
"</span><br>";
html += "</td><td>";
html += "<button type=\"button\" onclick=\"buyStaffVerbose('" +
staffName + "')\" class=\"disableWhenDead\">Buy</button>";
html += "<button type=\"button\" onclick=\"buyStaffVerbose('" +
staffName + "', 10)\" class=\"disableWhenDead\">(10)</button>";
html += "</td></tr>";
return html;
}
function updateStaff() {
var staffList = document.getElementById("staff");
for (var staffName in staffRequirements) {
if (game.staff[staffName] === undefined && staffRequirements[staffName]()) {
staffList.innerHTML += staffHTML(staffName);
game.staff[staffName] = 0;
game.staffPrice[staffName] = baseStaffPrices[staffName];
}
}
}
function loadStaff() {
var staffList = document.getElementById("staff");
staffList.innerHTML = "";
for (var staffName in game.staff) {
staffList.innerHTML += staffHTML(staffName);
}
}
var upgradeNames = {
socialMedia: "Social media",
test: "Raunchy hex",
bears: "G******heim",
littleBrother: "Little brother",
questStack: "Quest stacking",
lessons: "D****'s lessons",
party: "Questing party",
arena: "Gold-lined arena",
valor: "Fight J****!",
rank7: "Rank 7 spells",
mount: "Awesome mount",
weed: "Extra-strength grendelweed",
winter: "Winter is coming",
goldFarm: "Half*** B******C****",
sun: "Sun magic",
bazaar: "Bazaar",
youtube: "YouTube",
war: "War on twizard intros",
pvpVideos: "PvP videos",
synergy1: "Synergy I: Border between PvE and PvP",
critical: "Criticality",
tc: "Treasure cards",
luis: "Secrets from Luis",
sun2: "Sun magic part 2",
ihateaz: "I hate A****a",
runLuis: "Run Run Dino!",
empire: "World empire",
wand: "Finger-shaped wand",
bastion: "B****** Restoration Project",
shadow: "Shadow magic",
evil: "So you have to be evil",
sea: "Starf*** Sea",
ww: "W****w***s",
com1: "First Chamber of the Mind",
com2: "Second Chamber of the Mind",
com3: "Third Chamber of the Mind",
a1f: "Defeat M**********",
a2f: "Defeat Shadow Queen",
empire2: "Galactic empire",
trivia: "KI Trivia",
tree: "B*****by's Wisdom",
dark: "D***m***",
arena2: "Mithril-lined arena",
arena3: "Orichalcum-lined arena",
arena4: "Draconium-lined arena",
antiTurtle: "Anti-turtling tactics",
luis3: "First-run double gear drop",
luisTrivia: "Dino school",
graduate: "Graduation ceremony",
penguin: "Penguin world",
newCrit: "New critical system",
the714: "Basstille Day",
baba: "Rope Baba Yaga",
darkHumor: "It really gets dark from here",
arcanum: "Arcanum access",
synergy2: "Synergy II: Border between Spiral and Arcanum",
tsubasa: "<b><i>QUACKQUACKQUACKQUACK</i></b>",
nezumi: "The Rat",
decay: "WRRRRYYYYYYY",
};
var upgradeDescriptions = {
socialMedia: "Your recruiting spreads quickly, and <b>recruiting is 10 times more effective.</b>",
test: "Clicking gives <b>2 more gold.</b>",
bears: "You establish trade with the bears, so <b>you and adept or higher wizards collect twice as much gold.</b>",
littleBrother: "Your little brother starts playing the game. He's not very good, but he collects <b>1 XP per second</b> for you.",
questStack: "You quest more efficiently; <b>clicking yields 50% more experience.</b>",
lessons: "Our favorite anthropomorphic unicorn offers you a lesson in combat; <b>you and initiate or higher wizards collect 50% more gold.</b>",
party: "With a team, you can complete dungeons faster. <b>Getting boss drops from clicking is twice as likely.</b>",
arena: "<b>The game shouldn't die as quickly.</b> (Despite what SkythekidRS suggests, the arena is <i>not</i> lined with butter.)",
valor: "Fight the hardest boss in the whole first arc, and earn the glory of <b>double gold to you and master or higher wizards!</b>",
rank7: "After loads of testing, these spells are available to you! <b>Clicking and master or higher wizards get 50% more gold.</b>",
mount: "(OK, I lied. I just bought one of the mounts in the Crown Shop that were available for gold.) <b>You gain twice as much gold and experience.</b>",
weed: "<b>Euphoria subsides half as quickly.</b>",
winter: "Provides access to Wintertusk.",
goldFarm: "You find a boss that drops great loot. <b>You and legendary or higher wizards have a chance to get loot.</b>",
sun: "As you find ways to make your attacks even powerful, <b>you and legendary or higher wizards collect 50% more gold.</b>",
bazaar: "You find that E*** is willing to buy your loot, so <b>you get twice as much money from selling loot.</b> (Needless to say, he isn't as willing to take your W****w**ks gear.)",
youtube: "People start watching your videos, and <b>recruiting is twice as powerful.</b>",
war: "As you fight tooth and nail against those spinning 3-D names coupled with loud music, <b>recruiting is twice as powerful.</b>",
pvpVideos: "You start recording yourself playing PvP matches. <b>The game should take even longer to die.</b>",
synergy1: "<b>Legendary or higher wizards get 1% more gold per PvP warlord. PvP warlords attract 0.1% more players for each wizard.</b>",
critical: "Clicking has a <b>10% chance of doubling your yield.<b> Your brother has a <b>10% chance to get twice as much experience.</b>",
tc: "All wizards earn <b>20% more gold.</b>",
luis: "You automatically click <b>every 5 seconds.</b>",
ihateaz: "You get <b>one wolf point.</b>",
sun2: "Sharpened Blade, Potent Trap, and Primordial, oh my! <b>You and archmage and higher wizards collect twice as much gold.</b>",
runLuis: "X*****a is falling, and <b>auto-clicking is twice as frequent.</b>",
empire: "Now that the whole world is playing ***ard101, <b>gold output and recruiting power are quadrupled.</b>",
wand: "Clicking is boosted by <b>1% of GPS.</b>",
bastion: "Claim whatever artifact you need and restore the B****** to its former glory.",
shadow: "Gold output is tripled for you and promethean or higher wizards, but <b>the game will take a hit in popularity.</b>",
evil: "You get <b>another wolf point.</b>",
sea: "Cross the treacherous sea inside the great beast. To the other side (and no, I don't mean dying)!",
ww: "Legendary or higher wizards <b>occasionally get gear</b>.",
com1: "Now you must land in the mind of the Shadow Queen, back when she was still a youngster, when she was in A*****, under the command of A******, and plot to kill the king.",
com2: "You are now at the R****wood School of Magic. You battle the Death professor M********* D****, but at what cost...",
com3: "Being ousted from R****wood, you partner with T***** C***r**** at the Crescent Beach for the promise of a great prize...",
a1f: "It all started when someone lost his wife and lost his sit. Time to end it. If you do, <b>clicking provides 50% more experience.</b>",
a2f: "Defeat M********, the shadow lord, and <b>you and exalted or higher wizards get five times more gold.</b>",
empire2: "***ard101 is so popular, aliens are buying computers just to play it themselves. <b>Clicking and recruiting are ten times more effective.</b>",
trivia: "Allows you to complete trivia questions <b>ten times every hour</b> for crowns.",
tree: "<b>+1% to gold drops</b> per hour of play.",
dark: "Exalted or higher wizards drop <b>even more gear</b>.",
arena2: "<b>The game should take even longer to die.</b> (Great. We were waiting for the time those sky fan fakes would shot op about gold.)",
arena3: "<b>PvP warlords will also earn gear every battle.</b>",
arena4: "<b>Euphoria wears off even more slowly.</b>",
antiTurtle: "PvP battles take <b>25% less time</b>.",
luis3: "Automatic clicking yields <b>65 times as much gold.</b>",
luisTrivia: "Every time you click automatically, you have a <b>1 in 1440 chance of automatically doing a trivia</b> if you can.",
graduate: "<b>You graduate.</b> How quaint. Now take your double gold from clicking and exalted or higher wizards.",
penguin: "Get another stew pet key. Interestingly, the real name of this world starts with a P too.",
newCrit: "What do you mean critical has been changed?!! You get two wolf points.",
the714: "Yeah you know what happens. Raid the prison, free your allies, and take back W***... er, P********whatever.",
baba: "Because she's an old hag and <i>totally</i> won't care. (Note: if you really rope people, you are a <b>MEGA</b> deck.)",
darkHumor: "You get <b>two wolf points.</b>",
arcanum: "What in the world is that?",
synergy2: "Wizards below prodigious will gain 10% more gold for every prodigious or higher wizard. Prodigious or higher wizards gain 0.1% more gold for every wizard below prodigious.",
tsubasa: "You and prodigious or higher wizards gain 4 times more gold.",
nezumi: "Defeat the Rat. Then defeat him over and over for that deck.",
decay: "The feeling when you should never have leveled up past 100. You get <b>three wolf points.</b>",
};
var upgradeRequirements = {
socialMedia: levelMinimum(5),
test: function() { return true; },
bears: levelMinimum(20),
littleBrother: levelMinimum(15),
questStack: levelMinimum(7),
lessons: levelMinimum(10),
party: levelMinimum(25),
arena: wizardMinimum(100),
valor: levelMinimum(40),
rank7: levelMinimum(48),
mount: function() { return true; },
weed: levelMinimum(45),
winter: levelMinimum(55),
goldFarm: function() {
return game.upgrades.winter;
},
sun: levelMinimum(58),
bazaar: levelMinimum(10),
youtube: levelMinimum(20),
war: levelMinimum(40),
pvpVideos: function() {
return game.upgrades.youtube && game.upgrades.arena;
},
synergy1: levelMinimum(70),
critical: levelMinimum(50),
tc: wizardMinimum(50),
luis: levelMinimum(75),
ihateaz: levelMinimum(81),
sun2: levelMinimum(86),
runLuis: levelMinimum(90),
empire: function() {
return game.resources.activePlayers.greaterOrEquals(game.resources.population);
},
wand: levelMinimum(15),
bastion: levelMinimum(93),
shadow: levelMinimum(95),
evil: function () {
return game.upgrades.shadow;
},
sea: levelMinimum(95),
ww: levelMinimum(60),
com1: levelMinimum(96),
com2: levelMinimum(97),
com3: levelMinimum(98),
a1f: levelMinimum(45),
a2f: levelMinimum(100),
empire2: function() {
return game.resources.activePlayers.divide(100).greaterOrEquals(game.resources.population);
},
trivia: levelMinimum(80),
tree: function() {
return game.upgrades.a2f;
},
dark: levelMinimum(100),
arena2: levelMinimum(65),
arena3: levelMinimum(85),
arena4: levelMinimum(105),
antiTurtle: function() {
return game.upgrades.arena2;
},
luis3: levelMinimum(104),
luisTrivia: function() {
return game.upgrades.runLuis && game.upgrades.trivia &&
staffCount("trivia") >= 5;
},
graduate: function() {
return game.upgrades.a2f;
},
penguin: function() {
return game.upgrades.graduate;
},
newCrit: levelMinimum(100),
the714: levelMinimum(102),
baba: levelMinimum(104),
darkHumor: function() {
return game.upgrades.baba;
},
arcanum: levelMinimum(106),
synergy2: function() {
return game.upgrades.arcanum;
},
tsubasa: levelMinimum(108),
nezumi: levelMinimum(110),
decay: levelMinimum(113),
};
var dependentUpgrades = {
valor: ["bears", "party"],
weed: ["valor"],
winter: ["valor"],
goldFarm: ["winter"],
youtube: ["socialMedia"],
war: ["youtube"],
pvpVideos: ["youtube", "arena"],
sun2: ["sun"],
runLuis: ["luis"],
shadow: ["bastion"],
evil: ["shadow"],
sea: ["bastion"],
com1: ["sea"],
com2: ["com1"],
com3: ["com2"],
a2f: ["com3"],
tree: ["a2f"],
dark: ["ww", "a2f"],
arena2: ["arena"],
arena3: ["arena2"],
arena4: ["arena3"],
antiTurtle: ["arena2"],
luis3: ["runLuis", "dark"],
luisTrivia: ["runLuis", "trivia"],
graduate: ["a2f"],
penguin: ["graduate"],
newCrit: ["penguin"],
the714: ["penguin"],
baba: ["the714"],
darkHumor: ["baba"],
arcanum: ["baba"],
synergy2: ["arcanum"],
tsubasa: ["arcanum"],
nezumi: ["arcanum"],
decay: ["nezumi"],
}
var defaultUpgrades = {};
var upgradePaths = {};
var availableUpgrades = {};
function findUpgradePaths() {
for (var upgrade in upgradeNames) {
var dependencies = dependentUpgrades[upgrade];
if (dependencies === undefined)
defaultUpgrades[upgrade] = true;
else {
for (var i = 0; i < dependencies.length; ++i) {
var dependency = dependencies[i];
if (upgradePaths[dependency] === undefined)
upgradePaths[dependency] = [];
upgradePaths[dependency].push(upgrade);
}
}
}