Celebration animations for purchases, XP gains & achievement unlocks
- New global celebration system: celebration-store (queue) + CelebrationOverlay (animated: count-up XP, filling bar, level-up pop, achievement cards; plays levelUp/award sounds; tap or auto-dismiss). Rendered in page.tsx. - Shop: every purchase now celebrates — XP packs animate XP gain + level-up, cosmetics show a "purchased!" pop. Newly-unlocked achievements (diffed from the profile before/after) animate too. - XP purchases now actually evaluate achievements: gamification.evaluateAchievements (client) + Gamification.EvaluateAchievements (server, called in ShopBuy xp path) unlock level milestones + grant their coins. Verified live: buying XP took L1→L5, unlocked level_5 server-side and credited its reward. tsc + dotnet + next build clean; images rebuilt :1500/:1505. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -148,6 +148,25 @@ public static class Gamification
|
||||
p.Xp = r.xp;
|
||||
}
|
||||
|
||||
/// <summary>Re-evaluate achievements vs current state (outside a match), unlock new
|
||||
/// ones + grant their coins, and return the newly-unlocked list.</summary>
|
||||
public static List<AchievementUnlockDto> EvaluateAchievements(ProfileDto p)
|
||||
{
|
||||
var list = new List<AchievementUnlockDto>();
|
||||
foreach (var d in Achs)
|
||||
{
|
||||
int prog = AchProgress(d, p.Stats, p.Rating, p.Level);
|
||||
p.Achievements[d.Id] = prog;
|
||||
if (prog >= d.Goal && !p.Unlocked.Contains(d.Id))
|
||||
{
|
||||
p.Unlocked.Add(d.Id);
|
||||
p.Coins += d.Coin;
|
||||
list.Add(new() { Id = d.Id, NameFa = d.NameFa, NameEn = d.NameEn, Icon = d.Icon, CoinReward = d.Coin });
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static (int level, int xp, bool up) AddXp(int level, int xp, int gain)
|
||||
{
|
||||
bool up = false;
|
||||
|
||||
@@ -131,6 +131,7 @@ public class ProfileService
|
||||
if (p.Coins < pk.Price) return (false, p, "insufficient");
|
||||
p.Coins -= pk.Price;
|
||||
Gamification.GrantXp(p, pk.Xp);
|
||||
Gamification.EvaluateAchievements(p); // unlock any level milestones reached
|
||||
await Save(p);
|
||||
await Ledger(uid, "xp", -pk.Price, id);
|
||||
return (true, p, "");
|
||||
|
||||
Reference in New Issue
Block a user