diff --git a/src/cheers/timeout.ts b/src/cheers/timeout.ts index 5d24ccb..75a6296 100644 --- a/src/cheers/timeout.ts +++ b/src/cheers/timeout.ts @@ -6,6 +6,7 @@ import { timeout } from "lib/timeout"; import { createTimeoutRecord } from "db/dbTimeouts"; import { createCheerEventRecord } from "db/dbCheerEvents"; import { parseCheerArgs } from "lib/parseCommandArgs"; +import { playAlert } from "web/alerts/serverFunctions"; const ITEMNAME = 'blaster'; @@ -20,7 +21,13 @@ export default new Cheer('timeout', 100, async (msg, user) => { if (result.status) await Promise.all([ sendMessage(`GOTTEM ${target.displayName} got BLASTED by ${user.displayName} GOTTEM`), createTimeoutRecord(user, target, ITEMNAME), - createCheerEventRecord(user, ITEMNAME) + createCheerEventRecord(user, ITEMNAME), + playAlert({ + name: 'userBlast', + user: user.displayName, + target: target.displayName + }) + ]); else { await handleNoTarget(msg, user, ITEMNAME); diff --git a/src/cheers/tnt.ts b/src/cheers/tnt.ts index 6162970..fd94277 100644 --- a/src/cheers/tnt.ts +++ b/src/cheers/tnt.ts @@ -7,6 +7,7 @@ import { createTimeoutRecord } from "db/dbTimeouts"; import { createCheerEventRecord } from "db/dbCheerEvents"; import { getTNTTargets } from "items/tnt"; import { redis } from "bun"; +import { playAlert } from "web/alerts/serverFunctions"; const ITEMNAME = 'tnt'; @@ -27,6 +28,12 @@ export default new Cheer('tnt', 1000, async (msg, user) => { ]); })); + playAlert({ + name: 'tntExplosion', + user: user.displayName, + targets + }); + await sendMessage(`RIPBOZO ${user.displayName} exploded ${targets.length} chatter${targets.length === 1 ? '' : 's'} with their TNT RIPBOZO`); }); diff --git a/src/items/blaster.ts b/src/items/blaster.ts index 791d689..2f30393 100644 --- a/src/items/blaster.ts +++ b/src/items/blaster.ts @@ -6,6 +6,7 @@ import { getUserRecord } from "db/dbUser"; import parseCommandArgs from "lib/parseCommandArgs"; import { timeout } from "lib/timeout"; import User from "user"; +import { playAlert } from "web/alerts/serverFunctions"; const ITEMNAME = 'blaster'; @@ -28,7 +29,12 @@ export default new Item(ITEMNAME, 'Blaster', 's', sendMessage(`GOTTEM ${target.displayName} got BLASTED by ${user.displayName} GOTTEM`), changeItemCount(user, userObj, ITEMNAME), createTimeoutRecord(user, target, ITEMNAME), - createUsedItemRecord(user, ITEMNAME) + createUsedItemRecord(user, ITEMNAME), + playAlert({ + name: 'userBlast', + user: user.displayName, + target: target.displayName + }) ]); else { switch (result.reason) { diff --git a/src/items/tnt.ts b/src/items/tnt.ts index 4290fc5..33df92c 100644 --- a/src/items/tnt.ts +++ b/src/items/tnt.ts @@ -6,6 +6,7 @@ import User from "user"; import { getUserRecord } from "db/dbUser"; import { createTimeoutRecord } from "db/dbTimeouts"; import { createUsedItemRecord } from "db/dbUsedItems"; +import { playAlert } from "web/alerts/serverFunctions"; const ITEMNAME = 'tnt'; @@ -35,6 +36,11 @@ export default new Item(ITEMNAME, 'TNT', 's', await Promise.all([ createUsedItemRecord(user, ITEMNAME), + playAlert({ + name: 'tntExplosion', + user: user.displayName, + targets + }), changeItemCount(user, userObj, ITEMNAME) ]); await user.clearLock(); diff --git a/src/web/alerts/www/public/explosion1.ogg b/src/web/alerts/www/public/explosion1.ogg new file mode 100644 index 0000000..9129b9e Binary files /dev/null and b/src/web/alerts/www/public/explosion1.ogg differ diff --git a/src/web/alerts/www/public/getrekt.jpg b/src/web/alerts/www/public/getrekt.jpg new file mode 100644 index 0000000..5a09df6 Binary files /dev/null and b/src/web/alerts/www/public/getrekt.jpg differ diff --git a/src/web/alerts/www/public/tnt.mp4 b/src/web/alerts/www/public/tnt.mp4 new file mode 100644 index 0000000..5084646 Binary files /dev/null and b/src/web/alerts/www/public/tnt.mp4 differ diff --git a/src/web/alerts/www/src/alerts/alertManager.ts b/src/web/alerts/www/src/alertManager.ts similarity index 97% rename from src/web/alerts/www/src/alerts/alertManager.ts rename to src/web/alerts/www/src/alertManager.ts index 4f23e31..c30220f 100644 --- a/src/web/alerts/www/src/alerts/alertManager.ts +++ b/src/web/alerts/www/src/alertManager.ts @@ -1,5 +1,5 @@ import { alert } from "web/alerts/types"; -import alerts from "./index"; +import alerts from "./alerts/index"; function generateRandomCSSIdentifier() { const firstChar = String.fromCharCode(97 + Math.floor(Math.random() * 26)); diff --git a/src/web/alerts/www/src/alerts/index.ts b/src/web/alerts/www/src/alerts/index.ts index eb48264..d538b73 100644 --- a/src/web/alerts/www/src/alerts/index.ts +++ b/src/web/alerts/www/src/alerts/index.ts @@ -1,5 +1,6 @@ import { alert } from "web/alerts/types"; import userBlast from "./userBlast"; +import tntExplosion from "./tntExplosion"; export type AlertRunner = { duration: number; @@ -15,5 +16,5 @@ export default { 'userBlast': userBlast, 'userExecute': userBlast, 'grenadeExplosion': userBlast, - 'tntExplosion': userBlast, + 'tntExplosion': tntExplosion, } as AlertMap; diff --git a/src/web/alerts/www/src/alerts/tntExplosion.ts b/src/web/alerts/www/src/alerts/tntExplosion.ts new file mode 100644 index 0000000..ebde2d2 --- /dev/null +++ b/src/web/alerts/www/src/alerts/tntExplosion.ts @@ -0,0 +1,31 @@ +import { userBlastAlert } from "web/alerts/types"; +import { AlertRunner } from "./index"; + +const duration = 1500; + +export default async function execute(alert: userBlastAlert): Promise { + const parentDiv = document.createElement('div'); + parentDiv.className = 'tntExplosionAlert'; + parentDiv.innerHTML = ` + + + `; + + const randomX = Math.floor(Math.random() * (window.innerWidth - 450 - 300)) + 150; + const randomY = Math.floor(Math.random() * (window.innerHeight - 800 - 300)) + 150; + + parentDiv.style.left = `${randomX}px`; + parentDiv.style.top = `${randomY}px`; + + return { blocking: false, duration, alertDiv: parentDiv }; +}; diff --git a/src/web/alerts/www/src/alerts/userBlast.ts b/src/web/alerts/www/src/alerts/userBlast.ts index c318338..a3cbda9 100644 --- a/src/web/alerts/www/src/alerts/userBlast.ts +++ b/src/web/alerts/www/src/alerts/userBlast.ts @@ -1,20 +1,57 @@ import { userBlastAlert } from "web/alerts/types"; import { AlertRunner } from "./index"; -const duration = 10000; +const duration = 500; export default async function execute(alert: userBlastAlert): Promise { + const audio = new Audio("/alerts/public/explosion1.ogg"); + const parentDiv = document.createElement('div'); parentDiv.className = 'userBlastAlert'; parentDiv.innerHTML = ` - ${alert.user} just blasted ${alert.target} for 60 seconds! Rip bozo! + + + ${alert.user} + + + ${alert.target} + -`; + `; + + const randomX = Math.floor(Math.random() * (window.innerWidth - 300)); + const randomY = Math.floor(Math.random() * (window.innerHeight - 300)); + + parentDiv.style.left = `${randomX}px`; + parentDiv.style.top = `${randomY}px`; + + audio.play(); + return { blocking: false, duration, alertDiv: parentDiv }; }; diff --git a/src/web/alerts/www/src/main.ts b/src/web/alerts/www/src/main.ts index 0162f17..0c054ea 100644 --- a/src/web/alerts/www/src/main.ts +++ b/src/web/alerts/www/src/main.ts @@ -1,6 +1,7 @@ import { serverInstruction } from "web/serverTypes"; import { alertEventData } from "web/alerts/types"; -import alertManager from "./alerts/alertManager"; +import alertManager from "./alertManager"; +import "@fontsource/jersey-15"; const socket = new WebSocket(`ws://${location.host}`); diff --git a/src/web/index.ts b/src/web/index.ts index 4909659..3d24dc2 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -18,7 +18,13 @@ export default Bun.serve({ "/chat/getBadges": getBadges, "/chat/getEmotes": getExternalEmotes, - "/alerts": alerts + "/alerts": alerts, + "/alerts/public/:filename": async req => { + const target = req.params.filename; + const file = Bun.file(`${import.meta.dir}/alerts/www/public/${target}`); + if (!await file.exists()) return new Response(`${target} not found`, { status: 404 }); + return new Response(file); + } }, websocket: { message(ws, omessage) {