using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using LitJson;
|
using System.Linq;
|
|
public class FuncOpen
|
{
|
private static FuncOpen _inst = null;
|
public static FuncOpen Instance {
|
get {
|
if (_inst == null)
|
{
|
_inst = new FuncOpen();
|
}
|
return _inst;
|
}
|
}
|
|
protected FuncOpen()
|
{
|
if (Application.isEditor)
|
{
|
if (!Application.isPlaying) return;
|
}
|
|
var allKeys = new List<int>(FuncOpenLVConfig.dic.Keys);//GetKeys();
|
funcArray = new int[allKeys.Count];
|
int _index = 0;
|
foreach (var key in allKeys)
|
{
|
int func = key;
|
funcOpenState[func] = false;
|
funcArray[_index] = func;
|
_index++;
|
}
|
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerDataInitializeEvent;
|
DTC0102_tagCDBPlayer.switchAccountEvent += SwitchAccountEvent;
|
|
funcClientLVLimitDict.Clear();
|
var jsonConfig = JsonMapper.ToObject(FuncConfigConfig.Get("FuncLevelLimitClient").Numerical1);
|
foreach (var key in jsonConfig.Keys)
|
{
|
funcClientLVLimitDict[int.Parse(key)] = int.Parse(jsonConfig[key].ToString());
|
}
|
}
|
|
private void BeforePlayerDataInitializeEvent()
|
{
|
for (int i = 0; i < funcArray.Length; i++)
|
{
|
funcOpenState[funcArray[i]] = false;
|
}
|
}
|
|
private void SwitchAccountEvent()
|
{
|
for (int i = 0; i < funcArray.Length; i++)
|
{
|
funcOpenState[funcArray[i]] = false;
|
if (OnFuncStateChangeEvent != null)
|
{
|
OnFuncStateChangeEvent(funcArray[i]);
|
}
|
}
|
}
|
|
// TaskModel m_TaskModel;
|
// TaskModel taskmodel { get { return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel<TaskModel>()); } }
|
private static Dictionary<int, bool> funcOpenState = new Dictionary<int, bool>();
|
private int[] funcArray;
|
|
public event Action<int> OnFuncStateChangeEvent;
|
|
//纯客户端的功能等级限制, key 以功能配置表的FuncLevelLimitClient为准
|
//1. 精彩活动-全服红包显示等级
|
public Dictionary<int, int> funcClientLVLimitDict = new Dictionary<int, int>();
|
public bool IsClientLVLimit(int key)
|
{
|
if (!funcClientLVLimitDict.ContainsKey(key))
|
return true;
|
|
if (PlayerDatas.Instance.baseData.LV >= funcClientLVLimitDict[key])
|
return true;
|
|
return false;
|
}
|
|
|
public void UpdateFuncState(HA302_tagMCFuncOpenStateList vNetData)
|
{
|
for (int i = 0; i < vNetData.FuncCount; i++)
|
{
|
|
var funcState = vNetData.FuncStateList[i];
|
|
bool bPerFuncIsOpen = false;
|
bool bAfterFuncIsOpen = false;
|
|
if (!funcOpenState.ContainsKey(funcState.FuncID))
|
{
|
funcOpenState.Add(funcState.FuncID, funcState.State == 1);
|
bAfterFuncIsOpen = true;
|
}
|
else
|
{
|
bPerFuncIsOpen = funcOpenState[funcState.FuncID];
|
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)
|
{
|
return false;
|
}
|
|
if (config.OpenDay > 0)
|
{
|
if (config.OpenDay > TimeUtility.OpenDay + 1)
|
{
|
errorCode = 2;
|
return false;
|
}
|
}
|
|
if (config.LimitMissionID > 0)
|
{
|
|
if (TaskManager.Instance.GetNeedFinishTaskCount(config.LimitMissionID) > 0)
|
{
|
errorCode = 4;
|
return false;
|
}
|
}
|
if (config.LimiRealmLV > 0 && PlayerDatas.Instance.baseData.realmLevel < config.LimiRealmLV)
|
{
|
errorCode = 3;
|
return false;
|
}
|
if (config.LimitLV > 0 && PlayerDatas.Instance.baseData.LV < config.LimitLV)
|
{
|
errorCode = 1;
|
return false;
|
}
|
if (config.ManLevel > 0 && PlayerDatas.Instance.baseData.ExAttr1 < config.ManLevel)
|
{
|
errorCode = 5;
|
return false;
|
}
|
return true;
|
// return false;
|
}
|
|
public bool IsFuncOpen(int key, bool tip = false)
|
{
|
bool isOpen = false;
|
if (funcOpenState.ContainsKey(key))
|
isOpen = funcOpenState[key];
|
if (!isOpen && tip)
|
ProcessorFuncErrorTip(key);
|
return isOpen;
|
}
|
|
public void ProcessorFuncErrorTip(int key)
|
{
|
var config = FuncOpenLVConfig.Get(key);
|
if (config != null)
|
{
|
SoundPlayer.Instance.PlayUIAudio(SoundPlayer.defaultClickNegativeAudio);
|
|
var errorCode = 0;
|
if (!IsFuncOpen(key, out errorCode))
|
{
|
switch (errorCode)
|
{
|
case 1:
|
SysNotifyMgr.Instance.ShowStringTip(Language.Get("FuncLimit_Level", config.LimitLV));
|
break;
|
case 2:
|
//开服多少天 一般是组合
|
if (config.LimitLV != 0)
|
{
|
SysNotifyMgr.Instance.ShowStringTip(Language.Get("FuncLimit_OpenDay_LV",
|
config.LimitLV, TimeUtility.OpenDay + 1, config.OpenDay));
|
|
}
|
else if (config.LimitMissionID != 0)
|
{
|
SysNotifyMgr.Instance.ShowStringTip(Language.Get("FuncLimit_OpenDay_Mission",
|
TaskManager.Instance.GetNeedFinishTaskCount(config.LimitMissionID), TimeUtility.OpenDay + 1, config.OpenDay));
|
}
|
else if (config.LimiRealmLV != 0)
|
{
|
SysNotifyMgr.Instance.ShowStringTip(Language.Get("FuncLimit_OpenDay_Realm",
|
RealmConfig.Get(config.LimiRealmLV).Name, TimeUtility.OpenDay + 1, config.OpenDay));
|
}
|
else
|
{
|
SysNotifyMgr.Instance.ShowStringTip(Language.Get("FuncLimit_OpenDay", config.OpenDay));
|
}
|
break;
|
case 3:
|
SysNotifyMgr.Instance.ShowStringTip(Language.Get("FuncLimit_Realm", RealmConfig.Get(config.LimiRealmLV).Name));
|
break;
|
case 4:
|
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));
|
break;
|
}
|
}
|
}
|
}
|
|
public int GetLimitLv(int key)
|
{
|
// FuncOpenLVConfig tagFuncOpenLVModel = FuncOpenLVConfig.Get(key);
|
// if (tagFuncOpenLVModel.LimitLV != 0)
|
// {
|
// return tagFuncOpenLVModel.LimitLV;
|
// }
|
// if (tagFuncOpenLVModel.LimitMissionID != 0)
|
// {
|
// var TaskConfig = PyTaskConfig.Get(tagFuncOpenLVModel.LimitMissionID);
|
// return TaskConfig.lv;
|
// }
|
|
return 1;
|
}
|
|
Dictionary<int, ICheckFuncOpen> m_CheckFuncDict = new Dictionary<int, ICheckFuncOpen>();
|
public void Register(int _key, ICheckFuncOpen _check)
|
{
|
if (!m_CheckFuncDict.ContainsKey(_key))
|
{
|
m_CheckFuncDict.Add(_key, _check);
|
}
|
}
|
|
public bool CheckFuncOpen(int _key)
|
{
|
if (m_CheckFuncDict.ContainsKey(_key))
|
{
|
return m_CheckFuncDict[_key].CheckFunc();
|
}
|
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 result = string.Join(connector, conditionStrs);
|
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
|
{
|
bool CheckFunc();
|
}
|