using Snxxz.UI; using System; using System.Collections.Generic; using System.Linq; using TableConfig; using UnityEngine; public class SelectEquipModel : Model { ComposeWinModel _composeWinModel; ComposeWinModel composeWinModel { get { return _composeWinModel ?? (_composeWinModel = ModelCenter.Instance.GetModel()); } } private FuncConfigConfig addonsTypeModel; private FuncConfigConfig addonsQualityModel; private Dictionary _unfixedItemDict = new Dictionary(); //key 物品在背包索引 private Dictionary _addonsItemDict = new Dictionary(); //key 物品在背包索引 private int[] _addonsTypelist = null; private int[] _addonsQualitylist = null; private Dictionary allBagItemInfo; private Dictionary haveUnfixedSelectItemDic = new Dictionary(); //用于存储已选择添加的不固定道具 private Dictionary haveAddSelectItemDic = new Dictionary();//用于存储已选择添加的道具 public SelectItemType selectItem = SelectItemType.Nomral; PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } PackModelInterface modelInterface { get { return ModelCenter.Instance.GetModel(); } } public event Action haveSelectItemRefresh; public int[] extraOneKeyPutCondis; public int[] noOneKeyPutCondis; public override void Init() { addonsTypeModel = ConfigManager.Instance.GetTemplate("ComposeAddonsType"); addonsQualityModel = ConfigManager.Instance.GetTemplate("ComposeAddonsQuality"); _addonsTypelist = ConfigParse.GetMultipleStr(addonsTypeModel.Numerical1); _addonsQualitylist = ConfigParse.GetMultipleStr(addonsQualityModel.Numerical1); FuncConfigConfig onekeyPut = ConfigManager.Instance.GetTemplate("ComposeAutoLimit"); extraOneKeyPutCondis = ConfigParse.GetMultipleStr(onekeyPut.Numerical1); noOneKeyPutCondis = ConfigParse.GetMultipleStr(onekeyPut.Numerical2); } public override void UnInit() { } public Dictionary GetUnfixedItemModel() { SinglePackModel singlePack = playerPack.GetSinglePackModel(PackType.rptItem); if (singlePack == null) return null; allBagItemInfo = singlePack.GetPackModelIndexDict(); _unfixedItemDict.Clear(); foreach (int key in allBagItemInfo.Keys) { if (!haveUnfixedSelectItemDic.ContainsKey(key)) { int i = 0; for (i = 0; i < composeWinModel.unfixedItemIDs.Length; i++) { if (composeWinModel.unfixedItemIDs[i] == allBagItemInfo[key].itemInfo.ItemID) { _unfixedItemDict.Add(key, allBagItemInfo[key]); break; } } } } return _unfixedItemDict; } public Dictionary GetAddItemModel() { SinglePackModel singlePack = playerPack.GetSinglePackModel(PackType.rptItem); if (singlePack == null) return null; allBagItemInfo = singlePack.GetPackModelIndexDict(); List modellist = allBagItemInfo.Values.ToList(); modellist.Sort(CompareByCondition); _addonsItemDict.Clear(); for(int i= 0; i < modellist.Count; i++) { int index = modellist[i].itemInfo.ItemPlace; if (!haveAddSelectItemDic.ContainsKey(index)) { int j = 0; for (j = 0; j < _addonsTypelist.Length; j++) { if (_addonsTypelist[j] == modellist[i].chinItemModel.Type) { if (modellist[i].chinItemModel.LV >= _addonsQualitylist[0] && modellist[i].chinItemModel.ItemColor >= _addonsQualitylist[1]) { _addonsItemDict.Add(index, modellist[i]); break; } } } } } return _addonsItemDict; } private List oneKeyPutlist = new List(); private List orderOneKeylist = new List(); public List GetOneKeyPutModel() { GetAddItemModel(); oneKeyPutlist.Clear(); orderOneKeylist.Clear(); foreach (var key in _addonsItemDict.Keys) { int isFightUp = modelInterface.IsFightUp(_addonsItemDict[key].itemId,_addonsItemDict[key].equipScore); if(isFightUp != 1) { if(_addonsItemDict[key].chinItemModel.ItemColor >= noOneKeyPutCondis[0] && _addonsItemDict[key].chinItemModel.StarLevel >= noOneKeyPutCondis[1]) { if(_addonsItemDict[key].chinItemModel.ItemColor == extraOneKeyPutCondis[0] && _addonsItemDict[key].chinItemModel.StarLevel == extraOneKeyPutCondis[1]) { oneKeyPutlist.Add(_addonsItemDict[key]); } } else { oneKeyPutlist.Add(_addonsItemDict[key]); } } } orderOneKeylist.AddRange(oneKeyPutlist); orderOneKeylist.Sort(CompareByOneKeyPut); return orderOneKeylist; } public int CompareByOneKeyPut(ItemModel start,ItemModel end) { int x = start.chinItemModel.ItemColor; int y = end.chinItemModel.ItemColor; if (x.CompareTo(y) != 0) return -x.CompareTo(y); x = start.chinItemModel.LV; y = end.chinItemModel.LV; if (x.CompareTo(y) != 0) return -x.CompareTo(y); x = start.chinItemModel.StarLevel; y = end.chinItemModel.StarLevel; if (x.CompareTo(y) != 0) return x.CompareTo(y); x = start.itemInfo.IsBind; y = end.itemInfo.IsBind; if (x.CompareTo(y) != 0) return -x.CompareTo(y); x = oneKeyPutlist.IndexOf(start); y = oneKeyPutlist.IndexOf(end); if (x.CompareTo(y) != 0) return x.CompareTo(y); return 0; } public int CompareByCondition(ItemModel start,ItemModel end) { int startIsBind = start.itemInfo.IsBind; int endIsBind = end.itemInfo.IsBind; if (startIsBind.CompareTo(endIsBind) != 0) return startIsBind.CompareTo(endIsBind); int startQuality = start.chinItemModel.ItemColor; int endQuality = end.chinItemModel.ItemColor; if (startQuality.CompareTo(endQuality) != 0) return startQuality.CompareTo(endQuality); int startStarLV = start.chinItemModel.StarLevel; int endStarLv = end.chinItemModel.StarLevel; if (startStarLV.CompareTo(endStarLv) != 0) return startStarLV.CompareTo(endStarLv); return 0; } public void AddHaveUnfixedSelectItem(int itemPlace) { ItemModel itemModel = playerPack.GetItemModelByIndex(PackType.rptItem, itemPlace); if (!haveUnfixedSelectItemDic.ContainsKey(itemPlace)) { haveUnfixedSelectItemDic.Add(itemPlace, itemModel); } if (haveSelectItemRefresh != null) { haveSelectItemRefresh(); } } public void RemoveHaveUnfixedSelectItem(int itemPlace) { if (haveUnfixedSelectItemDic.ContainsKey(itemPlace)) { haveUnfixedSelectItemDic.Remove(itemPlace); } if (haveSelectItemRefresh != null) { haveSelectItemRefresh(); } } public void AddHaveAddSelectItem(int itemPlace) { ItemModel itemModel = playerPack.GetItemModelByIndex(PackType.rptItem, itemPlace); if (!haveAddSelectItemDic.ContainsKey(itemPlace)) { haveAddSelectItemDic.Add(itemPlace, itemModel); } if (haveSelectItemRefresh != null) { haveSelectItemRefresh(); } } public void RemoveHaveAddSelectItem(int itemPlace) { if (haveAddSelectItemDic.ContainsKey(itemPlace)) { haveAddSelectItemDic.Remove(itemPlace); } if (haveSelectItemRefresh != null) { haveSelectItemRefresh(); } } public GameObject addParent { get; private set; } public void SetAddParent(GameObject go) { addParent = go; } public event Action selectEquipEvent; public void RefreshSelectEquip(ItemModel model) { if (selectEquipEvent != null) { selectEquipEvent(model, addParent,selectItem); } } public void ClearSelectModel() { addParent = null; haveAddSelectItemDic.Clear(); haveUnfixedSelectItemDic.Clear(); if(haveSelectItemRefresh != null) { haveSelectItemRefresh(); } } public Dictionary GetHaveUnfixedSelectItem() { return haveUnfixedSelectItemDic; } public Dictionary GetHaveAddSelectItem() { return haveAddSelectItemDic; } } public enum SelectItemType { Nomral, unfixed, addons, }