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>> GetLocalAvatarItems() { var userId = User.GetUserId(); List defaultItems; try { defaultItems = LockerAccess.HasFullInventory(db, userId) ? AvatarUnlockCatalog.GetSafeDefaultItems() : AvatarUnlockCatalog.GetStarterItems(); } catch (Exception) { defaultItems = new List(); } var playerItems = new List(); 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 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 }); } }