using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using UnityEngine.UI;
|
using System.Linq;
|
using LitJson;
|
using UnityEngine;
|
|
public class EquipEvolveModel : ILModel<EquipEvolveModel>
|
{
|
EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
public int resultFromEquipID; //进阶前记录的装备
|
public int resultToEquipID; //进阶成功后的装备
|
public Dictionary<int, int> fromEquipLegends = new Dictionary<int, int>(); //进阶前的传奇属性 id:value
|
public List<int> shenGirdIndexs = new List<int>(); //神装在背包中的索引
|
public List<int> shenDecomSelects = new List<int>(); //待分解的神装选中索引
|
public Dictionary<int, int> shenDecomMaterials = new Dictionary<int, int>(); //分解材料所得预览 id:count
|
public int[][] decomposeItem;
|
public Int2 materialJumpPos; //物品跳转(装备 材料)
|
|
public event Action SelectLevelEvent; //境界标签
|
public event Action SelectPlaceEvent; //装备位
|
public event Action SelectShenDecomEvent; //选中分解神装
|
|
public float decomPer;
|
private int m_SelectLevelType;
|
public int selectLevelType
|
{
|
get { return m_SelectLevelType; }
|
set
|
{
|
if (m_SelectLevelType != value)
|
{
|
m_SelectLevelType = value;
|
SelectLevelEvent?.Invoke();
|
}
|
}
|
}
|
|
private int m_SelectPlaceType;
|
public int selectPlaceType
|
{
|
get { return m_SelectPlaceType; }
|
set
|
{
|
if (m_SelectPlaceType != value)
|
{
|
m_SelectPlaceType = value;
|
SelectPlaceEvent?.Invoke();
|
}
|
}
|
}
|
protected override void Init()
|
{
|
GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
|
|
decomPer = int.Parse(FuncConfigConfig.Get("EquipShenDecompose").Numerical1)/100.0f;
|
}
|
|
protected override void UnInit()
|
{
|
GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
|
}
|
|
|
void ParseConfig()
|
{
|
|
}
|
|
|
void OnBeforePlayerDataInitialize()
|
{
|
m_SelectLevelType = 0;
|
m_SelectPlaceType = 0;
|
}
|
|
//进入后默认选中最低级境界的首件装备,若有满足可进阶的装备优先选中,次之选不满足的进阶红装
|
public Int2 FindSatisfyEquip()
|
{
|
Dictionary<int, int> materialCnts = new Dictionary<int, int>();
|
|
//材料类型少,先遍历数量
|
for (int i = 0; i < ILEquipShenEvolveConfig.materialIDs.Count; i++)
|
{
|
materialCnts[ILEquipShenEvolveConfig.materialIDs[i]] = packModel.GetItemCountByID(PackType.Item, ILEquipShenEvolveConfig.materialIDs[i]);
|
}
|
|
Int2 redEquipBak = Int2.zero; //备份一个材料不够的红装
|
|
//查找材料足够的红装
|
var equipSets = equipModel.GetUnLockedEquipSets();
|
for (int i = 0; i < equipSets.Count; i++)
|
{
|
//莲台没有进阶
|
for (int j = 1; j < 12; j++)
|
{
|
var position = new Int2(equipSets[i], j);
|
var equipGuid = equipModel.GetEquip(position);
|
if (string.IsNullOrEmpty(equipGuid))
|
{
|
continue;
|
}
|
var equipItem = packModel.GetItemByGuid(equipGuid);
|
var materials = ILEquipShenEvolveConfig.TryGetMaterial(equipItem.itemId);
|
if (materials == null)
|
{
|
continue;
|
}
|
|
bool enough = true;
|
for (int k = 0; k < materials.Length; k++)
|
{
|
int needCnt = materials[k][1];
|
int curCnt = materialCnts[materials[k][0]];
|
if (needCnt > curCnt)
|
{
|
enough = false;
|
if (redEquipBak == Int2.zero)
|
{
|
redEquipBak = new Int2(equipSets[i], j);
|
}
|
break;
|
}
|
}
|
if (enough)
|
return new Int2(equipSets[i], j);
|
|
}
|
}
|
if (redEquipBak != Int2.zero)
|
{
|
return redEquipBak;
|
}
|
return new Int2(1, 1);
|
}
|
|
|
|
//底层c#调用
|
//使用材料跳转,规则同FindSatisfyEquip 装备范围不同
|
public void UseMaterialJump(int itemID)
|
{
|
Dictionary<int, int> materialCnts = new Dictionary<int, int>();
|
|
//材料类型少,先遍历数量
|
for (int i = 0; i < ILEquipShenEvolveConfig.materialIDs.Count; i++)
|
{
|
materialCnts[ILEquipShenEvolveConfig.materialIDs[i]] = packModel.GetItemCountByID(PackType.Item, ILEquipShenEvolveConfig.materialIDs[i]);
|
}
|
|
Int2 redEquipBak = Int2.zero; //备份一个材料不够的红装
|
|
if (!ILEquipShenEvolveConfig.materialToEquipPos.ContainsKey(itemID))
|
{
|
materialJumpPos = new Int2(1, 1);
|
return ;
|
}
|
|
//查找材料足够的红装
|
var equipSets = ILEquipShenEvolveConfig.materialToEquipPos[itemID];
|
for (int i = 0; i < equipSets.Count; i++)
|
{
|
|
var position = equipSets[i];
|
var equipGuid = equipModel.GetEquip(position);
|
if (string.IsNullOrEmpty(equipGuid))
|
{
|
continue;
|
}
|
var equipItem = packModel.GetItemByGuid(equipGuid);
|
var materials = ILEquipShenEvolveConfig.TryGetMaterial(equipItem.itemId);
|
if (materials == null)
|
{
|
continue;
|
}
|
|
bool hasItem = false;
|
for (int k = 0; k < materials.Length; k++)
|
{
|
|
if (materials[k][0] == itemID)
|
{
|
hasItem = true;
|
}
|
}
|
if (!hasItem) continue;
|
|
bool enough = true;
|
for (int k = 0; k < materials.Length; k++)
|
{
|
int needCnt = materials[k][1];
|
int curCnt = materialCnts[materials[k][0]];
|
if (needCnt > curCnt)
|
{
|
enough = false;
|
if (redEquipBak == Int2.zero)
|
{
|
redEquipBak = equipSets[i];
|
}
|
break;
|
}
|
}
|
if (enough)
|
{
|
materialJumpPos = equipSets[i];
|
return;
|
}
|
}
|
if (redEquipBak != Int2.zero)
|
{
|
materialJumpPos = redEquipBak;
|
return;
|
}
|
materialJumpPos = new Int2(1, 1);
|
return;
|
}
|
|
public void EquipJump(int x, int y)
|
{
|
materialJumpPos = new Int2(x, y);
|
}
|
|
|
//判断红装品质 1神 2仙 3极 4普通
|
public int GetRedEquipQuality(int itemID)
|
{
|
var equip = EquipShenAttrConfig.Get(itemID);
|
if (equip == null)
|
{
|
return 4;
|
}
|
if (equip.ShenAttrID.Length != 0)
|
{
|
return 1;
|
}
|
if (equip.XianAttrID.Length != 0)
|
{
|
return 2;
|
}
|
if (equip.JiAttrID.Length != 0)
|
{
|
return 3;
|
}
|
|
return 4;
|
}
|
|
//获得最终极进阶装备
|
public int GetFinalEvolveEquip(int equipID)
|
{
|
for (int i = 0; i < 10; i++)
|
{
|
var info = ILEquipShenEvolveConfig.Get(equipID);
|
if (info == null)
|
{
|
return equipID;
|
}
|
equipID = info.EvolveID;
|
}
|
|
return equipID;
|
}
|
|
|
public void OnSelectShenDecom()
|
{
|
SelectShenDecomEvent?.Invoke();
|
}
|
|
public bool IsShowEvolveBtn(int itemID)
|
{
|
if (!FuncOpen.Instance.IsFuncOpen(196))
|
{
|
return false;
|
}
|
|
if (ILEquipShenEvolveConfig.Has(itemID))
|
return true;
|
|
return false;
|
}
|
}
|