Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.
Draft
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
69 changes: 69 additions & 0 deletions apps/idlebiz/src/game/multiplier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {
MultiplierSource,
type MultiplierType,
type PermanentMultiplier,
type Profile,
type TemporaryMultiplier,
} from "@/game/types";
import { mongo } from "@/lib/mongo";

export async function addTemporaryMultiplier(
discordId: string,
value: number,
duration: number,
source: MultiplierSource,
type: MultiplierType
) {
const now = new Date();
const expiredAt = new Date(now.getTime() + duration);

const multiplier: TemporaryMultiplier = {
value,
source,
type,
activatedAt: now,
expiredAt,
};

const client = await mongo();
const db = client.db();

return await db
.collection<Profile>("profiles")
.updateOne({ discordId: discordId }, { $push: { "multipliers.temporary": multiplier } });
}

export async function addPermanentMultiplier(
discordId: string,
value: number,
source: MultiplierSource,
type: MultiplierType
) {
const now = new Date();

const multiplier: PermanentMultiplier = {
value,
source,
type,
activatedAt: now,
};

const client = await mongo();
const db = client.db();

return await db
.collection<Profile>("profiles")
.updateOne({ discordId: discordId }, { $push: { "multipliers.permanent": multiplier } });
}

export async function updateReferralBonusMultiplier(discordId: string, value: number) {
const client = await mongo();
const db = client.db();

return await db
.collection<Profile>("profiles")
.updateOne(
{ discordId: discordId, "multipliers.permanent.source": MultiplierSource.ReferralBonus },
{ $set: { "multipliers.permanent.$.value": value } }
);
}
5 changes: 5 additions & 0 deletions apps/idlebiz/src/game/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./material";
export * from "./building";
export * from "./referral";
export * from "./multiplier";
export * from "./profile";
22 changes: 22 additions & 0 deletions apps/idlebiz/src/game/types/multiplier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export enum MultiplierSource {
DailyReward = "dailyReward",
ReferralBonus = "referralBonus",
ReferralClaim = "referralClaim",
}

export enum MultiplierType {
MaterialProduction = "materialProduction",
}

type Multiplier = {
value: number;
source: MultiplierSource;
type: MultiplierType;
activatedAt: Date;
};

export type PermanentMultiplier = Multiplier;

export type TemporaryMultiplier = Multiplier & {
expiredAt: Date;
};
12 changes: 12 additions & 0 deletions apps/idlebiz/src/game/types/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// TODO
import type { PermanentMultiplier, TemporaryMultiplier } from "@/game/types/multiplier";

export type Profile = {
discordId: string;
multipliers: ProfileMultipliers;
};

export type ProfileMultipliers = {
permanent: PermanentMultiplier[];
temporary: TemporaryMultiplier[];
};
6 changes: 6 additions & 0 deletions apps/idlebiz/src/game/types/referral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type Referral = {
userId: string;
ownerId: string;
code: string;
createdAt: Date;
};
2 changes: 0 additions & 2 deletions apps/idlebiz/src/lib/types/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/idlebiz/src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Building } from "@/game/types/building";
import type { Material } from "@/game/types/material";
import { mongo } from "@/lib/mongo";
import type { Building } from "@/lib/types/building";
import type { Material } from "@/lib/types/material";
import ms from "ms";

(async () => {
Expand Down