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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
using System.Collections.Generic;
using UnityEngine;
using LitJson;
using System;
 
//方案预设:流派设定
// 这里存储的是流派id设定; 功能预设在各个功能里如命格的是存在命格背包对应,武将是另外通知使用的格子索引
public class FuncPresetManager : GameSystemManager<FuncPresetManager>
{
    //预设方案:功能类型(含全局和子功能,配表)-子方案ID-预设方案解锁名称信息
    Dictionary<int, Dictionary<int, FuncPreset>> m_FuncPresetDict = new Dictionary<int, Dictionary<int, FuncPreset>>();
 
    //对应 BattlePreSetType 战斗类型 : 全局方案ID
    Dictionary<int, int> battlePreSetDict = new Dictionary<int, int>();
 
    //所有预设方案的保存信息 全局方案ID :子功能类型(配表):子方案ID
    Dictionary<int, Dictionary<int, int>> m_FuncPresetSaveDict = new Dictionary<int, Dictionary<int, int>>();
    public Action<int> OnFuncPresetUseDataEvent;  //0 更换子方案,1 更换全局方案,2 解锁/更改名
 
    public const int GlobalDefaultPresetID = 1; //默认全局方案ID
    public const int FuncDefaultPresetID = 1;   //默认子功能方案ID
 
    public int[] openConditions; //流派预设(也叫全局方案/战斗方案) 开启条件【开服第N天,主线通关X-Y,定军阁达到N层】
 
    public Action<int, int, int, bool> OnSelectPresetEvent; //选择功能预设方案事件 功能类型 方案ID 是否展开
 
