b66e7f77a5
Achievements: generator-driven, now 100+ across 7 categories (added Rulership) mirrored client + server with identical ids/goals/coins. New tracked stats: hakemRounds (be the hakem — incl. "7× Hakem"), roundsWon, plus losses metric. Custom achievement-only sticker packs (Rulership 👑, Firestorm 🔥) with new inline-SVG art (crown-gold, seven-zip, streak-fire), unlocked by hakem_7 / streak_10. Server GameRoom tallies hakem rounds per seat + rounds won per team; client tallies the same for vs-computer/private games (dealId-deduped). Forfeit (surrender): a player can request forfeit; if the teammate is a bot it auto-confirms, otherwise the human teammate gets a confirm/decline prompt (20s timeout). Result: forfeiting with ≥1 round won = normal loss; 0 rounds = Kot. Wired client↔server over the hub (RequestForfeit/ConfirmForfeit/DeclineForfeit + "forfeit" event); offline/vs-computer ends immediately in the store. Flag button + confirm dialogs in the table. Online count: never shows below 50 — live service floors the real count with a drifting believable number (mock base lowered to ~50–170). Matchmaking: real players get a longer priority window (9s) before bots fill; bots now occasionally react after winning a trick (humanize). Coins: starter pack is 95,000 Toman (50k coins); packs rescaled up (server + mock). Verified: dotnet build + tsc + next build clean; sim unlocks 57 achievements/500 matches; live server: starter=95000, a 7-hakem win unlocks hakem_7 + wins_1 with hakemRounds/roundsWon persisted. Images rebuilt on :1500/:1505. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
99 lines
3.4 KiB
TypeScript
99 lines
3.4 KiB
TypeScript
"use client";
|
|
|
|
import { Coins } from "lucide-react";
|
|
import { useEffect, useState } from "react";
|
|
import { ScreenHeader, ScreenShell } from "@/components/online/ScreenHeader";
|
|
import { useSessionStore } from "@/lib/session-store";
|
|
import { useI18n } from "@/lib/i18n";
|
|
import { getService } from "@/lib/online/service";
|
|
import { sound } from "@/lib/sound";
|
|
import { CoinPack } from "@/lib/online/types";
|
|
import { cn } from "@/lib/cn";
|
|
|
|
export function BuyCoinsScreen() {
|
|
const { t, locale } = useI18n();
|
|
const profile = useSessionStore((s) => s.profile);
|
|
const setProfile = useSessionStore((s) => s.setProfile);
|
|
const [packs, setPacks] = useState<CoinPack[]>([]);
|
|
const [busy, setBusy] = useState<string | null>(null);
|
|
const [gained, setGained] = useState<number | null>(null);
|
|
|
|
useEffect(() => {
|
|
getService().getCoinPacks().then(setPacks);
|
|
}, []);
|
|
|
|
const fmt = (n: number) =>
|
|
new Intl.NumberFormat(locale === "fa" ? "fa-IR" : "en-US").format(n);
|
|
|
|
const buy = async (p: CoinPack) => {
|
|
setBusy(p.id);
|
|
const res = await getService().buyCoins(p.id);
|
|
// Live: redirect to the ZarinPal gateway; we credit on return via callback.
|
|
if (res.redirectUrl) {
|
|
window.location.href = res.redirectUrl;
|
|
return;
|
|
}
|
|
// Mock/offline: instant credit.
|
|
if (res.ok && res.profile) {
|
|
setProfile(res.profile);
|
|
sound.play("purchase");
|
|
setGained(res.coins);
|
|
setTimeout(() => setGained(null), 2500);
|
|
}
|
|
setBusy(null);
|
|
};
|
|
|
|
return (
|
|
<ScreenShell>
|
|
<ScreenHeader
|
|
title={t("buy.title")}
|
|
right={
|
|
profile && (
|
|
<span className="glass rounded-full px-3 py-1.5 text-xs font-bold text-gold-300 flex items-center gap-1">
|
|
<Coins className="size-3.5 text-gold-400" />
|
|
{fmt(profile.coins)}
|
|
</span>
|
|
)
|
|
}
|
|
/>
|
|
<p className="text-center text-cream/50 text-xs mb-4">{t("buy.note")}</p>
|
|
|
|
{gained != null && (
|
|
<div className="mb-4 text-center text-teal-300 font-bold glass rounded-xl py-2 flex items-center justify-center gap-1.5">
|
|
+{fmt(gained)} <Coins className="size-4 text-gold-400" />
|
|
</div>
|
|
)}
|
|
|
|
<div className="grid grid-cols-2 gap-3 pb-6">
|
|
{packs.map((p) => (
|
|
<button
|
|
key={p.id}
|
|
disabled={busy !== null}
|
|
onClick={() => buy(p)}
|
|
className={cn(
|
|
"glass rounded-2xl p-4 pt-5 flex flex-col items-center gap-1 relative hover:bg-navy-800/80 transition disabled:opacity-60",
|
|
p.tag && "ring-2 ring-gold-400/50"
|
|
)}
|
|
>
|
|
{p.tag && (
|
|
<span className="absolute -top-2 rounded-full btn-gold text-[10px] font-bold px-2 py-0.5">
|
|
{p.tag === "best" ? t("buy.best") : p.tag === "starter" ? t("buy.starter") : t("buy.popular")}
|
|
</span>
|
|
)}
|
|
<Coins className="size-7 text-gold-400" />
|
|
<span className="text-xl font-black gold-text">{fmt(p.coins + p.bonus)}</span>
|
|
{p.bonus > 0 && (
|
|
<span className="text-[10px] text-teal-300">
|
|
+{fmt(p.bonus)} {t("buy.bonus")}
|
|
</span>
|
|
)}
|
|
<span className="mt-1 text-sm font-bold text-cream">
|
|
{fmt(p.priceToman)} {t("buy.toman")}
|
|
</span>
|
|
</button>
|
|
))}
|
|
</div>
|
|
</ScreenShell>
|
|
);
|
|
}
|