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

XFEWarframe

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

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

namespace XFEWarframe.Core.Services;

public sealed class MissionSpecialRewards(TimeProvider clock, bool syncOfficialEvents = true)
{
    public static void Reward(JArray rewards, string type, int count = 1) { if (count > 0) rewards.Add(new JObject { ["StoreItem"] = GameData.StoreType(type), ["ItemCount"] = count }); }
    public bool Bounty(JObject account, JObject body, JObject info, JArray rewards, JArray affiliations, JObject response, SeededRng rng, JObject? state = null)
    {
        var inv = account.Obj("Inventory"); var steel = body["Missions"]?.Value<int>("Tier") > 0 || body["Alerts"]?.Value<int>("Tier") > 0;
        if (!string.IsNullOrEmpty(info.Value<string>("jobId")))
        {
            var stage = (int)info.Integer("JobStage", 0, 10000); var (job, tag) = WorldBounties.Resolve(info, GameVersion.For(account), info.Value<string>("jobId")!.Contains("/Jobs/Events/", StringComparison.Ordinal) ? WorldApi.Generate(state ?? new JObject(), account.Value<string>("BuildLabel")!, clock.GetUtcNow().ToUnixTimeMilliseconds(), syncOfficialEvents) : null);
            var type = job.Value<string>("jobType") ?? ""; var table = job.Value<string>("rewards") ?? ""; var xp = (JArray)job["xpAmounts"]!; var rotations = new List<int>();
            var nokko = type.StartsWith("/Lotus/Types/Gameplay/NokkoColony/Jobs/NokkoJob", StringComparison.Ordinal);
            if (nokko) { if (stage == xp.Count - 1) rotations.AddRange([0, 1, 2]); }
            else if (type.EndsWith("Jobs/NewbieJob", StringComparison.Ordinal)) { rotations.Add(3); if (info.Value<bool>("Q")) rotations.Add(3); }
            else
            {
                rotations.Add(xp.Count == 1 || stage == 0 ? 0 : stage == xp.Count - 1 ? 3 : xp.Count == 5 && stage == 3 ? 2 : 1);
                if (info.Value<bool>("Q") && (stage == xp.Count - 1 || type.EndsWith("VaultBounty", StringComparison.Ordinal)) && !type.Contains("/Heists/", StringComparison.Ordinal) && !job.Value<bool>("endless") && table.Length > 0) rotations.Add(((JArray?)GameData.Table("Rewards")[table])?.Count - 1 ?? throw new ApiException(400, "Unknown bounty reward table"));
            }
            if (table.Length > 0 && rotations.Count > 0) MissionApi.Roll(table, rotations, rewards, rng);
            if (tag == "EntratiSyndicate")
            {
                var amount = 0;
                if (job.Value<bool>("endless")) amount = (int)Math.Floor(xp[stage % xp.Count].Value<int>() * (1 + .15000001 * (stage / (xp.Count - 1))));
                else if (job.Value<bool>("isVault") || stage < xp.Count) amount = (int)Math.Floor(xp[job.Value<bool>("isVault") ? 0 : stage].Value<int>() / (info.Value<bool>("Q") ? .8 : 1));
                Reward(rewards, "/Lotus/Types/Items/Deimos/EntratiFragmentUncommonB", amount); response["SyndicateXPItemReward"] = amount;
            }
            else if (!nokko) Standing.Add(inv, tag, Math.Floor(xp[stage < xp.Count ? stage : 0].Value<int>() / (info.Value<bool>("Q") ? .8 : 1)), affiliations);
            return true;
        }
        if (info.Value<string>("challengeMissionId") is not string challenge || challenge.Length == 0) return false;
        var parts = challenge.Split('_'); if (parts.Length < 2 || !int.TryParse(parts[1], out var tier) || tier < 0) throw new ApiException(400, "Invalid bounty challenge");
        var syndicate = parts[0]; var tablePath = syndicate switch
        {
            "EntratiLabSyndicate" when tier < 5 => $"EntratiLabJobMissionReward/Tier{(char)('A' + tier)}TableRewards",
            "ZarimanSyndicate" when tier < 5 => $"ZarimanJobMissionRewards/Tier{(char)('A' + tier)}Table{(tier == 2 ? "A" : "")}Rewards",
            "HexSyndicate" when tier < 7 => "1999MissionRewards/" + (tier == 6 ? "InfestedLichBountyRewards" : $"Tier{(char)('A' + tier)}BountyRewards"),
            _ => throw new ApiException(400, "Unknown bounty challenge tier")
        };
        MissionApi.Roll("/Lotus/Types/Game/MissionDecks/" + tablePath, [0], rewards, rng);
        if (syndicate == "ZarimanSyndicate") { var amount = (int)Math.Floor((tier + 1) * (steel ? 1.5 : 1) + .5); Reward(rewards, "/Lotus/Types/Gameplay/Zariman/Resources/ZarimanDogTagBounty", amount); response["SyndicateXPItemReward"] = amount; }
        else Standing.Add(inv, syndicate, (tier > 5 ? 7500 : (tier + 1) * 1000) * (steel ? 1.5 : 1), affiliations);
        if (syndicate == "HexSyndicate" && tier < 6 && parts.Length > 2)
        {
            if (!int.TryParse(parts[2], out var buddy) || buddy is < 0 or > 5) throw new ApiException(400, "Invalid chemistry buddy");
            var dialogueType = "/Lotus/Types/Gameplay/1999Wf/Dialogue/" + new[] { "Jabir", "Aoi", "Arthur", "Eleanor", "Lettie", "Quincy" }[buddy] + "Dialogue_rom.dialogue";
            var dialogue = Dialogues.Get(inv, dialogueType); var now = clock.GetUtcNow().ToUnixTimeMilliseconds();
            if (Wire.DateMs(dialogue["BountyChemExpiry"]) <= now) { dialogue["Chemistry"] = dialogue.Value<int>("Chemistry") + 20; dialogue["BountyChemExpiry"] = Wire.Date(inv.Value<bool>("noKimCooldowns") ? now : (now / WorldData.Day + 1) * WorldData.Day); }
        }
        if (steel) Reward(rewards, "/Lotus/Types/Items/MiscItems/SteelEssence"); return true;
    }
    public long Sortie(JObject account, JObject info, JArray rewards, bool completed)
    {
        if (info.Value<string>("sortieId") is not string sortie || sortie.Length == 0) return 0;
        var parts = sortie.Split('_'); var lite = parts.Length == 3 && parts[1] == "Lite"; var id = parts.Last();
        if (parts.Length < 2 || id.Length != 24 || !uint.TryParse(id[..8], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var time)) throw new ApiException(400, "Invalid sortie identifier");
        var inv = account.Obj("Inventory"); var stage = info.Value<string>("sortieTag"); var receipt = sortie + ":" + stage;
        var claimed = account.Array("SortieRewardClaims");
        if (stage == "Final" && !claimed.Any(x => x.ToString() == receipt) && !completed)
        {
            if (lite)
            {
                var boss = WorldRotations.LiteSortie(WorldData.WeekOf(time * 1000L)).Value<string>("Boss")!;
                var name = boss switch { "SORTIE_BOSS_AMAR" => "Amar", "SORTIE_BOSS_NIRA" => "Nira", _ => "Boreal" }; var tag = "NarmerSortie" + name + "CrystalRewards";
                var atten = inv.Array("SortieRewardAttenuation").OfType<JObject>().FirstOrDefault(x => x.Value<string>("Tag") == tag);
                var mythic = Random.Shared.NextDouble() < .2 + (atten?.Value<double>("Atten") ?? 0);
                if (mythic) atten?.Remove(); else if (atten is null) inv.Array("SortieRewardAttenuation").Add(new JObject { ["Tag"] = tag, ["Atten"] = .2 }); else atten["Atten"] = atten.Value<double>("Atten") + .2;
                Reward(rewards, "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystal" + name + (mythic ? "Mythic" : ""));
            }
            var table = "/Lotus/Types/Game/MissionDecks/" + (lite ? "ArchonSortieRewards" : "SortieRewards"); MissionApi.Roll(table, [0], rewards);
            inv[lite ? "LastLiteSortieReward" : "LastSortieReward"] = new JArray(new JObject { ["SortieId"] = Wire.Oid(id), ["StoreItem"] = rewards.Last!["StoreItem"]!.DeepClone(), ["Manifest"] = table });
            claimed.Add(receipt); while (claimed.Count > 300) claimed.RemoveAt(0);
        }
        return stage switch { "Mission1" => 20000, "Mission2" => 30000, "Final" => 50000, _ => 0 };
    }
    public void Storm(JObject account, JObject info, JObject? node, JArray rewards)
    {
        if (string.IsNullOrEmpty(info.Value<string>("voidStormTier")) || node is null) return;
        var planet = node.Value<int>("systemIndex") switch { 1 => "Venus", 2 => "Earth", 5 => "Saturn", 7 => "Neptune", 8 => "Pluto", 20 => "Veil", _ => null }; if (planet is null) return;
        MissionApi.Roll("/Lotus/Types/Game/MissionDecks/RailjackMissionRewards/VoidStorm" + planet + "Rewards", [0], rewards);
        if (GameVersion.For(account) >= GameVersion.Of("39.0.0")) Reward(rewards, "/Lotus/Types/Items/MiscItems/GranumBucks", planet == "Veil" ? 2 : 1);
    }
    public static long Alert(JObject world, JObject inv, JObject info, JObject body, JArray rewards)
    {
        if (info.Value<string>("alertId") is not string id || id.Length == 0 || inv.Array("CompletedAlerts").Any(x => x.ToString() == id)) return 0;
        var alert = world.Array("Alerts").OfType<JObject>().FirstOrDefault(x => Wire.Id(x["_id"]) == id) ?? WorldClassicAlerts.Find(id, world.Value<string>("BuildLabel"), world.Value<long>("Time") * 1000) ?? throw new ApiException(404, "Alert not found");
        if (!inv.Value<bool>("alertsRepeatable")) inv.Array("CompletedAlerts").Add(id);
        if (alert["MissionInfo"]?["missionReward"] is not JObject reward) return 0;
        reward = (JObject)reward.DeepClone();
        if (alert.Value<string>("Tag") is "12MinWarEvent" or "JadeShadows" && body["Missions"]?.Value<int>("Tier") > 0)
            foreach (var item in reward["countedItems"] as JArray ?? []) item["ItemCount"] = (int)Math.Floor(item.Value<int>("ItemCount") * 1.5);
        return MissionApi.FixedRewards(reward, rewards);
    }
}