diff --git a/index.html b/index.html
index bdd4328cc..d32e95dc1 100644
--- a/index.html
+++ b/index.html
@@ -13,7 +13,7 @@
-
+
Synergism
diff --git a/src/Login.ts b/src/Login.ts
index afd2acd25..022cff0c7 100644
--- a/src/Login.ts
+++ b/src/Login.ts
@@ -44,7 +44,9 @@ export const activeConsumables: Record = {
HAPPY_HOUR_BELL: 0
}
-export let happyHourEndTime = 0
+export const allConsumableTimes: Record> = {
+ HAPPY_HOUR_BELL: []
+}
const messageSchema = z.preprocess(
(data, ctx) => {
@@ -75,6 +77,15 @@ const messageSchema = z.preprocess(
}).array(),
tips: z.number().int().nonnegative()
}),
+ z.object({
+ type: z.literal('info-all'),
+ active: z.object({
+ name: z.string(),
+ internalName: z.string(),
+ endsAt: z.number().int()
+ }).array(),
+ tips: z.number().int().nonnegative()
+ }),
/** Received after the *user* successfully redeems a consumable. */
z.object({ type: z.literal('thanks') }),
/** Received when a user is tipped */
@@ -330,6 +341,13 @@ const queue: string[] = []
const exponentialBackoff = [5000, 15000, 30000, 60000]
let tries = 0
+function resetConsumables () {
+ for (const key in activeConsumables) {
+ activeConsumables[key as PseudoCoinConsumableNames] = 0
+ allConsumableTimes[key as PseudoCoinConsumableNames].length = 0 // Specifically for info-all
+ }
+}
+
function handleWebSocket () {
assert(!ws || ws.readyState === WebSocket.CLOSED, 'WebSocket has been set and is not closed')
@@ -344,6 +362,7 @@ function handleWebSocket () {
Notification(
'Could not re-establish your connection. Consumables and events related to Consumables will not work.'
)
+ resetConsumables()
}
})
@@ -355,6 +374,7 @@ function handleWebSocket () {
}
queue.length = 0
+ sendToWebsocket(JSON.stringify({ type: 'info-all' }))
})
ws.addEventListener('message', (ev) => {
@@ -363,6 +383,7 @@ function handleWebSocket () {
if (data.type === 'error') {
Notification(data.message, 5_000)
+ resetConsumables()
} else if (data.type === 'consumed') {
activeConsumables[data.consumable as PseudoCoinConsumableNames]++
Notification(`Someone redeemed a(n) ${data.consumable}!`)
@@ -382,10 +403,22 @@ function handleWebSocket () {
ends = Math.max(ends, endsAt)
}
- happyHourEndTime = ends
+ Notification(message)
+ }
+
+ tips = data.tips
+ } else if (data.type === 'info-all') { // new, needs to be checked
+ resetConsumables() // So that we can get an accurate count each time
+ if (data.active.length !== 0) {
+ let message = 'The following consumables are active:\n'
+
+ for (const { internalName, name, endsAt } of data.active) {
+ activeConsumables[internalName as PseudoCoinConsumableNames]++
+ allConsumableTimes[internalName as PseudoCoinConsumableNames].push(endsAt)
+ message += `${name}, until ${endsAt}\n`
+ }
Notification(message)
- updateEventsPage(ends)
}
tips = data.tips
@@ -405,14 +438,6 @@ function handleWebSocket () {
})
}
-function updateEventsPage (endsAt: number) {
- const amount = document.getElementById('consumableEventBonus')!
- const timer = document.getElementById('consumableEventTimer')!
-
- timer.textContent = new Date(endsAt).toLocaleString()
- amount.textContent = `${Object.values(activeConsumables).reduce((a, b) => a + b, 0)}`
-}
-
export function sendToWebsocket (message: string) {
if (ws?.readyState !== WebSocket.OPEN) {
queue.push(message)
diff --git a/src/UpdateVisuals.ts b/src/UpdateVisuals.ts
index 1ce4fa245..6cd70d200 100644
--- a/src/UpdateVisuals.ts
+++ b/src/UpdateVisuals.ts
@@ -31,7 +31,7 @@ import type { IMultiBuy } from './Cubes'
import { BuffType, consumableEventBuff, eventBuffType, getEvent, getEventBuff } from './Event'
import type { hepteractTypes } from './Hepteracts'
import { hepteractTypeList } from './Hepteracts'
-import { activeConsumables, happyHourEndTime } from './Login'
+import { activeConsumables, allConsumableTimes, type PseudoCoinConsumableNames } from './Login'
import { PCoinUpgradeEffects } from './PseudoCoinUpgrades'
import { getQuarkBonus, quarkHandler } from './Quark'
import { displayRuneInformation } from './Runes'
@@ -1809,6 +1809,14 @@ export const visualUpdateShop = () => {
} Quarks Each`
}
+export const constructConsumableTimes = (p: PseudoCoinConsumableNames) => {
+ const msg: string[] = []
+ for (const time of allConsumableTimes[p]) {
+ msg.push(timeReminingHours(new Date(time)))
+ }
+ return msg.join(', ')
+}
+
export const visualUpdateEvent = () => {
const event = getEvent()
if (event !== null) {
@@ -1835,7 +1843,7 @@ export const visualUpdateEvent = () => {
}
const { HAPPY_HOUR_BELL } = activeConsumables
if (HAPPY_HOUR_BELL > 0) {
- DOMCacheGetOrSet('consumableEventTimer').textContent = timeReminingHours(new Date(happyHourEndTime))
+ DOMCacheGetOrSet('consumableEventTimer').textContent = constructConsumableTimes('HAPPY_HOUR_BELL')
DOMCacheGetOrSet('consumableEventBonus').textContent = `${HAPPY_HOUR_BELL}`
for (let i = 0; i < eventBuffType.length; i++) {