mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
99 lines
3.1 KiB
C#
99 lines
3.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using RadicadeServer.DB;
|
|
using RadicadeServer.RecNet.Avatar;
|
|
using RadicadeServer.RecNet.Enums.Players;
|
|
using RadicadeServer.RecNet.Store;
|
|
using RadicadeServer.RecNet.Storefront;
|
|
|
|
namespace RadicadeServer.API.Storefront.V3;
|
|
|
|
[Route("api/storefronts/v3")]
|
|
[Route("econ/api/storefronts/v3")]
|
|
public class StorefrontsV3(RecDBContext db) : Controller
|
|
{
|
|
[HttpGet("giftdropstore/{type}")]
|
|
public async Task<IActionResult> GetGiftDropStore(StorefrontTypes type)
|
|
{
|
|
var items = await StorefrontShared.GetStoreItems(db, (long)type);
|
|
items = ProjectStoreItemsForClient(
|
|
items,
|
|
User.FindFirst("rn.plat")?.Value,
|
|
AvatarUnlockCatalog.IsClientResolvableDescription);
|
|
Console.WriteLine($"[Storefront v3] GET giftdropstore {type} ({(long)type}): returning {items.Count} item(s).");
|
|
|
|
return Ok(new GiftDropStorefront
|
|
{
|
|
StorefrontType = type,
|
|
NextUpdate = DateTime.MaxValue,
|
|
NewUntil = null,
|
|
StoreItems = items
|
|
});
|
|
}
|
|
|
|
public static List<PurchasableGiftDrop> ProjectStoreItemsForClient(
|
|
IEnumerable<PurchasableGiftDrop> items,
|
|
string? platformClaim,
|
|
Func<string?, bool> canResolveAvatarItem)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(items);
|
|
ArgumentNullException.ThrowIfNull(canResolveAvatarItem);
|
|
|
|
if (!string.Equals(platformClaim, ((int)Platforms.Standalone).ToString(), StringComparison.Ordinal))
|
|
return items.ToList();
|
|
|
|
var projected = new List<PurchasableGiftDrop>();
|
|
foreach (var item in items)
|
|
{
|
|
var projectedGifts = new List<Gift>();
|
|
var changed = false;
|
|
|
|
foreach (var gift in item.GiftDrops)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(gift.AvatarItemDesc) || canResolveAvatarItem(gift.AvatarItemDesc))
|
|
{
|
|
projectedGifts.Add(gift);
|
|
continue;
|
|
}
|
|
|
|
changed = true;
|
|
if (HasNonAvatarReward(gift))
|
|
{
|
|
var giftCopy = gift.Clone();
|
|
giftCopy.AvatarItemDesc = string.Empty;
|
|
projectedGifts.Add(giftCopy);
|
|
}
|
|
}
|
|
|
|
if (!changed)
|
|
{
|
|
projected.Add(item);
|
|
continue;
|
|
}
|
|
|
|
|
|
|
|
if (projectedGifts.Count == 0) continue;
|
|
|
|
projected.Add(new PurchasableGiftDrop
|
|
{
|
|
PurchasableItemId = item.PurchasableItemId,
|
|
Type = item.Type,
|
|
Prices = item.Prices.ToList(),
|
|
SubscriberPrices = item.SubscriberPrices.ToList(),
|
|
IsFeatured = item.IsFeatured,
|
|
EndDate = item.EndDate,
|
|
NewUntil = item.NewUntil,
|
|
GiftDrops = projectedGifts
|
|
});
|
|
}
|
|
|
|
return projected;
|
|
}
|
|
|
|
private static bool HasNonAvatarReward(Gift gift) =>
|
|
!string.IsNullOrWhiteSpace(gift.ConsumableItemDesc)
|
|
|| !string.IsNullOrWhiteSpace(gift.EquipmentPrefabName)
|
|
|| gift.Currency > 0
|
|
|| gift.Xp > 0;
|
|
}
|