From b80fbaa58d967773733b1d336dc2c839d337cc8a Mon Sep 17 00:00:00 2001 From: Khafra Date: Sun, 30 Jun 2024 17:59:29 -0400 Subject: [PATCH 1/4] fixup --- src/Login.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Login.ts b/src/Login.ts index cac9419de..591e1c73e 100644 --- a/src/Login.ts +++ b/src/Login.ts @@ -93,10 +93,19 @@ export async function handleLogin () { currentBonus.textContent = `Generous patrons give you a bonus of ${globalBonus}% more Quarks!` + const cookies = parseDocumentCookie() + + if (cookies.id || cookies.patreonId) { + Alert('You may need to login to your account again for bonuses to apply! Thank you!') + } + + if (cookies.id) document.cookie = 'id=;Max-Age=0' + if (cookies.patreonId) document.cookie = 'patreonId=;Max-Age=0' + if (location.hostname !== 'synergism.cc') { // TODO: better error, make link clickable, etc. subtabElement.textContent = 'Login is not available here, go to https://synergism.cc instead!' - } else if (parseDocumentCookie().id || parseDocumentCookie().patreonId) { + } else if (cookies.token) { if (!member) { console.log(response, globalBonus, member, personalBonus, document.cookie) } From c2601f31b905f38f7690073c9f7b5578184c8601 Mon Sep 17 00:00:00 2001 From: Khafra Date: Mon, 1 Jul 2024 16:09:25 -0400 Subject: [PATCH 2/4] fixup! blank account page --- src/ImportExport.ts | 28 +++++++++++++++++++++++----- src/Login.ts | 2 ++ src/Octeracts.ts | 3 +-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/ImportExport.ts b/src/ImportExport.ts index c12dfdc67..8045a74db 100644 --- a/src/ImportExport.ts +++ b/src/ImportExport.ts @@ -620,13 +620,31 @@ export const promocodes = async (input: string | null, amount?: number) => { } 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)) + 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)) + } 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 diff --git a/src/Login.ts b/src/Login.ts index 591e1c73e..8ba169d0b 100644 --- a/src/Login.ts +++ b/src/Login.ts @@ -108,6 +108,8 @@ export async function handleLogin () { } else if (cookies.token) { if (!member) { console.log(response, globalBonus, member, personalBonus, document.cookie) + Alert('Your individual bonuses were not applied. Try refreshing the page!') + return } currentBonus.textContent += diff --git a/src/Octeracts.ts b/src/Octeracts.ts index 4eb48160d..f9a27bf7d 100644 --- a/src/Octeracts.ts +++ b/src/Octeracts.ts @@ -169,8 +169,7 @@ export class OcteractUpgrade extends DynamicUpgrade { if (this.level >= actualFreeLevels) { return actualFreeLevels + this.level - } - else { + } else { return 2 * Math.sqrt(actualFreeLevels * this.level) } } From 50646bff5c76c4e1d0ff0ae5681491b38207b9fc Mon Sep 17 00:00:00 2001 From: Khafra Date: Tue, 2 Jul 2024 20:19:41 -0400 Subject: [PATCH 3/4] fixup! always use synergism.cc for quark bonus --- src/Quark.ts | 84 ---------------------------------------------------- 1 file changed, 84 deletions(-) diff --git a/src/Quark.ts b/src/Quark.ts index ffb8702a1..64e523ab5 100644 --- a/src/Quark.ts +++ b/src/Quark.ts @@ -1,44 +1,5 @@ -/* Functions which Handle Quark Gains, */ - -import { DOMCacheGetOrSet } from './Cache/DOM' import { calculateCubeQuarkMultiplier, calculateQuarkMultiplier } from './Calculate' import { format, player } from './Synergism' -import { Alert } from './UpdateHTML' - -const getBonus = async (): Promise => { - if (!navigator.onLine) { - return null - } - if (document.visibilityState === 'hidden') { - return null - } - - try { - const r = await fetch('https://synergism-quarks.khafra.workers.dev/') - const j = await r.json() as { bonus: number } - - return j.bonus - } catch (e) { - console.log(`workers.dev: ${(e as Error).message}`) - } - - try { - const r = await fetch('https://api.github.com/gists/44be6ad2dcf0d44d6a29dffe1d66a84a', { - headers: { - Accept: 'application/vnd.github.v3+json' - } - }) - - const t = await r.json() as { files: Record } - const b = Number(t.files['SynergismQuarkBoost.txt'].content) - - return b - } catch (e) { - console.log(`GitHub Gist: ${(e as Error).message}`) - } - - return null -} export const quarkHandler = () => { let maxTime = 90000 // In Seconds @@ -82,21 +43,12 @@ export class QuarkHandler { /** Quark amount */ private QUARKS = 0 - private interval: ReturnType | null = null - constructor ({ bonus, quarks }: { bonus?: number; quarks: number }) { this.QUARKS = quarks if (bonus) { this.BONUS = bonus - } else { - void this.getBonus() } - - if (this.interval) clearInterval(this.interval) - - // although the values are cached for 15 mins, refresh every 5 - this.interval = setInterval(this.getBonus.bind(this), 60 * 1000 * 5) } /*** Calculates the number of quarks to give with the current bonus. */ @@ -122,42 +74,6 @@ export class QuarkHandler { return this } - async getBonus () { - const el = DOMCacheGetOrSet('currentBonus') - - if (location.hostname === 'synergism.cc') { - return - } - - if (localStorage.getItem('quarkBonus') !== null) { // is in cache - const { bonus, fetched } = JSON.parse(localStorage.getItem('quarkBonus')!) as { bonus: number; fetched: number } - if (Date.now() - fetched < 60 * 1000 * 15) { // cache is younger than 15 minutes - el.textContent = `Generous patrons give you a bonus of ${bonus}% more Quarks!` - return this.BONUS = bonus - } - } else if (!navigator.onLine) { - return el.textContent = 'Current Bonus: N/A% (offline)!' - } else if (document.hidden) { - return el.textContent = 'Current Bonus: N/A% (unfocused)!' - } - - const b = await getBonus() - - if (b === null) { - return - } else if (Number.isNaN(b) || typeof b !== 'number') { - return Alert('No bonus could be applied, a network error occurred! [Invalid Bonus] :(') - } else if (!Number.isFinite(b)) { - return Alert('No bonus could be applied, an error occurred. [Infinity] :(') - } else if (b < 0) { - return Alert('No bonus could be applied, an error occurred. [Zero] :(') - } - - el.textContent = `Generous patrons give you a bonus of ${b}% more Quarks!` - localStorage.setItem('quarkBonus', JSON.stringify({ bonus: b, fetched: Date.now() })) - this.BONUS = b - } - public toString (val: number): string { return format(Math.floor(this.applyBonus(val)), 0, true) } From ded36166f552ee8e6ccadc45ee4deb7043a5346d Mon Sep 17 00:00:00 2001 From: Khafra Date: Tue, 2 Jul 2024 22:13:01 -0400 Subject: [PATCH 4/4] fixup! fix shitty bonus code --- package.json | 1 + src/BlueberryUpgrades.ts | 3 ++- src/Calculate.ts | 6 +++--- src/ImportExport.ts | 4 ++-- src/Login.ts | 8 +++----- src/Quark.ts | 15 +++++++-------- src/Synergism.ts | 6 +++--- src/UpdateVisuals.ts | 4 ++-- src/saves/PlayerSchema.ts | 2 +- 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 591e854ac..919689051 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "lint:fix": "npx @biomejs/biome lint --apply .", "lint:fix-unsafe": "npx @biomejs/biome lint --apply-unsafe .", "fmt": "npx dprint fmt", + "format": "npx dprint fmt", "csslint": "npx stylelint Synergism.css", "csslint:fix": "npx stylelint Synergism.css --fix", "htmllint": "npx htmlhint index.html", diff --git a/src/BlueberryUpgrades.ts b/src/BlueberryUpgrades.ts index 5d9d4dd84..246bf7682 100644 --- a/src/BlueberryUpgrades.ts +++ b/src/BlueberryUpgrades.ts @@ -4,6 +4,7 @@ import { calculateAmbrosiaGenerationSpeed, calculateAmbrosiaLuck } from './Calcu import { DynamicUpgrade } from './DynamicUpgrade' import type { IUpgradeData } from './DynamicUpgrade' import { exportData, saveFilename } from './ImportExport' +import { getQuarkBonus } from './Quark' import { format, player } from './Synergism' import type { Player } from './types/Synergism' import { Alert, Confirm, Prompt } from './UpdateHTML' @@ -665,7 +666,7 @@ export const blueberryUpgradeData: Record< return baseCost * (Math.pow(level + 1, 2) - Math.pow(level, 2)) }, rewards: (n: number) => { - const val = 1 + (n * player.worlds.BONUS) / 100 + const val = 1 + (n * getQuarkBonus()) / 100 return { blueberryGeneration: val, desc: String( diff --git a/src/Calculate.ts b/src/Calculate.ts index b6a33711f..700077ac7 100644 --- a/src/Calculate.ts +++ b/src/Calculate.ts @@ -7,7 +7,7 @@ import { BuffType, calculateEventSourceBuff } from './Event' import { addTimers, automaticTools } from './Helper' import { hepteractEffective } from './Hepteracts' import { disableHotkeys, enableHotkeys } from './Hotkeys' -import { quarkHandler } from './Quark' +import { getQuarkBonus, quarkHandler } from './Quark' import { reset } from './Reset' import { calculateSingularityDebuff } from './singularity' import { getFastForwardTotalMultiplier } from './singularity' @@ -2082,7 +2082,7 @@ export const getOcteractValueMultipliers = () => { +player.singularityUpgrades.singOcteractGain5.getEffect().bonus, // Patreon bonus 1 - + (player.worlds.BONUS / 100) + + (getQuarkBonus() / 100) * +player.singularityUpgrades.singOcteractPatreonBonus.getEffect().bonus, // octeracts for dummies 1 + 0.2 * +player.octeractUpgrades.octeractStarter.getEffect().bonus, @@ -2488,7 +2488,7 @@ export const calculateGoldenQuarkMultiplier = (computeMultiplier = false) => { const arr = [ 1 + Math.max(0, Math.log10(player.challenge15Exponent + 1) - 20) / 2, // Challenge 15 Exponent - 1 + player.worlds.BONUS / 100, // Patreon Bonus + 1 + getQuarkBonus() / 100, // Patreon Bonus +player.singularityUpgrades.goldenQuarks1.getEffect().bonus, // Golden Quarks I 1 + 0.12 * player.cubeUpgrades[69], // Cookie Upgrade 19 +player.singularityChallenges.noSingularityUpgrades.rewards.goldenQuarks, // No Singularity Upgrades diff --git a/src/ImportExport.ts b/src/ImportExport.ts index 8045a74db..27b8bd7ff 100644 --- a/src/ImportExport.ts +++ b/src/ImportExport.ts @@ -8,7 +8,7 @@ import { octeractGainPerSecond } from './Calculate' import { testing, version } from './Config' import { Synergism } from './Events' import { addTimers } from './Helper' -import { quarkHandler } from './Quark' +import { getQuarkBonus, quarkHandler } from './Quark' import { playerJsonSchema } from './saves/PlayerJsonSchema' import { shopData } from './Shop' import { singularityData } from './singularity' @@ -240,7 +240,7 @@ export const exportSynergism = async ( const quarkData = quarkHandler() let bonusGQMultiplier = 1 - bonusGQMultiplier *= 1 + player.worlds.BONUS / 100 + bonusGQMultiplier *= 1 + getQuarkBonus() / 100 bonusGQMultiplier *= player.highestSingularityCount >= 100 ? 1 + player.highestSingularityCount / 50 : 1 diff --git a/src/Login.ts b/src/Login.ts index 8ba169d0b..83b94986f 100644 --- a/src/Login.ts +++ b/src/Login.ts @@ -1,7 +1,7 @@ import i18next from 'i18next' import localforage from 'localforage' import { DOMCacheGetOrSet } from './Cache/DOM' -import { QuarkHandler } from './Quark' +import { QuarkHandler, setQuarkBonus } from './Quark' import { player } from './Synergism' import { Alert } from './UpdateHTML' @@ -86,10 +86,8 @@ export async function handleLogin () { | SynergismDiscordUserAPIResponse | SynergismPatreonUserAPIResponse - player.worlds = new QuarkHandler({ - quarks: Number(player.worlds), - bonus: 100 * (1 + globalBonus / 100) * (1 + personalBonus / 100) - 100 // Multiplicative - }) + setQuarkBonus(100 * (1 + globalBonus / 100) * (1 + personalBonus / 100) - 100) + player.worlds = new QuarkHandler(Number(player.worlds)) currentBonus.textContent = `Generous patrons give you a bonus of ${globalBonus}% more Quarks!` diff --git a/src/Quark.ts b/src/Quark.ts index 64e523ab5..91d230925 100644 --- a/src/Quark.ts +++ b/src/Quark.ts @@ -37,24 +37,23 @@ export const quarkHandler = () => { } } +let bonus = 0 + +export const setQuarkBonus = (newBonus: number) => bonus = newBonus +export const getQuarkBonus = () => bonus + export class QuarkHandler { - /** Global quark bonus */ - public BONUS = 0 /** Quark amount */ private QUARKS = 0 - constructor ({ bonus, quarks }: { bonus?: number; quarks: number }) { + constructor (quarks: number) { this.QUARKS = quarks - - if (bonus) { - this.BONUS = bonus - } } /*** Calculates the number of quarks to give with the current bonus. */ applyBonus (amount: number) { const nonPatreon = calculateQuarkMultiplier() - return amount * (1 + (this.BONUS / 100)) * nonPatreon + return amount * (1 + (getQuarkBonus() / 100)) * nonPatreon } /** Subtracts quarks, as the name suggests. */ diff --git a/src/Synergism.ts b/src/Synergism.ts index ad2d23001..3e7733a51 100644 --- a/src/Synergism.ts +++ b/src/Synergism.ts @@ -158,7 +158,7 @@ import { init as i18nInit } from './i18n' import { handleLogin } from './Login' import { octeractData, OcteractUpgrade } from './Octeracts' import { updatePlatonicUpgradeBG } from './Platonic' -import { QuarkHandler } from './Quark' +import { getQuarkBonus, QuarkHandler } from './Quark' import { playerJsonSchema } from './saves/PlayerJsonSchema' import { playerSchema } from './saves/PlayerSchema' import { getFastForwardTotalMultiplier, singularityData, SingularityUpgrade } from './singularity' @@ -177,7 +177,7 @@ import type { PlayerSave } from './types/LegacySynergism' export const player: Player = { firstPlayed: new Date().toISOString(), - worlds: new QuarkHandler({ quarks: 0, bonus: 0 }), + worlds: new QuarkHandler(0), coins: new Decimal('1e2'), coinsThisPrestige: new Decimal('1e2'), coinsThisTranscension: new Decimal('1e2'), @@ -5040,7 +5040,7 @@ export const resetCheck = async ( i18next.t('main.singularityMessage4', { x: format(nextSingularityNumber), y: format(calculateGoldenQuarkGain(), 2, true), - z: format(player.worlds.BONUS) + z: format(getQuarkBonus()) }) ) await Alert(i18next.t('main.singularityMessage5')) diff --git a/src/UpdateVisuals.ts b/src/UpdateVisuals.ts index 2d7e8f07a..4ca4f2784 100644 --- a/src/UpdateVisuals.ts +++ b/src/UpdateVisuals.ts @@ -29,7 +29,7 @@ import { version } from './Config' import type { IMultiBuy } from './Cubes' import type { hepteractTypes } from './Hepteracts' import { hepteractTypeList } from './Hepteracts' -import { quarkHandler } from './Quark' +import { getQuarkBonus, quarkHandler } from './Quark' import { displayRuneInformation } from './Runes' import { getShopCosts, isShopUpgradeUnlocked, shopData, shopUpgradeTypes } from './Shop' import { getGoldenQuarkCost } from './singularity' @@ -1342,7 +1342,7 @@ export const visualUpdateSettings = () => { const maxExportQuarks = quarkData.capacity let goldenQuarkMultiplier = 1 - goldenQuarkMultiplier *= 1 + player.worlds.BONUS / 100 + goldenQuarkMultiplier *= 1 + getQuarkBonus() / 100 goldenQuarkMultiplier *= player.highestSingularityCount >= 100 ? 1 + player.highestSingularityCount / 50 : 1 diff --git a/src/saves/PlayerSchema.ts b/src/saves/PlayerSchema.ts index a02134759..bedbef91b 100644 --- a/src/saves/PlayerSchema.ts +++ b/src/saves/PlayerSchema.ts @@ -72,7 +72,7 @@ const hepteractCraftSchema = (k: keyof Player['hepteractCrafts']) => export const playerSchema = z.object({ firstPlayed: z.string().datetime().optional().default(() => new Date().toISOString()), - worlds: z.number().transform((quarks) => new QuarkHandler({ quarks })), + worlds: z.number().transform((quarks) => new QuarkHandler(quarks)), coins: decimalSchema, coinsThisPrestige: decimalSchema, coinsThisTranscension: decimalSchema,