-
-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathImportExport.ts
1256 lines (1112 loc) · 40.4 KB
/
ImportExport.ts
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
import ClipboardJS from 'clipboard'
import i18next from 'i18next'
import localforage from 'localforage'
import LZString from 'lz-string'
import { achievementaward } from './Achievements'
import { DOMCacheGetOrSet } from './Cache/DOM'
import { octeractGainPerSecond } from './Calculate'
import { testing, version } from './Config'
import { Synergism } from './Events'
import { addTimers } from './Helper'
import { getQuarkBonus, quarkHandler } from './Quark'
import { playerJsonSchema } from './saves/PlayerJsonSchema'
import { shopData } from './Shop'
import { singularityData } from './singularity'
import { synergismStage } from './Statistics'
import { blankSave, format, player, reloadShit, saveCheck, saveSynergy } from './Synergism'
import { changeSubTab, changeTab, Tabs } from './Tabs'
import type { Player } from './types/Synergism'
import { Alert, Confirm, Prompt } from './UpdateHTML'
import { cleanString, getElementById, productContents, sumContents } from './Utility'
import { btoa } from './Utility'
import { Globals as G } from './Variables'
const format24 = new Intl.DateTimeFormat('EN-GB', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
hour12: false,
minute: '2-digit',
second: '2-digit'
})
const format12 = new Intl.DateTimeFormat('EN-GB', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
hour12: true,
minute: '2-digit',
second: '2-digit'
})
const hour = 3600000
const getRealTime = (type = 'default', use12 = false) => {
const format = use12 ? format12 : format24
const datePartsArr = format
.formatToParts(new Date())
.filter((x) => x.type !== 'literal')
.map((p) => ({ [p.type]: p.value }))
const dateParts = Object.assign({}, ...datePartsArr) as Record<
string,
string
>
const period = use12 ? ` ${dateParts.dayPeriod.toUpperCase()}` : ''
const weekday = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
switch (type) {
case 'default':
return `${dateParts.year}-${dateParts.month}-${dateParts.day} ${dateParts.hour}_${dateParts.minute}_${dateParts.second}${period}`
case 'short':
return `${dateParts.year}${dateParts.month}${dateParts.day}${dateParts.hour}${dateParts.minute}${dateParts.second}`
case 'year':
return `${dateParts.year}`
case 'month':
return `${dateParts.month}`
case 'day':
return `${dateParts.day}`
case 'hour':
return `${dateParts.hour}`
case 'minute':
return `${dateParts.minute}`
case 'second':
return `${dateParts.second}`
case 'period':
return `${dateParts.dayPeriod.toUpperCase()}`
case 'weekday':
return `${weekday[new Date().getUTCDay()]}`
default:
return type
}
}
export const updateSaveString = (input: HTMLInputElement) => {
const value = input.value.slice(0, 100)
player.saveString = value === '' ? blankSave.saveString : cleanString(value)
;(DOMCacheGetOrSet('saveStringInput') as HTMLInputElement).value = player.saveString
}
export const getVer = () => /[\d?=.]+/.exec(version)?.[0] ?? version
export const saveFilename = () => {
const s = player.saveString
const t = s.replace(/\$(.*?)\$/g, (_, b) => {
switch (b) {
case 'VERSION':
return `v${version}`
case 'TIME':
return getRealTime()
case 'TIME12':
return getRealTime(undefined, true)
case 'SING':
return `Singularity ${player.singularityCount}`
case 'SINGS':
return `${player.singularityCount}`
case 'VER':
return getVer()
case 'TIMES':
return getRealTime('short')
case 'YEAR':
return getRealTime('year')
case 'Y':
return getRealTime('year')
case 'MONTH':
return getRealTime('month')
case 'M':
return getRealTime('month')
case 'DAY':
return getRealTime('day')
case 'D':
return getRealTime('day')
case 'HOUR':
return getRealTime('hour')
case 'H':
return getRealTime('hour')
case 'H12':
return getRealTime('hour', true)
case 'MINUTE':
return getRealTime('minute')
case 'MI':
return getRealTime('minute')
case 'SECOND':
return getRealTime('second')
case 'S':
return getRealTime('second')
case 'PERIOD':
return getRealTime('period', true)
case 'P':
return getRealTime('period', true)
case 'WEEKDAY':
return getRealTime('weekday')
case 'W':
return getRealTime('weekday')
case 'DATE':
return `${Date.now()}`
case 'DATES':
return `${Math.floor(Date.now() / 1000)}`
case 'QUARK':
return `${Math.floor(Number(player.worlds))}`
case 'QUARKS':
return format(Number(player.worlds))
case 'GQ':
return `${Math.floor(player.goldenQuarks)}`
case 'GQS':
return format(player.goldenQuarks)
case 'STAGE':
return synergismStage(0)
default:
return `${b}`
}
})
return cleanString(t)
}
export const exportData = async (text: string, fileName: string) => {
const toClipboard = getElementById<HTMLInputElement>('saveType').checked
if (toClipboard) {
try {
// This can fail for two reasons:
// - TypeError (browser doesn't support this feature)
// - Failed to copy (browser limitation; Safari)
await navigator.clipboard.writeText(text)
DOMCacheGetOrSet('exportinfo').textContent = i18next.t(
'importexport.copiedSave'
)
} catch (err) {
// So we fallback to the deprecated way of doing it,
// which isn't limited by any browser.
// Old/bad browsers (legacy Edge, Safari because of limitations)
const textArea = document.createElement('textarea')
textArea.setAttribute('style', 'top: 0; left: 0; position: fixed;')
// For future Khafra: html5 attributes have no limit in length
textArea.setAttribute('data-clipboard-text', text)
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
const clipboard = new ClipboardJS(textArea)
const cleanup = () => {
clipboard.destroy()
document.body.removeChild(textArea)
}
clipboard.on('success', () => {
DOMCacheGetOrSet('exportinfo').textContent = i18next.t(
'importexport.copiedSave'
)
cleanup()
})
clipboard.on('error', () => {
DOMCacheGetOrSet('exportinfo').textContent = i18next.t(
'importexport.exportFailed'
)
void Alert(i18next.t('importexport.unableCopySave')).finally(cleanup)
})
}
} else {
const a = document.createElement('a')
a.setAttribute('href', `data:text/plain;charset=utf-8,${text}`)
a.setAttribute('download', fileName)
a.setAttribute('id', 'downloadSave')
// "Starting in Firefox 75, the click() function works even when the element is not attached to a DOM tree."
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click
// so let's have it work on older versions of Firefox, doesn't change functionality.
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
DOMCacheGetOrSet('exportinfo').textContent = i18next.t(
'importexport.copiedFile'
)
}
setTimeout(() => (DOMCacheGetOrSet('exportinfo').textContent = ''), 15_000)
}
export const exportSynergism = async (
shouldSetLastSaveSoWeStopFuckingBotheringPeople = true
) => {
player.offlinetick = Date.now()
if (shouldSetLastSaveSoWeStopFuckingBotheringPeople) {
player.lastExportedSave = Date.now()
const quarkData = quarkHandler()
let bonusGQMultiplier = 1
bonusGQMultiplier *= 1 + getQuarkBonus() / 100
bonusGQMultiplier *= player.highestSingularityCount >= 100
? 1 + player.highestSingularityCount / 50
: 1
if (+player.singularityUpgrades.goldenQuarks3.getEffect().bonus > 0) {
player.goldenQuarks += Math.floor(
player.goldenQuarksTimer
/ (3600 / +player.singularityUpgrades.goldenQuarks3.getEffect().bonus)
) * bonusGQMultiplier
player.goldenQuarksTimer = player.goldenQuarksTimer
% (3600 / +player.singularityUpgrades.goldenQuarks3.getEffect().bonus)
}
if (quarkData.gain >= 1) {
player.worlds.add(quarkData.gain)
player.quarkstimer = player.quarkstimer % (3600 / quarkData.perHour)
}
}
const saved = await saveSynergy()
if (!saved) {
return
}
const save = (await localforage.getItem<Blob>('Synergysave2'))
?? localStorage.getItem('Synergysave2')
const saveString = typeof save === 'string' ? save : await save?.text()
if (saveString === undefined) {
return Alert('How?')
}
await exportData(saveString, saveFilename())
setTimeout(() => (DOMCacheGetOrSet('exportinfo').textContent = ''), 15_000)
}
export const reloadDeleteGame = async () => {
await Alert(i18next.t('importexport.reloadDeletePrompt'))
await resetGame(true)
}
export const resetGame = async (force = true) => {
if (!force) {
const a = window.crypto.getRandomValues(new Uint16Array(1))[0] % 16
const b = window.crypto.getRandomValues(new Uint16Array(1))[0] % 16
const result = await Prompt(
i18next.t('importexport.resetPrompt', { a, b, sum: a + b })
)
if (result === null || Number(result) !== a + b) {
return Alert(i18next.t('importexport.wrongAnswer'))
}
}
const hold = playerJsonSchema.safeParse(blankSave)
// Reset Displays
changeTab(Tabs.Buildings)
changeSubTab(Tabs.Buildings, { page: 0 })
changeSubTab(Tabs.Runes, { page: 0 }) // Set 'runes' subtab back to 'runes' tab
changeSubTab(Tabs.Challenges, { page: 0 }) // Set 'challenges' subtab back to 'normal' tab
changeSubTab(Tabs.WowCubes, { page: 0 }) // Set 'cube tribues' subtab back to 'cubes' tab
changeSubTab(Tabs.Corruption, { page: 0 }) // set 'corruption main'
changeSubTab(Tabs.Singularity, { page: 0 }) // set 'singularity main'
changeSubTab(Tabs.Settings, { page: 0 }) // set 'statistics main'
// Import Game
await importSynergism(btoa(JSON.stringify(hold.data)), true)
}
export const importData = async (
e: Event,
importFunc: typeof importSynergism
) => {
const element = e.target as HTMLInputElement
const file = element.files![0]
let save = ''
// https://developer.mozilla.org/en-US/docs/Web/API/Blob/text
// not available in (bad) browsers like Safari 11
if (typeof Blob.prototype.text === 'function') {
save = await file.text()
} else {
const reader = new FileReader()
reader.readAsText(file)
const text = await new Promise<string>((res) => {
reader.addEventListener('load', () => res(reader.result!.toString()))
})
save = text
}
element.value = ''
handleLastModified(file.lastModified)
return importFunc(save, false)
}
export const importSynergism = async (input: string | null, reset: boolean) => {
if (typeof input !== 'string') {
return Alert(i18next.t('importexport.unableImport'))
}
const d = LZString.decompressFromBase64(input)
const f = d ? (JSON.parse(d) as Player) : (JSON.parse(atob(input)) as Player)
if (
f.exporttest === 'YES!'
|| f.exporttest === true
|| (f.exporttest === false && testing)
|| (f.exporttest === 'NO!' && testing)
) {
const saveString = btoa(JSON.stringify(f))
if (saveString === null) {
return Alert(i18next.t('importexport.unableImport'))
}
saveCheck.canSave = false
const item = new Blob([saveString], { type: 'text/plain' })
localStorage.setItem('Synergysave2', saveString)
await localforage.setItem<Blob>('Synergysave2', item)
localStorage.setItem('saveScumIsCheating', Date.now().toString())
await reloadShit(reset)
saveCheck.canSave = true
return
} else {
return Alert(i18next.t('importexport.loadTestInLive'))
}
}
export const promocodesInfo = (input: string) => {
const textElement = DOMCacheGetOrSet('promocodeinfo')
let textMessage = `'${input}': `
let availableUses = 0
switch (input) {
case 'daily':
if (player.dailyCodeUsed) {
textMessage += i18next.t('importexport.daily0Uses')
} else {
textMessage += i18next.t('importexport.daily1Uses')
}
break
case 'add':
availableUses = addCodeAvailableUses()
if (availableUses === 0) {
textMessage += i18next.t('importexport.add0Uses', {
x: 0,
y: format(addCodeTimeToNextUse(), 0)
})
} else if (availableUses !== 1) {
textMessage += i18next.t('importexport.addUses', { x: availableUses })
} else {
textMessage += i18next.t('importexport.add1Uses', { x: availableUses })
}
break
case 'time':
availableUses = timeCodeAvailableUses()
if (availableUses === 0) {
textMessage += i18next.t('importexport.add0Uses', {
x: 0,
y: format(timeCodeTimeToNextUse(), 0)
})
} else {
textMessage += i18next.t('importexport.timeMultiplier', {
x: availableUses,
y: format(timeCodeRewardMultiplier(), 2, true)
})
}
break
default:
textMessage = ''
}
textElement.textContent = textMessage
}
export const promocodesPrompt = async () => {
const input = await Prompt(i18next.t('importexport.promocodePrompt'))
void promocodes(input)
}
export const promocodes = async (input: string | null, amount?: number) => {
const el = DOMCacheGetOrSet('promocodeinfo')
if (input === null) {
return Alert(i18next.t('importexport.comeBackSoon'))
}
if (
input === '23andme'
&& !player.codes.get(48)
&& G.isEvent
) {
if (!player.dailyCodeUsed) {
return Alert(
'This event code gives you another usage of code \'daily\'. Please use that code and try this event code again.'
)
}
player.codes.set(48, true)
player.quarkstimer = quarkHandler().maxTime
player.goldenQuarksTimer = 3600 * 24
addTimers('ascension', 8 * 3600)
player.dailyCodeUsed = false
if (
player.challenge15Exponent >= 1e15
|| player.highestSingularityCount > 0
) {
player.hepteractCrafts.quark.CAP *= 2
player.hepteractCrafts.quark.BAL += Math.min(
1e13,
player.hepteractCrafts.quark.CAP / 2
)
}
if (player.highestSingularityCount > 0) {
player.singularityUpgrades.goldenQuarks1.freeLevels += 1 + Math.floor(player.highestSingularityCount / 10)
player.singularityUpgrades.goldenQuarks2.freeLevels += 1 + Math.floor(player.highestSingularityCount / 10)
player.singularityUpgrades.goldenQuarks3.freeLevels += 1 + Math.floor(player.highestSingularityCount / 10)
if (player.singularityUpgrades.octeractUnlock.getEffect().bonus) {
player.octeractUpgrades.octeractImprovedQuarkHept.freeLevels += 0.05
}
}
return Alert(
`Not sponsored by the company! Your Quark timer(s) have been replenished and you have been given 8 real life hours of Ascension progress! Your daily code has also been reset for you.
${
player.challenge15Exponent >= 1e15
|| player.highestSingularityCount > 0
? 'Derpsmith also hacked your save to expand Quark Hepteract for free, and (to a limit) automatically filled the extra amount! What a generous, handsome gigachad.'
: ''
}
${
player.highestSingularityCount > 0
? 'You were also given free levels of GQ1-3!'
: ''
}
${
player.singularityUpgrades.octeractUnlock.getEffect()
.bonus
? 'Finally, you were given a tiny amount of free Octeract Quark Hepteract Improver upgrade!'
: ''
}`
)
}
if (input === 'synergism2021' && !player.codes.get(1)) {
player.codes.set(1, true)
player.runeshards += 25
player.worlds.add(50)
el.textContent = i18next.t('importexport.promocodes.synergism2021')
} else if (input === ':unsmith:' && player.achievements[243] < 1) {
achievementaward(243)
el.textContent = i18next.t('importexport.promocodes.unsmith')
} else if (input === ':antismith:' && player.achievements[244] < 1) {
achievementaward(244)
el.textContent = i18next.t('importexport.promocodes.antismith')
} else if (input === 'Khafra' && !player.codes.get(26)) {
player.codes.set(26, true)
const quarks = Math.floor(Math.random() * (400 - 100 + 1) + 100)
player.worlds.add(quarks)
el.textContent = i18next.t('importexport.promocodes.khafra', {
x: player.worlds.applyBonus(quarks)
})
} else if (input === 'alonso bribe' && !player.codes.get(47)) {
const craft = player.hepteractCrafts.quark
if (!craft.UNLOCKED) {
return Alert(i18next.t('importexport.promocodes.bribe.notUnlocked'))
}
const cap = craft.computeActualCap()
if (cap >= 1e300) {
return Alert(i18next.t('importexport.promocodes.bribe.overCapacity'))
}
player.codes.set(47, true)
craft.CAP = Math.min(1e300, craft.CAP * 2)
return Alert(i18next.t('importexport.promocodes.bribe.thanks'))
} else if (input.toLowerCase() === 'daily' && !player.dailyCodeUsed) {
player.dailyCodeUsed = true
let rewardMessage = i18next.t('importexport.promocodes.daily.message')
const rewards = dailyCodeReward()
const quarkMultiplier = 1 + Math.min(49, player.highestSingularityCount)
let actualQuarkAward = player.worlds.applyBonus(
rewards.quarks * quarkMultiplier
)
if (actualQuarkAward > 1e5) {
actualQuarkAward = Math.pow(1e5, 0.75) * Math.pow(actualQuarkAward, 0.25)
}
player.worlds.add(actualQuarkAward, false)
player.goldenQuarks += rewards.goldenQuarks
rewardMessage += `\n${format(actualQuarkAward, 0, true)} Quarks`
if (rewards.goldenQuarks > 0) {
rewardMessage += `\n${
format(
rewards.goldenQuarks,
0,
true
)
} Golden Quarks`
}
await Alert(rewardMessage)
if (player.highestSingularityCount > 0) {
const upgradeDistribution = {
goldenQuarks3: { value: 0.2, pdf: (x: number) => 0 <= x && x <= 1 },
goldenQuarks2: { value: 0.2, pdf: (x: number) => 1 <= x && x <= 3 },
goldenQuarks1: { value: 0.2, pdf: (x: number) => 3 <= x && x <= 10 },
singCubes3: { value: 0.25, pdf: (x: number) => 10 < x && x <= 15 },
singObtainium3: { value: 0.25, pdf: (x: number) => 15 < x && x <= 20 },
singOfferings3: { value: 0.25, pdf: (x: number) => 20 < x && x <= 25 },
singCubes2: { value: 0.5, pdf: (x: number) => 25 < x && x <= 80 },
singObtainium2: { value: 0.5, pdf: (x: number) => 80 < x && x <= 140 },
singOfferings2: { value: 0.5, pdf: (x: number) => 140 < x && x <= 200 },
singCubes1: { value: 1, pdf: (x: number) => 200 < x && x <= 400 },
singObtainium1: { value: 1, pdf: (x: number) => 400 < x && x <= 600 },
singOfferings1: { value: 1, pdf: (x: number) => 600 < x && x <= 800 },
ascensions: { value: 1, pdf: (x: number) => 800 < x && x <= 1000 }
}
let rolls = 3 * Math.sqrt(player.highestSingularityCount)
rolls += +player.octeractUpgrades.octeractImprovedDaily.getEffect().bonus
rolls += player.shopUpgrades.shopImprovedDaily2
rolls += player.shopUpgrades.shopImprovedDaily3
rolls += player.shopUpgrades.shopImprovedDaily4
rolls += +player.singularityUpgrades.platonicPhi.getEffect().bonus
* Math.min(50, (5 * player.singularityCounter) / (3600 * 24))
rolls += +player.octeractUpgrades.octeractImprovedDaily3.getEffect().bonus
rolls *= +player.octeractUpgrades.octeractImprovedDaily2.getEffect().bonus
rolls *= 1
+ +player.octeractUpgrades.octeractImprovedDaily3.getEffect().bonus / 200
if (player.highestSingularityCount >= 200) {
rolls *= 2
}
rolls = Math.floor(rolls)
const keys = Object.keys(player.singularityUpgrades).filter(
(key) => key in upgradeDistribution
) as (keyof typeof upgradeDistribution)[]
rewardMessage = i18next.t('importexport.promocodes.daily.message2')
// The same upgrade can be drawn several times, so we save the sum of the levels gained, to display them only once at the end
const freeLevels: Record<string, number> = {}
for (let i = 0; i < rolls; i++) {
const num = 1000 * Math.random()
for (const key of keys) {
if (upgradeDistribution[key].pdf(num)) {
player.singularityUpgrades[key].freeLevels += upgradeDistribution[key].value
freeLevels[key]
? (freeLevels[key] += upgradeDistribution[key].value)
: (freeLevels[key] = upgradeDistribution[key].value)
}
}
}
if (player.highestSingularityCount >= 20) {
player.singularityUpgrades.goldenQuarks1.freeLevels += 0.2
freeLevels.goldenQuarks1
? (freeLevels.goldenQuarks1 += 0.2)
: (freeLevels.goldenQuarks1 = 0.2)
player.singularityUpgrades.goldenQuarks2.freeLevels += 0.2
freeLevels.goldenQuarks2
? (freeLevels.goldenQuarks2 += 0.2)
: (freeLevels.goldenQuarks2 = 0.2)
player.singularityUpgrades.goldenQuarks3.freeLevels += 1
freeLevels.goldenQuarks3
? (freeLevels.goldenQuarks3 += 1)
: (freeLevels.goldenQuarks3 = 1)
}
if (player.highestSingularityCount >= 200 && player.highestSingularityCount < 205) {
const freeLevelOct1 = Math.max(
player.octeractUpgrades.octeractGain.level / 100,
Math.pow(
player.octeractUpgrades.octeractGain.level * player.octeractUpgrades.octeractGain.freeLevels / 1000,
0.5
)
)
player.octeractUpgrades.octeractGain.freeLevels += freeLevelOct1
freeLevels.octeractGain = freeLevelOct1
} else if (player.highestSingularityCount >= 205) {
const freeLevelOct1 = Math.max(
player.octeractUpgrades.octeractGain.level / 100,
Math.pow(
player.octeractUpgrades.octeractGain.level * player.octeractUpgrades.octeractGain.freeLevels / 640,
0.5
)
)
const freeLevelOct2 = Math.max(
player.octeractUpgrades.octeractGain2.level / 100,
Math.pow(
Math.pow(player.octeractUpgrades.octeractGain2.level, 2) * player.octeractUpgrades.octeractGain2.freeLevels
/ 125000,
0.333
)
)
player.octeractUpgrades.octeractGain.freeLevels += freeLevelOct1
player.octeractUpgrades.octeractGain2.freeLevels += freeLevelOct2
freeLevels.octeractGain = freeLevelOct1
freeLevels.octeractGain2 = freeLevelOct2
}
for (const key of Object.keys(freeLevels)) {
rewardMessage += dailyCodeFormatFreeLevelMessage(key, freeLevels[key])
}
await Alert(rewardMessage)
}
return
} else if (input.toLowerCase() === 'add') {
const availableUses = addCodeAvailableUses()
const maxUses = addCodeMaxUses().total
const timeToNextUse = format(addCodeTimeToNextUse(), 0)
const timeInterval = addCodeInterval().time
if (availableUses < 1) {
el.textContent = i18next.t('importexport.noAddCodes', {
x: timeToNextUse
})
return
}
let attemptsUsed: string | null = null
if (amount) {
attemptsUsed = amount.toString()
} else {
attemptsUsed = await Prompt(
i18next.t('importexport.useXAdds', { x: availableUses }),
availableUses.toString()
)
}
if (attemptsUsed === null) {
return Alert(i18next.t('importexport.cancelAdd'))
}
const toUse = Number(attemptsUsed)
if (
Number.isNaN(toUse)
|| !Number.isInteger(toUse)
|| toUse === 0
|| (toUse < 0 && -toUse >= availableUses)
) {
return Alert(i18next.t('general.validation.invalidNumber'))
}
const addEffects = addCodeBonuses()
const realAttemptsUsed = toUse > 0 ? Math.min(availableUses, toUse) : availableUses + toUse
const actualQuarks = Math.floor(addEffects.quarks * realAttemptsUsed)
const [first, second] = window.crypto.getRandomValues(new Uint8Array(2))
// Allows storage of up to (24 + 2 * calc2 levels) Add Codes, lol!
const v = Math.max(
Date.now() - (maxUses - realAttemptsUsed) * timeInterval,
player.rngCode + timeInterval * realAttemptsUsed
)
const remaining = Math.floor((Date.now() - v) / timeInterval)
const timeToNext = Math.floor(
(timeInterval - (Date.now() - v - timeInterval * remaining)) / 1000
)
// Calculator 3: Adds ascension timer.
const ascensionTimer = realAttemptsUsed * addEffects.ascensionTimer
const ascensionTimerText = player.shopUpgrades.calculator3 > 0
? i18next.t('importexport.promocodes.add.calculator3', {
x: format(ascensionTimer)
})
: ''
// Calculator 5: Adds GQ export timer.
const gqTimer = realAttemptsUsed * addEffects.gqTimer
const gqTimerText = player.shopUpgrades.calculator5 > 0
? i18next.t('importexport.promocodes.add.calculator5', {
x: format(gqTimer)
})
: ''
// Calculator 6: Octeract Generation
const octeractTime = realAttemptsUsed * addEffects.octeractTime
const octeractTimeText = player.shopUpgrades.calculator6 > 0
? i18next.t('importexport.promocodes.add.calculator6', {
x: format(octeractTime)
})
: ''
// Calculator 7: Blueberry Generation Time
const blueberryTime = realAttemptsUsed * addEffects.blueberryTime
const blueberryTimeText = player.shopUpgrades.calculator7 > 0
? i18next.t('importexport.promocodes.add.calculator7', {
x: format(blueberryTime, 2, true)
})
: ''
// Midas' Millenium-Aged Gold perk
const freeLevelsText = player.highestSingularityCount >= 150
? i18next.t('importexport.promocodes.add.freeLevel', {
x: format(0.01 * realAttemptsUsed, 2),
y: format(0.05 * realAttemptsUsed, 2)
})
: ''
// Calculator Maxed: you don't need to insert anything!
if (player.shopUpgrades.calculator === shopData.calculator.maxLevel) {
player.worlds.add(actualQuarks)
addTimers('ascension', ascensionTimer)
player.goldenQuarksTimer += gqTimer
addTimers('octeracts', octeractTime)
addTimers('ambrosia', blueberryTime)
if (player.highestSingularityCount >= 150) {
player.singularityUpgrades.goldenQuarks1.freeLevels += 0.01 * realAttemptsUsed
player.singularityUpgrades.goldenQuarks3.freeLevels += 0.05 * realAttemptsUsed
}
player.rngCode = v
if (amount) {
// No message when using Add x1 Special action, we refresh the info message
promocodesInfo('add')
return
} else {
return Alert(
i18next.t('importexport.promocodes.add.calculatorMaxed', {
a: first,
b: second,
c: first + second,
d: player.worlds.toString(actualQuarks),
e: ascensionTimerText,
f: gqTimerText,
g: octeractTimeText,
h: freeLevelsText,
i: blueberryTimeText,
j: remaining,
k: timeToNext.toLocaleString()
})
)
}
}
// If your calculator isn't maxed but has levels, it will provide the solution.
const options = {
w: player.worlds.toString(actualQuarks),
x: first,
y: second,
z: first + second
}
const promptText = player.shopUpgrades.calculator > 0
? i18next.t('importexport.promocodes.add.calculatorSolution', options)
: i18next.t('importexport.promocodes.add.calculatorPrompt', options)
const addPrompt = await Prompt(promptText)
if (addPrompt === null) {
return Alert(i18next.t('importexport.promocodes.add.cancelled'))
}
player.rngCode = v
if (first + second === +addPrompt) {
player.worlds.add(actualQuarks)
addTimers('ascension', ascensionTimer)
player.goldenQuarksTimer += gqTimer
addTimers('octeracts', octeractTime)
addTimers('ambrosia', blueberryTime)
await Alert(
i18next.t('importexport.promocodes.add.reward', {
a: player.worlds.toString(actualQuarks),
b: ascensionTimerText,
c: gqTimerText,
d: octeractTimeText,
e: remaining,
f: timeToNext.toLocaleString(navigator.language)
})
)
} else {
await Alert(
i18next.t('importexport.promocodes.add.wrong', {
w: addPrompt,
x: first + second,
y: remaining,
z: timeToNext.toLocaleString(navigator.language)
})
)
}
} else if (input === 'sub') {
const amount = 1 + (window.crypto.getRandomValues(new Uint16Array(1))[0] % 16) // [1, 16]
const quarks = Number(player.worlds)
await Alert(i18next.t('importexport.promocodes.sub.subbed', { x: amount }))
if (quarks < amount) {
await Alert(
i18next.t('importexport.promocodes.sub.gave', {
x: amount - quarks,
y: amount
})
)
}
player.worlds.sub(quarks < amount ? amount - quarks : amount)
} else if (input === 'gamble') {
if (
typeof player.skillCode === 'number'
|| typeof localStorage.getItem('saveScumIsCheating') === 'string'
) {
if (
(Date.now() - player.skillCode!) / 1000 < 3600
|| (Date.now() - Number(localStorage.getItem('saveScumIsCheating')))
/ 1000
< 3600
) {
return (el.textContent = i18next.t(
'importexport.promocodes.gamble.wait'
))
}
}
const confirmed = await Confirm(
i18next.t('importexport.promocodes.gamble.confirm')
)
if (!confirmed) {
return (el.textContent = i18next.t(
'importexport.promocodes.gamble.cancelled'
))
}
const bet = Number(
await Prompt(i18next.t('importexport.promocodes.gamble.betPrompt'))
)
if (Number.isNaN(bet) || bet <= 0) {
return (el.textContent = i18next.t('general.validation.zeroOrLess'))
} else if (bet > 1e4) {
return (el.textContent = i18next.t(
'importexport.promocodes.gamble.cheaters'
))
} else if (Number(player.worlds) < bet) {
return (el.textContent = i18next.t(
'general.validation.moreThanPlayerHas'
))
}
localStorage.setItem('saveScumIsCheating', Date.now().toString())
const dice = (window.crypto.getRandomValues(new Uint8Array(1))[0] % 6) + 1 // [1, 6]
if (dice === 1) {
const won = bet * 0.25 // lmao
player.worlds.add(won, false)
player.skillCode = Date.now()
return (el.textContent = i18next.t('importexport.promocodes.gamble.won', {
x: won
}))
}
player.worlds.sub(bet)
el.textContent = i18next.t('importexport.promocodes.gamble.lost', {
x: bet
})
} else if (input === 'time') {
const availableUses = timeCodeAvailableUses()
if (availableUses === 0) {
return Alert(i18next.t('importexport.promocodes.time.wait'))
}
const rewardMult = timeCodeRewardMultiplier()
const random = Math.random() * 15000 // random time within 15 seconds
const start = Date.now()
const playerConfirmed = await Confirm(
i18next.t('importexport.promocodes.time.confirm', {
x: format(2500 + 125 * player.cubeUpgrades[61], 0, true),
y: format(rewardMult, 2, true)
})
)
if (playerConfirmed) {
const diff = Math.abs(Date.now() - (start + random))
player.promoCodeTiming.time = Date.now()
if (diff <= 2500 + 125 * player.cubeUpgrades[61]) {
const reward = Math.floor(
Math.min(1000, 125 + 25 * player.highestSingularityCount)
* (1 + player.cubeUpgrades[61] / 50)
)
let actualQuarkAward = player.worlds.applyBonus(reward)
let blueberryTime = 0
if (actualQuarkAward > 66666) {
actualQuarkAward = Math.pow(actualQuarkAward, 0.35) * Math.pow(66666, 0.65)
}
if (player.visitedAmbrosiaSubtab) {
blueberryTime = 1800 * rewardMult
}
player.worlds.add(actualQuarkAward * rewardMult, false)
G.ambrosiaTimer += blueberryTime
const winText = i18next.t('importexport.promocodes.time.won', {
x: format(actualQuarkAward * rewardMult, 0, true)
})
const ambrosiaText = blueberryTime > 0
? i18next.t('importexport.promocodes.time.ambrosia', {
blueberryTime
})
: ''
return Alert(winText + ambrosiaText)
} else {
return Alert(i18next.t('importexport.promocodes.time.lost'))
}
}
} else if (input === 'spoiler') {
const perSecond = octeractGainPerSecond()
if (perSecond > 1) {
return Alert(
i18next.t('importexport.promocodes.spoiler.moreThan1', {
x: format(perSecond, 2, true)
})
)
} else {
return Alert(
i18next.t('importexport.promocodes.spoiler.one', {
x: format(1 / perSecond, 2, true)
})
)
}
} else {
el.textContent = i18next.t('importexport.promocodes.invalid')
}
const saved = await saveSynergy() // should fix refresh bug where you can continuously enter promocodes
if (!saved) {
return
}
Synergism.emit('promocode', input)
setTimeout(() => (el.textContent = ''), 15000)
}
const addCodeSingularityPerkBonus = (): number => {
const levels = [
10,
16,
25,
36,
49,
64,
81,
100,