Initial commit of assort generator code

This commit is contained in:
Chomp 2021-09-05 20:54:44 +01:00
parent efc5bedace
commit e21ccb711c
24 changed files with 249735 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AssortGenerator.Models\AssortGenerator.Models.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Assets\items.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,22 @@
using System;
using System.IO;
namespace Common
{
public static class DiskHelpers
{
public static void CreateDirIfDoesntExist(string path)
{
if (!Directory.Exists($"{path}"))
{
//create dump dir
Directory.CreateDirectory($"{path}");
}
}
public static string[] GetJsonFiles(string path)
{
return Directory.GetFiles(path, "*.json", SearchOption.TopDirectoryOnly);
}
}
}

View File

@ -0,0 +1,25 @@
using System.Collections.Generic;
namespace Common.Extensions
{
public static class StringToolsExtensions
{
/// <summary>
/// Add a string to a list only if it doesnt already exist
/// </summary>
public static void AddUnique(this IList<string> self, string item)
{
if (!self.Contains(item))
self.Add(item);
}
public static void AddUniqueRange(this IList<string> self, IList<string> itemsToAdd)
{
foreach (var item in itemsToAdd)
{
if (!self.Contains(item))
self.Add(item);
}
}
}
}

View File

@ -0,0 +1,21 @@
using Common;
using System.Collections.Generic;
using System.Linq;
namespace AssortGenerator.Common.Helpers
{
public static class InputFileHelper
{
private static List<string> _inputFilePaths;
public static void SetInputFiles(string assortsPath)
{
_inputFilePaths = DiskHelpers.GetJsonFiles(assortsPath).ToList();
}
public static IEnumerable<string> GetInputFilePaths()
{
return _inputFilePaths;
}
}
}

View File

@ -0,0 +1,63 @@
using AssortGenerator.Models.Input;
using AssortGenerator.Models.Other;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
namespace AssortGenerator.Common.Helpers
{
public static class QuestHelper
{
private static QuestRoot _questData;
private static List<AssortUnlocks> _assortUnlocks;
public static QuestRoot GetQuestData()
{
if (_questData == null)
{
var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("resp.client.quest.list"));
var questDataJson = File.ReadAllText(questFilePath);
_questData = JsonSerializer.Deserialize<QuestRoot>(questDataJson);
}
return _questData;
}
public static List<AssortUnlocks> GetAssortUnlocks()
{
if (_assortUnlocks == null)
{
_assortUnlocks = new List<AssortUnlocks>();
foreach (var quest in GetQuestData().data)
{
if (quest._id == "5b478b1886f7744d1b23c57d")
{
var x = 1;
}
foreach (var reward in quest.rewards.Success)
{
if (string.Equals(reward.type, "assortmentunlock", System.StringComparison.OrdinalIgnoreCase))
{
_assortUnlocks.Add(new AssortUnlocks
{
AssortUnlockId = reward.id,
ItemUnlockedId = reward.target,
ItemUnlockedTemplateId = reward.items[0]._tpl,
LoyaltyLevel = (int)reward.loyaltyLevel,
QuestId = quest._id,
QuestRewardId = reward.id,
TraderId = reward.traderId,
TraderType = TraderHelper.GetTraderTypeById(reward.traderId),
Criteria = "Success"
}
);
}
}
}
}
return _assortUnlocks;
}
}
}

View File

