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.Services;
using Xunit;

namespace XFEWarframe.Tests;

public sealed partial class EngineTests
{
    private const string CodaManifest = "/Lotus/Types/Enemies/InfestedLich/InfestedLichManifest";
    private const string InstantSecure = "/Lotus/Upgrades/Mods/DataSpike/Potency/GainAntivirusLargeOnSingleUseMod";
    private const string ImmunoShield = "/Lotus/Upgrades/Mods/DataSpike/Potency/GainAntivirusOnUseMod";

    private async Task<(JObject Knife, JObject[] Potency, string Antivirus)> EquipCoda(
        Dictionary<string, string> query, int symbol, string[]? potencyTypes = null, bool raw = false)
    {
        string[] words = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"];
        var antivirus = "/Lotus/Upgrades/Mods/Immortal/Antivirus" + words[symbol] + "Mod";
        potencyTypes ??= [InstantSecure, ImmunoShield];
        await Give(query, Parazon);
        await Give(query, antivirus);
        var inv = await InventoryOf(query);
        var knife = (JObject)inv["DataKnives"]![0]!;
        var potency = potencyTypes.Select(type => new JObject
        {
            ["ItemId"] = Wire.Oid(Wire.NewId()), ["ItemType"] = type,
            ["UpgradeFingerprint"] = "{\"lvl\":0}"
        }).ToArray();
        foreach (var mod in potency)
            if (raw) inv.Array("RawUpgrades").Add(new JObject { ["ItemType"] = mod["ItemType"]!.DeepClone(), ["ItemCount"] = 1 });
            else inv.Array("Upgrades").Add(mod);
        var slots = new JArray("", "", "", "", "", antivirus);
        for (var i = 0; i < potency.Length; i++) slots[3 + i] = raw ? potency[i].Value<string>("ItemType") : Wire.Id(potency[i]["ItemId"]);
        // The selected Parazon preset is at index 7; index 8 belongs to the Necramech.
        // Config A deliberately has no potency, while the selected config B does.
        knife["Configs"] = new JArray(new JObject { ["Upgrades"] = new JArray("", "", "", antivirus, "", "") },
            new JObject { ["Upgrades"] = slots });
        var presetA = Wire.NewId(); var presetB = Wire.NewId();
        var ids = new JArray(Enumerable.Range(0, 11).Select(_ => Wire.Oid("000000000000000000000001")));
        ids[7] = Wire.Oid(presetB); ids[8] = Wire.Oid(presetA);
        await Import(query, new JObject
        {
            ["DataKnives"] = new JArray(knife), ["RawUpgrades"] = inv["RawUpgrades"]!.DeepClone(),
            ["Upgrades"] = inv["Upgrades"]!.DeepClone(), ["CurrentLoadOutIds"] = ids,
            ["LoadOutPresets"] = new JObject { ["DATAKNIFE"] = new JArray(
                new JObject { ["ItemId"] = Wire.Oid(presetA), ["s"] = new JObject { ["ItemId"] = knife["ItemId"]!.DeepClone(), ["mod"] = 0 } },
                new JObject { ["ItemId"] = Wire.Oid(presetB), ["s"] = new JObject { ["ItemId"] = knife["ItemId"]!.DeepClone(), ["mod"] = 1 } }) }
        });
        return (knife, potency, antivirus);
    }

    private static JObject CodaStab(JObject knife, JObject[] potency, string antivirus, int symbol, int guessSlot = 0)
    {
        int[] symbols = [8, 8, 8]; symbols[guessSlot] = symbol;
        return new JObject
        {
            ["guess"] = symbols[0] | symbols[1] << 4 | symbols[2] << 8, ["position"] = 0,
            ["knife"] = new JObject
            {
                ["Item"] = knife.DeepClone(), ["ModSlot"] = 1, ["CustSlot"] = 0,
                // Native attachment enumeration need not be in physical config-slot order.
                ["AttachedUpgrades"] = new JArray(new[] { new JObject { ["ItemType"] = antivirus } }.Concat(potency)),
                ["Skins"] = new JArray(), ["HiddenWhenHolstered"] = false
            }
        };
    }

