XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using XFEWarframe.Core;
using XFEWarframe.Core.Data;
using XFEWarframe.Core.Services;
using Xunit;

namespace XFEWarframe.Tests;

public sealed partial class EngineTests
{
    [Fact] public async Task RivenChallengeRerollAndCommitPreserveCurrencyAndOwnedIdentity()
    {
        var q = await Login(); const string raw = "/Lotus/Upgrades/Mods/Randomized/RawRifleRandomMod"; const string cipher = "/Lotus/Types/Items/MiscItems/RivenIdentifier"; const string kuva = "/Lotus/Types/Items/MiscItems/Kuva";
        await Give(q, raw); var activate = await Call("/api/activateRandomMod.php", new { ItemType = raw }, q); Assert.True(activate.Status == 200, activate.Body);
        var mod = JObject.Parse(activate.Body)["NewMod"]!; var id = Wire.Id(mod["ItemId"]); Assert.IsType<JObject>(mod["UpgradeFingerprint"]); Assert.Equal(0, Count(await InventoryOf(q), "RawUpgrades", raw));
        Assert.Equal(409, (await Call("/api/rerollRandomMod.php", new { ItemIds = new[] { id } }, q)).Status);
        await Give(q, cipher); Assert.Equal(200, (await Call("/api/completeRandomModChallenge.php", new { ItemId = id }, q)).Status);
        Assert.Equal(409, (await Call("/api/completeRandomModChallenge.php", new { ItemId = id }, q)).Status);
        Assert.Equal(200, (await Call("/api/rerollRandomMod.php", new { ItemIds = new[] { id } }, q)).Status);
        var unveiled = (await InventoryOf(q))["Upgrades"]!.First(x => Wire.Id(x["ItemId"]) == id); var original = JObject.Parse(unveiled.Value<string>("UpgradeFingerprint")!);
        Assert.NotNull(original["compat"]); Assert.InRange(original["buffs"]!.Count(), 2, 3); Assert.Equal(original["buffs"]!.Count(), original["buffs"]!.Select(x => x.Value<string>("Tag")).Distinct().Count());
        var before = await InventoryOf(q); Assert.Equal(400, (await Call("/api/rerollRandomMod.php", new { ItemIds = new[] { id } }, q)).Status); Assert.True(JToken.DeepEquals(before, await InventoryOf(q)));
        await Import(q, new { MiscItems = new[] { new { ItemType = kuva, ItemCount = 1900 } } }); var roll = await Call("/api/rerollRandomMod.php", new { ItemIds = new[] { id } }, q); Assert.True(roll.Status == 200, roll.Body); Assert.Equal(900, JObject.Parse(roll.Body).Value<int>("cost"));
        Assert.Equal(409, (await Call("/api/rerollRandomMod.php", new { ItemIds = new[] { id } }, q)).Status);
        var rejected = await Call("/api/rerollRandomMod.php", new { ItemId = id, CommitReroll = false }, q); var kept = JObject.Parse(rejected.Body); Assert.Equal(1, kept.Value<int>("rerolls")); Assert.True(JToken.DeepEquals(original["buffs"], kept["buffs"]));
        var next = await Call("/api/rerollRandomMod.php", new { ItemIds = new[] { id } }, q); Assert.Equal(1000, JObject.Parse(next.Body).Value<int>("cost")); var pending = JObject.Parse(next.Body)["changes"]![0]!.Value<string>("PendingRerollFingerprint");
        Assert.Equal(pending, (await Call("/api/rerollRandomMod.php", new { ItemId = id, CommitReroll = true }, q)).Body); Assert.Equal(0, Count(await InventoryOf(q), "MiscItems", kuva));
    }
    [Fact] public async Task AllSortieRewardTypesCanBeAcquiredAndRivenPacksReturnRawMods()
    {
        var q = await Login(); foreach (var table in new[] { "SortieRewards", "ArchonSortieRewards" })
            foreach (var reward in GameData.Table("Rewards")["/Lotus/Types/Game/MissionDecks/" + table]![0]!)
                await store.Update(state => { var account = Accounts.All(state).First(x => x.Value<string>("id") == q["accountId"]); return new ItemAcquisition(new ItemCatalog(), account: account).Add(account.Obj("Inventory"), reward.Value<string>("type")!, reward.Value<int>("itemCount"), premium: true); });
        var before = (await InventoryOf(q))["RawUpgrades"]!.Sum(x => x.Value<int>("ItemCount")); await Give(q, "/Lotus/Types/BoosterPacks/CalendarRivenPack", 2);
        Assert.Equal(before + 2, (await InventoryOf(q))["RawUpgrades"]!.Sum(x => x.Value<int>("ItemCount")));
    }
    [Fact] public async Task FocusShardConversionAndUnlocksAreAtomicAndDoNotSpendDailyCap()
    {
        var q = await Login(); const string shard = "/Lotus/Types/Gameplay/Eidolon/Resources/SentientShards/SentientShardBrilliantItem";
        await Give(q, shard, 4); var before = await InventoryOf(q); var query = new Dictionary<string, string>(q) { ["op"] = "9" };
        var convert = new { Polarity = "AP_ATTACK", Shards = new[] { new { ItemType = shard, ItemCount = 4 } } }; Assert.Equal(200, (await Call("/api/focus.php", convert, query)).Status);
        var after = await InventoryOf(q); Assert.Equal(100000, after["FocusXP"]!.Value<int>("AP_ATTACK")); Assert.Equal(before.Value<int>("DailyFocus"), after.Value<int>("DailyFocus"));
        Assert.Equal(400, (await Call("/api/focus.php", convert, query)).Status); Assert.True(JToken.DeepEquals(after, await InventoryOf(q)));
        query["op"] = "3"; const string upgrade = "/Lotus/Upgrades/Focus/Attack/Active/AttackEfficiencyFocusUpgrade";
        Assert.Equal(200, (await Call("/api/focus.php", new { FocusTypes = new[] { upgrade } }, query)).Status); Assert.Equal(5000, (await InventoryOf(q))["FocusXP"]!.Value<int>("AP_ATTACK"));
        Assert.Equal(409, (await Call("/api/focus.php", new { FocusTypes = new[] { upgrade } }, query)).Status);
        query["op"] = "4"; var noPoints = await Call("/api/focus.php", new { FocusInfos = new[] { new { ItemType = upgrade, FocusXpCost = 10000, Level = 1 } } }, query); Assert.Equal(400, noPoints.Status);
        Assert.Equal(0, (await InventoryOf(q))["FocusUpgrades"]!.First(x => x.Value<string>("ItemType") == upgrade).Value<int>("Level"));
    }
    [Theory] [InlineData("abc", 474475568u)] [InlineData("/Lotus/Types/Game/VendorManifests/Deimos/EntratiFragmentVendorProductsManifest", 774716692u)]
    public void VendorHashMatchesJavaScriptDoubleArithmetic(string text, uint hash) => Assert.Equal(hash, VendorApi.Hash(text));
    [Fact] public void EveryExportVendorGeneratesWithoutChangingMetadata()
    {
        var state = new JObject(); var vendors = GameData.Table("Vendors"); var original = vendors.ToString(Formatting.None); var failures = new List<string>();
        foreach (var vendor in vendors.Properties())
            try
            {
                var info = VendorApi.Generate(state, vendor.Name, GameVersion.Of("43.5.0"), new DateTimeOffset(2026, 9, 24, 12, 0, 0, TimeSpan.Zero).ToUnixTimeMilliseconds());
                Assert.NotEmpty(info["ItemManifest"]!); Assert.All(info["ItemManifest"]!, x => { Assert.Equal(24, Wire.Id(x["Id"]).Length); Assert.True(x.Value<int>("QuantityMultiplier") > 0); });
            }
            catch (Exception ex) { failures.Add(vendor.Name + ": " + ex.Message); }
        Assert.Empty(failures); Assert.Equal(original, vendors.ToString(Formatting.None));
    }
    [Fact] public async Task VendorPurchaseUsesServerOfferAndFailedPaymentRollsBack()
    {
        var q = await Login(); const string vendor = "/Lotus/Types/Game/VendorManifests/Deimos/ConservationRewardsManifest";
        var infoResponse = await Call("/api/getVendorInfo.php", query: new(q) { ["vendor"] = vendor }); Assert.True(infoResponse.Status == 200, infoResponse.Body);
        var info = JObject.Parse(infoResponse.Body)["VendorInfo"]!; var offer = info["ItemManifest"]![0]!; var before = await InventoryOf(q);
        var request = new { PurchaseParams = new { Source = 7, SourceId = Wire.Id(info["_id"]), StoreItem = offer.Value<string>("StoreItem"), Quantity = 1, UsePremium = false, ExtraPurchaseInfoJson = JsonConvert.SerializeObject(new { ItemId = Wire.Id(offer["Id"]) }) } };
        Assert.Equal(400, (await Call("/api/purchase.php", request, q)).Status); Assert.True(JToken.DeepEquals(before, await InventoryOf(q)));
        foreach (var price in offer["ItemPrices"]!) await Give(q, price.Value<string>("ItemType")!, price.Value<int>("ItemCount"));
        var result = await Call("/api/purchase.php", request, q); Assert.True(result.Status == 200, result.Body); var after = await InventoryOf(q);
        Assert.Equal(1, Count(after, "ShipDecorations", GameData.ItemType(offer.Value<string>("StoreItem")!))); Assert.Equal(1, after["RecentVendorPurchases"]![0]!["PurchaseHistory"]![0]!.Value<int>("NumPurchased"));
    }
    [Fact] public async Task LoginRewardsPersistChoicesAndCannotBeClaimedTwice()
    {
        var time = new TestClock(new DateTimeOffset(2026, 9, 24, 12, 0, 0, TimeSpan.Zero)); engine = new(store, options, time); var q = await Login();
        var response = await Call("/api/loginRewards.php", query: q); Assert.True(response.Status == 200, response.Body); var info = JObject.Parse(response.Body)["DailyTributeInfo"]!; Assert.NotEmpty(info["Rewards"]!);
        var type = info["Rewards"]![0]!.Value<string>("StoreItemType")!;
        if (!info.Value<bool>("HasChosenReward")) { var repeat = await Call("/api/loginRewards.php", query: q); Assert.Equal(response.Body, repeat.Body); var chosen = await Call("/api/loginRewardsSelection.php", new { ChosenReward = type, IsMilestoneReward = false }, q); Assert.True(chosen.Status == 200, chosen.Body); }
        var after = await InventoryOf(q); Assert.Equal(200, (await Call("/api/loginRewardsSelection.php", new { ChosenReward = type, IsMilestoneReward = false }, q)).Status); Assert.True(JToken.DeepEquals(after, await InventoryOf(q)));
        Assert.Equal(409, (await Call("/api/loginRewardsSelection.php", new { ChosenReward = "/Lotus/Types/StoreItems/Packages/Login5Pack", IsMilestoneReward = true }, q)).Status);
        time.Now = time.Now.AddDays(1); Assert.NotNull(JObject.Parse((await Call("/api/loginRewards.php", query: q)).Body)["DailyTributeInfo"]!["Rewards"]);
    }
}