@ -0,0 +1,45 @@
using AssortGenerator.Models.Other;
using System;
using System.Collections.Generic;
namespace AssortGenerator.Common.Helpers
{
public static class TraderHelper
{
private static Dictionary<Trader, string> _traders;
public static Dictionary<Trader, string> GetTraders()
{
if (_traders == null)
{
_traders = new Dictionary<Trader, string>
{
{ Trader.Prapor, "54cb50c76803fa8b248b4571" },
{ Trader.Therapist, "54cb57776803fa99248b456e"},
{ Trader.Skier, "58330581ace78e27b8b10cee"},
{ Trader.Peacekeeper, "5935c25fb3acc3127c3d8cd9"},
{ Trader.Mechanic, "5a7c2eca46aef81a7ca2145d"},
{ Trader.Ragman, "5ac3b934156ae10c4430e83c"},
{ Trader.Jaeger, "5c0647fdd443bc2504c2d371"}
};
}
return _traders;
}
public static Trader GetTraderTypeById(string traderId)
{
Trader returnType = 0;
foreach (var item in GetTraders())
{
if (item.Value == traderId)
{
returnType = item.Key;
break;
}
}
return returnType;
}
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using Item = Common.Models.Item;
namespace AssortGenerator.Common
{
public static class ItemTemplateHelper
{
private static Dictionary<string, Item> _itemCache;
public static Dictionary<string, Item> Items
{
get
{
if (_itemCache == null)
{
var itemsFilePath = $"{Directory.GetCurrentDirectory()}\\Assets\\items.json";
if (!File.Exists(itemsFilePath))
{
throw new Exception($"Missing items.json under assets ({itemsFilePath})");
}
var itemsJson = File.ReadAllText(itemsFilePath);
_itemCache = JsonSerializer.Deserialize<Dictionary<string, Item>>(itemsJson);
}
return _itemCache;
}
}
public static Item GetTemplateById(string templateId)
{
if (Items.ContainsKey(templateId))
{
return Items[templateId];
}
LoggingHelpers.LogToConsole($"Could not locate item template with id {templateId}", ConsoleColor.Red);
return null;
}
}
}

View File

@ -0,0 +1,29 @@
using Common;
using System;
using System.IO;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;
namespace AssortGenerator.Common
{
public static class JsonWriter
{
public static void WriteJson<T>(T itemToSerialise, string outputFolderName, string workingPath, string fileName)
{
var outputPath = $"{workingPath}\\output\\{outputFolderName}";
DiskHelpers.CreateDirIfDoesntExist(outputPath);
Console.WriteLine($"Writing json file to {outputPath}");
var options = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Cyrillic)
};
var json = JsonSerializer.Serialize(itemToSerialise, options);
File.WriteAllText($"{outputPath}\\{fileName}.json", json);
}
}
}

View File

@ -0,0 +1,68 @@
using System;
namespace AssortGenerator.Common
{
public static class LoggingHelpers
{
public static string LogTimeTaken(double totalSeconds)
{
return Math.Round(totalSeconds, 2, MidpointRounding.ToEven).ToString();
}
public static void LogWarning(string message)
{
Console.BackgroundColor = ConsoleColor.DarkYellow;
Console.ForegroundColor = ConsoleColor.Black;
Console.Write(message);
ResetConsoleColours();
Console.WriteLine();
}
public static void LogInfo(string message)
{
Console.BackgroundColor = ConsoleColor.Gray;
Console.ForegroundColor = ConsoleColor.Black;
Console.Write(message);
ResetConsoleColours();
Console.WriteLine();
}
public static void LogSuccess(string message)
{
Console.BackgroundColor = ConsoleColor.Green;
Console.ForegroundColor = ConsoleColor.Black;
Console.Write(message);
ResetConsoleColours();
Console.WriteLine();
}
public static void LogError(string message)
{
Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.White;
Console.Write(message);
ResetConsoleColours();
Console.WriteLine();
}
public static void LogToConsole(string message, ConsoleColor backgroundColour = ConsoleColor.Green)
{
Console.BackgroundColor = backgroundColour;
Console.ForegroundColor = ConsoleColor.Black;
Console.Write(message);
ResetConsoleColours();
Console.WriteLine();
}
private static void ResetConsoleColours()
{
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
}
}
}

View File

