mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using RadicadeServer.DB;
|
|
using RadicadeServer.Extensions;
|
|
using RadicadeServer.RecNet.Avatar;
|
|
using RadicadeServer.RecNet.Enums.Players;
|
|
|
|
namespace RadicadeServer.API.Avatars.V4;
|
|
|
|
[Route("api/avatar/v4")]
|
|
[Route("econ/api/avatar/v4")]
|
|
public class AvatarV4(RecDBContext db) : Controller
|
|
{
|
|
[HttpGet("items")]
|
|
public async Task<ActionResult<List<AvatarItemV4>>> GetLocalAvatarItems()
|
|
{
|
|
var userId = User.GetUserId();
|
|
|
|
List<AvatarItem> defaultItems;
|
|
|
|
try
|
|
{
|
|
defaultItems = LockerAccess.HasFullInventory(db, userId)
|
|
? AvatarUnlockCatalog.GetSafeDefaultItems()
|
|
: AvatarUnlockCatalog.GetStarterItems();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
defaultItems = new List<AvatarItem>();
|
|
}
|
|
|
|
var playerItems = new List<AvatarItem>();
|
|
|
|
if (userId.HasValue)
|
|
{
|
|
var playerUnlocks = await db.Unlocks.FirstOrDefaultAsync(x => x.AccountId == userId);
|
|
var unlockedItems = playerUnlocks?.GetAvatarItems();
|
|
playerItems = User.FindFirst("rn.plat")?.Value == ((int)Platforms.Standalone).ToString()
|
|
? AvatarUnlockCatalog.KeepResolvableItems(unlockedItems)
|
|
: AvatarUnlockCatalog.KeepSupportedItems(unlockedItems);
|
|
}
|
|
|
|
var items = defaultItems
|
|
.Concat(playerItems)
|
|
.Where(x => !string.IsNullOrWhiteSpace(x.AvatarItemDesc))
|
|
.GroupBy(x => x.AvatarItemDesc, StringComparer.OrdinalIgnoreCase)
|
|
.Select(x => x.First())
|
|
.ToList();
|
|
|
|
return Ok(items.Select(item => new AvatarItemV4(item)).ToList());
|
|
}
|
|
|
|
[HttpPost("saved/set"), Authorize]
|
|
public async Task<IActionResult> SetSavedOutfit([FromBody] Outfit? outfit)
|
|
{
|
|
var userId = User.GetUserId();
|
|
if (userId == null) return Unauthorized();
|
|
|
|
var saved = await SavedOutfits.SaveAsync(db, userId.Value, outfit);
|
|
if (saved == null) return BadRequest(new { error = "invalid_slot" });
|
|
|
|
return Ok(new { Success = true, Slot = saved.Slot });
|
|
}
|
|
}
|