From 98efb71cc66bf6ac73ec6ae8b97cc0c8cdc665ae Mon Sep 17 00:00:00 2001 From: MaikyM <51415805+MaikyM@users.noreply.github.com> Date: Sat, 23 Nov 2019 16:29:38 -0600 Subject: [PATCH] Implemented RewardsTable on Challenges. --- .../ChallengeID/ChallengeBundleInfos.cs | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/FModel/Methods/Assets/IconCreator/ChallengeID/ChallengeBundleInfos.cs b/FModel/Methods/Assets/IconCreator/ChallengeID/ChallengeBundleInfos.cs index 41d03b96..e8b6b05d 100644 --- a/FModel/Methods/Assets/IconCreator/ChallengeID/ChallengeBundleInfos.cs +++ b/FModel/Methods/Assets/IconCreator/ChallengeID/ChallengeBundleInfos.cs @@ -132,6 +132,7 @@ namespace FModel.Methods.Assets.IconCreator.ChallengeID //rewards array to catch the reward name (not path) and the quantity JArray rewardsDataArray = AssetsUtility.GetPropertyTagText(AssetProperties, "Rewards", "data"); JArray hiddenRewardsDataArray = AssetsUtility.GetPropertyTagText(AssetProperties, "HiddenRewards", "data"); + JToken rewardsTable = AssetsUtility.GetPropertyTagImport(AssetProperties, "RewardsTable"); if (rewardsDataArray != null) { if (rewardsDataArray[0]["struct_name"] != null && rewardsDataArray[0]["struct_type"] != null && string.Equals(rewardsDataArray[0]["struct_name"].Value(), "FortItemQuantityPair")) @@ -222,6 +223,71 @@ namespace FModel.Methods.Assets.IconCreator.ChallengeID } } } + else if (rewardsTable != null) + { + string rewardsTablePath = AssetEntries.AssetEntriesDict.Where(x => x.Key.ToLowerInvariant().Contains("/" + rewardsTable.Value().ToLowerInvariant() + ".uasset")).Select(d => d.Key).FirstOrDefault(); + if (!string.IsNullOrEmpty(rewardsTablePath)) + { + reader = AssetsUtility.GetPakReader(rewardsTablePath.Substring(0, rewardsTablePath.LastIndexOf(".", StringComparison.InvariantCultureIgnoreCase))); + if (reader != null) + { + entriesList = AssetsUtility.GetPakEntries(rewardsTablePath.Substring(0, rewardsTablePath.LastIndexOf(".", StringComparison.InvariantCultureIgnoreCase))); + jsonData = AssetsUtility.GetAssetJsonData(reader, entriesList); + + if (AssetsUtility.IsValidJson(jsonData)) + { + dynamic AssetRewarsTableData = JsonConvert.DeserializeObject(jsonData); + JToken AssetRewarsTableMainToken = null; + if (jsonData.StartsWith("[") && jsonData.EndsWith("]")) + { + JArray AssetArray = JArray.FromObject(AssetRewarsTableData); + AssetRewarsTableMainToken = AssetArray[0]; + } + else if (jsonData.StartsWith("{") && jsonData.EndsWith("}")) + { + AssetRewarsTableMainToken = AssetRewarsTableData; + } + + if (AssetRewarsTableMainToken != null) + { + JArray propertiesArray = AssetRewarsTableMainToken["rows"].Value(); + if (propertiesArray != null) + { + JArray propertiesRewardTable = AssetsUtility.GetPropertyTagItemData(propertiesArray, "Default", "properties"); + if (propertiesRewardTable != null) + { + JToken templateIdToken = propertiesRewardTable.Where(item => string.Equals(item["name"].Value(), "TemplateId")).FirstOrDefault(); + if (templateIdToken != null) + { + string templateId = templateIdToken["tag_data"].Value(); + if (templateId.Contains(":")) + templateId = templateId.Split(':')[1]; + + string templateIdPath = AssetEntries.AssetEntriesDict.Where(x => x.Key.ToLowerInvariant().Contains("/" + templateId.ToLowerInvariant() + ".uasset")).Select(d => d.Key).FirstOrDefault(); + if (!string.IsNullOrEmpty(templateIdPath)) + { + rewardPath = templateIdPath.Substring(0, templateIdPath.LastIndexOf(".", StringComparison.InvariantCultureIgnoreCase)); + } + + JToken quantityToken = propertiesRewardTable.Where(item => string.Equals(item["name"].Value(), "Quantity")).FirstOrDefault(); + if (quantityToken != null) + { + rewardQuantity = quantityToken["tag_data"].Value(); + } + + BundleInfosEntry currentData = new BundleInfosEntry(questDescription, questCount, unlockType, rewardPath, rewardQuantity); + if (!BundleData.Any(item => item.TheQuestDescription.Equals(currentData.TheQuestDescription, StringComparison.InvariantCultureIgnoreCase) && item.TheQuestCount == currentData.TheQuestCount)) + { + BundleData.Add(currentData); + } + } + } + } + } + } + } + } + } else { BundleInfosEntry currentData = new BundleInfosEntry(questDescription, questCount, unlockType, "", ""); @@ -259,4 +325,4 @@ namespace FModel.Methods.Assets.IconCreator.ChallengeID } } } -} \ No newline at end of file +}