using System.Collections.Generic;
|
using System.Linq;
|
using vnxbqy.UI;
|
|
public class ZhanLingHActBuyModel : Model
|
{
|
public int zhanLingType; //高级战令类型
|
public int showGiftType; //1 普通战令礼包 2 高级战令礼包
|
public int nowNeedValue;
|
|
public Dictionary<int, List<int>> ctgIdDictH = new Dictionary<int, List<int>>();
|
public Dictionary<int, List<int>> ctgIdDict = new Dictionary<int, List<int>>();
|
|
public override void Init()
|
{
|
ctgIdDict = GeneralDefine.ZhanLingCtgIdDict;
|
ctgIdDictH = GeneralDefine.ZhanLingCtgIdHDict;
|
}
|
|
public override void UnInit()
|
{
|
}
|
|
public void ShowZhanLingHBuy(int zhanLingType, int showGiftType, int nowNeedValue)
|
{
|
this.zhanLingType = zhanLingType;
|
this.showGiftType = showGiftType;
|
this.nowNeedValue = nowNeedValue;
|
if (!WindowCenter.Instance.IsOpen<ZhanLingHActBuyWin>())
|
WindowCenter.Instance.Open<ZhanLingHActBuyWin>();
|
}
|
|
public int GetCtgID()
|
{
|
int ctgid = 0;
|
if (showGiftType == 1)
|
{
|
ctgid = ctgIdDict[zhanLingType][0];
|
}
|
else if (showGiftType == 2)
|
{
|
ctgid = ctgIdDictH[zhanLingType][0];
|
}
|
return ctgid;
|
}
|
|
//获取购买后所有等级的奖励
|
public List<Item> GetGiftAllItem()
|
{
|
List<int> collectList = new List<int>();
|
var dict = ILZhanlingConfig.GetTypeToIDDict(zhanLingType);
|
var arr = dict.Keys.ToArray();
|
for (int i = 0; i < arr.Length; i++)
|
{
|
int needValue = arr[i];
|
int zhanLingId = dict[needValue];
|
collectList.Add(zhanLingId);
|
}
|
return CollectItems(collectList);
|
}
|
|
//获取购买后当前等级的奖励
|
public List<Item> GetGiftNowItem()
|
{
|
List<int> collectList = new List<int>();
|
var dict = ILZhanlingConfig.GetTypeToIDDict(zhanLingType);
|
var arr = dict.Keys.ToArray();
|
for (int i = 0; i < arr.Length; i++)
|
{
|
int needValue = arr[i];
|
int zhanLingId = dict[needValue];
|
if (needValue > nowNeedValue)
|
break;
|
collectList.Add(zhanLingId);
|
}
|
return CollectItems(collectList);
|
}
|
|
private List<Item> CollectItems(List<int> collectList)
|
{
|
//<物品ID,物品数量>
|
Dictionary<int, int> resultDict = new Dictionary<int, int>();
|
for (int i = 0; i < collectList.Count; i++)
|
{
|
int zhanLingId = collectList[i];
|
int[][] itemArr = GetItemArr(zhanLingId, showGiftType);
|
if (itemArr.IsNullOrEmpty())
|
continue;
|
|
for (int j = 0; j < itemArr.Length; j++)
|
{
|
int itemID = itemArr[j][0];
|
int count = itemArr[j][1];
|
if (resultDict.ContainsKey(itemID))
|
{
|
resultDict[itemID] += count;
|
}
|
else
|
{
|
resultDict[itemID] = count;
|
}
|
}
|
}
|
List<Item> result = GetItemListByDict(resultDict);
|
result.Sort(Cmp);
|
return result;
|
}
|
|
private int[][] GetItemArr(int zhanLingId, int showGiftType)
|
{
|
if (!ILZhanlingConfig.Has(zhanLingId))
|
return new int[][] { };
|
|
if (showGiftType == 1)
|
{
|
return ILZhanlingConfig.Get(zhanLingId).ZLRewardItemList;
|
}
|
else if (showGiftType == 2)
|
{
|
return ILZhanlingConfig.Get(zhanLingId).ZLRewardItemListH;
|
}
|
else
|
{
|
return new int[][] { };
|
}
|
}
|
|
//将传入的<物品ID,物品数量>字典转成List<Item>
|
private List<Item> GetItemListByDict(Dictionary<int, int> dict)
|
{
|
List<Item> result = new List<Item>();
|
var arr = dict.Keys.ToArray();
|
for (int i = 0; i < arr.Length; i++)
|
{
|
int itemID = arr[i];
|
int count = dict[itemID];
|
result.Add(new Item(itemID, count));
|
}
|
return result;
|
}
|
|
private int Cmp(Item a, Item b)
|
{
|
int count1 = a.count;
|
int count2 = b.count;
|
int quality1 = ItemConfig.Get(a.id).ItemColor;
|
int quality2 = ItemConfig.Get(b.id).ItemColor;
|
|
//品质高的排在前面
|
if (quality1 != quality2)
|
{
|
return quality2.CompareTo(quality1);
|
}
|
|
// 品质相同时,数量少的排在前面
|
if (count1 != count2)
|
{
|
return count1.CompareTo(count2);
|
}
|
|
// 如果品质和数量都相同,保持原有顺序
|
return 0;
|
}
|
}
|