| | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using LitJson; |
| | | using System.Linq; |
| | | |
| | | public class FuncOpen |
| | | { |
| | |
| | | { |
| | | for (int i = 0; i < vNetData.FuncCount; i++) |
| | | { |
| | | |
| | | |
| | | var funcState = vNetData.FuncStateList[i]; |
| | | |
| | | bool bPerFuncIsOpen = false; |
| | |
| | | funcOpenState[funcState.FuncID] = funcState.State == 1; |
| | | bAfterFuncIsOpen = funcOpenState[funcState.FuncID]; |
| | | } |
| | | |
| | | awardStateDict[funcState.FuncID] = funcState.AwardState == 1; |
| | | UpdatePreviewRedpoint(); |
| | | |
| | | if (OnFuncStateChangeEvent != null) |
| | | { |
| | | OnFuncStateChangeEvent(funcState.FuncID); |
| | |
| | | |
| | | private bool IsFuncOpen(int key, out int errorCode) |
| | | { |
| | | |
| | | |
| | | errorCode = 0; |
| | | var config = FuncOpenLVConfig.Get(key); |
| | | if (config == null) |
| | |
| | | if (config.OpenDay > 0) |
| | | { |
| | | if (config.OpenDay > TimeUtility.OpenDay + 1) |
| | | { |
| | | { |
| | | errorCode = 2; |
| | | return false; |
| | | } |
| | |
| | | SysNotifyMgr.Instance.ShowStringTip(Language.Get("FuncLimit_Mission", TaskManager.Instance.GetNeedFinishTaskCount(config.LimitMissionID))); |
| | | break; |
| | | case 5: |
| | | SysNotifyMgr.Instance.ShowStringTip(Language.Get("FuncLimit_ManLevel", config.ManLevel/10000, config.ManLevel/100%100, config.ManLevel%100)); |
| | | SysNotifyMgr.Instance.ShowStringTip(Language.Get("FuncLimit_ManLevel", config.ManLevel / 10000, config.ManLevel / 100 % 100, config.ManLevel % 100)); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public string GetErrorTip(int key) |
| | | { |
| | | if (!FuncOpenLVConfig.HasKey(key)) |
| | | return string.Empty; |
| | | FuncOpenLVConfig config = FuncOpenLVConfig.Get(key); |
| | | if (!IsFuncOpen(key, out int errorCode)) |
| | | { |
| | | switch (errorCode) |
| | | { |
| | | case 1: |
| | | return Language.Get("FuncLimit_Level", config.LimitLV); |
| | | case 2: |
| | | //开服多少天 一般是组合 |
| | | if (config.LimitLV != 0) |
| | | { |
| | | return Language.Get("FuncLimit_OpenDay_LV", config.LimitLV, TimeUtility.OpenDay + 1, config.OpenDay); |
| | | |
| | | } |
| | | else if (config.LimitMissionID != 0) |
| | | { |
| | | return Language.Get("FuncLimit_OpenDay_Mission", TaskManager.Instance.GetNeedFinishTaskCount(config.LimitMissionID), TimeUtility.OpenDay + 1, config.OpenDay); |
| | | } |
| | | else if (config.LimiRealmLV != 0) |
| | | { |
| | | return Language.Get("FuncLimit_OpenDay_Realm", RealmConfig.Get(config.LimiRealmLV).Name, TimeUtility.OpenDay + 1, config.OpenDay); |
| | | } |
| | | else |
| | | { |
| | | return Language.Get("FuncLimit_OpenDay", config.OpenDay); |
| | | } |
| | | case 3: |
| | | return Language.Get("FuncLimit_Realm", RealmConfig.Get(config.LimiRealmLV).Name); |
| | | case 4: |
| | | return Language.Get("FuncLimit_Mission", TaskManager.Instance.GetNeedFinishTaskCount(config.LimitMissionID)); |
| | | case 5: |
| | | return Language.Get("FuncLimit_ManLevel", config.ManLevel/10000, config.ManLevel/100%100, config.ManLevel%100); |
| | | } |
| | | } |
| | | return string.Empty; |
| | | } |
| | | |
| | | public int GetLimitLv(int key) |
| | |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | #region 功能预告 |
| | | Dictionary<int, bool> awardStateDict = new Dictionary<int, bool>(); |
| | | |
| | | Dictionary<int, int> funcIndexDict = new Dictionary<int, int>(); |
| | | public Dictionary<int, int> GetFuncIndexDict() |
| | | { |
| | | if (funcIndexDict.IsNullOrEmpty()) |
| | | { |
| | | foreach (var funcId in FuncOpenLVConfig.GetKeys()) |
| | | { |
| | | FuncOpenLVConfig config = FuncOpenLVConfig.Get(funcId); |
| | | if (config.PreviewIndex > 0) |
| | | { |
| | | funcIndexDict[config.FuncId] = config.PreviewIndex; |
| | | } |
| | | } |
| | | } |
| | | return funcIndexDict; |
| | | } |
| | | |
| | | public List<int> GetSortShowList() |
| | | { |
| | | List<int> sortShowList = new List<int>(); |
| | | Dictionary<int, int> indexDict = GetFuncIndexDict(); |
| | | // 按状态优先级排序:状态1(可领取)> 状态0(未解锁)> 状态2(已领取) |
| | | // 每种状态内按 PreviewIndex 升序,相同则按 FuncId 升序 |
| | | sortShowList = indexDict |
| | | .Select(kv => new { FuncId = kv.Key, PreviewIndex = kv.Value, State = GetState(kv.Key) }) |
| | | .OrderBy(x => x.State == 1 ? 0 : (x.State == 0 ? 1 : 2)) // 映射优先级:1→0, 0→1, 2→2 |
| | | .ThenBy(x => x.PreviewIndex) |
| | | .ThenBy(x => x.FuncId) |
| | | .Select(x => x.FuncId) |
| | | .ToList(); |
| | | return sortShowList; |
| | | } |
| | | |
| | | |
| | | |
| | | //第一个可领取的物品所在行索引 |
| | | public bool TryGetJumpIndex(out int index) |
| | | { |
| | | index = 0; |
| | | List<int> list = GetSortShowList(); |
| | | if (list.IsNullOrEmpty()) |
| | | return false; |
| | | for (int i = 0; i < list.Count; i++) |
| | | { |
| | | if (GetState(list[i]) == 1) |
| | | { |
| | | index = i; |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private bool IsAwardHave(int funcId) |
| | | { |
| | | return !awardStateDict.TryGetValue(funcId, out bool state) ? false : state; |
| | | } |
| | | |
| | | // 0-未解锁 1-可领取 2-已领取 |
| | | public int GetState(int funcId) |
| | | { |
| | | if (IsAwardHave(funcId)) |
| | | return 2; |
| | | return IsFuncOpen(funcId) ? 1 : 0; |
| | | } |
| | | |
| | | |
| | | |
| | | public string GetErrorStr(int funcId) |
| | | { |
| | | if (!FuncOpenLVConfig.HasKey(funcId)) |
| | | return string.Empty; |
| | | FuncOpenLVConfig config = FuncOpenLVConfig.Get(funcId); |
| | | List<string> conditionStrs = new List<string>(); |
| | | if (config.LimitLV > 0) |
| | | { |
| | | conditionStrs.Add(Language.Get("FunctionPreviewErr01", config.LimitLV)); |
| | | } |
| | | |
| | | if (config.LimiRealmLV > 0) |
| | | { |
| | | conditionStrs.Add(Language.Get("FunctionPreviewErr02", RealmConfig.Get(config.LimiRealmLV).Name)); |
| | | } |
| | | |
| | | if (config.LimitMissionID > 0) |
| | | { |
| | | conditionStrs.Add(Language.Get("FunctionPreviewErr03", TaskManager.Instance.GetNeedFinishTaskCount(config.LimitMissionID))); |
| | | } |
| | | |
| | | if (config.OpenDay > 0) |
| | | { |
| | | conditionStrs.Add(Language.Get("FunctionPreviewErr04", config.OpenDay)); |
| | | } |
| | | |
| | | if (config.ManLevel > 0) |
| | | { |
| | | conditionStrs.Add(Language.Get("FunctionPreviewErr05", config.ManLevel / 10000, config.ManLevel / 100 % 100, config.ManLevel % 100)); |
| | | } |
| | | |
| | | if (conditionStrs.Count == 0) |
| | | { |
| | | return string.Empty; |
| | | } |
| | | string connector = Language.Get("FunctionPreview01"); // "且" |
| | | string unlockStr = Language.Get("FunctionPreview02"); // "解锁" |
| | | string result = string.Join(connector, conditionStrs) + unlockStr; |
| | | return result; |
| | | } |
| | | |
| | | public void SendGetAward(int funcId) |
| | | { |
| | | var pack = new CA504_tagCMPlayerGetReward(); |
| | | pack.RewardType = 17; |
| | | pack.DataEx = (uint)funcId; |
| | | GameNetSystem.Instance.SendInfo(pack); |
| | | } |
| | | |
| | | Redpoint redpoint = new Redpoint(MainRedDot.RightFuncRedpoint, MainRedDot.FunctionPreviewRepoint); |
| | | |
| | | public void UpdatePreviewRedpoint() |
| | | { |
| | | redpoint.state = RedPointState.None; |
| | | if (!TryGetJumpIndex(out int index)) |
| | | return; |
| | | redpoint.state = RedPointState.Simple; |
| | | } |
| | | #endregion |
| | | } |
| | | |
| | | public interface ICheckFuncOpen |