@ -0,0 +1,55 @@
using System.Collections.Generic;
namespace Common.Models
{
public class ItemsLibRoot
{
public List<Dictionary<string, Item>> items { get; set; }
}
public class Item
{
public string _id { get; set; }
public string _name { get; set; }
public string _parent { get; set; }
public string _type { get; set; }
public Props _props { get; set; }
}
public class Props
{
public string Name { get; set; }
public string ShortName { get; set; }
public string Description { get; set; }
public List<Chamber> Chambers { get; set; }
public List<Slot> Slots { get; set; }
public string defAmmo { get; set; }
}
public class Chamber
{
public string _name { get; set; }
public string _id { get; set; }
public string _parent { get; set; }
public ChamberProps _props { get; set; }
public bool _required { get; set; }
public bool _mergeSlotWithChildren { get; set; }
public string _proto { get; set; }
}
public class Slot
{
public string _name { get; set; }
public bool _required { get; set; }
}
public class ChamberProps
{
public List<Filter> filters { get; set; }
}
public class Filter
{
public List<string> filter { get; set; }
}
}

View File

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace AssortGenerator.Models.Input
{
public class CustomisationRoot
{
public int err { get; set; }
public object errmsg { get; set; }
public List<Suit> data { get; set; }
}
}

View File

