using System; using System.Collections.Generic; using System.Linq; using System.Text; using TableConfig; using UnityEngine.UI; using UnityEngine; using Snxxz.UI; namespace Snxxz.UI { public class GemModel : Model, IBeforePlayerDataInitialize { PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } public override void Init() { ParseGemOpen(); ParseGemOpenVip(); ParseGemFormula(); InitRedPoint(); gemTagRedPoint = new Redpoint(106, GEM_REDPOINT); playerPack.RefreshItemCountAct += 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.rptItem) { return; } OnUpdateRedPoint(); } public override void UnInit() { playerPack.RefreshItemCountAct -= OnRefreshPackItem; } #region 配置 public const int GEM_ITEMTABLE_TYPE = 25; public int[] gemOpenArray = null; private void ParseGemOpen() { FuncConfigConfig cfg = Config.Instance.Get("GemOpen"); if (cfg != null) { gemOpenArray = ConfigParse.GetMultipleStr(cfg.Numerical1); } } public int gemVipHoleLv { get; private set; } private void ParseGemOpenVip() { FuncConfigConfig cfg = Config.Instance.Get("GemOpenVip"); if (cfg != null) { gemVipHoleLv = int.Parse(cfg.Numerical1); } } public bool IsHightestLevelGem(int _id) { var _itemCfg = Config.Instance.Get(_id); var _nextCfg = Config.Instance.Get(_id + 1); if (_itemCfg != null && _nextCfg != null && _itemCfg.Type == _nextCfg.Type && _itemCfg.EffectValueA1 == _nextCfg.EffectValueA1) { return false; } return true; } public Dictionary gemShopIds = null; public int gemComposeCount { get; private set; } private void ParseGemFormula() { FuncConfigConfig cfg = Config.Instance.Get("GemUpCostFormula"); if (cfg != null) { gemShopIds = ConfigParse.GetDic(cfg.Numerical1); gemComposeCount = int.Parse(cfg.Numerical2); } } 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; SinglePackModel singlePack = playerPack.GetSinglePackModel(PackType.rptItem); List _list = null; singlePack.GetItemCountByType(GEM_ITEMTABLE_TYPE, out _list); for (int i = 0; i < _list.Count; i++) { ItemModel _itemModel = _list[i]; ItemConfig _itemCfg = Config.Instance.Get(_itemModel.itemInfo.ItemID); if (_itemCfg.EffectValueA1 == _type && _itemCfg.EffectValueB1 == _level) { if (_bind) { if (_itemModel.itemInfo.IsBind == _isBind) { _count += _itemModel.itemInfo.ItemCount; } } else { _count += _itemModel.itemInfo.ItemCount; } } } 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; } } DebugEx.LogError("表格配置错误"); return 0; } #endregion #region 红点 public const int GEM_REDPOINT = 10602; public const int REDPOINT_INTERVAL = 100; public Redpoint gemTagRedPoint { get; private set; } public List redpointList = new List(10); public List gemHoleReds = new List(4); public List gemComposeReds = new List(4); #endregion public int presentGemEquip { get; set; } public int presentGemHole { get; set; } public event Action 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 == 4) { levelUp.HoleIndex = 10; } else { levelUp.HoleIndex = (byte)(hole - 1); } levelUp.UpWay = (byte)levelUpType; GameNetSystem.Instance.SendInfo(levelUp); } public bool EquipHoleSatisfy(int _id, int _hole) { var _itemCfg = Config.Instance.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.GetItemModelByIndex(PackType.rptEquip, 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 = Config.Instance.Get((int)_id); if (_itemCfg.EffectValueB1 < _level) { _hole = k; return true; } } } return false; } public bool SatisfyBetter(int _itemId) { var config = Config.Instance.Get(_itemId); var _place = 0; var _hole = 0; return SatisfyCondition(config.EffectValueA1, config.EffectValueB1, out _place, out _hole); } /*旧版红点规则 public void OnUpdateRedPoint() { if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Gem)) { return; } UpdateHoleRedpoint(presentGemEquip); for (int i = 1; i <= 10; i++) { ItemModel item = playerPack.GetItemModelByIndex(PackType.rptEquip, i); redpointList[i - 1].state = RedPointState.None; if (item != null) { ItemConfig itemCfg = Config.Instance.Get((int)item.itemInfo.ItemID); List list = IsBagHaveGem(FuncConfigConfig.GetGemTypeByEquipPos(item.itemInfo.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) { redpointList[i - 1].state = RedPointState.Simple; break; } else { bool _replace = false; foreach (var gemItem in list) { if (gemItem.itemInfo.ItemID > stones[j]) { redpointList[i - 1].state = RedPointState.Simple; _replace = true; break; } } if (!_replace && IsSatisfyGemCompose(i, j, (int)stones[j])) { redpointList[i - 1].state = RedPointState.Simple; continue; } } } } } } public void UpdateHoleRedpoint(int _index) { 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; } ItemModel item = playerPack.GetItemModelByIndex(PackType.rptEquip, _index); if (item != null) { ItemConfig itemCfg = Config.Instance.Get((int)item.itemInfo.ItemID); List list = IsBagHaveGem(FuncConfigConfig.GetGemTypeByEquipPos(item.itemInfo.ItemPlace)); if (list == null || list.Count == 0) { return; } uint[] stones = PlayerStoneData.Instance.GetStoneInfo(_index); 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) { gemHoleReds[j].state = RedPointState.Simple; continue; } else { bool _replace = false; foreach (var gemItem in list) { if (gemItem.itemInfo.ItemID > stones[j]) { gemHoleReds[j].state = RedPointState.Simple; _replace = true; break; } } if (!_replace && IsSatisfyGemCompose(_index, j, (int)stones[j])) { gemComposeReds[j].state = RedPointState.Simple; gemHoleReds[j].state = RedPointState.Simple; continue; } } } } }*/ private Dictionary> gemHoleRedpoints = new Dictionary>(); 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.GetItemModelByIndex(PackType.rptEquip, i); redpointList[i - 1].state = RedPointState.None; if (item == null) { continue; } ItemConfig itemCfg = Config.Instance.Get((int)item.itemInfo.ItemID); List list = IsBagHaveGem(FuncConfigConfig.GetGemTypeByEquipPos(item.itemInfo.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.GetItemModelByIndex(PackType.rptEquip, i); if (equip == null) { continue; } if (FuncConfigConfig.GetGemTypeByEquipPos(equip.itemInfo.ItemPlace) != _type) { continue; } var itemConfig = Config.Instance.Get((int)equip.itemInfo.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 m_GemLevelCountDict = new Dictionary(); public bool IsSatisfyGemCompose(int _place, int _index, int _item) { if (IsHightestLevelGem(_item)) { return false; } var _itemCfg = Config.Instance.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.GetItemModelByIndex(PackType.rptEquip, i); if (_equip == null) { continue; } var itemCfg = Config.Instance.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 = Config.Instance.Get((int)_gem).EffectValueB1; GemReduce(m_GemLevelCountDict, _level); } } } if (m_GemLevelCountDict[_itemCfg.EffectValueB1] >= 2) { return true; } return false; } private void GemReduce(Dictionary _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 IsBagHaveGem(int type) { List list = null; SinglePackModel singlePack = playerPack.GetSinglePackModel(PackType.rptItem); singlePack.GetItemCountByType(GEM_ITEMTABLE_TYPE, out list); if (list != null && list.Count > 0) { for (int i = 0; i < list.Count; i++) { ItemModel item = list[i]; ItemConfig cfg = Config.Instance.Get((int)item.itemInfo.ItemID); if (cfg.EffectValueA1 != type) { list.RemoveAt(i); i--; } } } return list; } 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 dict = new Dictionary(); 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 m_GemPropertys; [SerializeField] List 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 = Config.Instance.Get(_id); m_GemNameTxt.text = _itemCfg.ItemName; m_GemBG.SetItemBackGround(_itemCfg.ItemColor); m_LockIcon.gameObject.SetActive(_isBind == 1); var _funcCfg = Config.Instance.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 = Config.Instance.Get(_itemCfg.Effect2); m_GemPropertys[0].text = _propertyCfg.Name; m_GemPropertyValues[0].text = StringUtility.Contact("+", UIHelper.ReplacePercentage(_itemCfg.EffectValueA2, _propertyCfg.ISPercentage), _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 = Config.Instance.Get(_itemCfg.Effect3); m_GemPropertys[1].text = _propertyCfg.Name; m_GemPropertyValues[1].text = StringUtility.Contact("+", UIHelper.ReplacePercentage(_itemCfg.EffectValueA3, _propertyCfg.ISPercentage), _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 = Config.Instance.Get(_itemCfg.Effect4); m_GemPropertys[2].text = _propertyCfg.Name; m_GemPropertyValues[2].text = StringUtility.Contact("+", UIHelper.ReplacePercentage(_itemCfg.EffectValueA4, _propertyCfg.ISPercentage), _propertyCfg.ISPercentage == 1 ? "%" : string.Empty); } } } }