using vnxbqy.UI; using System; using System.Collections.Generic; using LitJson; using System.Linq; using UnityEngine; public class ILAchievementModel : ILModel { PackModel packModel { get { return ModelCenter.Instance.GetModelEx(); } } AchievementModel achievementModel { get { return ModelCenter.Instance.GetModelEx(); } } public int[] m_NewAchieveMentGroup; public Dictionary typeToGroup = new Dictionary(); public Dictionary> scoreAwards = new Dictionary>(); public Redpoint redpoint = new Redpoint(MainRedDot.RedPoint_key, MainRedPoint.achievementRedpoint); Dictionary redpoints = new Dictionary(); public event Action UpdateScoreAwardState; public event Action UpdateAchievement; public int m_ScoreAwardState; int m_SelectIndex; //分组 public event Action OnSelectUpdate; public int selectIndex { get { return m_SelectIndex; } set { if (m_SelectIndex != value) { m_SelectIndex = value; OnSelectUpdate?.Invoke(); } } } int m_NewSuccID; // 新成就可领取奖励 用于提示 public event Action OnNewSuccAward; public int newSuccID { get { return m_NewSuccID; } set { if (m_NewSuccID != value) { m_NewSuccID = value; OnNewSuccAward?.Invoke(); } } } protected override void Init() { GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitializeEvent; GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitializeEvent; GameEvent.playerDataRefreshEvent -= OnPlayerDataRefreshEvent; GameEvent.playerDataRefreshEvent += OnPlayerDataRefreshEvent; GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent; GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; achievementModel.achievementAwardableEvent -= OnAchievementAwardableEvent; achievementModel.achievementAwardableEvent += OnAchievementAwardableEvent; ParseConfig(); } protected override void UnInit() { } void OnAchievementAwardableEvent(int succID) { if (DTC0403_tagPlayerLoginLoadOK.neverLoginOk) return; if (achievementModel.reachSuccessIDs.Contains(succID)) return; var config = SuccessConfig.Get(succID); if (config == null) return; if (!typeToGroup.ContainsKey(config.Type)) { return; } var idList = achievementModel.GetAchievementsByCategory(typeToGroup[config.Type]); if (!idList.Contains(succID)) return; newSuccID = succID; WindowCenter.Instance.Open(); } void ParseConfig() { m_NewAchieveMentGroup = GeneralDefine.GetIntArray("NewAchieveMent"); for (int i = 0; i < m_NewAchieveMentGroup.Length; i++) { redpoints.Add(m_NewAchieveMentGroup[i], new Redpoint(MainRedPoint.achievementRedpoint, MainRedPoint.achievementRedpoint * 100000 + m_NewAchieveMentGroup[i])); var typeList = achievementModel.groupToType[m_NewAchieveMentGroup[i]]; for (int j = 0; j < typeList.Count; j++) { typeToGroup[typeList[j]] = m_NewAchieveMentGroup[i]; } } var scoreDict = JsonMapper.ToObject(FuncConfigConfig.Get("SucceeScore").Numerical1); var keys = scoreDict.Keys.ToList(); for (int i = 0; i < keys.Count; i++) { var key = int.Parse(scoreDict[keys[i]][0].ToJson()); var arr = JsonMapper.ToObject(scoreDict[keys[i]][1].ToJson()); scoreAwards[key] = arr[0].ToList(); } } void OnBeforePlayerDataInitializeEvent() { m_ScoreAwardState = 0; } void OnPlayerDataRefreshEvent(PlayerDataType dataType) { if (dataType != PlayerDataType.default19) { return; } UpdateScoreAwardState?.Invoke(); } void OnSecondEvent() { RefreshSuccessRedpoint(); if (refreshAgain) { UpdateAchievement?.Invoke(); refreshAgain = false; } } public void UpdateSuccessRedpoint(HA340_tagMCSuccessInfoList netPack) { bool isRefresh = false; for (int i = 0; i < netPack.SuccessInfoList.Length; i++) { bool refresh; UpdateSuccessRedpoint(0, netPack.SuccessInfoList[i].SuccType, out refresh); if (refresh) isRefresh = true; } if (isRefresh) UpdateAchievement?.Invoke(); } //进度和领取封包 A340 A342 不同的封包需要延迟刷新 //记录刷新的成就类型,控制刷新频率 List refreshType = new List(); public void UpdateSuccessRedpoint(int successID, int successType, out bool refresh) { refresh = false; if (successType != 0) { if (refreshType.Contains(successType)) { return; } if (!typeToGroup.ContainsKey(successType)) { return; } refreshType.Add(successType); refresh = true; return; } var config = SuccessConfig.Get(successID); if (config == null) return; if (refreshType.Contains(config.Type)) { return; } if (!typeToGroup.ContainsKey(config.Type)) { return; } refreshType.Add(config.Type); refresh = true; return; } public void RefreshSuccessRedpoint() { if (refreshType.Count == 0) { return; } for (int i = 0; i < refreshType.Count; i++) { int group = typeToGroup[refreshType[i]]; var idList = achievementModel.GetAchievementsByCategory(group); bool state = false; for (int j = 0; j < idList.Count; j++) { var successID = idList[j]; Achievement achievement; if (!achievementModel.TryGetAchievement(successID, out achievement)) { continue; } if (!Achievement.IsReach(successID, achievement.progress) && !achievement.completed) { continue; } if (!achievement.completed) { state = true; break; } } redpoints[group].state = state ? RedPointState.Simple : RedPointState.None; } refreshType.Clear(); } public void UpdateSuccessScoreInfo(IL_HA343_tagMCSuccessScoreInfo netPack) { m_ScoreAwardState = (int)netPack.ScoreAwardState; UpdateScoreAwardState?.Invoke(); } public int GetScoreAwardShowIndex() { int index = -1; var keys = scoreAwards.Keys.ToList(); keys.Sort(); for (int i = 0; i < keys.Count; i++) { if (((int)Math.Pow(2, i) & m_ScoreAwardState) == 0) { index = i; break; } } return index; } public ulong GetShowScore(int showIndex) { var keys = scoreAwards.Keys.ToList(); keys.Sort(); return HeroControler.Instance.GetMoneyCntIL(39); } private int SuccessSort(int x, int y) { Achievement achievementX; achievementModel.TryGetAchievement(x, out achievementX); Achievement achievementY; achievementModel.TryGetAchievement(y, out achievementY); if (achievementX.completed == achievementY.completed) { var xconfig = SuccessConfig.Get(x); var yconfig = SuccessConfig.Get(y); bool canGetX = achievementX.progress >= xconfig.NeedCnt; bool canGetY = achievementY.progress >= yconfig.NeedCnt; if (canGetX == canGetY) return xconfig.ReOrder.CompareTo(yconfig.ReOrder); return canGetY.CompareTo(canGetX); } return achievementX.completed.CompareTo(achievementY.completed); } public List GetAchieveIDs(int group) { var ids = achievementModel.GetAchievementsByCategory(group); ids.Sort(SuccessSort); return ids; } //成就是两个封包A340 A342合并逻辑,没有通知进度的情况下已领取则代表进度满; 只有修仙之路是战令购买特殊处理 //批量领取同类型成就 public void GetAchievementReward(int successID, byte isPassport = 0) { var config = SuccessConfig.Get(successID); var ids = GetAchieveIDs(config.Group); int sendCount = 0; for (int i = 0; i < ids.Count; i++) { var configEx = SuccessConfig.Get(ids[i]); Achievement achievement; achievementModel.TryGetAchievement(ids[i], out achievement); if (configEx.Type != config.Type) continue; int process = Mathf.Min(achievement.progress, configEx.NeedCnt); if (achievement.completed) process = configEx.NeedCnt; if (isPassport == 0) { if (achievement.completed) continue; } else { if (achievement.completedBP && achievement.completed) continue; } if (process < configEx.NeedCnt) { if (isPassport == 1) continue; else return; } if (sendCount > 30) return; //分批 var sendInfo = new CA542_tagMCGetSuccessAward(); sendInfo.SuccID = (uint)ids[i]; sendInfo.IsPassport = isPassport; GameNetSystem.Instance.SendInfo(sendInfo); sendCount++; } } public bool refreshAgain = false; //批量领取二次刷新 public void UpdateAchievementRecord(HA342_tagMCSuccessFinishAwardRecordList vNetData) { bool refresh = false; Achievement achievement; for (int i = 0; i < vNetData.RecordList.Length; i++) { var record = vNetData.RecordList[i]; var _index = record.RecordIndex; for (int j = 0; j < 31; j++) { var achievementId = _index * 31 + j; if (achievementModel.TryGetAchievement(achievementId, out achievement)) { bool isRefresh; UpdateSuccessRedpoint(achievementId, 0, out isRefresh); if (isRefresh) refresh = true; } } } if (refresh) { //UpdateAchievement?.Invoke(); if (WindowCenter.Instance.IsOpen("ILAchievementActivityWin")) { refreshAgain = true; } } } int jumpSuccessGroup = 0; public void SetJumpSuccessGroup(int group) { jumpSuccessGroup = group; } public int GetJumpIndex() { if (jumpSuccessGroup != 0) { for (int i = 0; i < m_NewAchieveMentGroup.Length; i++) { if (m_NewAchieveMentGroup[i] == jumpSuccessGroup) { jumpSuccessGroup = 0; return i; } } jumpSuccessGroup = 0; return 0; } for (int i = 0; i < m_NewAchieveMentGroup.Length; i++) { if (redpoints[m_NewAchieveMentGroup[i]].state == RedPointState.Simple) return i; } return 0; } }