74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NBF.Utils;
|
|
|
|
namespace NBF
|
|
{
|
|
public static class GoodsConfigHelper
|
|
{
|
|
public static readonly List<TabItemData> TabItemList = new List<TabItemData>();
|
|
|
|
/// <summary>
|
|
/// 组合和id映射关系
|
|
/// </summary>
|
|
private static readonly Dictionary<uint, List<uint>> _group2Id = new Dictionary<uint, List<uint>>();
|
|
|
|
private static readonly Dictionary<uint, GoodsConfig> _googs = new Dictionary<uint, GoodsConfig>();
|
|
|
|
// private static readonly Dictionary<>
|
|
|
|
|
|
public static void Init()
|
|
{
|
|
var listGoods = GoodsConfig.GetList();
|
|
TabItemList.Clear();
|
|
|
|
|
|
foreach (var goodsConfig in listGoods)
|
|
{
|
|
if (goodsConfig.Group < 1)
|
|
{
|
|
goodsConfig.Group = goodsConfig.Id;
|
|
}
|
|
|
|
if (!_group2Id.TryGetValue(goodsConfig.Group, out List<uint> ids))
|
|
{
|
|
ids = new List<uint>();
|
|
_group2Id.Add(goodsConfig.Group, ids);
|
|
}
|
|
|
|
ids.Add(goodsConfig.Id);
|
|
_googs[goodsConfig.Id] = goodsConfig;
|
|
}
|
|
|
|
Dictionary<ItemType, List<GoodsConfig>> tabDic = new Dictionary<ItemType, List<GoodsConfig>>();
|
|
foreach (var goodsId in _group2Id.Keys)
|
|
{
|
|
var good = _googs[goodsId];
|
|
var awards = good.Awards;
|
|
var type = awards.First().Id.GetItemType();
|
|
if (!tabDic.ContainsKey(type))
|
|
{
|
|
tabDic.Add(type, new List<GoodsConfig>());
|
|
}
|
|
|
|
tabDic[type].Add(good);
|
|
}
|
|
|
|
foreach (var (key, list) in tabDic)
|
|
{
|
|
list.Sort((x, y) => (int)(y.Price1 - x.Price1));
|
|
}
|
|
|
|
foreach (var (type, list) in tabDic)
|
|
{
|
|
TabItemData tabItem = new TabItemData
|
|
{
|
|
Key = type.ToString()
|
|
};
|
|
tabItem.Items.AddRange(list);
|
|
TabItemList.Add(tabItem);
|
|
}
|
|
}
|
|
}
|
|
} |