clerk
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import type * as Party from 'partykit/server';
|
||||
|
||||
interface GameState {
|
||||
totalClicks: number;
|
||||
users: Record<string, { name: string; clicks: number; lastSeen: number }>;
|
||||
@@ -47,7 +50,7 @@ const MILESTONES = [
|
||||
];
|
||||
|
||||
export default class GameServer implements Party.Server {
|
||||
constructor(readonly party: Party.Party) {}
|
||||
constructor(readonly party: Party.Party) { }
|
||||
|
||||
gameState: GameState = {
|
||||
totalClicks: 0,
|
||||
@@ -65,11 +68,11 @@ export default class GameServer implements Party.Server {
|
||||
|
||||
autoClickInterval?: NodeJS.Timeout;
|
||||
|
||||
onConnect(conn: Party.Connection, ctx: Party.ConnectionContext) {
|
||||
onConnect(conn: Party.Connection, _ctx: Party.ConnectionContext) {
|
||||
conn.send(JSON.stringify({ type: 'game-state', state: this.gameState }));
|
||||
}
|
||||
|
||||
onMessage(message: string, sender: Party.Connection) {
|
||||
onMessage(message: string, _sender: Party.Connection) {
|
||||
const data = JSON.parse(message) as Message;
|
||||
|
||||
switch (data.type) {
|
||||
@@ -100,9 +103,9 @@ export default class GameServer implements Party.Server {
|
||||
|
||||
handleClick(data: ClickMessage) {
|
||||
const clickValue = this.gameState.clickMultiplier;
|
||||
|
||||
|
||||
this.gameState.totalClicks += clickValue;
|
||||
|
||||
|
||||
if (!this.gameState.users[data.userId]) {
|
||||
this.gameState.users[data.userId] = {
|
||||
name: data.userName,
|
||||
@@ -110,7 +113,7 @@ export default class GameServer implements Party.Server {
|
||||
lastSeen: Date.now()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
this.gameState.users[data.userId].clicks += clickValue;
|
||||
this.gameState.users[data.userId].lastSeen = Date.now();
|
||||
|
||||
@@ -120,16 +123,16 @@ export default class GameServer implements Party.Server {
|
||||
handlePurchaseUpgrade(data: PurchaseUpgradeMessage) {
|
||||
const upgrade = UPGRADES[data.upgradeId as keyof typeof UPGRADES];
|
||||
const currentUpgrade = this.gameState.upgrades[data.upgradeId];
|
||||
|
||||
|
||||
if (!upgrade || !currentUpgrade) return;
|
||||
|
||||
const userClicks = this.gameState.users[data.userId]?.clicks || 0;
|
||||
|
||||
|
||||
if (userClicks >= currentUpgrade.cost) {
|
||||
this.gameState.users[data.userId].clicks -= currentUpgrade.cost;
|
||||
currentUpgrade.owned += 1;
|
||||
currentUpgrade.cost = Math.floor(upgrade.baseCost * Math.pow(upgrade.multiplier, currentUpgrade.owned));
|
||||
|
||||
|
||||
this.updateGameMultipliers();
|
||||
}
|
||||
}
|
||||
@@ -140,10 +143,10 @@ export default class GameServer implements Party.Server {
|
||||
|
||||
Object.entries(this.gameState.upgrades).forEach(([upgradeId, upgrade]) => {
|
||||
const config = UPGRADES[upgradeId as keyof typeof UPGRADES];
|
||||
if (config.clickBonus) {
|
||||
if ('clickBonus' in config && config.clickBonus) {
|
||||
this.gameState.clickMultiplier += config.clickBonus * upgrade.owned;
|
||||
}
|
||||
if (config.autoClickRate) {
|
||||
if ('autoClickRate' in config && config.autoClickRate) {
|
||||
this.gameState.autoClickRate += config.autoClickRate * upgrade.owned;
|
||||
}
|
||||
});
|
||||
@@ -180,4 +183,4 @@ export default class GameServer implements Party.Server {
|
||||
}
|
||||
}
|
||||
|
||||
GameServer satisfies Party.Worker;
|
||||
GameServer satisfies Party.Worker;
|
||||
|
||||
Reference in New Issue
Block a user