[NR-CORE] Json shop system.
Replace MerchantsList.cs with this.
And all you need to add now is a file in to bin called shop it needs to be json... This is how you would structure your shops.
@MikeRaarupBirk it's up now bitch
Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using common;
using common.resources;
using log4net;
using Newtonsoft.Json;
using wServer.realm.terrain;
namespace wServer.realm.entities.vendors
{
public class ShopItem : ISellableItem
{
public ushort ItemId { get; private set; }
public int Price { get; }
public int Count { get; }
public string Name { get; }
public ShopItem(string name, ushort price, int count = -1)
{
ItemId = ushort.MaxValue;
Price = price;
Count = count;
Name = name;
}
public void SetItem(ushort item)
{
if (ItemId != ushort.MaxValue)
throw new AccessViolationException("Can't change item after it has been set.");
ItemId = item;
}
}
internal static class MerchantLists
{
private static readonly ILog Log = LogManager.GetLogger(typeof(MerchantLists));
public static readonly Dictionary<TileRegion, Tuple<List<ISellableItem>, CurrencyType, /*
Req*/int>> Shops = new Dictionary<TileRegion, Tuple<List<ISellableItem>, CurrencyType, int>>();
public static void Init(RealmManager manager)
{
var json = JsonConvert.DeserializeObject<List<ShopSettings>>(File.ReadAllText("shop.json"));
foreach (var item in json)
{
var list = new List<ISellableItem>();
var currency = (CurrencyType)Enum.Parse(typeof(CurrencyType), item.Currency);
var region = (TileRegion)Enum.Parse(typeof(TileRegion), item.ShopId);
list.Add(new ShopItem(item.Item, item.Price));
Shops.Add(region, new Tuple<List<ISellableItem>, CurrencyType, int>(list, currency, item.Price));
}
foreach (var shop in Shops)
foreach (var shopItem in shop.Value.Item1.OfType<ShopItem>())
{
ushort id;
if (!manager.Resources.GameData.IdToObjectType.TryGetValue(shopItem.Name, out id))
Log.WarnFormat("Item name: {0}, not found.", shopItem.Name);
else
shopItem.SetItem(id);
}
}
public partial class ShopSettings
{
public string Currency { get; set; }
public string Item { get; set; }
public ushort Price { get; set; }
[JsonProperty("Shop_Id")]
public string ShopId { get; set; }
}
}
}
Code:
[
{
"Currency": "Fame",
"Item": "Sword of Acclaim",
"Price": 100,
"Shop_Id": "Store_1"
},
{
"Currency": "Fame",
"Item": "Demon Blade",
"Price": 100,
"Shop_Id": "Store_2"
}
]


Did u read the code i posted?