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.Data;

namespace XFEWarframe.Core.Services;

public static class ShipFeatureProgress
{
    public static void RestoreCompletedQuests(JObject account)
    {
        var inventory = account.Obj("Inventory");
        var features = account.Obj("PersonalRooms").Obj("Ship").Array("Features");
        foreach (var quest in inventory.Array("QuestKeys").OfType<JObject>().Where(x => x.Value<bool>("Completed")))
        {
            var metadata = GameData.Find("Keys", quest.Value<string>("ItemType"));
            if (metadata is null) continue;
            RestoreRewards(metadata);
            foreach (var stage in (metadata["chainStages"] as JArray ?? []).OfType<JObject>())
            {
                foreach (var item in stage["itemsToGiveWhenTriggered"] as JArray ?? []) Restore(item.Value<string>());
                if (GameData.Find("Keys", stage.Value<string>("key")) is JObject mission) RestoreRewards(mission);
            }
            if (quest.Value<string>("ItemType") == "/Lotus/Types/Keys/RailJackBuildQuest/RailjackBuildQuestKeyChain"
                && (inventory["CrewShips"] as JArray ?? []).Any(x => x.Value<string>("ItemType") == "/Lotus/Types/Game/CrewShip/Ships/RailJack"))
            {
                // These activation features come from a recipe and a scripted hand-in,
                // so restoring the quest's direct rewards alone leaves an imported
                // completed Railjack stuck at the reliquary prompt. Preserve the ship,
                // its loadouts and spare parts; only recover its installed features.
                Restore("/Lotus/Types/Items/ShipFeatureItems/RailjackCephalonShipFeatureItem");
                Restore("/Lotus/Types/Items/ShipFeatureItems/RailjackKeyShipFeatureItem");
            }
        }

        void RestoreRewards(JObject metadata)
        {
            foreach (var reward in (metadata["rewards"] as JArray ?? []).OfType<JObject>())
                if (reward.Value<string>("rewardType") == "RT_STORE_ITEM") Restore(reward.Value<string>("itemType"));
            if (metadata["missionReward"] is not JObject fixedRewards) return;
            foreach (var item in fixedRewards["items"] as JArray ?? []) Restore(item.Value<string>());
            foreach (var item in (fixedRewards["countedItems"] as JArray ?? []).OfType<JObject>()) Restore(item.Value<string>("ItemType"));
            foreach (var item in (fixedRewards["countedStoreItems"] as JArray ?? []).OfType<JObject>()) Restore(item.Value<string>("StoreItem"));
        }

        void Restore(string? type)
        {
            if (type is null) return;
            type = GameData.ItemType(type);
            // Inventory-only imports can omit PersonalRooms. Recover earned modules
            // without replaying quest rewards or consuming the player's spare parts.
            if (type.StartsWith("/Lotus/Types/Items/ShipFeatureItems/", StringComparison.Ordinal)
                && GameData.Find("Resources", type) is not null) features.UniqueAdd(type);
        }
    }
}