using Core.Models.Common; using Core.Models.Eft.Common.Tables; using Core.Models.Spt.Config; using Core.Models.Spt.Server; using Core.Utils; namespace _13AddTraderWithAssortJson { public class AddTraderHelper { /** * Add record to trader config to set the refresh time of trader in seconds (default is 60 minutes) * @param traderConfig trader config to add our trader to * @param baseJson json file for trader (db/base.json) * @param refreshTimeSecondsMin How many seconds between trader stock refresh min time * @param refreshTimeSecondsMax How many seconds between trader stock refresh max time */ public void SetTraderUpdateTime(TraderConfig traderConfig, dynamic baseJson, int refreshTimeSecondsMin, int refreshTimeSecondsMax) { // Add refresh time in seconds to config var traderRefreshRecord = new UpdateTime { TraderId = baseJson.id, Seconds = new MinMax(refreshTimeSecondsMin, refreshTimeSecondsMax) }; traderConfig.UpdateTime.Add(traderRefreshRecord); } /** * Add our new trader to the database * @param traderDetailsToAdd trader details * @param tables database * @param jsonUtil json utility class */ public void AddTraderToDb(dynamic traderDetailsToAdd, DatabaseTables tables, JsonUtil jsonUtil, object assortJson) { // Create trader data ready to add to database var traderDataToAdd = new Trader { Assort = jsonUtil.Deserialize( jsonUtil.Serialize(assortJson)), // Deserialise/serialise creates a copy of the json Base = jsonUtil.Deserialize( jsonUtil.Serialize(traderDetailsToAdd)), // Deserialise/serialise creates a copy of the json QuestAssort = new Dictionary> // questassort is empty as trader has no assorts unlocked by quests { { "Started", new Dictionary() }, { "Success", new Dictionary() }, { "Fail", new Dictionary() } } }; // Add trader to trader table, key is the traders id tables.Traders.Add(traderDetailsToAdd._id, traderDataToAdd); } /** * Add traders name/location/description to the locale table * @param baseJson json file for trader (db/base.json) * @param tables database tables * @param fullName Complete name of trader * @param firstName First name of trader * @param nickName Nickname of trader * @param location Location of trader (e.g. "Here in the cat shop") * @param description Description of trader */ public void AddTraderToLocales(dynamic baseJson, DatabaseTables tables, string fullName, string firstName, string nickName, string location, string description) { // For each language, add locale for the new trader var locales = tables.Locales.Global; foreach (var (key, value) in locales) { value.Value[$"{baseJson._id} FullName"] = fullName; value.Value[$"{baseJson._id} FirstName"] = firstName; value.Value[$"{baseJson._id} Nickname"] = nickName; value.Value[$"{baseJson._id} Location"] = location; value.Value[$"{baseJson._id} Description"] = description; } } } }