    [Theory]
    [InlineData(0, 0)] [InlineData(0, 2)]
    [InlineData(65, 0)] [InlineData(65, 2)]
    [InlineData(95, 0)] [InlineData(95, 2)]
    public async Task CodaCorrectAntivirusUsesSelectedPotencyAndCanReachOneHundred(int progress, int guessSlot)
    {
        var query = await LoginAugustClient();
        var nemesis = await StartNemesis(query, CodaManifest, 51); var symbol = NemesisData.Passcode(nemesis)[0];
        var (knife, potency, antivirus) = await EquipCoda(query, symbol);
        nemesis["HenchmenKilled"] = (double)progress;
        await Import(query, new { Nemesis = nemesis });
        var body = CodaStab(knife, potency, antivirus, symbol, guessSlot);
        var mode = new Dictionary<string, string>(query) { ["mode"] = "r" };
        var response = await Call("/api/nemesis.php", body, mode);
        Assert.True(response.Status == 200, response.Body);
        var inv = await InventoryOf(query); var saved = (JObject)inv["Nemesis"]!;
        Assert.Equal(Math.Min(100, progress + 35), saved.Value<int>("HenchmenKilled"));
        Assert.Equal(JTokenType.Integer, saved["HenchmenKilled"]!.Type);
        Assert.Equal(progress >= 65, saved.Value<bool>("Weakened"));
        foreach (var mod in potency)
            Assert.Equal(1, JObject.Parse(inv["Upgrades"]!.Single(x => Wire.Id(x["ItemId"]) == Wire.Id(mod["ItemId"])).Value<string>("UpgradeFingerprint")!).Value<int>("lvl"));
        Assert.Equal(progress >= 65 ? 3 : 2, JObject.Parse(response.Body)["UpgradeIds"]!.Count());
        Assert.True(JToken.DeepEquals(knife["Configs"]![0], inv["DataKnives"]![0]!["Configs"]![0]));
        if (progress >= 65) Assert.Equal("CrewBattleNode559", Assert.Single(saved["InfNodes"]!).Value<string>("Node"));
        Assert.Equal(response.Body, (await Call("/api/nemesis.php", body, mode)).Body);
        Assert.True(JToken.DeepEquals(inv, await InventoryOf(query)));
    }

    [Fact]
    public async Task CodaRawPotencyChargesBecomeOwnedModsOnlyInActiveConfig()
    {
        var query = await Login(); var nemesis = await StartNemesis(query, CodaManifest, 51);
        var symbol = NemesisData.Passcode(nemesis)[0]; var (knife, potency, antivirus) = await EquipCoda(query, symbol, raw: true);
        var response = await Call("/api/nemesis.php", CodaStab(knife, potency, antivirus, symbol), new Dictionary<string, string>(query) { ["mode"] = "r" });
        Assert.True(response.Status == 200, response.Body);
        var inv = await InventoryOf(query); Assert.Equal(35, inv["Nemesis"]!.Value<int>("HenchmenKilled"));
        Assert.Equal(new[] { true, true }, JObject.Parse(response.Body)["UpgradeNew"]!.Values<bool>());
        foreach (var mod in potency)
        {
            Assert.Equal(0, Count(inv, "RawUpgrades", mod.Value<string>("ItemType")!));
            var charged = inv["Upgrades"]!.Single(x => x.Value<string>("ItemType") == mod.Value<string>("ItemType"));
            Assert.Equal(1, JObject.Parse(charged.Value<string>("UpgradeFingerprint")!).Value<int>("lvl"));
            Assert.Contains(Wire.Id(charged["ItemId"]), inv["DataKnives"]![0]!["Configs"]![1]!["Upgrades"]!.Values<string>());
        }
        Assert.True(JToken.DeepEquals(knife["Configs"]![0], inv["DataKnives"]![0]!["Configs"]![0]));
    }

    [Theory]
    [InlineData("GainAntivirusAndSpeedOnUseMod", 10)]
    [InlineData("GainAntivirusAndWeaponDamageOnUseMod", 10)]
    [InlineData("GainAntivirusSmallOnSingleUseMod", 10)]
    [InlineData("GainAntivirusLargeOnSingleUseMod", 15)]
    [InlineData("GainAntivirusOnUseMod", 15)]
    public async Task CodaAllPotencyTypesApplyTheirBonus(string name, int bonus)
    {
        var query = await Login(); var nemesis = await StartNemesis(query, CodaManifest, 51);
        var symbol = NemesisData.Passcode(nemesis)[0];
        var (knife, potency, antivirus) = await EquipCoda(query, symbol, ["/Lotus/Upgrades/Mods/DataSpike/Potency/" + name]);
        var response = await Call("/api/nemesis.php", CodaStab(knife, potency, antivirus, symbol), new Dictionary<string, string>(query) { ["mode"] = "r" });
        Assert.True(response.Status == 200, response.Body);
        Assert.Equal(5 + bonus, (await InventoryOf(query))["Nemesis"]!.Value<int>("HenchmenKilled"));
        Assert.Single(JObject.Parse(response.Body)["UpgradeIds"]!);
    }

    [Fact]
    public async Task CodaRejectsUnequippedAntivirusWithoutProgressOrChargeLoss()
    {
        var query = await Login(); var nemesis = await StartNemesis(query, CodaManifest, 51);
        var correct = NemesisData.Passcode(nemesis)[0]; var wrong = (correct + 1) % 8;
        var (knife, potency, antivirus) = await EquipCoda(query, wrong);
        var mode = new Dictionary<string, string>(query) { ["mode"] = "r" }; var before = await InventoryOf(query);
        var response = await Call("/api/nemesis.php", CodaStab(knife, potency, antivirus, correct), mode);
        Assert.Equal(400, response.Status); Assert.True(JToken.DeepEquals(before, await InventoryOf(query)));
        response = await Call("/api/nemesis.php", CodaStab(knife, potency, antivirus, wrong), mode);
        Assert.True(response.Status == 200, response.Body);
        var after = await InventoryOf(query);
        Assert.Equal(0, after["Nemesis"]!.Value<int>("HenchmenKilled"));
        Assert.True(JToken.DeepEquals(before["Upgrades"], after["Upgrades"]));
        Assert.False(after["Nemesis"]!.Value<bool>("Weakened"));
    }

    [Fact]
    public async Task CodaMissionCapDoesNotRegressACompletedAntivirusCheck()
    {
        var query = await LoginAugustClient(); var nemesis = await StartNemesis(query, CodaManifest, 51);
        var symbol = NemesisData.Passcode(nemesis)[0]; var (knife, potency, antivirus) = await EquipCoda(query, symbol);
        nemesis["HenchmenKilled"] = 90.0; await Import(query, new { Nemesis = nemesis });
        var node = nemesis["InfNodes"]![0]!.Value<string>("Node");
        var mission = new { EndOfMatchUpload = true, MissionStatus = "GS_SUCCESS", RewardInfo = new { node, rewardSeed = 17 } };
        var response = await Call("/api/updateInventory.php", mission, query); Assert.True(response.Status == 200, response.Body);
        Assert.Equal(95, (await InventoryOf(query))["Nemesis"]!.Value<int>("HenchmenKilled"));
        response = await Call("/api/nemesis.php", CodaStab(knife, potency, antivirus, symbol), new Dictionary<string, string>(query) { ["mode"] = "r" });
        Assert.True(response.Status == 200, response.Body);
        response = await Call("/api/updateInventory.php", new { EndOfMatchUpload = true, MissionStatus = "GS_SUCCESS", RewardInfo = new { node, rewardSeed = 18 } }, query);
        Assert.True(response.Status == 200, response.Body);
        var updated = JObject.Parse(response.Body)["InventoryChanges"]!["Nemesis"]!;
        Assert.Equal(100, updated.Value<int>("HenchmenKilled")); Assert.True(updated.Value<bool>("Weakened"));
        Assert.Equal(JTokenType.Integer, updated["HenchmenKilled"]!.Type);
        Assert.Equal("CrewBattleNode559", Assert.Single(updated["InfNodes"]!).Value<string>("Node"));
    }

