yyl
10 天以前 e038d0986f510de9d298ebdf6036e32c6b3733b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
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();
}