using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
|
public class SelectEquipModel : Model
|
{
|
ComposeWinModel composeWinModel { get { return ModelCenter.Instance.GetModel<ComposeWinModel>(); } }
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
private Dictionary<int, ItemModel> _unfixedItemDict = new Dictionary<int, ItemModel>(); //key 物品在背包索引
|
private Dictionary<int, ItemModel> _addonsItemDict = new Dictionary<int, ItemModel>(); //key 物品在背包索引
|
private List<int> addonsTypelist = new List<int>();
|
private int[] _addonsQualitylist = null;
|
private Dictionary<int, ItemModel> allBagItemInfo;
|
|
private Dictionary<int, ItemModel> haveUnfixedSelectItemDic = new Dictionary<int, ItemModel>(); //用于存储已选择添加的不固定道具
|
private Dictionary<int, ItemModel> haveAddSelectItemDic = new Dictionary<int, ItemModel>();//用于存储已选择添加的道具
|
|
public SelectItemType selectItem = SelectItemType.Nomral;
|
public event Action UpdateSelectItemsEvent;
|
|
public int[] extraOneKeyPutCondis;
|
public int[] noOneKeyPutCondis;
|
|
public override void Init()
|
{
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
public Dictionary<int, ItemModel> GetUnfixedItemModel()
|
{
|
if (composeWinModel.CurComposeModel == null) return null;
|
|
var packType = composeWinModel.GetPackTypeByMakerId(composeWinModel.CurComposeModel.makeID);
|
SinglePack singlePack = playerPack.GetSinglePack(packType);
|
if (singlePack == null) return null;
|
|
int[] unfixedIds = composeWinModel.CurComposeModel.unfixedItemID;
|
allBagItemInfo = singlePack.GetAllItems();
|
_unfixedItemDict.Clear();
|
foreach (int key in allBagItemInfo.Keys)
|
{
|
ItemModel itemModel = allBagItemInfo[key];
|
if (!haveUnfixedSelectItemDic.ContainsKey(key))
|
{
|
switch ((RoleEquipType)itemModel.config.EquipPlace)
|
{
|
case RoleEquipType.Guard:
|
bool isOverdue = ItemLogicUtility.Instance.IsOverdue(itemModel.guid);
|
if (isOverdue)
|
{
|
continue;
|
}
|
break;
|
}
|
|
int i = 0;
|
for (i = 0; i < unfixedIds.Length; i++)
|
{
|
if (unfixedIds[i] == allBagItemInfo[key].itemId)
|
{
|
_unfixedItemDict.Add(key, allBagItemInfo[key]);
|
break;
|
}
|
}
|
}
|
}
|
|
return _unfixedItemDict;
|
}
|
|
public Dictionary<int, ItemModel> GetAddItemModel()
|
{
|
if (composeWinModel.CurComposeModel == null) return null;
|
var packType = composeWinModel.GetPackTypeByMakerId(composeWinModel.CurComposeModel.makeID);
|
SinglePack singlePack = playerPack.GetSinglePack(packType);
|
if (singlePack == null) return null;
|
|
allBagItemInfo = singlePack.GetAllItems();
|
var items = allBagItemInfo.Values.ToList();
|
items.Sort(CompareByCondition);
|
_addonsItemDict.Clear();
|
|
for (int i = 0; i < items.Count; i++)
|
{
|
var item = items[i];
|
int index = item.gridIndex;
|
if (!haveAddSelectItemDic.ContainsKey(index))
|
{
|
if (ItemLogicUtility.Instance.IsOverdue(item.guid))
|
{
|
continue;
|
}
|
|
if (addonsTypelist.Contains(item.config.Type))
|
{
|
if (items[i].config.LV >= _addonsQualitylist[0] && items[i].config.ItemColor >= _addonsQualitylist[1])
|
{
|
_addonsItemDict.Add(index, items[i]);
|
}
|
}
|
}
|
}
|
|
return _addonsItemDict;
|
}
|
|
private List<ItemModel> oneKeyPutlist = new List<ItemModel>();
|
private List<ItemModel> orderOneKeylist = new List<ItemModel>();
|
public List<ItemModel> GetOneKeyPutModel()
|
{
|
GetAddItemModel();
|
oneKeyPutlist.Clear();
|
orderOneKeylist.Clear();
|
foreach (var key in _addonsItemDict.Keys)
|
{
|
int isFightUp = ItemLogicUtility.Instance.IsFightUp(_addonsItemDict[key].itemId, _addonsItemDict[key].score);
|
if (isFightUp != 1)
|
{
|
if (_addonsItemDict[key].config.ItemColor >= noOneKeyPutCondis[0]
|
&& _addonsItemDict[key].config.StarLevel >= noOneKeyPutCondis[1])
|
{
|
if (_addonsItemDict[key].config.ItemColor == extraOneKeyPutCondis[0]
|
&& _addonsItemDict[key].config.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.config.ItemColor;
|
int y = end.config.ItemColor;
|
if (x.CompareTo(y) != 0) return -x.CompareTo(y);
|
|
x = start.config.LV;
|
y = end.config.LV;
|
if (x.CompareTo(y) != 0) return -x.CompareTo(y);
|
|
x = start.config.StarLevel;
|
y = end.config.StarLevel;
|
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 startQuality = start.config.ItemColor;
|
int endQuality = end.config.ItemColor;
|
if (startQuality.CompareTo(endQuality) != 0) return startQuality.CompareTo(endQuality);
|
|
int startStarLV = start.config.StarLevel;
|
int endStarLv = end.config.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.GetItemByIndex(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.GetItemByIndex(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<ComposeMatCell, int, SelectItemType> 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<int, ItemModel> GetHaveUnfixedSelectItem()
|
{
|
return haveUnfixedSelectItemDic;
|
}
|
|
public Dictionary<int, ItemModel> GetHaveAddSelectItem()
|
{
|
return haveAddSelectItemDic;
|
}
|
}
|
|
public enum SelectItemType
|
{
|
Nomral,
|
unfixed,
|
addons,
|
}
|
|