using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
using UnityEngine.UI;
|
using UnityEngine;
|
using Snxxz.UI;
|
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class GemModel : Model, IBeforePlayerDataInitialize
|
{
|
public Dictionary<int, List<int>> equipGemTypeDict = new Dictionary<int, List<int>>();
|
public Dictionary<int, List<int>> gemGetWays = new Dictionary<int, List<int>>();
|
public Dictionary<int, int> gemHighestLevelDict = new Dictionary<int, int>();
|
public Dictionary<int, int> gemShopIds { get; private set; }
|
public int[] gemOpenArray { get; private set; }
|
public string[] equipPartNames { get; private set; }
|
public int gemVipHoleLv { get; private set; }
|
public int gemComposeCount { get; private set; }
|
|
public const int GEM_ITEMTABLE_TYPE = 25;
|
|
PackModel playerPack {
|
get { return ModelCenter.Instance.GetModel<PackModel>(); }
|
}
|
|
public override void Init()
|
{
|
ParseConfig();
|
InitRedPoint();
|
gemTagRedPoint = new Redpoint(106, GEM_REDPOINT);
|
playerPack.refreshItemCountEvent += OnRefreshPackItem;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
levelUpType = 0;
|
}
|
|
private void OnFuncStateChangeEvent(int func)
|
{
|
if (func == (int)FuncOpenEnum.Gem)
|
{
|
OnUpdateRedPoint();
|
}
|
}
|
|
private void OnRefreshPackItem(PackType packType, int index, int id)
|
{
|
if (packType != PackType.Item)
|
{
|
return;
|
}
|
OnUpdateRedPoint();
|
}
|
|
public override void UnInit()
|
{
|
playerPack.refreshItemCountEvent -= OnRefreshPackItem;
|
}
|
|
|
private void ParseConfig()
|
{
|
var config = FuncConfigConfig.Get("GemOpen");
|
gemOpenArray = ConfigParse.GetMultipleStr<int>(config.Numerical1);
|
config = FuncConfigConfig.Get("EquipArea");
|
equipPartNames = ConfigParse.GetMultipleStr(config.Numerical2);
|
|
config = FuncConfigConfig.Get("GemTypeCount");
|
var count = int.Parse(config.Numerical1);
|
for (int i = 1; i <= count; i++)
|
{
|
config = FuncConfigConfig.Get(StringUtility.Contact("GemType", i));
|
equipGemTypeDict.Add(i, new List<int>(ConfigParse.GetMultipleStr<int>(config.Numerical1)));
|
if (!string.IsNullOrEmpty(config.Numerical3))
|
{
|
gemGetWays.Add(i, new List<int>(ConfigParse.GetMultipleStr<int>(config.Numerical3)));
|
}
|
|
var level = 1;
|
var gemConfig = ItemConfig.GetGemDataByLevelAndType(level, i);
|
while (gemConfig != null && gemConfig.EffectValueA1 == i)
|
{
|
gemHighestLevelDict[i] = level;
|
level++;
|
gemConfig = ItemConfig.Get(gemConfig.EffectValueC1);
|
}
|
}
|
|
config = FuncConfigConfig.Get("GemOpenVip");
|
gemVipHoleLv = int.Parse(config.Numerical1);
|
|
config = FuncConfigConfig.Get("GemUpCostFormula");
|
gemShopIds = ConfigParse.GetDic<int, int>(config.Numerical1);
|
gemComposeCount = int.Parse(config.Numerical2);
|
}
|
|
public bool IsHightestLevelGem(int _id)
|
{
|
var _itemCfg = ItemConfig.Get(_id);
|
var _nextCfg = ItemConfig.Get(_id + 1);
|
if (_itemCfg != null && _nextCfg != null && _itemCfg.Type == _nextCfg.Type
|
&& _itemCfg.EffectValueA1 == _nextCfg.EffectValueA1)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
|
public int GemLevelUpCost(int _level, int _price)
|
{
|
return (int)Mathf.Pow(gemComposeCount, _level) * _price * (gemComposeCount - 1) / gemComposeCount;
|
}
|
|
public int GemCountByLevel(int _type, int _level, bool _bind = false, int _isBind = 0)
|
{
|
var _count = 0;
|
SinglePack singlePack = playerPack.GetSinglePack(PackType.Item);
|
var items = singlePack.GetItemsByType(GEM_ITEMTABLE_TYPE);
|
for (int i = 0; i < items.Count; i++)
|
{
|
var item = items[i];
|
ItemConfig _itemCfg = ItemConfig.Get(item.itemId);
|
if (_itemCfg.EffectValueA1 == _type && _itemCfg.EffectValueB1 == _level)
|
{
|
if (_bind)
|
{
|
if (item.isBind == _isBind)
|
{
|
_count += item.count;
|
}
|
}
|
else
|
{
|
_count += item.count;
|
}
|
}
|
}
|
return _count;
|
}
|
|
public int GetSingleGemPrice(int _type)
|
{
|
if (gemShopIds != null && gemShopIds.ContainsKey(_type))
|
{
|
int _itemId = gemShopIds[_type];
|
var _cfg = StoreConfig.GetStoreCfg(_itemId, 1);
|
if (_cfg != null)
|
{
|
return _cfg.MoneyNumber;
|
}
|
}
|
return 0;
|
}
|
|
#region 红点
|
public const int GEM_REDPOINT = 10602;
|
public const int REDPOINT_INTERVAL = 100;
|
public Redpoint gemTagRedPoint { get; private set; }
|
public List<Redpoint> redpointList = new List<Redpoint>(10);
|
public List<Redpoint> gemHoleReds = new List<Redpoint>(4);
|
public List<Redpoint> gemComposeReds = new List<Redpoint>(4);
|
#endregion
|
|
public int presentGemEquip { get; set; }
|
public int presentGemHole { get; set; }
|
public event Action<int> updateEquipPlateEvent;
|
public int levelUpType { get; set; }
|
public void UpdateEquipPlate(int _pos)
|
{
|
if (updateEquipPlateEvent != null)
|
{
|
updateEquipPlateEvent(_pos);
|
}
|
}
|
|
public void SendGemLevelUp(int pos, int hole)
|
{
|
CA306_tagCMEquipStoneUpgrade levelUp = new CA306_tagCMEquipStoneUpgrade();
|
levelUp.EquipIndex = (byte)pos;
|
if (hole == 3)
|
{
|
levelUp.HoleIndex = 10;
|
}
|
else
|
{
|
levelUp.HoleIndex = (byte)hole;
|
}
|
levelUp.UpWay = (byte)levelUpType;
|
GameNetSystem.Instance.SendInfo(levelUp);
|
}
|
|
public bool EquipHoleSatisfy(int _id, int _hole)
|
{
|
var _itemCfg = ItemConfig.Get(_id);
|
if (_hole < 3)
|
{
|
if (_itemCfg.LV >= gemOpenArray[_hole])
|
{
|
return true;
|
}
|
}
|
else if (_hole == 3)
|
{
|
if (PlayerDatas.Instance.baseData.VIPLv >= gemVipHoleLv && _itemCfg.LV >= gemOpenArray[0])
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool SatisfyCondition(int _type, int _level, out int _place, out int _hole)
|
{
|
_place = _hole = 0;
|
for (int i = 1; i <= 10; i++)
|
{
|
_place = i;
|
if (FuncConfigConfig.GetGemTypeByEquipPos(i) != _type)
|
{
|
continue;
|
}
|
var _equip = playerPack.GetItemByIndex(PackType.Equip, i);
|
if (_equip == null)
|
{
|
continue;
|
}
|
var _stones = PlayerStoneData.Instance.GetStoneInfo(i);
|
if (_stones == null || _stones.Length == 0)
|
{
|
if (EquipHoleSatisfy(_equip.itemId, 0))
|
{
|
_hole = 0;
|
}
|
return true;
|
}
|
for (int k = 0; k < _stones.Length; k++)
|
{
|
if (!EquipHoleSatisfy(_equip.itemId, k))
|
{
|
continue;
|
}
|
var _id = _stones[k];
|
if (_id == 0)
|
{
|
_hole = k;
|
return true;
|
}
|
}
|
for (int k = 0; k < _stones.Length; k++)
|
{
|
if (!EquipHoleSatisfy(_equip.itemId, k))
|
{
|
continue;
|
}
|
var _id = _stones[k];
|
var _itemCfg = ItemConfig.Get((int)_id);
|
if (_itemCfg.EffectValueB1 < _level)
|
{
|
_hole = k;
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
public bool SatisfyBetter(int _itemId)
|
{
|
var config = ItemConfig.Get(_itemId);
|
var _place = 0; var _hole = 0;
|
return SatisfyCondition(config.EffectValueA1, config.EffectValueB1, out _place, out _hole);
|
}
|
|
private Dictionary<int, Dictionary<int, bool>> gemHoleRedpoints = new Dictionary<int, Dictionary<int, bool>>();
|
|
public void OnUpdateRedPoint()
|
{
|
var _keys = gemHoleRedpoints.Keys.ToList();
|
for (int i = 0; i < _keys.Count; i++)
|
{
|
var _dict = gemHoleRedpoints[_keys[i]];
|
var _poses = _dict.Keys.ToList();
|
for (int k = 0; k < _poses.Count; k++)
|
{
|
_dict[_poses[k]] = false;
|
}
|
}
|
for (int i = 0; i < redpointList.Count; i++)
|
{
|
redpointList[i].state = RedPointState.None;
|
}
|
for (int i = 0; i < gemHoleReds.Count; i++)
|
{
|
gemHoleReds[i].state = RedPointState.None;
|
gemComposeReds[i].state = RedPointState.None;
|
}
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Gem))
|
{
|
return;
|
}
|
for (int i = 1; i <= 10; i++)
|
{
|
ItemModel item = playerPack.GetItemByIndex(PackType.Equip, i);
|
redpointList[i - 1].state = RedPointState.None;
|
if (item == null)
|
{
|
continue;
|
}
|
ItemConfig itemCfg = ItemConfig.Get((int)item.itemId);
|
List<ItemModel> list = IsBagHaveGem(FuncConfigConfig.GetGemTypeByEquipPos(item.itemPlace));
|
if (list == null || list.Count == 0)
|
{
|
continue;
|
}
|
uint[] stones = PlayerStoneData.Instance.GetStoneInfo(i);
|
for (int j = 0; j < 4; j++)
|
{
|
if (j == 3)
|
{
|
if (PlayerDatas.Instance.baseData.VIPLv < gemVipHoleLv || itemCfg.LV < gemOpenArray[0])
|
{
|
continue;
|
}
|
}
|
else
|
{
|
if (itemCfg.LV < gemOpenArray[j])
|
{
|
continue;
|
}
|
}
|
|
if ((stones != null && stones[j] != 0) && list.Count > 0)
|
{
|
if (IsSatisfyGemCompose(i, j, (int)stones[j]))
|
{
|
redpointList[i - 1].state = RedPointState.Simple;
|
continue;
|
}
|
}
|
}
|
}
|
for (int i = 1; i <= 2; i++)
|
{
|
var list = IsBagHaveGem(i);
|
if (list == null || list.Count == 0)
|
{
|
continue;
|
}
|
list.Sort((ItemModel x, ItemModel y) =>
|
{
|
return -x.itemId.CompareTo(y.itemId);
|
});
|
int _pos = 0; int _hole = 0;
|
for (int k = 0; k < list.Count; k++)
|
{
|
if (GetMinLevelGem(i, list[k].itemId, out _pos, out _hole))
|
{
|
redpointList[_pos - 1].state = RedPointState.Simple;
|
gemHoleRedpoints[_pos][_hole] = true;
|
break;
|
}
|
}
|
}
|
UpdateHoleRedpoint(presentGemEquip);
|
}
|
|
public bool GetMinLevelGem(int _type, int _itemId, out int _pos, out int _hole)
|
{
|
_pos = 0; _hole = 0;
|
int _minItemId = 0;
|
for (int i = 1; i <= 10; i++)
|
{
|
var equip = playerPack.GetItemByIndex(PackType.Equip, i);
|
if (equip == null)
|
{
|
continue;
|
}
|
if (FuncConfigConfig.GetGemTypeByEquipPos(equip.itemPlace) != _type)
|
{
|
continue;
|
}
|
var itemConfig = ItemConfig.Get((int)equip.itemId);
|
uint[] stones = PlayerStoneData.Instance.GetStoneInfo(i);
|
for (int j = 0; j < 4; j++)
|
{
|
if (j == 3)
|
{
|
if (PlayerDatas.Instance.baseData.VIPLv < gemVipHoleLv || itemConfig.LV < gemOpenArray[0])
|
{
|
continue;
|
}
|
}
|
else
|
{
|
if (itemConfig.LV < gemOpenArray[j])
|
{
|
continue;
|
}
|
}
|
|
if ((stones == null || stones[j] == 0))
|
{
|
_pos = i; _hole = j;
|
return true;
|
}
|
else
|
{
|
if (stones[j] >= _itemId)
|
{
|
continue;
|
}
|
if (_minItemId == 0 || _minItemId > stones[j])
|
{
|
_minItemId = (int)stones[j];
|
_pos = i; _hole = j;
|
}
|
}
|
}
|
}
|
if (_minItemId != 0 && !IsHightestLevelGem(_minItemId))
|
{
|
return true;
|
}
|
return false;
|
}
|
|
public void UpdateHoleRedpoint(int _index)
|
{
|
if (!gemHoleRedpoints.ContainsKey(_index))
|
{
|
return;
|
}
|
var stones = PlayerStoneData.Instance.GetStoneInfo(_index);
|
for (int i = 0; i < 4; i++)
|
{
|
bool _compose = false;
|
if (stones != null && stones[i] != 0
|
&& IsSatisfyGemCompose(_index, i, (int)stones[i]))
|
{
|
_compose = true;
|
gemComposeReds[i].state = RedPointState.Simple;
|
}
|
gemHoleReds[i].state = gemHoleRedpoints[_index][i] || _compose ? RedPointState.Simple : RedPointState.None;
|
}
|
}
|
|
public bool GetHoleRedpoint(int _index)
|
{
|
if (gemHoleRedpoints.ContainsKey(presentGemEquip))
|
{
|
return gemHoleRedpoints[presentGemEquip][_index];
|
}
|
return false;
|
}
|
|
public bool CheckEquipHole(int _pos, int _hole, int _itemId)
|
{
|
uint[] stones = PlayerStoneData.Instance.GetStoneInfo(_pos);
|
if (stones == null || stones[_hole] == 0)
|
{
|
return true;
|
}
|
return _itemId > stones[_hole];
|
}
|
|
private Dictionary<int, int> m_GemLevelCountDict = new Dictionary<int, int>();
|
public bool IsSatisfyGemCompose(int _place, int _index, int _item)
|
{
|
if (IsHightestLevelGem(_item))
|
{
|
return false;
|
}
|
var _itemCfg = ItemConfig.Get(_item);
|
var _type = FuncConfigConfig.GetGemTypeByEquipPos(_place);
|
if (GemCountByLevel(_type, _itemCfg.EffectValueB1) < 2)
|
{
|
return false;
|
}
|
m_GemLevelCountDict.Clear();
|
for (int i = _itemCfg.EffectValueB1; i <= 9; i++)
|
{
|
m_GemLevelCountDict.Add(i, GemCountByLevel(_type, i));
|
}
|
for (int i = 1; i <= 10; i++)
|
{
|
if (FuncConfigConfig.GetGemTypeByEquipPos(i) != _type)
|
{
|
continue;
|
}
|
ItemModel _equip = playerPack.GetItemByIndex(PackType.Equip, i);
|
if (_equip == null)
|
{
|
continue;
|
}
|
var itemCfg = ItemConfig.Get(_equip.itemId);
|
var _stones = PlayerStoneData.Instance.GetStoneInfo(i);
|
for (int j = 0; j < 4; j++)
|
{
|
if (j == 3)
|
{
|
if (PlayerDatas.Instance.baseData.VIPLv < gemVipHoleLv || itemCfg.LV < gemOpenArray[0])
|
{
|
continue;
|
}
|
}
|
else
|
{
|
if (itemCfg.LV < gemOpenArray[j])
|
{
|
continue;
|
}
|
}
|
if (_stones == null || _stones[j] == 0)
|
{
|
GemReduce(m_GemLevelCountDict, 0);
|
continue;
|
}
|
else
|
{
|
var _gem = _stones[j];
|
var _level = ItemConfig.Get((int)_gem).EffectValueB1;
|
GemReduce(m_GemLevelCountDict, _level);
|
}
|
}
|
}
|
if (m_GemLevelCountDict[_itemCfg.EffectValueB1] >= 2)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
private void GemReduce(Dictionary<int, int> _dict, int _level)
|
{
|
var _list = _dict.Keys.ToList();
|
for (int i = _list.Count - 1; i >= 0; i--)
|
{
|
if (_level < _list[i] && _dict[_list[i]] > 0)
|
{
|
_dict[_list[i]]--;
|
break;
|
}
|
}
|
}
|
|
public List<ItemModel> IsBagHaveGem(int type)
|
{
|
SinglePack singlePack = playerPack.GetSinglePack(PackType.Item);
|
var items = singlePack.GetItemsByType(GEM_ITEMTABLE_TYPE);
|
|
if (items != null && items.Count > 0)
|
{
|
for (int i = 0; i < items.Count; i++)
|
{
|
var item = items[i];
|
ItemConfig cfg = ItemConfig.Get((int)item.itemId);
|
if (cfg.EffectValueA1 != type)
|
{
|
items.RemoveAt(i);
|
i--;
|
}
|
}
|
}
|
return items;
|
}
|
|
public void InitRedPoint()
|
{
|
for (int i = 1; i <= 10; i++)
|
{
|
Redpoint redpoint = new Redpoint(GEM_REDPOINT, GEM_REDPOINT * REDPOINT_INTERVAL + i);
|
redpointList.Add(redpoint);
|
redpoint.state = RedPointState.None;
|
Dictionary<int, bool> dict = new Dictionary<int, bool>();
|
for (int k = 0; k < 4; k++)
|
{
|
dict.Add(k, false);
|
}
|
gemHoleRedpoints.Add(i, dict);
|
}
|
for (int i = 1; i <= 4; i++)
|
{
|
Redpoint redpoint = new Redpoint(GEM_REDPOINT, GEM_REDPOINT * REDPOINT_INTERVAL + 10 + i);
|
gemHoleReds.Add(redpoint);
|
redpoint.state = RedPointState.None;
|
Redpoint composeRedpoint = new Redpoint(GEM_REDPOINT, GEM_REDPOINT * REDPOINT_INTERVAL + 20 + i);
|
gemComposeReds.Add(composeRedpoint);
|
composeRedpoint.state = RedPointState.None;
|
}
|
}
|
|
public RedPointState GetRedpointState(int _pos)
|
{
|
return redpointList[_pos - 1].state;
|
}
|
}
|
|
[Serializable]
|
public class GemHoleData
|
{
|
public RectTransform m_ContainerInlaied;
|
public RectTransform m_ContainerInlay;
|
public Image m_LockImg;
|
[SerializeField] Image m_GemBG;
|
public Image m_GemIcon;
|
public Text m_ConditionTxt;
|
[SerializeField] Text m_GemNameTxt;
|
[SerializeField] List<Text> m_GemPropertys;
|
[SerializeField] List<Text> m_GemPropertyValues;
|
[SerializeField] Image m_LockIcon;
|
public Text m_GemTypeTxt;
|
public UIEffect m_GemEffect;
|
public UIEffect m_GemEquipEffect;
|
public Button m_GemBtn;
|
|
public void DisplayGemProperty(int _id, int _isBind = 0)
|
{
|
var _itemCfg = ItemConfig.Get(_id);
|
m_GemNameTxt.text = _itemCfg.ItemName;
|
m_GemBG.SetItemBackGround(_itemCfg.ItemColor);
|
m_LockIcon.gameObject.SetActive(_isBind == 1);
|
var _funcCfg = FuncConfigConfig.Get("GemAttr");
|
PlayerPropertyConfig _propertyCfg = null;
|
m_GemPropertys[0].gameObject.SetActive(_itemCfg.Effect2 != 0);
|
m_GemPropertyValues[0].gameObject.SetActive(_itemCfg.Effect2 != 0);
|
if (_itemCfg.Effect2 != 0)
|
{
|
_propertyCfg = PlayerPropertyConfig.Get(_itemCfg.Effect2);
|
m_GemPropertys[0].text = _propertyCfg.Name;
|
m_GemPropertyValues[0].text = StringUtility.Contact("+", UIHelper.ReplacePercentage(_itemCfg.EffectValueA2, _propertyCfg.ISPercentage
|
, _propertyCfg.ISPercentage == 1 ? 2 : 1),
|
_propertyCfg.ISPercentage == 1 ? "%" : string.Empty);
|
}
|
m_GemPropertys[1].gameObject.SetActive(_itemCfg.Effect3 != 0);
|
m_GemPropertyValues[1].gameObject.SetActive(_itemCfg.Effect3 != 0);
|
if (_itemCfg.Effect3 != 0)
|
{
|
_propertyCfg = PlayerPropertyConfig.Get(_itemCfg.Effect3);
|
m_GemPropertys[1].text = _propertyCfg.Name;
|
m_GemPropertyValues[1].text = StringUtility.Contact("+", UIHelper.ReplacePercentage(_itemCfg.EffectValueA3, _propertyCfg.ISPercentage
|
, _propertyCfg.ISPercentage == 1 ? 2 : 1),
|
_propertyCfg.ISPercentage == 1 ? "%" : string.Empty);
|
}
|
m_GemPropertys[2].gameObject.SetActive(_itemCfg.Effect4 != 0);
|
m_GemPropertyValues[2].gameObject.SetActive(_itemCfg.Effect4 != 0);
|
if (_itemCfg.Effect4 != 0)
|
{
|
_propertyCfg = PlayerPropertyConfig.Get(_itemCfg.Effect4);
|
m_GemPropertys[2].text = _propertyCfg.Name;
|
m_GemPropertyValues[2].text = StringUtility.Contact("+", UIHelper.ReplacePercentage(_itemCfg.EffectValueA4, _propertyCfg.ISPercentage
|
, _propertyCfg.ISPercentage == 1 ? 2 : 1),
|
_propertyCfg.ISPercentage == 1 ? "%" : string.Empty);
|
}
|
}
|
}
|
}
|
|