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> ctgIdDictH = new Dictionary>(); public Dictionary> ctgIdDict = new Dictionary>(); 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()) WindowCenter.Instance.Open(); } 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 GetGiftAllItem() { List collectList = new List(); 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 GetGiftNowItem() { List collectList = new List(); 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 CollectItems(List collectList) { //<物品ID,物品数量> Dictionary resultDict = new Dictionary(); 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 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 private List GetItemListByDict(Dictionary dict) { List result = new List(); 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; } }