Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix merge conflicts? #607

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/BlueberryUpgrades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/Calculate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
32 changes: 25 additions & 7 deletions src/ImportExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 15 additions & 6 deletions src/Login.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -86,19 +86,28 @@ 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!`

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)
Alert('Your individual bonuses were not applied. Try refreshing the page!')
return
}

currentBonus.textContent +=
Expand Down
3 changes: 1 addition & 2 deletions src/Octeracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
99 changes: 7 additions & 92 deletions src/Quark.ts
Original file line number Diff line number Diff line change
@@ -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<null | number> => {
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<string, { content: string }> }
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
Expand Down Expand Up @@ -76,33 +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

private interval: ReturnType<typeof setInterval> | null = null

constructor ({ bonus, quarks }: { bonus?: number; quarks: number }) {
constructor (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. */
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. */
Expand All @@ -122,42 +73,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)
}
Expand Down
6 changes: 3 additions & 3 deletions src/Synergism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'),
Expand Down Expand Up @@ -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'))
Expand Down
4 changes: 2 additions & 2 deletions src/UpdateVisuals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/saves/PlayerSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading