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

XFEWarframe

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

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

namespace XFEWarframe.Tests;

public sealed partial class EngineTests
{
    [Fact] public async Task ModdingSearchUsesOriginalEffectsAndCombinedElementIngredientsOffline()
    {
        var q = await Login(); await Give(q, "/Lotus/Weapons/Tenno/Rifle/Rifle");
        var types = new[] { "WeaponFreezeDamageMod", "WeaponToxinDamageMod", "WeaponFireDamageMod", "WeaponFireRateMod", "WeaponCritChanceMod" }
            .Select(x => "/Lotus/Upgrades/Mods/Rifle/" + x).ToArray();
        foreach (var type in types) await Give(q, type);
        var inv = await InventoryOf(q); var id = Wire.Id(inv["LongGuns"]![0]!["ItemId"]);
        var view = await ReadEditor(q, "LongGuns", id); var cards = view["modding"]!["cards"]!.ToObject<ModCard[]>()!;
        var index = new ModSearchIndex(cards);
        Assert.Equal(types.Take(2).Order(), index.Search("病毒").Select(x => x.Type).Order());
        Assert.Equal(types.Take(2).Order(), index.Search("VIRAL").Select(x => x.Type).Order());
        var critical = Assert.Single(index.Search("暴击 几率")); Assert.Equal(types[4], critical.Type);
        Assert.Contains("Critical Chance", critical.SearchText); Assert.Contains("暴击几率", critical.SearchText);
        Assert.Contains("+25%", critical.SearchText); Assert.DoesNotContain("+150%", critical.SearchText);
        Assert.Equal(types[4], Assert.Single(index.Search("critical chance")).Type);
        Assert.Equal(types[2], Assert.Single(index.Search("火" )).Type);
        Assert.DoesNotContain(index.Search("火"), x => x.Type == types[3]);
    }
    [Fact] public async Task RivenModdingSearchIndexesOnlyActualPositiveAndNegativeEffects()
    {
        var q = await Login(); await Give(q, "/Lotus/Weapons/Tenno/Rifle/Rifle");
        var type = RivenCalculator.Prefix + "LotusRifleRandomModRare";
        var fp = new JObject { ["lvl"] = 8, ["compat"] = "/Lotus/Weapons/Tenno/Rifle/Rifle", ["pol"] = "AP_ATTACK",
            ["buffs"] = new JArray(new JObject { ["Tag"] = "WeaponToxinDamageMod", ["Value"] = RivenCalculator.Scale / 2 }),
            ["curses"] = new JArray(new JObject { ["Tag"] = "WeaponCritChanceMod", ["Value"] = RivenCalculator.Scale / 2 }) };
        await Import(q, new JObject { ["Upgrades"] = new JArray(new JObject { ["ItemId"] = Wire.Oid(Wire.NewId()), ["ItemType"] = type, ["UpgradeFingerprint"] = fp.ToString(Newtonsoft.Json.Formatting.None) }) });
        var inv = await InventoryOf(q); var view = await ReadEditor(q, "LongGuns", Wire.Id(inv["LongGuns"]![0]!["ItemId"]));
        var card = Assert.Single(view["modding"]!["cards"]!.ToObject<ModCard[]>()!, x => x.Type == type);
        Assert.True(ModSearch.Matches(card, "病毒 暴击")); Assert.True(ModSearch.Matches(card, "negative critical"));
        Assert.False(ModSearch.Matches(card, "冰")); Assert.False(ModSearch.Matches(card, "磁力"));
    }
    [Theory]
    [InlineData("Suits", "/Lotus/Powersuits/Infestation/Infestation", "/Lotus/Upgrades/Mods/Warframe/AvatarHealthMaxMod")]
    [InlineData("Pistols", "/Lotus/Weapons/Tenno/Pistol/Pistol", "/Lotus/Upgrades/Mods/Pistol/WeaponDamageAmountMod")]
    [InlineData("LongGuns", "/Lotus/Weapons/Tenno/Rifle/Rifle", "/Lotus/Upgrades/Mods/Rifle/WeaponDamageAmountMod")]
    [InlineData("Melee", "/Lotus/Weapons/Tenno/Melee/LongSword/LongSword", "/Lotus/Upgrades/Mods/Melee/WeaponMeleeDamageMod")]
    public async Task SharedModdingConvertsOwnedCardsAndPreservesOtherConfigs(string category, string type, string modType)
    {
        var q = await Login(); await Give(q, type); await Give(q, modType, 2);
        var inv = await InventoryOf(q); var item = (JObject)inv[category]![0]!; var id = Wire.Id(item["ItemId"]);
        item["ModSlotPurchases"] = 3;
        item["Configs"] = new JArray(new JObject { ["Name"] = "keep A", ["Skins"] = new JArray("skin") }, new JObject(), new JObject { ["Name"] = "old C" });
        await Import(q, new JObject { [category] = inv[category]!.DeepClone() });
        var view = await ReadEditor(q, category, id);
        Assert.NotNull(view["modding"]); Assert.Equal(6, view["actions"]!.Count(x => x.Value<string>("key")!.StartsWith("loadout.mods.")));
        Assert.Contains(view["modding"]!["cards"]!, x => x.Value<string>("key") == "raw:" + modType && x["compatibleSlots"]!.Values<int>().Contains(0));
        var values = EditorValues(view, "loadout.mods.2"); values["mod0"] = "raw:" + modType; values["name"] = "new C";
        var result = await Edit(q, view, "loadout.mods.2", values, id); Assert.True(result.Status == 200, result.Body);
        inv = await InventoryOf(q); item = (JObject)inv[category]![0]!;
        Assert.Equal("keep A", item["Configs"]![0]!.Value<string>("Name")); Assert.Equal("skin", item["Configs"]![0]!["Skins"]![0]!.ToString());
        var uid = item["Configs"]![2]!["Upgrades"]![0]!.ToString(); Assert.Equal(24, uid.Length);
        Assert.Contains(inv["Upgrades"]!, x => Wire.Id(x["ItemId"]) == uid && x.Value<string>("ItemType") == modType);
        Assert.Equal(1, inv["RawUpgrades"]!.Single(x => x.Value<string>("ItemType") == modType).Value<int>("ItemCount"));
    }
    [Fact] public async Task ModdingRejectsBadCardsCapacityAndStaleWritesAtomically()
    {
        var (q, id) = await ExaltedHost(); await Give(q, "/Lotus/Upgrades/Mods/Warframe/AvatarHealthMaxMod", 2);
        var inv = await InventoryOf(q); var gear = (JObject)inv["Suits"]![0]!;
        gear["XP"] = 0; gear["Polarity"] = new JArray(Enumerable.Range(0,10).Select(i => new JObject { ["Slot"] = i, ["Value"] = "AP_UNIVERSAL" }));
        await Import(q, new JObject { ["Suits"] = inv["Suits"]!.DeepClone(), ["PlayerLevel"] = 0 });
        inv = await InventoryOf(q); var view = await ReadEditor(q, item:id); var values = EditorValues(view, "loadout.mods.0");
        foreach (var bad in new[] { "ffffffffffffffffffffffff", "raw:" + HornetStrike, "raw:/Lotus/Upgrades/Mods/Warframe/AvatarHealthMaxMod" })
        {
            values["mod0"] = bad; Assert.Equal(400, (await Edit(q, view, "loadout.mods.0", values, id)).Status);
            Assert.True(JToken.DeepEquals(inv, await InventoryOf(q)));
        }
        values["mod0"] = ""; values["name"] = "accepted";
        Assert.Equal(200, (await Edit(q, view, "loadout.mods.0", values, id)).Status);
        Assert.Equal(409, (await Edit(q, view, "loadout.mods.0", values, id)).Status);
    }
    [Fact] public async Task PlayerModdingMatchesAdminAndPermissionRevocationRemovesDataAndRejectsWrites()
    {
        var player = await RegisterPlayer(); var token = player.Value<string>("token");
        var q = await Login("portal@example.invalid", XFEWarframe.Core.Services.Accounts.GamePassword("PortalTest-123"));
        await Give(q, "/Lotus/Powersuits/Infestation/Infestation"); var inv = await InventoryOf(q); var id = Wire.Id(inv["Suits"]![0]!["ItemId"]);
        await SetEditorPermissions(new { loadout = true, exalted = false });
        var admin = await ReadEditor(q, item: id); var response = await Portal("editor", token:token, query:new() { ["category"] = "Suits", ["item"] = id });
        Assert.Equal(200, response.Status);
        var view = JObject.Parse(response.Body);
        Assert.True(JToken.DeepEquals(admin["modding"], view["modding"]));
        Assert.All(view["actions"]!, x => Assert.StartsWith("loadout.mods.", x.Value<string>("key")));
        var values = EditorValues(view, "loadout.mods.0"); values["name"] = "player layout";
        var body = new { category="Suits", item=id, action="loadout.mods.0", version=view.Value<string>("version"), values };
        Assert.Equal(200, (await Portal("editor", body, token)).Status);
        await SetEditorPermissions(new { loadout = false, experience = true });
        Assert.Equal(403, (await Portal("editor", body, token)).Status);
        view = JObject.Parse((await Portal("editor", token:token, query:new() { ["category"] = "Suits", ["item"] = id })).Body);
        Assert.Null(view["modding"]); Assert.DoesNotContain(view["actions"]!, x => x.Value<string>("key")!.StartsWith("loadout.mods."));
    }
}