using Newtonsoft.Json.Linq; using XFEWarframe.Core.Data; namespace XFEWarframe.Core.Services; public static class PlayerPermissions { public static bool Currency(JObject state, ServerOptions options) => state.Obj("config").Value("allowPlayerCurrencyGrant") ?? options.AllowPlayerCurrencyGrant; public static bool Items(JObject state, ServerOptions options) => state.Obj("config").Value("allowPlayerItemGrant") ?? options.AllowPlayerItemGrant; // Currency packs, random packs and mail can indirectly grant currency. They are administered separately. public static bool Grantable(string category) => category is not ("CreditBundles" or "FusionBundles" or "Bundles" or "BoosterPacks" or "EmailItems" or "SpecialItems") && (Inventory.EquipmentKeys.Contains(category) || Inventory.CountedKeys.Contains(category) || category is "FlavourItems" or "WeaponSkins" or "Boosters" or "FusionTreasures" or "SlotItems"); public static void CheckItem(ItemCatalog catalog, string type, int depth = 0) { if (depth > 8) throw new ApiException(400, "物品附加内容过多。"); var (category, meta) = catalog.Get(type); if (!Grantable(category) && !(depth > 0 && category == "SpecialItems")) throw new ApiException(403, "此物品需由管理员发放。"); foreach (var key in new[] { "additionalItems", "exalted" }) foreach (var extra in meta[key] as JArray ?? []) CheckItem(catalog, extra.ToString(), depth + 1); if (meta.Value("defaultWeapon") is string weapon) CheckItem(catalog, weapon, depth + 1); if (meta.Value("bayonetOtherWeaponType") is string counterpart && !meta.Value("excludeFromMarket")) CheckItem(catalog, counterpart, depth + 1); } }