@ -0,0 +1,60 @@
using System.Collections.Generic;
namespace AssortGenerator.Models.Input
{
public class QuestRoot
{
public int err { get; set; }
public object errmsg { get; set; }
public List<Quest> data { get; set; }
}
public class Quest
{
public string _id { get; set; }
public string traderId { get; set; }
public string location { get; set; }
public string image { get; set; }
public string type { get; set; }
public bool isKey { get; set; }
public bool restartable { get; set; }
public bool instantComplete { get; set; }
public bool secretQuest { get; set; }
public int min_level { get; set; }
public bool canShowNotificationsInGame { get; set; }
public Rewards rewards { get; set; }
}
public class Rewards
{
public List<RewardStatus> Started { get; set; }
public List<RewardStatus> Success { get; set; }
public List<RewardStatus> Fail { get; set; }
}
public class RewardStatus
{
public string value { get; set; }
public string id { get; set; }
public string type { get; set; }
public int index { get; set; }
public string target { get; set; }
public List<QuestRewardItem> items { get; set; }
public int? loyaltyLevel { get; set; }
public string traderId { get; set; }
}
public class QuestRewardItem
{
public string _id { get; set; }
public string _tpl { get; set; }
public QuestRewardUpd upd { get; set; }
public string parentId { get; set; }
public string slotId { get; set; }
}
public class QuestRewardUpd
{
public int StackObjectsCount { get; set; }
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace AssortGenerator.Models.Input
{
public class Items
{
public string _id { get; set; }
public string _tpl { get; set; }
public string parentId { get; set; }
public string slotId { get; set; }
public TraderUpd upd { get; set; }
}
public class TraderUpd
{
public bool UnlimitedCount { get; set; }
public int StackObjectsCount { get; set; }
public int? BuyRestrictionMax { get; set; }
public int? BuyRestrictionCurrent { get; set; }
}
public class BarterScheme
{
}
public class LoyaltyLevelItems
{
Dictionary<string, int> items { get; set;}
}
}

View File

@ -0,0 +1,15 @@
namespace AssortGenerator.Models.Other
{
public class AssortUnlocks
{
public string QuestId { get; set; }
public string AssortUnlockId { get; set; }
public string QuestRewardId { get; set; }
public string TraderId { get; set; }
public string ItemUnlockedId { get; set; }
public string ItemUnlockedTemplateId { get; set; }
public Trader TraderType { get; set; }
public int LoyaltyLevel { get; set; }
public string Criteria { get; set; }
}
}

View File

@ -0,0 +1,14 @@
namespace AssortGenerator.Models.Other
{
public enum Trader
{
Unknown = 0,
Prapor = 1,
Therapist = 2,
Skier = 3,
Peacekeeper = 4,
Mechanic = 5,
Ragman = 6,
Jaeger = 7
}
}

View File

@ -0,0 +1,34 @@
using System.Collections.Generic;
namespace AssortGenerator.Models.Output
{
public class AssortRoot
{
public List<Item> items { get; set; }
public Dictionary<string, object> barter_scheme { get; set; }
public Dictionary<string, int> loyal_level_items { get; set; }
}
public class Item
{
public string _id { get; set; }
public string _tpl { get; set; }
public string parentId { get; set; }
public string slotId { get; set; }
public Upd upd { get; set; }
}
public class Upd
{
public bool UnlimitedCount { get; set; }
public int StackObjectsCount { get; set; }
public int? BuyRestrictionMax { get; set; }
public int? BuyRestrictionCurrent { get; set; }
}
public class BarterObject
{
public int count { get; set; }
public string _tpl { get; set; }
}
}

View File

@ -0,0 +1,67 @@
using System.Collections.Generic;
namespace AssortGenerator.Models.Output
{
public class BaseRoot
{
public List<Base> data { get; set; }
}
public class Base
{
public string _id { get; set; }
public bool customization_seller { get; set; }
public string name { get; set; }
public string surname { get; set; }
public string nickname { get; set; }
public string location { get; set; }
public string avatar { get; set; }
public int balance_rub { get; set; }
public int balance_dol { get; set; }
public int balance_eur { get; set; }
public bool unlockedByDefault { get; set; }
public int discount { get; set; }
public int discount_end { get; set; }
public bool buyer_up { get; set; }
public string currency { get; set; }
public int nextResupply { get; set; }
public Repair repair { get; set; }
public Insurance insurance { get; set; }
public bool medic { get; set; }
public int gridHeight { get; set; }
public List<LoyaltyLevel> loyaltyLevels { get; set; }
public List<string> sell_category { get; set; }
}
public class Repair
{
public bool availability { get; set; }
public string quality { get; set; }
public List<object> excluded_id_list { get; set; }
public List<object> excluded_category { get; set; }
public string currency { get; set; }
public int currency_coefficient { get; set; }
public int price_rate { get; set; }
}
public class Insurance
{
public bool availability { get; set; }
public int min_payment { get; set; }
public int min_return_hour { get; set; }
public int max_return_hour { get; set; }
public int max_storage_time { get; set; }
public List<object> excluded_category { get; set; }
}
public class LoyaltyLevel
{
public object minLevel { get; set; }
public object minSalesSum { get; set; }
public object minStanding { get; set; }
public int buy_price_coef { get; set; }
public object repair_price_coef { get; set; }
public object insurance_price_coef { get; set; }
public int exchange_price_coef { get; set; }
public object heal_price_coef { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System.Collections.Generic;
namespace AssortGenerator.Models.Output
{
public class QuestAssort
{
public QuestAssort()
{
started = new Dictionary<string, string>();
success = new Dictionary<string, string>();
fail = new Dictionary<string, string>();
}
public Dictionary<string, string> started { get; set; }
public Dictionary<string, string> success { get; set; }
public Dictionary<string, string> fail { get; set; }
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace AssortGenerator.Models.Input
{
public class Suit
{
public string _id { get; set; }
public string tid { get; set; }
public string suiteId { get; set; }
public bool isActive { get; set; }
public Requirements requirements { get; set; }
}
public class Requirements
{
public int loyaltyLevel { get; set; }
public int profileLevel { get; set; }
public int standing { get; set; }
public List<object> skillRequirements { get; set; }
public List<string> questRequirements { get; set; }
public List<ItemRequirement> itemRequirements { get; set; }
}
public class ItemRequirement
{
public int count { get; set; }
public string _tpl { get; set; }
public bool onlyFunctional { get; set; }
}
}

37
AssortGenerator.sln Normal file
View File

@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31624.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssortGenerator", "AssortGenerator\AssortGenerator.csproj", "{747ED3CB-DED2-47CB-9BD6-493FB05B6C2B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssortGenerator.Models", "AssortGenerator.Models\AssortGenerator.Models.csproj", "{BC63C9C4-A796-4C25-AC3E-8C9565F041DC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssortGenerator.Common", "AssortGenerator.Common\AssortGenerator.Common.csproj", "{FED37D1A-85E4-45C6-9D55-EFD05065251B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{747ED3CB-DED2-47CB-9BD6-493FB05B6C2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{747ED3CB-DED2-47CB-9BD6-493FB05B6C2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{747ED3CB-DED2-47CB-9BD6-493FB05B6C2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{747ED3CB-DED2-47CB-9BD6-493FB05B6C2B}.Release|Any CPU.Build.0 = Release|Any CPU
{BC63C9C4-A796-4C25-AC3E-8C9565F041DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC63C9C4-A796-4C25-AC3E-8C9565F041DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC63C9C4-A796-4C25-AC3E-8C9565F041DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC63C9C4-A796-4C25-AC3E-8C9565F041DC}.Release|Any CPU.Build.0 = Release|Any CPU
{FED37D1A-85E4-45C6-9D55-EFD05065251B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FED37D1A-85E4-45C6-9D55-EFD05065251B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FED37D1A-85E4-45C6-9D55-EFD05065251B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FED37D1A-85E4-45C6-9D55-EFD05065251B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {91DF85C3-CCE8-4AE9-96FE-CA2DDE52AE42}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AssortGenerator.Common\AssortGenerator.Common.csproj" />
<ProjectReference Include="..\AssortGenerator.Models\AssortGenerator.Models.csproj" />
</ItemGroup>
</Project>

192
AssortGenerator/Program.cs Normal file
View File

@ -0,0 +1,192 @@
using AssortGenerator.Common;
using AssortGenerator.Common.Helpers;
using AssortGenerator.Models.Input;
using AssortGenerator.Models.Other;
using AssortGenerator.Models.Output;
using Common;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
namespace AssortGenerator
{
partial class Program
{
static void Main(string[] args)
{
var assortsPath = CreateWorkingFolders();
InputFileHelper.SetInputFiles(assortsPath);
// Get trader assort files from assorts input folder
var traderAssortFilePaths = InputFileHelper.GetInputFilePaths().Where(x => TraderHelper.GetTraders().Values.Any(x.Contains)).ToList();
foreach (var trader in TraderHelper.GetTraders())
{
// Get relevant trader dump
var assortDumpPath = traderAssortFilePaths.Find(x => x.Contains(trader.Value));
// convert input dump json into object
var json = File.ReadAllText(assortDumpPath);
var jsonObject = JsonDocument.Parse(json);
// find root data node
var data = jsonObject.RootElement.GetProperty("data");
// find items node and parse into object
string itemsJson = data.GetProperty("items").ToString();
List<Item> items = JsonSerializer.Deserialize<List<Item>>(itemsJson);
// Find barter scheme node and parse into object
var barterSchemeJson = data.GetProperty("barter_scheme").ToString();
var barterSchemeItems = JsonSerializer.Deserialize<Dictionary<string, object>>(barterSchemeJson);
// Find loyalty level node and parse into object
var loyaltyLevelItemsJson = data.GetProperty("loyal_level_items").ToString();
var loyaltyLevelItems = JsonSerializer.Deserialize<Dictionary<string, int>>(loyaltyLevelItemsJson);
WriteOutputFilesForTrader(trader, items, barterSchemeItems, loyaltyLevelItems);
}
}
private static string CreateWorkingFolders()
{
var workingPath = Directory.GetCurrentDirectory();
// create input folder
var inputPath = $"{workingPath}//input";
DiskHelpers.CreateDirIfDoesntExist(inputPath);
// create sub folder in input called assorts
var assortsPath = $"{inputPath}//assorts";
DiskHelpers.CreateDirIfDoesntExist(assortsPath);
// create output folder
var outputPath = $"{workingPath}//output";
DiskHelpers.CreateDirIfDoesntExist(outputPath);
// create traders sub-folder
var tradersPath = $"{outputPath}//traders";
DiskHelpers.CreateDirIfDoesntExist(tradersPath);
return assortsPath;
}
private static BaseRoot GetTraderData(IEnumerable<string> filesInAssortsFolder)
{
var traderDataPath = filesInAssortsFolder.FirstOrDefault(x => x.Contains("resp.client.trading.api.traderSettings"));
var traderDataJson = File.ReadAllText(traderDataPath);
return JsonSerializer.Deserialize<BaseRoot>(traderDataJson);
}
private static void WriteOutputFilesForTrader(KeyValuePair<Trader, string> trader,
List<Item> items,
Dictionary<string, object>
barterSchemeItems,
Dictionary<string, int> loyaltyLevelItems)
{
var workingPath = Directory.GetCurrentDirectory();
var traderData = GetTraderData(InputFileHelper.GetInputFilePaths());
var traderFolderPath = $"traders\\{trader.Value}";
// create assort file, serialise into json and save into output folder
var outputAssortFile = new AssortRoot
{
items = items,
barter_scheme = barterSchemeItems,
loyal_level_items = loyaltyLevelItems
};
JsonWriter.WriteJson(outputAssortFile, traderFolderPath, workingPath, "assorts");
// create base file, serialise into json and save into output folder
var outputBaseFile = traderData.data.Find(x => x._id == trader.Value);
JsonWriter.WriteJson(outputBaseFile, traderFolderPath, workingPath, "base");
QuestAssort questAssort = GenerateQuestAssort(trader.Key, outputAssortFile);
JsonWriter.WriteJson(questAssort, traderFolderPath, workingPath, "questassort");
// create suits file for ragman
if (trader.Key == Trader.Ragman)
{
var customisationFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("resp.client.trading.customization"));
var traderDataJson = File.ReadAllText(customisationFilePath);
var suitData = JsonSerializer.Deserialize<CustomisationRoot>(traderDataJson);
var outputSuitData = new List<Suit>();
outputSuitData.AddRange(suitData.data);
JsonWriter.WriteJson(outputSuitData, traderFolderPath, workingPath, "suits");
}
}
private static QuestAssort GenerateQuestAssort(Trader trader, AssortRoot assortRoot)
{
var result = new QuestAssort();
var questData = QuestHelper.GetQuestData();
// Find assortunlocks
List<AssortUnlocks> assortUnlocks = QuestHelper.GetAssortUnlocks();
// TODO: find out how the fuck the assort unlock is associated to the quest
foreach (var assortUnlock in assortUnlocks.Where(x => x.TraderType == trader))
{
// Get unlock items name
var assortItemName = ItemTemplateHelper.Items.FirstOrDefault(x=> x.Key == assortUnlock.ItemUnlockedTemplateId).Value._name;
// TODO: handle started
// TODO: handle fail
// handle quest success for now
if (assortUnlock.Criteria == "Success")
{
//Find assorts that match the quest unlocks item template
var assortItemsThatMatch = assortRoot.items.Where(x => x._tpl == assortUnlock.ItemUnlockedTemplateId).ToList();
// no assort found for this unlock, log and skip it
if (assortItemsThatMatch == null || assortItemsThatMatch.Count == 0)
{
LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no assort item found. ({assortItemName})");
continue;
}
// Iterate over assorts that match. goal is to find which assort fits the best (traders assort has same loyalty level unlock as quest expects)
string assortIdUnlockedByQuest = string.Empty;
foreach (var match in assortItemsThatMatch)
{
// Look up item in Loyalty Level array
var associatedLoyaltyLevelItem = assortRoot.loyal_level_items.FirstOrDefault(x => x.Key == match._id);
if (associatedLoyaltyLevelItem.Key == null)
{
// end loop if no record found
LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no loyalty record found. ({assortItemName})");
break;
}
if (associatedLoyaltyLevelItem.Value != assortUnlock.LoyaltyLevel)
{
// loyalty level is different to what was expected, skip
LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no match found in LL array. LL{associatedLoyaltyLevelItem.Value}. questListLevel: {assortUnlock.LoyaltyLevel}. ({assortItemName})");
continue;
}
//LoggingHelpers.LogInfo($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} {assortItemName}. MATCH FOUND. LL{assortUnlock.LoyaltyLevel}");
assortIdUnlockedByQuest = associatedLoyaltyLevelItem.Key;
}
if (result.success.ContainsKey(assortUnlock.QuestId))
{
LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. ALREADY EXISTS. SKIPPING. ({assortItemName})");
continue;
}
LoggingHelpers.LogSuccess($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. ADDING TO QUEST-ASSORT. ({assortItemName})");
result.success.Add(assortUnlock.QuestId, assortIdUnlockedByQuest);
}
}
return result;
}
}
}