using System.Collections; using System.Collections.Generic; using UnityEngine; using TableConfig; using System; using Snxxz.UI; namespace Snxxz.UI { public class RolePromoteModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, IPlayerLoginOk { PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } public override void Init() { ParseConfig(); playerPack.RefreshItemCountAct += RefreshItemCountAct; PlayerStoneData.OnRefreshStoneData += OnRefreshStoneData; PlayerMountDatas.Event_MountHA301A += OnRefreshMountData; PlayerPetDatas.Event_H0704Add += OnRefreshPetData; PlayerPetDatas.Event_H0704Update += OnRefreshPetData; petmodel.PlayerLoginOkData += OnRefreshPetData; equipWashModel.RefreshWashModelEvent += RefreshWashModelEvent; RedpointCenter.Instance.redpointValueChangeEvent += RedpointValueChangeEvent; modelInterface.RefreshGetBetterEquipEvent += RefreshGetBetterEquipEvent; PlayerMountDatas.PlayerLoginOKData += PlayerLoginOKData; OnBeforePlayerDataInitialize(); } public override void UnInit() { } public void OnBeforePlayerDataInitialize() { } public void OnAfterPlayerDataInitialize() { } public void OnPlayerLoginOk() { CheckPromoteDetailEffect(); RefreshData(); } public void RefreshData() { GetAllStoneLv(); GetWashCntDic(); GetPetCntDic(); GetMountCntDic(); } EquipWashModel m_EquipWashModel; EquipWashModel equipWashModel { get { return m_EquipWashModel ?? (m_EquipWashModel = ModelCenter.Instance.GetModel()); } } TreasureModel m_TreasureModel; TreasureModel treasureModel { get { return m_TreasureModel ?? (m_TreasureModel = ModelCenter.Instance.GetModel()); } } MagicianModel m_MagicianModel; MagicianModel magicianModel { get { return m_MagicianModel ?? (m_MagicianModel = ModelCenter.Instance.GetModel()); } } RuneModel m_RuneModel; RuneModel runeModel { get { return m_RuneModel ?? (m_RuneModel = ModelCenter.Instance.GetModel()); } } PlayerPetDatas m_petModel; PlayerPetDatas petmodel { get { return m_petModel ?? (m_petModel = ModelCenter.Instance.GetModel()); } } PlayerMountDatas m_HorseModel; PlayerMountDatas horsemodel { get { return m_HorseModel ?? (m_HorseModel = ModelCenter.Instance.GetModel()); } } PlayerStrengthengDatas m_StrengthengModel; PlayerStrengthengDatas strengthengmodel { get { return m_StrengthengModel ?? (m_StrengthengModel = ModelCenter.Instance.GetModel()); } } PlayerSuitModel _suitModel; PlayerSuitModel SuitModel { get { return _suitModel ?? (_suitModel = ModelCenter.Instance.GetModel()); } } GemModel gemModel { get { return ModelCenter.Instance.GetModel(); } } BlastFurnaceModel blastFurnaceModel { get { return ModelCenter.Instance.GetModel(); } } RoleModel roleModel { get { return ModelCenter.Instance.GetModel(); } } #region 配置 public Dictionary wingLv2GenerDict = new Dictionary(); public Dictionary> roleStrongerDic = new Dictionary>(); void ParseConfig() { var dict = ConfigManager.Instance.GetAllValues(); foreach (var cfg in dict) { List list = null; roleStrongerDic.TryGetValue(cfg.funcType, out list); if (list == null) { list = new List(); roleStrongerDic.Add(cfg.funcType, list); } list.Add(cfg); } var _funcCfg = ConfigManager.Instance.GetTemplate("WingLV"); LitJson.JsonData _json = LitJson.JsonMapper.ToObject(_funcCfg.Numerical1); foreach (var _wingLv in _json.Keys) { wingLv2GenerDict.Add(int.Parse(_wingLv), int.Parse(_json[_wingLv].ToString())); } } public List GetRoleStrongerList(int funcType) { List list = null; roleStrongerDic.TryGetValue(funcType, out list); return list; } public bool IsHighestStage(int funcType, int id) { List list = GetRoleStrongerList(funcType); if (list != null && list.Count > 0) { if (id == list[list.Count - 1].id) { return true; } } return false; } #endregion public RoleStrongerConfig GetPresentRoleStronger(int funcType, out int presentValue, out bool reached) { presentValue = 0; List list = GetRoleStrongerList(funcType); reached = false; int i = 0; int presentLevel = PlayerDatas.Instance.baseData.LV; if (list != null && list.Count > 0) { switch ((FuncPowerType)list[0].funcType) { case FuncPowerType.Equip: { for (i = 0; i < list.Count; i++) { presentValue = GetEquipCnt(list[i].conditions[0] , list[i].conditions.Length > 1 ? list[i].conditions[1] : 0 , list[i].conditions.Length > 2 ? list[i].conditions[2] : 0); if (presentLevel < list[i].LV) { break; } if (presentValue < list[i].targetValue) { return list[i]; } } } break; case FuncPowerType.Plus: { var packTypeModel = playerPack.GetSinglePackModel(PackType.rptEquip); if (packTypeModel == null || packTypeModel.GetPackModelIndexDict() == null || packTypeModel.GetPackModelIndexDict().Count == 0) { return list[0]; } foreach (var itemPlace in packTypeModel.GetPackModelIndexDict().Keys) { presentValue += strengthengmodel.StrengthenTheCeiling(itemPlace); } for (i = 0; i < list.Count; i++) { if (presentLevel < list[i].LV) { break; } if (presentValue < list[i].targetValue) { return list[i]; } } } break; case FuncPowerType.Rune: { for (i = 0; i < list.Count; i++) { bool _satisfy = GetRuneCnt(list[i].conditions[0], out presentValue); if (presentLevel < list[i].LV) { break; } if (!_satisfy || presentValue < list[i].targetValue) { return list[i]; } } } break; case FuncPowerType.GodWeapon: { for (i = 0; i < list.Count; i++) { var magicianData = magicianModel.GetMagicianData(list[i].conditions[0]); if (magicianData == null) { return list[i]; } presentValue = magicianData.level; if (presentLevel < list[i].LV) { break; } if (presentValue < list[i].targetValue) { return list[i]; } } } break; case FuncPowerType.Horse: { for (i = 0; i < list.Count; i++) { int _itemColor = list[i].conditions.Length > 1 ? list[i].conditions[1] : 0; int _lv = list[i].conditions.Length > 0 ? list[i].conditions[0] : 0; presentValue = GetMountCnt(_itemColor, _lv); if (presentLevel < list[i].LV) { break; } if (presentValue < list[i].targetValue) { return list[i]; } } } break; case FuncPowerType.Wing: { var itemModel = playerPack.GetItemModelByIndex(PackType.rptEquip, (int)RoleEquipType.retWing); if (itemModel == null) { presentValue = 0; break; } ItemConfig _tagChinItemModel = ConfigManager.Instance.GetTemplate((int)itemModel.itemInfo.ItemID); presentValue = wingLv2GenerDict[_tagChinItemModel.LV]; for (i = 0; i < list.Count; i++) { if (presentLevel < list[i].LV) { break; } if (presentValue < list[i].conditions[0]) { presentValue = 0; return list[i]; } } } break; case FuncPowerType.Stone: { presentValue = allStoneLv; for (i = 0; i < list.Count; i++) { if (presentLevel < list[i].LV) { break; } if (presentValue < list[i].targetValue) { return list[i]; } } } break; case FuncPowerType.Suit: { for (i = 0; i < list.Count; i++) { presentValue = SuitModel.GetSameSuitCntByType((SuitType)list[i].conditions[0]); if (presentLevel < list[i].LV) { break; } if (presentValue < list[i].targetValue) { return list[i]; } } } break; case FuncPowerType.Wash: { for (i = 0; i < list.Count; i++) { presentValue = GetWashCnt(list[i].conditions[0]); if (presentLevel < list[i].LV) { break; } if (presentValue < list[i].targetValue) { return list[i]; } } } break; case FuncPowerType.Prestige: { for (i = 0; i < list.Count; i++) { presentValue = PlayerDatas.Instance.baseData.realmLevel; if (presentLevel < list[i].LV) { break; } if (presentValue < list[i].targetValue) { return list[i]; } } } break; case FuncPowerType.Pet: { for (i = 0; i < list.Count; i++) { presentValue = GetPetCnt(list[i].conditions.Length > 1 ? list[i].conditions[1] : list[i].conditions[0]); if (presentLevel < list[i].LV) { break; } if (presentValue < list[i].targetValue) { return list[i]; } } } break; case FuncPowerType.Demon: case FuncPowerType.Fairy: case FuncPowerType.Human: { for (i = 0; i < list.Count; i++) { if (presentLevel < list[i].LV) { break; } Treasure treasure = null; presentValue = 0; if (treasureModel.TryGetTreasure(list[i].targetValue, out treasure)) { if (treasure.state == TreasureState.Collected) { presentValue = 1; continue; } } return list[i]; } } break; case FuncPowerType.BlastFurnace: { for (i = 0; i < list.Count; i++) { presentValue = GetBlastFurnaceDragUseCount(list[i].conditions.Length > 0 ? list[i].conditions[0] : 1); if (presentLevel < list[i].LV) { break; } if (presentValue < list[i].targetValue) { return list[i]; } } } break; } reached = true; i = Mathf.Max(0, i - 1); i = Mathf.Min(list.Count - 1, i); return list[i]; } return null; } #region 装备 private void RefreshItemCountAct(PackType packType, int itemPlace, int id) { if (packType == PackType.rptEquip || packType == PackType.rptItem) { CheckPromoteDetailEffect(); } else if (packType == PackType.rptPetPack) { GetPetCntDic(); } else if (packType == PackType.rptHorse) { GetMountCntDic(); } } public int GetEquipCnt(int _color, int _starlv, int _lv) { int _count = 0; SinglePackModel packTypeModel = playerPack.GetSinglePackModel(PackType.rptEquip); if (packTypeModel == null || packTypeModel.GetPackModelIndexDict() == null || packTypeModel.GetPackModelIndexDict().Count == 0) { return _count; } foreach (var _itemModel in packTypeModel.GetPackModelIndexDict().Values) { var _itemCfg = ConfigManager.Instance.GetTemplate(_itemModel.itemId); if (_itemCfg != null) { if (_itemCfg.ItemColor < _color || _itemCfg.LV < _lv) { continue; } if (_itemCfg.ItemColor > _color) { _count++; continue; } if (_itemCfg.ItemColor == _color) { if (_itemCfg.StarLevel >= _starlv) { _count++; } } } } return _count; } #endregion #region 符印 public bool GetRuneCnt(int _tatalLv, out int _count) { int totalLv = 0; var _runeHoleDatas = runeModel.GetAllRuneData(); foreach (var _rune in _runeHoleDatas.Values) { totalLv += _rune.lv; } _count = totalLv >= _tatalLv ? _runeHoleDatas.Count : 0; return totalLv >= _tatalLv; } #endregion #region 宝石 private void OnRefreshStoneData() { GetAllStoneLv(); } private int m_AllStoneLv = 0; public int allStoneLv { get { return m_AllStoneLv; } } private void GetAllStoneLv() { m_AllStoneLv = 0; var dict = PlayerStoneData.Instance.GetAllStone(); foreach (uint[] array in dict.Values) { if (array == null || array.Length == 0) continue; for (int i = 0; i < array.Length; i++) { if (array[i] == 0) continue; ItemConfig _tagChinItemModel = ConfigManager.Instance.GetTemplate((int)array[i]); if (_tagChinItemModel == null) continue; m_AllStoneLv += _tagChinItemModel.EffectValueB1; } } } #endregion #region 坐骑 private void PlayerLoginOKData() { GetMountCntDic(); } private void OnRefreshMountData(int _HorseID) { GetMountCntDic(); } private Dictionary> mountCntDic = new Dictionary>(); private void GetMountCntDic() { foreach (var dict in mountCntDic.Values) { dict.Clear(); } var mountDict = horsemodel._DicHorse; if (mountDict == null || mountDict.Count == 0) return; foreach (var horseID in mountDict.Keys) { HorseConfig _tagHorseModel = ConfigManager.Instance.GetTemplate(horseID); if (_tagHorseModel == null) { continue; } ItemConfig _tagChinItemModel = ConfigManager.Instance.GetTemplate(_tagHorseModel.ItemID); Dictionary dict = null; mountCntDic.TryGetValue(_tagChinItemModel.ItemColor, out dict); if (dict == null) { dict = new Dictionary(); mountCntDic.Add(_tagChinItemModel.ItemColor, dict); dict[mountDict[horseID].Lv] = 0; } if (!dict.ContainsKey(mountDict[horseID].Lv)) { dict.Add(mountDict[horseID].Lv, 0); } dict[mountDict[horseID].Lv]++; } } public int GetMountCnt(int _itemColor, int _lv) { int val = 0; foreach (var itemColor in mountCntDic.Keys) { if (itemColor < _itemColor) { continue; } foreach (var lv in mountCntDic[itemColor].Keys) { if (lv < _lv) { continue; } val += mountCntDic[itemColor][lv]; } } return val; } public int GetMountTotallv() { var mountDict = horsemodel._DicHorse; if (mountDict == null || mountDict.Count == 0) { return 0; } var _lv = 0; foreach (var _horse in mountDict.Values) { _lv += _horse.Lv; } return _lv; } #endregion #region 灵宠 private void OnRefreshPetData(HB701_tagMCPetLV info) { GetPetCntDic(); } private void OnRefreshPetData() { GetPetCntDic(); } private Dictionary petCntDic = new Dictionary(); private void GetPetCntDic() { petCntDic.Clear(); var dict = petmodel._DicPetBack; if (dict == null) return; foreach (var pet in dict.Values) { if (!petCntDic.ContainsKey(pet.PetClass)) { petCntDic.Add(pet.PetClass, 0); } petCntDic[pet.PetClass]++; } } public int GetPetCnt(int lv) { int val = 0; foreach (var key in petCntDic.Keys) { if (key >= lv) { val += petCntDic[key]; } } return val; } #endregion #region 洗练 private void RefreshWashModelEvent() { GetWashCntDic(); } private Dictionary washCntDic = new Dictionary(); private void GetWashCntDic() { washCntDic.Clear(); var dict = equipWashModel.GetWashInfoDict(); if (dict == null) { return; } foreach (var wash in dict.Values) { if (!washCntDic.ContainsKey(wash.XLAttrLV)) { washCntDic.Add(wash.XLAttrLV, 1); } else { washCntDic[wash.XLAttrLV]++; } } } public int GetWashCnt(int lv) { int val = 0; foreach (var key in washCntDic.Keys) { if (lv <= key) { val += washCntDic[key]; } } return val; } #endregion #region 炼丹 public int GetBlastFurnaceDragUseCount(int _lv) { var list = playerPack.makeDruglist; var count = 0; if (list != null) { for (int i = 0; i < list.Count; i++) { var config = ConfigManager.Instance.GetTemplate(list[i].ID); if (config != null && config.LV == _lv) { count += playerPack.GetSumUseCntByID(config.ID); } } } return count; } #endregion #region 主界面提升 PlayerMethodData methodData { get { return ModelCenter.Instance.GetModel(); } } RealmModel realmModel { get { return ModelCenter.Instance.GetModel(); } } PackModelInterface _modelInterface; PackModelInterface modelInterface { get { return _modelInterface ?? (_modelInterface = ModelCenter.Instance.GetModel()); } } public Redpoint m_PromoteRedpoint = new Redpoint(31); private void RefreshGetBetterEquipEvent(string _str) { CheckPromoteDetailEffect(); } public void CheckPromoteDetailEffect() { m_PromoteRedpoint.state = RedPointState.None; for (int i = 0; i < (int)PromoteDetailType.RolePromote; i++) { if (GetPromoteDetailShow((PromoteDetailType)i)) { m_PromoteRedpoint.state = RedPointState.Simple; break; } } } private void RedpointValueChangeEvent(int _id) { if (_id == strengthengmodel.StrengthRedpoint.id || _id == MainRedDot.RedPoint_MountPackKey || _id == MainRedDot.Instance.redPonintPetFunc2.id || _id == MainRedDot.Instance.redPointWashFunc.id || _id == runeModel.runeMosaicRedpoint.id || _id == magicianModel.magicianRedpoint.id || _id == methodData.fairyHeartRedpoint.id || _id == realmModel.realmRedpoint.id || _id == gemModel.gemTagRedPoint.id || _id == roleModel.MakeDrugRedpoint.id || IsTreasureRedpoint(_id)) { CheckPromoteDetailEffect(); } } private bool IsTreasureRedpoint(int _id) { for (int k = 1; k < (int)TreasureCategory.Zerg; k++) { var list = treasureModel.GetTreasureCategory((TreasureCategory)k); if (list == null) { continue; } for (int j = 0; j < list.Count; j++) { Treasure treasure; if (treasureModel.TryGetTreasure(list[j], out treasure) && treasure.skillLevelUpRedpoint != null && treasure.skillLevelUpRedpoint.id == _id) { return true; } } } return false; } public bool GetPromoteDetailShow(PromoteDetailType _type) { switch (_type) { case PromoteDetailType.BetterEquip: return modelInterface.CheckBetterEquip(RoleEquipType.retSpiritAnimal); case PromoteDetailType.EquipStrength: return strengthengmodel.StrengthRedpoint.state == RedPointState.Simple; case PromoteDetailType.Mount: return MainRedDot.Instance.redPointMountFunc.state == RedPointState.Simple; case PromoteDetailType.Pet: return MainRedDot.Instance.redPonintPetFunc2.state == RedPointState.Simple; case PromoteDetailType.RuneMosaic: return runeModel.runeMosaicRedpoint.state == RedPointState.Simple; case PromoteDetailType.GodWeapon: return magicianModel.magicianRedpoint.state == RedPointState.Simple; case PromoteDetailType.TreasurePotential: for (int k = 1; k < (int)TreasureCategory.Zerg; k++) { var list = treasureModel.GetTreasureCategory((TreasureCategory)k); if (list != null) { for (int j = 0; j < list.Count; j++) { Treasure treasure; if (treasureModel.TryGetTreasure(list[j], out treasure) && treasure.state == TreasureState.Collected && treasure.skillLevelUpRedpoint != null && treasure.skillLevelUpRedpoint.state == RedPointState.Simple) { return true; } } } } break; case PromoteDetailType.Gem: return gemModel.gemTagRedPoint.state == RedPointState.Simple; case PromoteDetailType.Wash: return MainRedDot.Instance.redPointWashFunc.state == RedPointState.Simple; case PromoteDetailType.RolePromote: return true; case PromoteDetailType.FairyHeart: return ModelCenter.Instance.GetModel().fairyHeartRedpoint.state == RedPointState.Simple; case PromoteDetailType.BlastFurnace: return roleModel.MakeDrugRedpoint.state == RedPointState.Simple; case PromoteDetailType.max: break; } return false; } #endregion public enum PromoteDetailType { BetterEquip, EquipStrength, Mount, Pet, RuneMosaic, Gem, Wash, GodWeapon, FairyHeart, TreasurePotential, BlastFurnace,//八卦炉 RolePromote, max, } } }