mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using RadicadeServer.API.Royale;
|
|
using RadicadeServer.DB;
|
|
using RadicadeServer.Extensions;
|
|
using RadicadeServer.RecNet.Progression;
|
|
using RadicadeServer.RecNet.Responses;
|
|
|
|
namespace RadicadeServer.API.Players.V2
|
|
{
|
|
[Route("api/players/v2")]
|
|
public class PlayersV2(RecDBContext db) : Controller
|
|
{
|
|
[HttpGet("progression/bulk")]
|
|
public async Task<List<ProgressionResponse>?> GetBulkProgressionV2([FromQuery] int[] id)
|
|
{
|
|
var res = new List<ProgressionResponse>();
|
|
foreach (int i in id)
|
|
{
|
|
var data = await db.Progression.FirstOrDefaultAsync((x) => x.PlayerId == i);
|
|
data ??= new ProgressionData { PlayerId = i };
|
|
res.Add(new ProgressionResponse(data));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
[HttpPost("objectives"), Authorize]
|
|
public async Task<ActionResult<List<ProgressionResponse>>> CompleteObjectives([FromBody] List<CompleteObjectivesDTO>? objectives)
|
|
{
|
|
var userId = User.GetUserId();
|
|
if (userId == null) return Unauthorized();
|
|
if (objectives == null) return BadRequest();
|
|
|
|
int additionalXp = objectives
|
|
.Where(o => o.AdditionalXp > 0)
|
|
.Sum(o => o.AdditionalXp);
|
|
|
|
var strings = new List<string>();
|
|
await RoyaleShared.AwardXpAsync(db, userId.Value, additionalXp, "Objective", strings);
|
|
|
|
var stored = await db.Progression.AsNoTracking().FirstOrDefaultAsync(x => x.PlayerId == userId.Value)
|
|
?? new ProgressionData { PlayerId = userId.Value };
|
|
|
|
return Ok(new List<ProgressionResponse> { new(stored) });
|
|
}
|
|
}
|
|
|
|
public class CompleteObjectivesDTO
|
|
{
|
|
public int ObjectiveType { get; set; }
|
|
public int AdditionalXp { get; set; }
|
|
public bool InParty { get; set; }
|
|
}
|
|
}
|