mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RadicadeServer.DB;
|
||||
using RadicadeServer.RecNet.Progression;
|
||||
|
||||
namespace RadicadeServer.Utils
|
||||
{
|
||||
public static class ProgressionAwardService
|
||||
{
|
||||
public const int XpPerGiftBoxOpened = 1;
|
||||
|
||||
public const int XpPerGameCompleted = 2;
|
||||
|
||||
public static async Task<int> AwardXpAsync(RecDBContext db, long playerId, int xp, string reason)
|
||||
{
|
||||
if (playerId <= 0 || xp <= 0) return 0;
|
||||
|
||||
var progression = await db.Progression.FirstOrDefaultAsync(x => x.PlayerId == playerId);
|
||||
if (progression == null)
|
||||
{
|
||||
progression = new ProgressionData { PlayerId = playerId };
|
||||
await db.Progression.AddAsync(progression);
|
||||
}
|
||||
|
||||
int granted = (int)Math.Min(xp, int.MaxValue);
|
||||
if (granted <= 0)
|
||||
{
|
||||
await db.SaveChangesAsync();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int oldLevel = progression.Level;
|
||||
progression.XP = (int)Math.Min(progression.XP + granted, int.MaxValue);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
int computedLevel = LevelUpGiftService.ComputeLevel(LevelUpGiftService.ParseMap(), progression.XP);
|
||||
if (computedLevel > progression.Level) progression.Level = computedLevel;
|
||||
|
||||
await LevelUpGiftService.DeliverLevelUpGiftsAsync(db, playerId,
|
||||
recomputeFromXp: true, fromLevel: oldLevel, notify: true);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await RoomProgressionService.SendProgressionLevelUpdateAsync(db, playerId, progression);
|
||||
|
||||
return granted;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user