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 { private const string Parazon = "/Lotus/Weapons/Tenno/HackingDevices/TnHackingDevice/TnHackingDeviceWeapon"; private async Task StartNemesis(Dictionary q, string manifest, long seed = -1399275245665749231) { const string suit = "/Lotus/Powersuits/Ember/Ember"; await Give(q, suit); var response = await Call("/api/nemesis.php", new { target = new { fp = seed, manifest, KillingSuit = suit, killingDamageType = 3, AgentIdx = 0, BirthNode = "SolNode1" } }, new Dictionary(q) { ["mode"] = "s" }); Assert.True(response.Status == 200, response.Body); return (JObject)JObject.Parse(response.Body)["target"]!; } private async Task EquipRequiems(Dictionary q, int[] symbols, bool antivirus = false) { string[] words = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]; var mods = symbols.Select(x => "/Lotus/Upgrades/Mods/Immortal/" + (antivirus ? "Antivirus" : "Immortal") + words[x] + "Mod").ToArray(); await Give(q, Parazon); foreach (var mod in mods) await Give(q, mod); var inv = await InventoryOf(q); var knife = (JObject)inv["DataKnives"]![0]!; knife["Configs"] = new JArray(new JObject { ["Upgrades"] = new JArray(new[] { "", "", "" }.Concat(mods)) }); await Import(q, new JObject { ["DataKnives"] = new JArray(knife) }); } [Fact] public async Task NemesisRequiemsConsumeOwnedModsOnceAndKillCreatesClaimableWeapon() { var q = await Login(); var nemesis = await StartNemesis(q, "/Lotus/Types/Game/Nemesis/KuvaLich/KuvaLichManifestVersionSeven"); Assert.Equal(-1399275245665749231, nemesis.Value("fp")); var code = NemesisData.Passcode(nemesis); await EquipRequiems(q, code); var mode = new Dictionary(q) { ["mode"] = "r" }; var before = await InventoryOf(q); Assert.Equal(409, (await Call("/api/nemesis.php", new { guess = code[2], position = 2 }, mode)).Status); Assert.True(JToken.DeepEquals(before, await InventoryOf(q))); for (var i = 0; i < 3; i++) { var guess = await Call("/api/nemesis.php", new { guess = code[i], position = i }, mode); Assert.True(guess.Status == 200, guess.Body); if (i == 2) Assert.Equal(3, JObject.Parse(guess.Body)["UpgradeIds"]!.Count()); } var after = await InventoryOf(q); Assert.True(after["Nemesis"]!.Value("Weakened")); Assert.Equal(3, after["Upgrades"]!.Count()); Assert.All(after["Upgrades"]!, x => Assert.Equal(1, JObject.Parse(x.Value("UpgradeFingerprint")!).Value("lvl"))); Assert.Equal(200, (await Call("/api/nemesis.php", new { guess = code[2], position = 2 }, mode)).Status); Assert.True(JToken.DeepEquals(after, await InventoryOf(q))); await Import(q, new { NemesisTaxedCredits = 321 }); var upload = new { EndOfMatchUpload = true, MissionStatus = "GS_SUCCESS", RewardInfo = new { node = "CrewBattleNode557", rewardSeed = 7 }, NemesisKillConvert = new { killed = true, nemesisName = "TEST LICH", weaponLoc = "forged localization" } }; var result = await Call("/api/updateInventory.php", upload, q); Assert.True(result.Status == 200, result.Body); Assert.Equal(321, JObject.Parse(result.Body)["RecoveredItemInfo"]!.Value("RecoveredCredits")); var completed = await InventoryOf(q); Assert.Null(completed["Nemesis"]); Assert.Single(completed["NemesisHistory"]!); Assert.Single(completed["PendingRecipes"]!); var retry = await Call("/api/updateInventory.php", upload, q); Assert.Equal(result.Body, retry.Body); Assert.True(JToken.DeepEquals(completed, await InventoryOf(q))); var pending = completed["PendingRecipes"]![0]!; var fp = JObject.Parse(pending.Value("TargetFingerprint")!); var claimed = await Call("/api/claimCompletedRecipe.php", new { RecipeIds = new[] { pending["ItemId"] } }, q); Assert.True(claimed.Status == 200, claimed.Body); var inventory = await InventoryOf(q); var weapon = Inventory.EquipmentKeys.SelectMany(x => inventory[x] as JArray ?? []).Single(x => x.Value("ItemName") == fp.Value("Name")); Assert.Equal(fp["UpgradeFingerprint"]!.ToString(Newtonsoft.Json.Formatting.None), weapon.Value("UpgradeFingerprint")); Assert.DoesNotContain("forged", weapon.Value("ItemName")!); Assert.Equal(404, (await Call("/api/claimCompletedRecipe.php", new { RecipeIds = new[] { pending["ItemId"] } }, q)).Status); } [Fact] public async Task SisterCompletionBuildsOwnedHoundWithDeterministicParts() { var q = await Login(); var nemesis = await StartNemesis(q, "/Lotus/Types/Enemies/Corpus/Lawyers/LawyerManifestVersionFive", 42); var profile = NemesisData.Profile(nemesis); nemesis["Weakened"] = true; await Import(q, new { Nemesis = nemesis }); var result = await Call("/api/updateInventory.php", new { EndOfMatchUpload = true, MissionStatus = "GS_SUCCESS", RewardInfo = new { node = "CrewBattleNode558", rewardSeed = 7 }, NemesisKillConvert = new { killed = true, nemesisName = "TEST SISTER" } }, q); Assert.True(result.Status == 200, result.Body); var inv = await InventoryOf(q); Assert.Equal(2, inv["PendingRecipes"]!.Count()); var pending = inv["PendingRecipes"]!.First(x => JObject.Parse(x.Value("TargetFingerprint")!)["Parts"] is JArray); var claim = await Call("/api/claimCompletedRecipe.php", new { RecipeIds = new[] { pending["ItemId"] } }, q); Assert.True(claim.Status == 200, claim.Body); inv = await InventoryOf(q); Assert.Single(inv["MoaPets"]!); Assert.True(JToken.DeepEquals(profile["Parts"], inv["MoaPets"]![0]!["ModularParts"])); Assert.EndsWith("|TEST SISTER", inv["MoaPets"]![0]!.Value("ItemName")); Assert.NotEmpty(inv["SentinelWeapons"]!); } [Fact] public async Task InfestedAntivirusWeakensAndResolutionAwardsTokensOnce() { var q = await Login(); var nemesis = await StartNemesis(q, "/Lotus/Types/Enemies/InfestedLich/InfestedLichManifest", 51); var code = NemesisData.Passcode(nemesis); await EquipRequiems(q, code, true); nemesis["HenchmenKilled"] = 95; await Import(q, new { Nemesis = nemesis }); var response = await Call("/api/nemesis.php", new { guess = code[0] | 8 << 4 | 8 << 8, position = 0 }, new Dictionary(q) { ["mode"] = "r" }); Assert.True(response.Status == 200, response.Body); Assert.Single(JObject.Parse(response.Body)["UpgradeIds"]!); Assert.True((await InventoryOf(q))["Nemesis"]!.Value("Weakened")); var upload = new { EndOfMatchUpload = true, MissionStatus = "GS_SUCCESS", RewardInfo = new { node = "CrewBattleNode559", rewardSeed = 7 }, NemesisKillConvert = new { killed = true, nemesisName = "TEST BAND" } }; response = await Call("/api/updateInventory.php", upload, q); Assert.True(response.Status == 200, response.Body); var inv = await InventoryOf(q); Assert.InRange(Count(inv, "MiscItems", "/Lotus/Types/Items/MiscItems/CodaWeaponBucks"), 10, 15); Assert.Equal(response.Body, (await Call("/api/updateInventory.php", upload, q)).Body); Assert.True(JToken.DeepEquals(inv, await InventoryOf(q))); } [Fact] public async Task ValenceFusionRejectsDifferentWeaponsAndPreservesDestinationExperience() { var q = await Login(); const string karak = "/Lotus/Weapons/Grineer/KuvaLich/LongGuns/Karak/KuvaKarak"; const string kohm = "/Lotus/Weapons/Grineer/KuvaLich/LongGuns/Kohm/KuvaKohm"; await Give(q, karak, 2); await Give(q, kohm); var inv = await InventoryOf(q); var weapons = inv["LongGuns"]!.OfType().ToArray(); weapons[0]["XP"] = 10000; await Import(q, new { LongGuns = weapons }); var mode = new Dictionary(q) { ["mode"] = "f" }; var body = new JObject { ["Category"] = "LongGuns", ["DestWeapon"] = weapons[0]["ItemId"]!.DeepClone(), ["SourceWeapon"] = weapons[2]["ItemId"]!.DeepClone(), ["UseSourceDmgType"] = true }; inv = await InventoryOf(q); Assert.Equal(400, (await Call("/api/nemesis.php", body, mode)).Status); Assert.True(JToken.DeepEquals(inv, await InventoryOf(q))); body["SourceWeapon"] = weapons[1]["ItemId"]!.DeepClone(); var response = await Call("/api/nemesis.php", body, mode); Assert.True(response.Status == 200, response.Body); inv = await InventoryOf(q); Assert.Equal(2, inv["LongGuns"]!.Count()); var destination = inv["LongGuns"]!.First(x => Wire.Id(x["ItemId"]) == Wire.Id(weapons[0]["ItemId"])); Assert.Equal(10000, destination.Value("XP")); Assert.Equal(404, (await Call("/api/nemesis.php", body, mode)).Status); } }