using LitJson; using Snxxz.UI; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace Snxxz.UI { public class RealmModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize { Dictionary> m_RealmProperties = new Dictionary>(); Dictionary> m_RealmPreviewEquips = new Dictionary>(); List> m_RealmStages = new List>(); public int realmMaxLevel { get; private set; } public bool isBossPass { get; private set; } public const int REALM_DUNGEON_ID = 31110; public readonly Redpoint levelUpRedpoint = new Redpoint(114, 11401); public readonly Redpoint challengeRedpoint = new Redpoint(114, 11402); int m_SelectRealm = 0; public int selectRealm { get { return m_SelectRealm; } set { if (m_SelectRealm != value) { m_SelectRealm = value; if (selectRealmRefresh != null) { selectRealmRefresh(); } } } } public event Action selectRealmRefresh; EquipModel equipModel { get { return ModelCenter.Instance.GetModel(); } } public override void Init() { ParseConfig(); } public void OnBeforePlayerDataInitialize() { isBossPass = false; } public void OnPlayerLoginOk() { } public override void UnInit() { } void ParseConfig() { realmMaxLevel = 0; List stages = new List(); m_RealmStages.Add(stages); var configs = RealmConfig.GetValues(); foreach (var config in configs) { if (config.Lv > realmMaxLevel) { realmMaxLevel = config.Lv; } if (config.AddAttrType != null && config.AddAttrType.Length > 0) { Dictionary dict = new Dictionary(); for (int i = 0; i < config.AddAttrType.Length; i++) { dict.Add(config.AddAttrType[i], config.AddAttrNum[i]); } m_RealmProperties.Add(config.Lv, dict); } if (stages.Contains(config.Lv)) { stages = new List(); m_RealmStages.Add(stages); } stages.Add(config.Lv); if (config.BossID != 0) { var nextConfig = RealmConfig.Get(config.Lv + 1); if (nextConfig != null) { stages.Add(config.Lv + 1); } } if (!string.IsNullOrEmpty(config.equips)) { var json = LitJson.JsonMapper.ToObject(config.equips); Dictionary dict = new Dictionary(); foreach (var jobKey in json.Keys) { var job = int.Parse(jobKey); var equipArray = LitJson.JsonMapper.ToObject(json[jobKey].ToJson()); dict.Add(job, equipArray); } m_RealmPreviewEquips.Add(config.Lv, dict); } } } public bool TryGetRealmProperty(int level, out Dictionary propertyDict) { return m_RealmProperties.TryGetValue(level, out propertyDict); } public bool TryGetRealmStages(int index, out List stages) { stages = null; if (index < m_RealmStages.Count) { stages = m_RealmStages[index]; return true; } return false; } public bool TryGetRealmPreviewEquips(int level, int job, out int[] equips) { equips = null; if (m_RealmPreviewEquips.ContainsKey(level)) { return m_RealmPreviewEquips[level].TryGetValue(job, out equips); } return false; } public bool IsUnlockEquipRealm(int realmLevel, out int level) { level = 0; var equipSets = equipModel.GetAllEquipSets(); var index = equipSets.FindIndex((x) => { var equipSet = equipModel.GetEquipSet(x); if (equipSet != null) { return equipSet.realm == realmLevel; } return false; }); if (index != -1) { level = equipSets[index]; return true; } return false; } public int GetRealmStage(int realmLevel) { for (int i = 0; i < m_RealmStages.Count; i++) { var stages = m_RealmStages[i]; if (stages.Contains(realmLevel)) { return i; } } return m_RealmStages.Count - 1; } public void SendLevelUpRealm() { CA523_tagCMRealmLVUp pak = new CA523_tagCMRealmLVUp(); GameNetSystem.Instance.SendInfo(pak); } public void ReceivePackage(HA311_tagMCSyncRealmInfo package) { isBossPass = package.IsPass == 1; } } }