    [Fact]
    public async Task CodaThirdPotencyChargeCompletesTheCheckWithoutResolvingSpentModsAgain()
    {
        var query = await LoginAugustClient(); var nemesis = await StartNemesis(query, CodaManifest, 51);
        var symbol = NemesisData.Passcode(nemesis)[0]; var (knife, potency, antivirus) = await EquipCoda(query, symbol);
        var mode = new Dictionary<string, string>(query) { ["mode"] = "r" };
        for (var encounter = 0; encounter < 3; encounter++)
        {
            var before = await InventoryOf(query);
            var body = CodaStab((JObject)before["DataKnives"]![0]!, potency, antivirus, symbol);
            var response = await Call("/api/nemesis.php", body, mode); Assert.True(response.Status == 200, response.Body);
            var after = await InventoryOf(query);
            Assert.Equal(Math.Min(100, before["Nemesis"]!.Value<int>("HenchmenKilled") + 35), after["Nemesis"]!.Value<int>("HenchmenKilled"));
            foreach (var mod in potency)
                Assert.Equal(encounter + 1, JObject.Parse(after["Upgrades"]!.Single(x => Wire.Id(x["ItemId"]) == Wire.Id(mod["ItemId"])).Value<string>("UpgradeFingerprint")!).Value<int>("lvl"));
            Assert.Equal(response.Body, (await Call("/api/nemesis.php", body, mode)).Body);
            if (encounter < 2)
            {
                var node = after["Nemesis"]!["InfNodes"]![0]!.Value<string>("Node");
                response = await Call("/api/updateInventory.php", new { EndOfMatchUpload = true, MissionStatus = "GS_SUCCESS", RewardInfo = new { node, rewardSeed = 31 + encounter } }, query);
                Assert.True(response.Status == 200, response.Body);
                Assert.Equal((encounter + 1) * 40, (await InventoryOf(query))["Nemesis"]!.Value<int>("HenchmenKilled"));
            }
        }
        var finished = await InventoryOf(query);
        Assert.True(finished["Nemesis"]!.Value<bool>("Weakened"));
        Assert.Equal(1, JObject.Parse(finished["Upgrades"]!.Single(x => x.Value<string>("ItemType") == antivirus).Value<string>("UpgradeFingerprint")!).Value<int>("lvl"));
    }

    [Fact]
    public async Task CodaMultiplierKeepsFractionalProgressAndIgnoresForgedAttachmentBonuses()
    {
        var query = await Login(); var nemesis = await StartNemesis(query, CodaManifest, 51);
        var symbol = NemesisData.Passcode(nemesis)[0]; var (knife, potency, antivirus) = await EquipCoda(query, symbol, [InstantSecure]);
        await Import(query, new { nemesisAntivirusGainMultiplier = 1.125 });
        var body = CodaStab(knife, potency, antivirus, symbol);
        ((JArray)body["knife"]!["AttachedUpgrades"]!).Add(new JObject { ["ItemType"] = ImmunoShield });
        var response = await Call("/api/nemesis.php", body, new Dictionary<string, string>(query) { ["mode"] = "r" });
        Assert.True(response.Status == 200, response.Body);
        var inv = await InventoryOf(query);
        Assert.Equal(22, inv["Nemesis"]!.Value<int>("HenchmenKilled"));
        Assert.Single(JObject.Parse(response.Body)["UpgradeIds"]!);
        var backup = JObject.Parse((await Call($"/control/v1/accounts/{query["accountId"]}/export", admin: true)).Body);
        Assert.Equal(22.5, backup["Nemesis"]!.Value<double>("HenchmenKilled"));
    }

    [Theory] [InlineData(65.0, 65)] [InlineData(65.75, 65)]
    public async Task CodaGameProgressIsAnIntegerWithoutLosingBackupPrecision(double progress, int displayed)
    {
        var query = await LoginAugustClient(); var nemesis = await StartNemesis(query, CodaManifest, 51);
        nemesis["HenchmenKilled"] = progress; await Import(query, new { Nemesis = nemesis });
        var response = await Call("/api/nemesis.php", new { }, new Dictionary<string, string>(query) { ["mode"] = "w" });
        Assert.True(response.Status == 200, response.Body);
        var target = JObject.Parse(response.Body)["target"]!;
        var inv = await InventoryOf(query);
        Assert.Equal(JTokenType.Integer, target["HenchmenKilled"]!.Type);
        Assert.Equal(JTokenType.Integer, inv["Nemesis"]!["HenchmenKilled"]!.Type);
        Assert.Equal(displayed, target.Value<int>("HenchmenKilled"));
        var backup = JObject.Parse((await Call($"/control/v1/accounts/{query["accountId"]}/export", admin: true)).Body);
        Assert.Equal(progress, backup["Nemesis"]!.Value<double>("HenchmenKilled"));
    }
}