using System; using System.Collections.Generic; using UnityEngine; using TableConfig; using Snxxz.UI; using System.Linq; public class WashProValue { public int XLAttrValue; // 当前属性值 public int XLAttrChange; // 洗练操作属性值, 当大于0时代表当前部位有还未确认的洗练结果, 与当前属性值相减得出洗练正负 public int addAttrValue; //增加洗练属性值 public WashState washState; } public enum WashState { None, //未洗练 MustWash, //必增洗练 normalWash, //普通洗练 } public class WashProCount { public int EquipPlace; // 装备位 public int XLAttrLV; // 洗练等级 public int XLAttrCnt; // 属性条数 public bool isPutOn = false; public string placeName = ""; public WashProValue[] proValuelist = null; // 属性列表,索引0的代表属性1,依次递增 } public class EquipWashModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, IPlayerLoginOk { public delegate void OnRefreshWashModel(); public event OnRefreshWashModel RefreshWashModelEvent; private Dictionary washEquipProDict = new Dictionary(); private FuncConfigConfig funcModel; private Dictionary _equipWashLimitDict; private List orderWashProlist = new List(); PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } private bool _isWashUI = true; public bool isWashUI { get { return _isWashUI; } set { _isWashUI = value; } } public bool isMustAddAttr { get; private set; } private bool FirstLogin = true; private void RefreshItemCount(PackType arg1, int arg2, int arg3) { switch (arg1) { case PackType.rptEquip: GetWashModellist(); break; case PackType.rptItem: if (arg3 == 5303) { GetWashModellist(); } break; } } private void WashFuncOpen(int obj) { if (obj != 91) return; GetWashModellist(); } public override void Init() { _equipWashLimitDict = null; funcModel = Config.Instance.Get("EquipWashMaxLV"); if (funcModel != null) _equipWashLimitDict = ConfigParse.GetDic(funcModel.Numerical1); } public override void UnInit() { FuncOpen.Instance.OnFuncStateChangeEvent -= WashFuncOpen; playerPack.RefreshItemCountAct -= RefreshItemCount; } public void OnBeforePlayerDataInitialize() { FirstLogin = true; isMustAddAttr = false; funcModel = null; _isWashUI = true; FuncOpen.Instance.OnFuncStateChangeEvent -= WashFuncOpen; playerPack.RefreshItemCountAct -= RefreshItemCount; InitWashModel(); } public void OnAfterPlayerDataInitialize() { FuncOpen.Instance.OnFuncStateChangeEvent += WashFuncOpen; playerPack.RefreshItemCountAct += RefreshItemCount; SetWashEquipRedPointlist(); GetWashModellist(); } public void OnPlayerLoginOk() { isMustAddAttr = true; FirstLogin = false; PlayerPrefs.DeleteKey(MasterGroup1ActiveKey); PlayerPrefs.DeleteKey(MasterGroup2ActiveKey); PlayerPrefs.DeleteKey(MasterGroup3ActiveKey); PlayerPrefs.DeleteKey(MasterGroup1RaiseKey); PlayerPrefs.DeleteKey(MasterGroup2RaiseKey); PlayerPrefs.DeleteKey(MasterGroup3RaiseKey); CheckIsMasterLv(); } public int[] washPlacelist { get; private set; } public List washProlist { get; private set; } private void InitWashModel() { FuncConfigConfig washDisPlayer = Config.Instance.Get("StrengthenDisplay"); washPlacelist = ConfigParse.GetMultipleStr(washDisPlayer.Numerical1); washEquipProDict.Clear(); if (washPlacelist != null) { for (int i = 0; i < washPlacelist.Length; i++) { WashProCount proCount = new WashProCount(); proCount.EquipPlace = washPlacelist[i]; proCount.isPutOn = false; proCount.XLAttrCnt = 3; proCount.XLAttrLV = 1; proCount.proValuelist = new WashProValue[proCount.XLAttrCnt]; if (proCount.XLAttrCnt > 0) { for (int j = 0; j < proCount.XLAttrCnt; j++) { proCount.proValuelist[j] = new WashProValue(); proCount.proValuelist[j].XLAttrValue = 0; proCount.proValuelist[j].XLAttrChange = 0; proCount.proValuelist[j].addAttrValue = 0; proCount.proValuelist[j].washState = WashState.None; } } washEquipProDict.Add(washPlacelist[i], proCount); } } washProlist = washEquipProDict.Values.ToList(); } public void ReFreshModel(HA3BB_tagMCEquipPartXLAttrInfo info) { for (int i = 0; i < info.Count; i++) { if (washEquipProDict.ContainsKey(info.InfoList[i].EquipPlace)) { WashProCount proCount = washEquipProDict[info.InfoList[i].EquipPlace]; proCount.EquipPlace = info.InfoList[i].EquipPlace; proCount.XLAttrLV = info.InfoList[i].XLAttrLV; proCount.XLAttrCnt = info.InfoList[i].XLAttrCnt; proCount.isPutOn = false; if (proCount.XLAttrCnt > 0) { for (int j = 0; j < proCount.XLAttrCnt; j++) { proCount.proValuelist[j].XLAttrChange = (int)info.InfoList[i].XLAttrList[j].XLAttrChange; if (proCount.proValuelist[j].XLAttrChange <= 0) { proCount.proValuelist[j].addAttrValue = (int)info.InfoList[i].XLAttrList[j].XLAttrValue - proCount.proValuelist[j].XLAttrValue; switch (proCount.proValuelist[j].washState) { case WashState.None: if (isMustAddAttr) { if (proCount.proValuelist[j].addAttrValue > 0) { proCount.proValuelist[j].washState = WashState.MustWash; } } break; case WashState.MustWash: proCount.proValuelist[j].washState = WashState.None; break; case WashState.normalWash: proCount.proValuelist[j].washState = WashState.None; break; } } else { proCount.proValuelist[j].washState = WashState.normalWash; proCount.proValuelist[j].addAttrValue = 0; } proCount.proValuelist[j].XLAttrValue = (int)info.InfoList[i].XLAttrList[j].XLAttrValue; } } } } if (RefreshWashModelEvent != null) RefreshWashModelEvent(); if (!FirstLogin) { CheckIsMasterLv(); } GetWashModellist(); } //设置洗练数据的排列顺序 public void SetModelOrder() { orderWashProlist.Clear(); orderWashProlist.AddRange(washProlist); SinglePackModel rptEquipPack = playerPack.GetSinglePackModel(PackType.rptEquip); Dictionary itemPlaceDict = null; if (rptEquipPack != null) { itemPlaceDict = rptEquipPack.GetPackModelIndexDict(); } int i = 0; for (i = 0; i < washPlacelist.Length; i++) { if (washEquipProDict.ContainsKey(washPlacelist[i])) { if (itemPlaceDict != null) { if (itemPlaceDict.ContainsKey(washPlacelist[i])) { washEquipProDict[washPlacelist[i]].isPutOn = true; } else { washEquipProDict[washPlacelist[i]].isPutOn = false; } } } } orderWashProlist.Sort(CompareByIsPutOn); } public int CompareByIsPutOn(WashProCount start, WashProCount end) { bool startIsput = start.isPutOn; bool endIsPut = end.isPutOn; if (startIsput.CompareTo(endIsPut) != 0) return -startIsput.CompareTo(endIsPut); int startIndex = washProlist.IndexOf(start); int endIndex = washProlist.IndexOf(end); if (startIndex.CompareTo(endIndex) != 0) return startIndex.CompareTo(endIndex); return 0; } public List GetWashModellist() { SetModelOrder(); ReachWashCondition(); return orderWashProlist; } public Dictionary GetWashInfoDict() { return washEquipProDict; } public WashProCount GetWashEquipInfo(int equipPlace) { if (washEquipProDict.ContainsKey(equipPlace)) return washEquipProDict[equipPlace]; else return null; } //得到洗练群组类型 public int OnGetWashType(int itemPlace) { FuncConfigConfig washGroup1Model = Config.Instance.Get("EquipWashGroup1"); FuncConfigConfig washGroup2Model = Config.Instance.Get("EquipWashGroup2"); FuncConfigConfig washGroup3Model = Config.Instance.Get("EquipWashGroup3"); int[] _equipPlacelist1 = ConfigParse.GetMultipleStr(washGroup1Model.Numerical1); int[] _equipPlacelist2 = ConfigParse.GetMultipleStr(washGroup2Model.Numerical1); int[] _equipPlacelist3 = ConfigParse.GetMultipleStr(washGroup3Model.Numerical1); int i = 0; for (i = 0; i < _equipPlacelist1.Length; i++) { if (_equipPlacelist1[i] == itemPlace) return 1; } for (i = 0; i < _equipPlacelist2.Length; i++) { if (_equipPlacelist2[i] == itemPlace) return 2; } for (i = 0; i < _equipPlacelist3.Length; i++) { if (_equipPlacelist3[i] == itemPlace) return 3; } return 0; } public List washGroup1 = null; public List washGroup2 = null; public List washGroup3 = null; //得到大师洗练的数据 public void OnGetMasterModel(List washInfolist) { washGroup1 = new List(); washGroup2 = new List(); washGroup3 = new List(); int i = 0; for (i = 0; i < washInfolist.Count; i++) { if (OnGetWashType(washInfolist[i].EquipPlace) == 1) washGroup1.Add(washInfolist[i]); else if (OnGetWashType(washInfolist[i].EquipPlace) == 2) washGroup2.Add(washInfolist[i]); else if (OnGetWashType(washInfolist[i].EquipPlace) == 3) washGroup3.Add(washInfolist[i]); } if (washGroup1.Count > 1) washGroup1.Sort(Compare); if (washGroup2.Count > 1) washGroup2.Sort(Compare); if (washGroup3.Count > 1) washGroup3.Sort(Compare); } public int Compare(WashProCount start, WashProCount next) { int startLevel = start.XLAttrLV; int nextLevel = next.XLAttrLV; if (startLevel.CompareTo(nextLevel) != 0) return startLevel.CompareTo(nextLevel); return 0; } //得到当前装备的洗练数值 public int[] WashProValues(int itemPlace) { if (washEquipProDict.ContainsKey(itemPlace)) { int[] values = new int[washEquipProDict[itemPlace].proValuelist.Length]; int i = 0; for (i = 0; i < washEquipProDict[itemPlace].proValuelist.Length; i++) { values[i] = (int)washEquipProDict[itemPlace].proValuelist[i].XLAttrValue; } return values; } else { return null; } } /// /// 得打装备等级对应的最大洗练等级 /// /// /// public int GetWashFullLv(int equipLv) { if (_equipWashLimitDict == null) return 0; if (_equipWashLimitDict.ContainsKey(equipLv)) return _equipWashLimitDict[equipLv]; else return 0; } /// /// 判断当前装备是否洗练满阶 /// /// private ItemConfig chinItemModel; public bool IsWashFull(ItemModel model, WashProCount washPro, EquipWashConfig tagEquipWash) { if (model == null) return false; chinItemModel = Config.Instance.Get((int)model.itemInfo.ItemID); int fullLv = GetWashFullLv(chinItemModel.LV); if (washPro.XLAttrLV == fullLv) { if (washPro.proValuelist[0].XLAttrValue < tagEquipWash.attMax1) { return false; } if (washPro.proValuelist[1].XLAttrValue < tagEquipWash.attMax2) { return false; } if (washPro.proValuelist[2].XLAttrValue < tagEquipWash.attMax3) { return false; } return true; } else if (washPro.XLAttrLV > fullLv) { return true; } else return false; } public bool IsCanWash(ItemModel model) { if (model == null || _equipWashLimitDict == null) return false; chinItemModel = Config.Instance.Get((int)model.itemInfo.ItemID); int[] equipLvs = _equipWashLimitDict.Keys.ToArray(); if (chinItemModel.LV >= equipLvs[0]) return true; else return false; } public int WashMinLV() { if (_equipWashLimitDict == null) return -1; int[] equipLvs = _equipWashLimitDict.Keys.ToArray(); return equipLvs[0]; } /// /// 得到装备位最大洗练等级 /// /// public int GetMaxWashLv() { if (_equipWashLimitDict == null) return 0; int[] washLvs = _equipWashLimitDict.Values.ToArray(); return washLvs[washLvs.Length - 1]; } public string GetCurWashLvStr(WashProCount washPro, EquipWashConfig tagEquipWash) { int maxWashLv = GetMaxWashLv(); if (washPro.XLAttrLV < maxWashLv) { return Language.Get("EquipWash108", washPro.XLAttrLV); } else { if (washPro.proValuelist[0].XLAttrValue < tagEquipWash.attMax1) { return Language.Get("EquipWash109"); } if (washPro.proValuelist[1].XLAttrValue < tagEquipWash.attMax2) { return Language.Get("EquipWash109"); } if (washPro.proValuelist[2].XLAttrValue < tagEquipWash.attMax3) { return Language.Get("EquipWash109"); } return Language.Get("EquipWash110"); } } /// /// 判断当前洗练装备是否保存洗练数值 /// /// /// public bool IsSaveWashValue(WashProCount washPro) { int i = 0; for (i = 0; i < washPro.proValuelist.Length; i++) { if (washPro.proValuelist[i].XLAttrChange != 0) { return false; } } return true; } public bool IsEnoughMat(EquipWashConfig tagWashModel) { if (playerPack.GetItemCountByID(PackType.rptItem, tagWashModel.costItem) >= tagWashModel.costCount) return true; else return false; } public void SendWashQuest(int equipPlace, int code) { CA325_tagCMEquipXLAttrChange equipWash = new CA325_tagCMEquipXLAttrChange(); equipWash.EquipPlace = (byte)equipPlace; equipWash.CheckUseGoldAttr = (byte)code; GameNetSystem.Instance.SendInfo(equipWash); } #region 红点逻辑处理 public List washEquipRedPointlist { get; private set; } public const int WashBtnRed_Key = 1060501; public Redpoint washBtnRedpoint = new Redpoint(WashBtnRed_Key); public void SetWashEquipRedPointlist() { washEquipRedPointlist = new List(); int i = 0; for (i = 0; i < 10; i++) { int id = MainRedDot.RedPoint_WashFuncKey * 1000 + i; Redpoint washRedPoint = new Redpoint(MainRedDot.RedPoint_WashFuncKey, id); washEquipRedPointlist.Add(washRedPoint); } } Dictionary RedpointWashDict = new Dictionary(); public int JumpToIndex { get; set;} public void ReachWashCondition() { RedpointWashDict.Clear(); JumpToIndex = 0; int i = 0; for(i = 0; i < orderWashProlist.Count; i++) { washEquipRedPointlist[i].state = RedPointState.None; } for (i = 0; i < orderWashProlist.Count; i++) { ItemModel model = playerPack.GetItemModelByIndex(PackType.rptEquip, orderWashProlist[i].EquipPlace); EquipWashConfig washModel = EquipWashConfig.GetCurrentWashEquipModel(OnGetWashType(orderWashProlist[i].EquipPlace), orderWashProlist[i].XLAttrLV); if (model != null && washModel != null) { if (IsCanWash(model) && IsEnoughMat(washModel) && !IsWashFull(model, orderWashProlist[i], washModel) && FuncOpen.Instance.IsFuncOpen(91)) { RedpointWashDict.Add(i, orderWashProlist[i]); } } } List redpointlist = RedpointWashDict.Values.ToList(); redpointlist.Sort(CompareByLv); foreach(var key in RedpointWashDict.Keys) { if(RedpointWashDict[key].EquipPlace == redpointlist[0].EquipPlace) { washEquipRedPointlist[key].state = RedPointState.Simple; JumpToIndex = key; return; } } } public int CompareByLv(WashProCount start,WashProCount end) { int startLv = start.XLAttrLV; int endLv = end.XLAttrLV; if (startLv.CompareTo(endLv) != 0) return startLv.CompareTo(endLv); int startIndex = orderWashProlist.IndexOf(start); int endIndex = orderWashProlist.IndexOf(end); if (startIndex.CompareTo(endIndex) != 0) return startIndex.CompareTo(endIndex); return 0; } #endregion public string GetProValueTypeStr(PlayerPropertyConfig playerproModel, int value) { string s = ""; if (playerproModel.ISPercentage == 0) { s = value.ToString(); } else if (playerproModel.ISPercentage == 1) { s = (float)Math.Round(value / 100f, 1) + "%"; } else if (playerproModel.ISPercentage == 2) { s = ((float)Math.Round(value / 100f, 1)).ToString(); } return s; } #region 大师洗练数据 public int washType { get; private set; } public int washLv { get; private set; } public void SetWashMasterModel(int type, int groupLv) { washType = type; washLv = groupLv; } public readonly string MasterGroup1ActiveKey = "MasterGroup1Active"; public readonly string MasterGroup2ActiveKey = "MasterGroup2Active"; public readonly string MasterGroup3ActiveKey = "MasterGroup3Active"; public readonly string MasterGroup1RaiseKey = "MasterGroup1Raise"; public readonly string MasterGroup2RaiseKey = "MasterGroup2Raise"; public readonly string MasterGroup3RaiseKey = "MasterGroup3Raise"; public int MasterWashState { get; private set; } //1 激活 2 升级 private void CheckIsMasterLv() { List washAttrlist = washEquipProDict.Values.ToList(); OnGetMasterModel(washAttrlist); for (int i = 1; i < 4; i++) { int curTypeLv = 0; switch (i) { case 1: curTypeLv = washGroup1[0].XLAttrLV; SetMasterGroupActiveRecord(curTypeLv,1,MasterGroup1ActiveKey); SetMasterGroupRaiseRecord(curTypeLv, 1, MasterGroup1RaiseKey); break; case 2: curTypeLv = washGroup2[0].XLAttrLV; SetMasterGroupActiveRecord(curTypeLv,2, MasterGroup2ActiveKey); SetMasterGroupRaiseRecord(curTypeLv, 2, MasterGroup2RaiseKey); break; case 3: curTypeLv = washGroup3[0].XLAttrLV; SetMasterGroupActiveRecord(curTypeLv, 3, MasterGroup3ActiveKey); SetMasterGroupRaiseRecord(curTypeLv, 3, MasterGroup3RaiseKey); break; } } } public void SetMasterGroupRaiseRecord(int curGroupLv, int type, string groupRaise) { List tagSpecModellist = EquipWashSpecConfig.GetWashSpecModel(type); for(int i = 0; i < tagSpecModellist.Count; i++) { if(curGroupLv < tagSpecModellist[i].levelNeed) { if(i == 0) { LocalSave.SetInt(groupRaise, tagSpecModellist[i].levelNeed); } else { if (!PlayerPrefs.HasKey(groupRaise)) { LocalSave.SetInt(groupRaise, tagSpecModellist[i-1].levelNeed); } else { int groupLv = LocalSave.GetInt(groupRaise); if (tagSpecModellist[i - 1].levelNeed > groupLv) { MasterWashState = 2; SetWashMasterModel(type, curGroupLv); WindowCenter.Instance.Open(); LocalSave.SetInt(groupRaise, tagSpecModellist[i - 1].levelNeed); } } } return; } else if(curGroupLv >= tagSpecModellist[tagSpecModellist.Count -1].levelNeed) { if (!PlayerPrefs.HasKey(groupRaise)) { LocalSave.SetInt(groupRaise, tagSpecModellist[tagSpecModellist.Count - 1].levelNeed); } else { int groupLv = LocalSave.GetInt(groupRaise); if (tagSpecModellist[tagSpecModellist.Count - 1].levelNeed > groupLv) { MasterWashState = 2; SetWashMasterModel(type, curGroupLv); WindowCenter.Instance.Open(); LocalSave.SetInt(groupRaise, tagSpecModellist[tagSpecModellist.Count - 1].levelNeed); } } return; } } } public void SetMasterGroupActiveRecord(int curGroupLv,int type,string groupActive) { List tagSpecModellist = EquipWashSpecConfig.GetWashSpecModel(type); if (curGroupLv >= tagSpecModellist[0].levelNeed) { if (!PlayerPrefs.HasKey(groupActive)) { LocalSave.SetBool(groupActive, true); } else { bool isActive = LocalSave.GetBool(groupActive); if (!isActive) { MasterWashState = 1; SetWashMasterModel(type, curGroupLv); WindowCenter.Instance.Open(); } LocalSave.SetBool(groupActive, true); } } else { LocalSave.SetBool(groupActive, false); } } #endregion }