-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
2364 lines (2283 loc) · 69.9 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
/**setup**/
const Jimp = require(`jimp`);
const fs = require(`fs`);
fs.exists('./other.json', function (exists) {
if (!exists) {
let other = {
imageSize : 1024,
uniPre : `-`,
version : ``,
waitTimes : [],
commandTags: [],
servers : [],
map : []
};
other = JSON.stringify(other);
fs.writeFile(`other.json`, other, function (err) {
if (err) {
throw err;
}
console.log(`created other.json`);
});
}
});
fs.exists('./accounts.json', function (exists) {
if (!exists) {
fs.writeFile(`accounts.json`, `{}`, function (err) {
if (err) {
throw err;
}
console.log(`created accounts.json`);
});
}
});
fs.exists('./factions.json', function (exists) {
if (!exists) {
let facs = {
factions: []
};
fs.writeFile(`factions.json`, `${JSON.stringify(facs)}`, function (err) {
if (err) {
throw err;
}
console.log(`created factions.json`);
});
}
});
const otherJson = require(`./other.json`);
let universalPrefix = otherJson.uniPre;
const Discord = require(`discord.js`);
const client = new Discord.Client();
const version = otherJson.version;
/**varibles**/
let upTime = 0;
let map = otherJson.map;
let factions = [], servers = [], accounts = [], waitTimes = otherJson.waitTimes;
let everySecond = false;
/**functions**/
function getValidName(name,amo){
let newName = "";
if (isValidText(name)) {
newName = name;
}
else {
for (let j = 0; j < name.length; j++) {
if (name.charCodeAt(j) > 127) {
newName += "*";
}
else {
newName += name[j];
}
}
}
if (name.length > amo) {
name = name.substring(0, amo-3);
name += "...";
}
let spaceName = "";
for (let j = 0; j < amo - name.length; j++) {
spaceName += " ";
}
return newName+spaceName;
}
function isValidText(str) {
if (typeof(str) !== 'string') {
return false;
}
for (let i = 0; i < str.length; i++) {
if (str.charCodeAt(i) > 127) {
return false;
}
}
return true;
}
function everySecondFun() {
if (waitTimes.length) {
for (let i = 0; i < waitTimes.length; i++) {
if (waitTimes[i].expires <= Date.now()) {
let acc = Account.findFromId(waitTimes[i].playerID);
let embed = new Discord.RichEmbed()
switch (waitTimes[i].type) {
case `warp`:
acc.location = copyObject(waitTimes[i].to);
embed= new Discord.RichEmbed()
.setColor(colors.blue)
.setTitle(`Warp complete`)
.setDescription(`Your new location is Galaxy \`${waitTimes[i].to[0] + 1}\` Position: \`${waitTimes[i].to[2] + 1}x${waitTimes[i].to[1] + 1}\``);
acc.send({embed});
acc.warping = false;
break;
case `research`:
acc[waitTimes[i].which]++;
embed = new Discord.RichEmbed()
.setColor(colors.yellow)
.setTitle(`Research complete!`)
.setDescription(`You have now leveled up **${waitTimes[i].which}**`);
acc.send({embed});
acc.researching = false;
break;
case `heal`:
acc.health = 100;
embed = new Discord.RichEmbed()
.setColor(colors.yellow)
.setTitle(`Healing complete!`)
.setDescription(`You have healed yourself.\nYou now have \`100\` Health Points`);
acc.send({embed});
acc.healing = false;
break;
}
waitTimes.splice(i, 1);
saveJSON();
}
}
}
}
function importJSON() {
console.log(`Inporting started`);
fs.readFile(`./factions.json`, `utf8`, function (err, data) {
if (err) throw err;
let dataParse = JSON.parse(data);
for (let i = 0; i < dataParse.factions.length; i++) {
factions.push(new Faction(dataParse.factions[i]));
}
console.log(`Factions complete.`);
});
fs.readFile(`./other.json`, `utf8`, function (err, data) {
if (err) throw err;
let dataParse = JSON.parse(data);
for (let i = 0; i < dataParse.servers.length; i++) {
servers.push(new server(dataParse.servers[i]));
}
console.log(`servers complete.`);
});
fs.readFile(`./accounts.json`, `utf8`, function (err, data) {
if (err) throw err;
let dataParse = JSON.parse(data);
for (let i = 0; i < dataParse.accounts.length; i++) {
accounts.push(new Account(dataParse.accounts[i]));
}
console.log(`Accounts complete.`);
});
}
function saveJSON() {
console.log("Saving started");
fs.writeFileSync(`./factions.json`, JSON.stringify({factions: factions}, null, 4));
fs.writeFileSync(`./other.json`, JSON.stringify(otherJson, null, 4));
fs.writeFileSync(`./accounts.json`, JSON.stringify({accounts: accounts}, null, 4));
}
function copyObject(obj) {
return JSON.parse(JSON.stringify(obj));
}
function getTimeRemaining(time) {
time = parseInt(time, 10);
if (time < 0) {
time = parseInt(((`${time}`).substring(1, (`${time}`).length)), 10)
}
let times = [[31557600000000, `millennial`], [3155760000000, `century`], [315576000000, `decade`], [31557600000, `year`], [86400000, `day`], [3600000, `hour`], [60000, `minute`], [1000, `second`], [1, `millisecond`]];
let timesLeft = [];
let timeLeftText = ``;
let fakeTime = time;
for (let i = 0; i < times.length; i++) {
if (fakeTime >= times[i][0]) {
timesLeft.push([times[i][1], 0]);
while (fakeTime >= times[i][0]) {
fakeTime -= times[i][0];
timesLeft[timesLeft.length - 1][1]++;
}
}
}
for (let i = 0; i < timesLeft.length; i++) {
if (timesLeft[i][1] > 0) {
timeLeftText += `\`${timesLeft[i][1]}\` ${timesLeft[i][0]}`;
if (timesLeft[i][1] > 1) {
timeLeftText += `s`;
}
if (i + 2 === timesLeft.length) {
timeLeftText += ` and `
}
else if (i + 2 !== timesLeft.length) {
timeLeftText += `, `
}
}
}
return timeLeftText;
}
function spellCheck(input, text, inaccuracy) {
/**CREDIT TO GRANDZAM**/
//first, strip all spaces
while (input.charCodeAt(input.length - 1) === 32) {
input = input.slice(0, -1);
}
let inputArray = input.toLowerCase().split(``);
let textArray = text.toLowerCase().split(``);
let mistakes = 0;
//first, check if corresponding characters are the same
for (let i = 0; i < (inputArray.length > textArray.length ? inputArray.length : textArray.length); i++) {
if (inputArray[i] !== textArray[i]) {
//next, we check if it is just a character that has been omitted. If so we align the arrays so it doesn't keep registering mistakes
if (inputArray[i] === textArray[i + 1]) {
inputArray.splice(i, 0, ` `);
}
//then we check if it is an extra character that has been added and remove the character, but still register it as a mistake
else if (inputArray[i + 1] === textArray[i]) {
inputArray.splice(i, 1);
}
mistakes++;
}
if (mistakes > inaccuracy) {
break;
}
}
if (mistakes > inaccuracy) {
return false;
}
if (mistakes > 0) {
return true;
}
else {
return true;
}
}
function spacing(text, text2, max) {
let newText = text;
let len = max - text.length - text2.length;
for (let i = 0; i < len; i++) {
newText += ` `;
}
newText += text2;
return newText;
}
function getNumbers(text, parsed) {
let numbers = [`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`];
let whichWordAreWeAt = 0;
let wordsWithNumbers = [];
let foundNumber = false;
for (let i = 0; i < text.length; i++) {
let currentTextIsNumber = false;
for (let j = 0; j < numbers.length; j++) {
if (text[i] === numbers[j]) {
if (!wordsWithNumbers.length) {
wordsWithNumbers[0] = ``;
}
foundNumber = true;
wordsWithNumbers[whichWordAreWeAt] += text[i];
currentTextIsNumber = true;
}
}
if (!currentTextIsNumber && foundNumber) {
if (parsed) {
wordsWithNumbers[whichWordAreWeAt] = parseInt(wordsWithNumbers[whichWordAreWeAt], 10);
}
whichWordAreWeAt++;
foundNumber = false;
wordsWithNumbers[whichWordAreWeAt] = ``;
}
}
return wordsWithNumbers;
}
function sendBasicEmbed(args) {
if (args.channel != null && args.color != null && args.content != null) {
let embed = new Discord.RichEmbed()
.setColor(args.color)
.setDescription(args.content);
args.channel.send({embed});
}
else {
throw `${args} must contain a COLOR, CHANNEL and CONTENT`;
}
}
function createMap(galaxys, xSize, ySize) {
let planets = [
{
name : `empty`,
chance: 10
},
{
name : `Ocean`,
chance: 1
},
{
name : `Mine`,
chance: 1
},
{
name : `Terrestrial`,
chance: 1
},
{
name : `Gas`,
chance: 1
},
{
name : `Rocky`,
chance: 1
},
{
name : `Haven`,
chance: 1
}
];
let chance = 0;
for (let p = 0; p < planets.length; p++) {
chance += planets[p].chance;//puts together the entire "chance" of all planets
}
let map = [];
for (let g = 0; g < galaxys; g++) {
let galaxy = [];
for (let y = 0; y < ySize; y++) {
let yMap = [];
for (let x = 0; x < xSize; x++) {
let whichPlanet = Math.round(Math.random() * chance);
let planet = undefined;
let amountRightNow = 0;
for (let p = 0; p < planets.length; p++) {
amountRightNow += planets[p].chance;
if (whichPlanet <= amountRightNow) {
planet = p;
break;
}
}
if (planet === undefined) {
planet = 0;
}
let item = `planet`;
if (planets[planet].name === `empty`) {
item = `empty`;
}
if (x < 3 && y < 3) {
yMap.push({
type : `Safe Zone`,
item : `SafeZone`,
ownersID : null,
soonOwner: null
})
}
else if (x > xSize - 3 && y > ySize - 3) {
yMap.push({
type : `Domination Zone`,
item : `DominateZone`,
ownersID : null,
soonOwner: null
})
}
else {
yMap.push({
type : planets[planet].name,
item : item,
ownersID : null,
soonOwner: null
});
}
}
galaxy.push(yMap);
}
map.push(galaxy);
}
return map;
}
function canRunCommand(command, message) {
for (let i = 0; i < command.conditions.length; i++) {
let commandCond = command.conditions[i].cond(message);
if (commandCond.val === false) {
return commandCond;
}
}
return {val: true, msg: ``};
}
function captilize(word) {
if (typeof word === `string` && word.length) {
return word[0].toUpperCase() + word.substring(1).toLowerCase()
}
return false
}
function getBorders(location) {
let bordering = [];
if (location[1] > 0) {
bordering.push(map[location[0]][location[1] - 1][location[2]]);
}
if (location[1] + 1 < map[location[0]].length) {
bordering.push(map[location[0]][location[1] + 1][location[2]]);
}
if (location[2] > 0) {
bordering.push(map[location[0]][location[1]][location[2] - 1]);
}
if (location[2] + 1 < map[location[0]][location[1]].length) {
bordering.push(map[location[0]][location[1]][location[2] + 1]);
}
return bordering;
}
function matchArray(arr1, arr2) {
return JSON.stringify(arr1) === JSON.stringify(arr2);
}
/**items**/
const planets = {
names : [`Ocean`, `Colony`, `Mine`, `Terrestrial`, `Gas`, `Rocky`],
"Ocean" : {
bonuses : [[`Agriculture Station`, 15], [`Military Station`, 10]],
inhabitedMax : 80,
generatesRates: [`people 50`],
loseRates : []
},
"Haven" : {
bonuses : [[`Agriculture Station`, `Life Station`, 15], [`Military Station`, 10]],
inhabitedMax : 150,
generatesRates: [`credits 1 perPerson 10`],
loseRates : []
},
"Mine" : {
bonuses : [[`Mining Station`, 25], [`Refining Station`, 10]],
inhabitedMax : 60,
generatesRates: [`steel 1 perPerson 20`],
loseRates : []
},
"Terrestrial": {
bonuses : [[`Life Station`, 20], [`Research Station`, 15]],
inhabitedMax : 60,
generatesRates: [`food 1 perPerson 20`, `credits 1 perPerson 10`],
loseRates : []
},
"Gas" : {
bonuses : [[`Research Station`, 20], [`Magnetic Smelter`, 20], [`Electronic Propulsion Station`, 20]],
inhabitedMax : 0,
generatesRates: [],
loseRates : []
},
"Rocky" : {
bonuses : [[`Mining Station`, 20], [`Refining Station`, 20], [`Military Station`, 20]],
inhabitedMax : 40,
generatesRates: [],
loseRates : []
}
};
const stations = {
names : [`Mining Station`, `Refining Station`, `Research Station`, `Agriculture Station`, `Military Station`, `Magnetic Smelter`, `Electronic Propulsion Station`],
"Mining Station" : {
name : `Mining Station`,
maintenance : `low`,
description : `Gives ⛓ Steel`,
crewSize : 24,
gives : [[`steel 1`], [`steel 2`], [`steel 4`], [`steel 6`], [`steel 10`]],
costs : [[`steel 5`], [`steel 10`], [`steel 15`], [`steel 30`], [`steel 45`]],
extra : {upgradeTo: `Metalloid Accelerator`},
destroyBonus: [`steel 10`]
},
"Refining Station" : {
name : `Refining Station`,
maintenance : `medium`,
description : `Converts ⛓ Steel into 🔗 Beryllium`,
crewSize : 16,
gives : [[`steel -10`, `beryllium 1`], [`steel -10`, `beryllium 2`], [`steel -6`, `beryllium 2`], [`steel -4`, `beryllium 2`]],
costs : [[`steel 10`], [`steel 15`, `beryllium 5`], [`steel 20`, `beryllium 10`], [`steel 30`, `beryllium 10`]],
extra : {upgradeTo: `Metalloid Accelerator`},
destroyBonus: [`steel 10`, `beryllium 2`]
},
"Research Station" : {
name : `Research Station`,
maintenance : `low`,
description : `Gives 💡 research`,
crewSize : 14,
gives : [[`research 3`], [`research 6`], [`research 10`]],
costs : [[`steel 20`, `beryllium 10`], [`steel 40`, `beryllium 20`], [`steel 60`, `beryllium 30`]],
extra : {},
destroyBonus: [`research 10`, `steel 10`]
},
"Agriculture Station" : {
name : `Agriculture Station`,
maintenance : `low`,
description : `gives 🍎 food`,
crewSize : 20,
gives : [[`food 3`], [`food 6`], [`food 10`], [`food 15`], [`food 20`]],
costs : [[`steel 10`], [`steel 20`, `food 10`], [`steel 50`, `beryllium 10`, `food 25`], [`steel 100`, `beryllium 20`, `food 50`]],
extra : {},
destroyBonus: [`food 10`]
},
"Military Station" : {
name : `Military Station`,
maintenance : `medium`,
description : `Watches an area and alerts you of any player’s presence and damages and debuffs nearby enemies`,
crewSize : 20,
gives : [[`damage 2`], [`damage 3`], [`damage 4`], [`damage 6`]],
costs : [[`steel 20`, `beryllium 5`], [`steel 50`, `beryllium 10`], [`steel 100`, `beryllium 20`], [`200`, `beryllium 50`]],
extra : {},
destroyBonus: [`beryllium 10`, `steel 50`]
},
"Magnetic Smelter" : {
name : `Magnetic Station`,
maintenance : `low`,
description : `Gives 🌀 neutronium and ⬛ Carbon`,
crewSize : 0,
gives : [[`carbon 1`], [`carbon 2`], [`carbon 3`, `neutronium 1`], [`carbon 4`, `neutronium 2`], [`carbon 5`, `neutronium 3`]],
costs : [[`steel 200`, `beryllium 100`], [`steel 400`, `beryllium 200`, `carbon 20`], [`steel 600`, `beryllium 300`, `carbon 30`], [`steel 800`, `beryllium 400`, `carbon 40`, `neutronium 10`], [`steel 1000`, `beryllium 500`, `carbon 50`, `neutronium 20`]],
extra : {},
destroyBonus: [`steel 200`, `beryllium 100`, `carbon 10`]
},
"Electronic Propulsion Station": {
name : `Electronic Propulsion Station`,
maintenance : `high`,
description : `Gives ⚡ Electricity`,
crewSize : 16,
gives : [[`electricity 3`], [`electricity 5`], [`electricity 10`], [`electricity 15`]],
costs : [[`beryllium 10`, `carbon 50`], [`beryllium 20`, `carbon 50`, `neutronium 10`], [`beryllium 30`, `carbon 80`, `neutronium 20`], [`beryllium 40`, `carbon 100`, `neutronium 20`]],
extra : {},
destroyBonus: [`electricity 10`, `steel 50`]
}
};
const colors = {
purple : 0x993499,//Moderation
yellow : 0xadb60c,//Research
pink : 0xFF21F8,//stations
red : 0xce001f,//Invalid, Something Bad
blue : 0x00C8C8,//Game Notifications
darkblue: 0x252FF3,//Factions
green : 0x09c612,//Confirmed, Something Good
darkRed : 0x640000,//Attacking
orange : 0xE64403//warn user
};
const resources = {
names : [`credits`, `steel`, `electricity`, `food`, `people`, `beryllium`, `research`, `titanium`, `neutronium`, `carbon`, `silicon`, `power`],
"credits" : {
emoji : `💠`,
buyRate : 1,
sellRate: 1
},
"steel" : {
emoji : `⛓`,
buyRate : 7,
sellRate: 5
},
"electricity": {
emoji : `⚡`,
buyRate : 4,
sellRate: 2
},
"food" : {
emoji : `🍎`,
buyRate : 6,
sellRate: 5
},
"people" : {
emoji : `👦`,
buyRate : 5,
sellRate: 1
},
"beryllium" : {
emoji : `🔗`,
buyRate : 15,
sellRate: 10
},
"research" : {
emoji : `💡`,
buyRate : 7,
sellRate: 3
},
"titanium" : {
emoji : `🔩`,
buyRate : 20,
sellRate: 10
},
"neutronium" : {
emoji : `🌀`,
buyRate : 24,
sellRate: 15
},
"carbon" : {
emoji : `⬛`,
buyRate : 18,
sellRate: 13
},
"silicon" : {
emoji : `✴`,
buyRate : 30,
sellRate: 20
},
"power" : {
emoji : ``,
buyRate : 99999999999,
sellRate: 0
}
};
const ranks = {
list : [0, 50, 100, 250, 500, 1000, 1500, 2000, 2750, 3500, 5000],
names : [`Newbie`, `Learner`, `Recruit`, `Beginner`, `Toughie`, `Intermediate`, `Advanced`, `Megatron`, `Expert`, `SuperBeing`, `Godlike`],
"Newbie" : {
min : 0,
max : 3,
safe: 0,
dom : 1
},
"Learner" : {
min : 0,
max : 5,
safe: 0,
dom : 2
},
"Recruit" : {
min : 1,
max : 6,
safe: 1,
dom : 3
},
"Beginner" : {
min : 2,
max : 7,
safe: 1,
dom : 4
},
"Toughie" : {
min : 3,
max : 8,
safe: 2,
dom : 5
},
"Intermediate": {
min : 4,
max : 9,
safe: 4,
dom : 8
},
"Advanced" : {
min : 5,
max : 10,
safe: 6,
dom : 10
},
"Megatron" : {
min : 6,
max : 11,
safe: 8,
dom : 12
},
"Expert" : {
min : 7,
max : 12,
safe: 10,
dom : 15
},
"SuperBeing" : {
min : 8,
max : 13,
safe: 15,
dom : 20
},
"Godlike" : {
min : 10,
max : 15,
safe: 20,
dom : 25
}
};
const powerIncreases = {
colonize : 10,
buildStation : 10,
buildMiltary : 30,
attackMilitary: 20,
attackStation : 30,
attackColony : 25,
attackPlayer : 40,
stationDestroy : -5,
colonyDestroy : -5,
militaryDestroy: -20
};
const researches = {
names: [`Inductive Isolation Methods`, `Gravitic Purification`, `Compressed Laser Generators`, `HyperDrive Generator`, `Scientific Labs`, `Super Resource Containers`, `Domination Kingdoms`, `Super Galactic Shields`, `Eagle Eyed`],
/**EVERYTHING is in arrays for each of the levels**/
"Inductive Isolation Methods": {
//1:00,1:30,2:00,2:30,3:00
timesToResearch: [3600000, 5400000, 7200000, 9000000, 10800000],
does : [
`Gives \`1%\` more:\n • ⛓ Steel\n • 🔩 Titanium\n • ⬛ Carbon\n • 🌀 Neutronium\nIf researched`,
`Gives \`2%\` more:\n • ⛓ Steel\n • 🔩 Titanium\n • ⬛ Carbon\n • 🌀 Neutronium\nIf researched`,
`Gives \`3%\` more:\n • ⛓ Steel\n • 🔩 Titanium\n • ⬛ Carbon\n • 🌀 Neutronium\nIf researched`,
`Gives \`4%\` more:\n • ⛓ Steel\n • 🔩 Titanium\n • ⬛ Carbon\n • 🌀 Neutronium\nIf researched`,
`Gives \`5%\` more:\n • ⛓ Steel\n • 🔩 Titanium\n • ⬛ Carbon\n • 🌀 Neutronium\nIf researched`
],
costs : [100, 150, 200, 250, 300]
},
"Gravitic Purification" : {
timesToResearch: [3600000, 7200000, 14400000, 14400000, 21600000, 21600000, 25200000, 28800000, 600000],
does : [
`Unlocks:\n • Metalloid Accelerator\n • Refining Station level 2\n • Mining Station level 2`,
`Unlocks:\n • Refining Station level 3\n • Mining Station level 3\n • Agriculture Station level 2`,
`Unlocks:\n • Military Station\n • Refining Station level 4\n • Mining Station level 4\n • Research Station level 2\n • Agriculture Station level 3`,
`Unlocks:\n • Magnetic Smelter\n • Research Station level 3\n • Mining Station level 5\n • Military Station level 2\n • Agriculture Station level 4`,
`Unlocks:\n • Electronic Propulsion Station\n • Military Station level 3\n • Magnetic Smelter level 2\n • Agriculture Station level 5`,
`Unlocks:\n • Electronic Propulsion Station level 2\n • Magnetic Smelter level 3`,
`Unlocks:\n • Electronic Propulsion Station level 3\n • Magnetic Smelter level 4`,
`Unlocks:\n • Electronic Propulsion Station level 4\n • Magnetic Smelter level 5`,
`Insurance: keep all of *Gravitic Purification's* research the next time you die`
],
costs : [25, 50, 100, 200, 500, 1000, 1100, 1200, 1300, 100]
},
"Compressed Laser Generators": {
timesToResearch: [3600000, 7200000, 14400000, 21600000, 2800000, 36000000],
does : [
`5% more damage to ships, stations & planets`,
`10% more damage to ships, stations & planets`,
`15% more damage to ships, stations & planets`,
`20% more damage to ships, stations & planets`,
`25% more damage to ships, stations & planets`,
`30% more damage to ships, stations & planets`
],
costs : [50, 130, 200, 450, 700, 1000]
},
"HyperDrive Generator" : {
timesToResearch: [3600000, (3600000 * 2), (3600000 * 3), (3600000 * 4), (3600000 * 5), (3600000 * 6), (3600000 * 7), (3600000 * 8), (3600000 * 9), 36000000],
does : [
`Decreases Warp time by 1%`,
`Decreases Warp time by 2%`,
`Decreases Warp time by 3%`,
`Decreases Warp time by 4%`,
`Decreases Warp time by 5%`,
`Decreases Warp time by 6%`,
`Decreases Warp time by 7%`,
`Decreases Warp time by 8%`,
`Decreases Warp time by 9%`,
`Decreases Warp time by 10%`
],
costs : [50, 100, 150, 250, 300, 350, 400, 450, 500, 550]
},
"Scientific Labs" : {
timesToResearch: [3600000, (3600000 * 3), (3600000 * 6), (3600000 * 9)],
does : [
`Decreases research time by 5%`,
`Decreases research time by 10%`,
`Decreases research time by 15%`,
`Decreases research time by 20%`
],
costs : [500, 1000, 1500, 2000]
},
"Super Resource Containers" : {
timesToResearch: [3600000, 3600000 * 3, 3600000 * 6, 3600000 * 9, 3600000 * 12],
does : [
`Increases resource's storage by 10%`,
`Increases resource's storage by 20%`,
`Increases resource's storage by 30%`,
`Increases resource's storage by 40%`,
`Increases resource's storage by 50%`
],
costs : [1000, 2000, 3000, 4000, 5000]
},
"Domination Kingdoms" : {
timesToResearch: [3600000 * 3, 3600000 * 9, 3600000 * 24, 3600000 * 42],
does : [
`Gives you 1 more credit for ever 5 credits gained`,
`Gives you 1 more credit for ever 3 credits gained`,
`Gives you 2 more credits for ever 3 credits gained`,
`Gives double credits`
],
costs : [1000, 4000, 6000, 10000]
},
"Super Galactic Shields" : {
timesToResearch: [60000 * 30, 3600000, 3600000 * 2, 3600000 * 3, 3600000 * 4, 3600000 * 5],
does : [
`Take 5% less damage`,
`Take 10% less damage`,
`Take 15% less damage`,
`Take 20% less damage`,
`Take 25% less damage`,
`Take 30% less damage`
],
costs : [100, 300, 500, 700, 1000, 1500]
},
"Eagle Eyed" : {
timesToResearch: [3600000 * 42],
does : [
`increases your vision`
],
costs : [10000]
}
};
const timeTakes = {
/***
* 1000 = 1 second
* 60000 = 1 minute
* 600000 = 10 minutes
* 3600000 = 1 hour
*/
colonize : 60000 * 5,
attackColony : 60000 * 10,
buildStation : 60000 * 5,
attackStation : 60000 * 10,
warpPerPosition : 1000 * 5,
factionAdvertise: ((60000 * 60) * 24) * 3,
collectionRate : 60000 * 10,
collectionMax : 60000 * 120
};
//TODO add factions
/***
*/
/**ACCOUNTS**/
let Account = function (data) {
data = data || {};
/**USER**/
this.user = data.user || {};
this.userID = data.userID || ``;
this.id = data.id || 0;
this.rank = data.rank || `Newbie`;
this.username = data.username || ``;
this.user = data.user || false;
this.faction = data.faction || false;
this.location = data.location || [0, 0, 0];
this.stations = data.stations || [];
this.colonies = data.colonies || [];
this.lastCollection = data.lastCollection || Date.now();
this.messagesXp = data.messagesXp || 0;
this.didntMove = data.didntMove || false;
this.attacking = data.attacking || false;
this.healing = data.healing || false;
this.isDominating = data.isDominating || false;
this.isInSafeZone = data.isInSafeZone || false;
this.building = data.building || false;
this.warping = data.warping || false;
this.researching = data.researching || false;
this.colonizing = data.colonizing || false;
/**RESOURCES**/
this[`credits`] = data[`credits`] || 0;
this[`beryllium`] = data[`beryllium`] || 0;
this[`silicon`] = data[`silicon`] || 0;
this[`food`] = data[`food`] || 0;
this[`steel`] = data[`steel`] || 0;
this[`titanium`] = data[`titanium`] || 0;
this[`carbon`] = data[`carbon`] || 0;
this[`neutronium`] = data[`neutronium`] || 0;
this[`electricity`] = data[`electricity`] || 0;
this[`research`] = data[`research`] || 0;
this[`people`] = data[`people`] || 0;
this[`power`] = data[`power`] || 0;
this.health = data.health || 100;
//research
this[`Inductive Isolation Methods`] = data[`Inductive Isolation Methods`] || 0;
this[`Gravitic Purification`] = data[`Gravitic Purification`] || 0;
this[`Compressed Laser Generators`] = data[`Compressed Laser Generators`] || 0;
this[`HyperDrive Generator`] = data[`HyperDrive Generator`] || 0;
this[`Scientific Labs`] = data[`Scientific Labs`] || 0;
this[`Super Resource Containers`] = data[`Super Resource Containers`] || 0;
this[`Domination Kingdoms`] = data[`Domination Kingdoms`] || 0;
this[`Super Galactic Shields`] = data[`Super Galactic Shields`] || 0;
this[`Eagle Eyed`] = data[`Eagle Eyed`] || 0;
};
Account.getValidId = function () {
let id = 1;
while (true) {
id++;
let found = false;
for (let i = 0; i < accounts.length; i++) {
if (accounts[i].id === id) {
found = true;
break;
}
}
if (!found) {
this.id = id;
return id;
}
}
};
Account.addAccount = function (account) {
accounts.push(account);
};
Account.getAccounts = function () {
return accounts;
};
Account.findFromId = function (id) {
for (let i = 0; i < accounts.length; i++) {
if (accounts[i].id === id) {
return accounts[i];
}
if (accounts[i].userID === id) {
return accounts[i];
}
}
return false;
};
Account.prototype.addXp = function () {
this.messagesXp += Math.round(14 + (Math.random() * 10));
};
Account.prototype.addItem = function (item, amount) {
amount = amount || 1;
if (typeof amount !== `number`) {
throw amount + ` must be a number not a${typeof amount}`
}
if (this[item] === null) {
throw item + ` doesn't exist`
}
this[item] += amount;
};
Account.prototype.moveTo = function (loc) {
if (loc instanceof Array) {
this.location = loc;
}
else {
throw `loc must be an array not: ${loc}`
}
};
Account.prototype.remove = function () {
if (this.faction != null) {
let fac = Faction.findFactionFromName(this.faction);
if (fac) {
for (let i = 0; i < fac.members.length; i++) {
if (fac.members[i].id === player.id) {
if (fac.members[i].rank !== `owner`) {
fac.members.splice(i, 1);
}
else {
let found = false;
for (let j = 0; j < fac.members.length; i++) {
if (fac.members[j].rank === `mod`) {
fac.members[j].rank = `owner`;
found = true;
break;
}
}
if (!found) {
for (let j = 0; j < fac.members.length; i++) {
accountData[fac.members[j].id].faction = null;
}
delete factions[this.faction];
}
}
}
}
}
}
if (this.stations.length) {
for (let i = 0; i < this.stations.length; i++) {
let loc = this.stations[i].location;
map[loc[0]][loc[1]][loc[2]].item = `empty`;
map[loc[0]][loc[1]][loc[2]].type = `empty`;
map[loc[0]][loc[1]][loc[2]].ownersID = null;
}
}
let number = 0;
for(let i =0;i<accounts.length;i++){
if(this.userID === accounts.userID){
number = i;
break;
}
}
require(`./accounts.json`).accounts.splice(i,1);
};
Account.prototype.send = function (message) {
if (typeof this.user === "boolean") {
client.fetchUser(this.userID).then(function (user) {
user.send(message);
this.user = user;
});
}
else {
this.user.send(message);
}