    public override void Init()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitialize;
        ParseConfig();
    }
 
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize;
    }
 
 
    void ParseConfig()
    {
        var config = FuncConfigConfig.Get("FuncPreset");
        openConditions = JsonMapper.ToObject<int[]>(config.Numerical1);
    }
 
    private void OnBeforePlayerDataInitialize()
    {
        battlePreSetDict.Clear();
        m_FuncPresetSaveDict.Clear();
        InitFuncPreset();
    }
 
    //流派解锁
    public bool IsOpen()
    {
        //特殊约定
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.FuncPreset))
            return false;
 
        if (TimeUtility.OpenDay < openConditions[0] - 1)
        {
            return false;
        }
        if (PlayerDatas.Instance.baseData.ExAttr1 / 100 <= openConditions[1])
        {
            return false;
        }
        if (!WarlordPavilionManager.Instance.TryGetHistoryMaxFinishProgress(out int layerNum, out int levelNum))
            return false;
 
        if (layerNum*100 + levelNum < openConditions[2])
        {
            return false;
        }
        
        return true;
    }
 
    //提前显示
    public bool IsPreShow()
    {
        return FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.FuncPreset);
    }
 
    void InitFuncPreset()
    {
        m_FuncPresetDict.Clear();
        // if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Mingge))
        // {
        //     return;
        // }
        var keys = PresetUnlockConfig.GetKeys();
        for (int i = 0; i < keys.Count; i++)
        {
            var config = PresetUnlockConfig.Get(keys[i]);
            if (!m_FuncPresetDict.ContainsKey(config.PresetType))
            {
                m_FuncPresetDict[config.PresetType] = new Dictionary<int, FuncPreset>();
            }
            m_FuncPresetDict[config.PresetType][config.PresetID] = new FuncPreset()
            {
                unLock = config.UnlockType == 0,
                PresetName = Language.Get(config.PresetType == 1 ? "FuncPreset10" : "Mingge13", config.PresetID)
            };
        }
    }
 
    public void UpdateFuncPresetInfoList(HB161_tagSCFuncPresetInfoList vNetData)
    {
        for (int i = 0; i < vNetData.FuncCnt; i++)
        {
            var funcPresetInfo = vNetData.FuncPresetList[i];
            if (!m_FuncPresetDict.ContainsKey(funcPresetInfo.FuncPresetType))
            {
                m_FuncPresetDict[funcPresetInfo.FuncPresetType] = new Dictionary<int, FuncPreset>();
            }
            for (int j = 0; j < funcPresetInfo.PresetCnt; j++)
            {
                var preset = funcPresetInfo.PresetList[j];
                //该功能预设解锁状态,按预设ID二进制位运算记录是否已解锁
                bool _unlock = (funcPresetInfo.UnlockState & (1 << preset.PresetID)) != 0;
                m_FuncPresetDict[funcPresetInfo.FuncPresetType][preset.PresetID] = new FuncPreset()
                {
                    unLock = _unlock,
                    PresetName = string.IsNullOrEmpty(preset.PresetName) ?
                        Language.Get(funcPresetInfo.FuncPresetType == 1 ? "FuncPreset10" : "Mingge13", preset.PresetID) : preset.PresetName,
                };
            }
        }
 
        OnFuncPresetUseDataEvent?.Invoke(2);
    }
 
    //每个全局方案的存储信息
    public void UpdateFuncPresetUseData(HB162_tagSCFuncPresetSwitchInfo vNetData)
    {
        for (int i = 0; i < vNetData.BatPresetCnt; i++)
        {
            var batPreset = vNetData.BatPresetList[i];
            if (!m_FuncPresetSaveDict.ContainsKey(batPreset.BatPresetID))
            {
                m_FuncPresetSaveDict[batPreset.BatPresetID] = new Dictionary<int, int>();
            }
            for (int j = 0; j < batPreset.FuncCnt; j++)
            {
                var funcPreset = batPreset.FuncPresetList[j];
                m_FuncPresetSaveDict[batPreset.BatPresetID][funcPreset.FuncPresetType] = funcPreset.FuncPresetID;
            }
        }
        OnFuncPresetUseDataEvent?.Invoke(0);
    }
 
    //当前战斗功能的全局方案ID使用情况
    public void UpdateBatPresetNowUseInfo(HB163_tagSCBatPresetSwitchInfo netPack)
    {
        for (int i = 0; i < netPack.BatFuncCnt; i++)
        {
            battlePreSetDict[netPack.BatPresetList[i].BatPresetType] = netPack.BatPresetList[i].BatPresetID;
        }
        OnFuncPresetUseDataEvent?.Invoke(1);
    }
 
    //根据战斗获取全局方案ID,如果取不到默认方案1
    public int GetGlobalPresetID(int battlePresetType)
    {
        if (battlePreSetDict.ContainsKey(battlePresetType))
        {
            return battlePreSetDict[battlePresetType];
        }
        return 1;
    }
 
    //指定战斗模式下获取子功能方案ID,如果取不到默认方案1
    public int GetFuncPresetIDByBattleType(int battlePresetType, int funcType)
    {
        int globalPresetID = GetGlobalPresetID(battlePresetType);
        if (m_FuncPresetSaveDict.ContainsKey(globalPresetID) && m_FuncPresetSaveDict[globalPresetID].ContainsKey(funcType))
        {
            return m_FuncPresetSaveDict[globalPresetID][funcType];
        }
        return 1;
    }
 
    //指定流派获取子功能方案ID,如果取不到默认方案1
    public int GetFuncPresetID(int globalPresetID, int funcType)
    {
        if (m_FuncPresetSaveDict.ContainsKey(globalPresetID) && m_FuncPresetSaveDict[globalPresetID].ContainsKey(funcType))
        {
            return m_FuncPresetSaveDict[globalPresetID][funcType];
        }
        return 1;
    }
 
    //获取当前流派下的子功能的方案ID,如果取不到默认方案1
    public int GetFuncPresetID(int funcType)
    {
        int globalPresetID = GetGlobalPresetID((int)BattlePreSetType.Story);
        if (m_FuncPresetSaveDict.ContainsKey(globalPresetID) && m_FuncPresetSaveDict[globalPresetID].ContainsKey(funcType))
        {
            return m_FuncPresetSaveDict[globalPresetID][funcType];
        }
        return 1;
    }
 
    //指定预设信息
    public FuncPreset GetFuncPreset(int funcType, int presetID)
    {
        if (m_FuncPresetDict.ContainsKey(funcType) && m_FuncPresetDict[funcType].ContainsKey(presetID))
        {
            return m_FuncPresetDict[funcType][presetID];
        }
        return null;
    }
 
    // 这里虽然传的是 battleType,但是实际还是根据全局方案ID做对应修改;如果这个全局方案其他地方有使用也是同步变化
    public void SaveFuncPresetID(int battleType, int funcType, int presetID)
    {
        if (funcType == 1)
        {
            SaveBattlePresetID(battleType, presetID);
            return;
        }
        var pack = new CB262_tagCSFuncPresetSwitch();
        pack.FuncPresetType = (byte)funcType;
        pack.PresetID = (byte)presetID;
        pack.BatPresetID = (byte)GetGlobalPresetID(battleType);
        GameNetSystem.Instance.SendInfo(pack);
    }
 
    public void SaveBattlePresetID(int battleType, int globalPresetID)
    {
        var pack = new CB263_tagCSBatPresetSwitch();
        pack.BatPresetID = (byte)globalPresetID;
        pack.BatPresetType = (byte)battleType;
        GameNetSystem.Instance.SendInfo(pack);
    }
 
    public void UnLockPreset(int funcType, int presetID)
    {
        var pack = new CB260_tagCSFuncPresetUnlock();
        pack.FuncPresetType = (byte)funcType;
        pack.PresetID = (byte)presetID;
        GameNetSystem.Instance.SendInfo(pack);
        SysNotifyMgr.Instance.ShowTip("FuncPreset2");
    }
 
    //要显示的方案数量; 根据情况会包含未解锁
    //a. 按元宝解锁的为逐一开启,默认开启x个,第x+1个显示条件需要【流派预设】功能开启, 可解锁后逐一保留一个锁住的(直到全开启);
    //b. 按功能条件开启的,如果默认只开其一个方案的情况不显示,达到下一个方案的条件满足后全显示;默认大于1个的情况直接全显示
    public int GetShowFuncPresetCount(int funcType)
    {
        var unlockCnt = GetUnlockCnt(funcType);
        var maxCount = PresetUnlockConfig.GetFuncPresetMaxCount(funcType);
        var unlockType = PresetUnlockConfig.GetUnlockType(funcType);
        if (unlockType == 2)
        {
            //命格按推演境界解锁
            //只有1个方案则不显示,大于1个则全显示
            if (unlockCnt == 1)
            {
                var config = PresetUnlockConfig.GetPresetUnlockConfig(funcType, 2);
                if (MinggeManager.Instance.m_GanwuLV >= config.UnlockValue)
                {
                    return maxCount;
                }
                return 0;
            }
            return maxCount;
        }
        if (!IsOpen())
        {
            //未开启时,默认大于1则显示
            return unlockCnt == 1 ? 0 : unlockCnt;
        }
 
        return unlockCnt == maxCount ? unlockCnt : unlockCnt + 1;
    }
 
    public int GetUnlockCnt(int funcType)
    {
        int count = 0;
        if (m_FuncPresetDict.ContainsKey(funcType))
        {
            for (int i = 0; i < m_FuncPresetDict[funcType].Count; i++)
            {
                if (m_FuncPresetDict[funcType][i + 1].unLock)
                {
                    count++;
                }
            }
        }
        return count;
    }
 
    //选择方案:解锁或选中
    // 选择方案返回true,否则返回false
    public bool ClickFuncPreset(int battleType, int funcType, int id)
    {
        var config = PresetUnlockConfig.GetPresetUnlockConfig(funcType, id);
        var data = GetFuncPreset(funcType, id);
        if (!data.unLock)
        {
            // 未解锁 则购买
            if (config.UnlockType == 1)
            {
                ConfirmCancel.MoneyIconToggleConfirmByType(ToggleCheckType.FuncPreset, config.UnlockValue, 1,
                            Language.Get("FuncPreset12", UIHelper.GetIconNameWithMoneyType(1), config.UnlockValue), () =>
                                {
                                    if (!UIHelper.CheckMoneyCount(1, config.UnlockValue, 2))
                                        return;
 
                                    UnLockPreset(funcType, id);
                                });
            }
            else if (config.UnlockType == 2)
            {
 
                if (MinggeManager.Instance.m_GanwuLV < config.UnlockValue)
                {
                    SysNotifyMgr.Instance.ShowTip("FuncPreset1", config.UnlockValue);
                    return false;
                }
                UnLockPreset(funcType, id);
            }
            return false;
        }
 
        SaveFuncPresetID(battleType, funcType, id);
        return true;
    }
 
    // 点击流派/防守预设按钮
    public void ClickBattlePreset(int battleType)
    {
        if (battleType > 1)
        {
            UIManager.Instance.OpenWindow<FuncPresetWin>(battleType);
            return;
        }
 
        if (!IsOpen())
        {
            UIManager.Instance.OpenWindow<FuncPresetUnLockWin>(battleType);
        }
        else
        {
            UIManager.Instance.OpenWindow<FuncPresetWin>(battleType);
        }
    }
 
    //功能类的满足条件后,提示红点手动解锁
    // 某个方案是否要红点提示
    public bool ShowRed(int funcType, int id)
    {
        if (funcType == (int)FuncPresetType.Mingge)
        {
            var presetData = GetFuncPreset(funcType, id);
            if (presetData.unLock)
            {
                return false;
            }
            var config = PresetUnlockConfig.GetPresetUnlockConfig(funcType, id);
            if (config != null && config.UnlockType == 2 && MinggeManager.Instance.m_GanwuLV < config.UnlockValue)
            {
                return false;
            }
            return true;
        }
 
        return false;
    }
 
    public int GetNeedShowRedID(int funcType)
    {
        if (funcType == (int)FuncPresetType.Mingge)
        {
            var maxCnt = PresetUnlockConfig.GetFuncPresetMaxCount(funcType); ;
            for (int i = 1; i <= maxCnt; i++)
            {
                if (ShowRed(funcType, i))
                {
                    return i;
                }
            }
        }
        return 0;
    }
 
 
}
 
 
public class FuncPreset
{
    public bool unLock; //是否解锁
    public string PresetName;        //预设名称
}
 
 
 
//战斗功能区分对应存储全局方案ID,如演武场防守用哪个全局方案ID的分类
public enum BattlePreSetType
{
    None = 0,
    Story = 1, //主线
    Arena = 2,  //演武场防守
 
}
 
//功能预设类型 1-全局战斗;2-阵容;3-命格;
public enum FuncPresetType
{
    Global = 1,
    Team = 2,
    Mingge = 3,
}