using Snxxz.UI; using System; using System.Collections.Generic; using System.Linq; using TableConfig; using UnityEngine; [XLua.LuaCallCSharp] 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; public event Action UpdateSelectItemsEvent; PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } PackModelInterface modelInterface { get { return ModelCenter.Instance.GetModel(); } } public int[] extraOneKeyPutCondis; public int[] noOneKeyPutCondis; public override void Init() { addonsTypeModel = Config.Instance.Get("ComposeAddonsType"); addonsQualityModel = Config.Instance.Get("ComposeAddonsQuality"); _addonsTypelist = ConfigParse.GetMultipleStr(addonsTypeModel.Numerical1); _addonsQualitylist = ConfigParse.GetMultipleStr(addonsQualityModel.Numerical1); FuncConfigConfig onekeyPut = Config.Instance.Get("ComposeAutoLimit"); extraOneKeyPutCondis = ConfigParse.GetMultipleStr(onekeyPut.Numerical1); noOneKeyPutCondis = ConfigParse.GetMultipleStr(onekeyPut.Numerical2); } public override void UnInit() { } public Dictionary GetUnfixedItemModel() { if (composeWinModel.CurComposeModel == null) return null; var packType = composeWinModel.GetPackTypeByMakerId(composeWinModel.CurComposeModel.makeID); SinglePackModel singlePack = playerPack.GetSinglePackModel(packType); if (singlePack == null) return null; int[] unfixedIds = composeWinModel.CurComposeModel.unfixedItemID; allBagItemInfo = singlePack.GetPackModelIndexDict(); _unfixedItemDict.Clear(); foreach (int key in allBagItemInfo.Keys) { ItemModel itemModel = allBagItemInfo[key]; if (!haveUnfixedSelectItemDic.ContainsKey(key)) { switch((RoleEquipType)itemModel.chinItemModel.EquipPlace) { case RoleEquipType.retSpiritAnimal: bool isOverdue = modelInterface.IsOverdue(itemModel.itemInfo.ItemGUID, itemModel.itemId, itemModel.useDataDict); if(isOverdue) { continue; } break; } int i = 0; for (i = 0; i < unfixedIds.Length; i++) { if (unfixedIds[i] == allBagItemInfo[key].itemInfo.ItemID) { _unfixedItemDict.Add(key, allBagItemInfo[key]); break; } } } } return _unfixedItemDict; } public Dictionary GetAddItemModel() { if (composeWinModel.CurComposeModel == null) return null; var packType = composeWinModel.GetPackTypeByMakerId(composeWinModel.CurComposeModel.makeID); SinglePackModel singlePack = playerPack.GetSinglePackModel(packType); 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++) { ItemModel itemModel = modellist[i]; int index = itemModel.itemInfo.ItemPlace; if (!haveAddSelectItemDic.ContainsKey(index)) { switch ((RoleEquipType)itemModel.chinItemModel.EquipPlace) { case RoleEquipType.retSpiritAnimal: bool isOverdue = modelInterface.IsOverdue(itemModel.itemInfo.ItemGUID, itemModel.itemId, itemModel.useDataDict); if (isOverdue) { continue; } break; } 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) { if (composeWinModel.CurComposeModel == null) return; var packType = composeWinModel.GetPackTypeByMakerId(composeWinModel.CurComposeModel.makeID); ItemModel itemModel = playerPack.GetItemModelByIndex(packType, itemPlace); if (!haveUnfixedSelectItemDic.ContainsKey(itemPlace)) { haveUnfixedSelectItemDic.Add(itemPlace, itemModel); } } public void RemoveHaveUnfixedSelectItem(int itemPlace) { if (haveUnfixedSelectItemDic.ContainsKey(itemPlace)) { haveUnfixedSelectItemDic.Remove(itemPlace); } } public void AddHaveAddSelectItem(int itemPlace) { if (composeWinModel.CurComposeModel == null) return; var packType = composeWinModel.GetPackTypeByMakerId(composeWinModel.CurComposeModel.makeID); ItemModel itemModel = playerPack.GetItemModelByIndex(packType, itemPlace); if (!haveAddSelectItemDic.ContainsKey(itemPlace)) { haveAddSelectItemDic.Add(itemPlace, itemModel); } } public void RemoveHaveAddSelectItem(int itemPlace) { if (haveAddSelectItemDic.ContainsKey(itemPlace)) { haveAddSelectItemDic.Remove(itemPlace); } } public event Action UpdateSelectEvent; public ComposeMatCell selectMatCell { get; private set; } public void SetSelectMatCell(ComposeMatCell matCell) { selectMatCell = matCell; } public void UpdateSelectItem(int itemIndex) { if (UpdateSelectEvent != null) { UpdateSelectEvent(selectMatCell,itemIndex,selectItem); } } public void UpdateSelectItems() { if (UpdateSelectItemsEvent != null) { UpdateSelectItemsEvent(); } } public void ClearSelectModel() { selectMatCell = null; haveAddSelectItemDic.Clear(); haveUnfixedSelectItemDic.Clear(); } public Dictionary GetHaveUnfixedSelectItem() { return haveUnfixedSelectItemDic; } public Dictionary GetHaveAddSelectItem() { return haveAddSelectItemDic; } } public enum SelectItemType { Nomral, unfixed, addons, }