hch
2 天以前 f2c78eecd49edc328225b77492e7f45e157bad02
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
using System;
using LitJson;
 
using System.Collections.Generic;
using System.Linq;
 
//淘金功能
public class GoldRushManager : GameSystemManager<GoldRushManager>
{
    public const int funcID = 8;
    int campUnlockState;
    int workerUnlockState;
    public int panningCnt;  //累计总次数
    public int lastRecoverTime;  // 上次免费恢复淘金令时间戳,为0时可不用倒计时
    public int housekeeperEndTime;   // 自动管家到期时间戳,有值同时也代表免费试用已使用
    public byte[] warehouseIDList;  //完成的,包含0空,主要用于领取的索引
    public Dictionary<int, HB037_tagSCGoldRushCampInfo.tagSCGoldRushCamp> campInfoDict = new Dictionary<int, HB037_tagSCGoldRushCampInfo.tagSCGoldRushCamp>();
 
    public event Action<int> OnGoldRushCampEvent;    //服务端通知营地信息
    public event Action OnGoldRushInfoEvent;
 
 
    //行为事件
    public event Action<int> OnRefreshItemEvent; //刷新淘金道具
    public event Action<int, int, int> GoldRushEvent; //营地ID,执行事件(0出发,1返程),监工数量
    public event Action<PosEvent, bool, int, int, string> PathEvent; //事件,是否返程,营地ID,第几个工人,聊天内容(后续考虑传结构数据)
 
    public const int followWorkerCount = 3;   //小兵的数量,非监工
 
    public int m_MaxWorkerCount;   //配表的最大数量
    //监工的数量,解锁影响
    public int maxWorkerCount
    {
        get
        {
            int count = 0;
            for (int i = 1; i <= m_MaxWorkerCount; i++)
            {
                if (IsWorkerUnLock(i))
                {
                    count++;
                }
            }
            return count;
        }
    }
    public List<int> skinIDs = new List<int>(); //随机的监工皮肤 ,已解锁
 
    public int selectCampID;
    bool m_IsAutoWorking;   //是否暂停
    //是否在执行自动管家,没有淘金令时暂停,仓库满暂停
    public bool isAutoWorking
    {
        get
        {
            return m_IsAutoWorking && isOpenAuto;
        }
    }
    public bool isOpenAuto; //是否开启自动管家,重登会取消
 
    public event Action OnAutoWorkingEvent;
 
    //自动刷新物品,判断是ture开 false关, 因默认开启故值相反存储0是开,1是关
    public bool isAutoRefreshItem
    {
        get
        {
            //第十个数用于存储是否开启自动刷新,其他数用于存储物品等级
            var value = QuickSetting.Instance.GetQuickSettingValue<int>(QuickSettingType.AutoGoldRush, 10);
            return value == 0;
        }
        set
        {
            QuickSetting.Instance.SetQuickSetting<int>(QuickSettingType.AutoGoldRush, Convert.ToInt32(!value), 10);
 
            QuickSetting.Instance.SendPackage();
        }
    }
 
 
 
    //配置
    public int refreshMoneyType;
    public int[] refreshMoneyList;
    public Dictionary<int, int> itemIDUnLockFuncIDDict = new Dictionary<int, int>();
 
    bool openAutoGoldRush
    {
        get
        {
            return housekeeperEndTime > 0 && TimeUtility.AllSeconds < housekeeperEndTime;
        }
    }
 
    //淘金仓库(已完成任务未领取的存储)上限
    int warehouseBaseCnt;
    int warehouseAddCnt;
    public int warehouseMaxCnt
    {
        get
        {
            return warehouseBaseCnt + (openAutoGoldRush ? warehouseAddCnt : 0);
        }
    }
 
    //淘金令(任务未做的)上限
    int goldRushMissionBaseCnt;
    int goldRushMissionAddCnt;
    public int goldRushMissionMaxCnt
    {
        get
        {
            return goldRushMissionBaseCnt + (openAutoGoldRush ? goldRushMissionAddCnt : 0);
        }
    }
 
    public int restoreMissionSeconds;   //自动恢复任务时间
 
    public int freeAutoDays;   //免费试用天数
 
    public List<int> buyAutoDaysList = new List<int>();   //购买自动管家天数
    public List<int> buyAutoCTGIDList = new List<int>();   //购买自动管家CTGID
    public int[] autoRefreshItemIDs;    //自动刷新物品ID列表
 
 
    public PlayerDataType unLockMoneyType; //刷新用
 
 
    public override void Init()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitialize;
        PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefresh;
 
        m_MaxWorkerCount = GoldRushWorkerConfig.GetKeys().Count;
 
        ParseConfig();
    }
 
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize;
        PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefresh;
    }
 
    void ParseConfig()
    {
        var config = FuncConfigConfig.Get("GoldRushRefresh");
        refreshMoneyType = int.Parse(config.Numerical2);
        refreshMoneyList = JsonMapper.ToObject<int[]>(config.Numerical3);
        itemIDUnLockFuncIDDict = ConfigParse.ParseIntDict(config.Numerical5);
 
        config = FuncConfigConfig.Get("GoldRush");
        var countArr = ConfigParse.GetMultipleStr<int>(config.Numerical1);
        warehouseBaseCnt = countArr[0];
        warehouseAddCnt = countArr[1];
        countArr = ConfigParse.GetMultipleStr<int>(config.Numerical2);
        goldRushMissionBaseCnt = countArr[0];
        goldRushMissionAddCnt = countArr[1];
        restoreMissionSeconds = int.Parse(config.Numerical3) * 60;
 
        config = FuncConfigConfig.Get("GoldRushAuto");
        var tmpArr = JsonMapper.ToObject<int[]>(config.Numerical1);
        freeAutoDays = tmpArr[0];
        for (int i = 1; i < tmpArr.Length; i++)
        {
            buyAutoDaysList.Add(tmpArr[i]);
        }
        var tmpArr2 = JsonMapper.ToObject<int[][]>(config.Numerical2);
        for (int i = 0; i < tmpArr2.Length; i++)
        {
            buyAutoCTGIDList.Add(tmpArr2[i][0]);
        }
 
        autoRefreshItemIDs = JsonMapper.ToObject<int[]>(config.Numerical3);
    }
 
    void OnBeforePlayerDataInitialize()
    {
        campUnlockState = 0;
        workerUnlockState = 0;
        panningCnt = 0;
        housekeeperEndTime = 0;
        warehouseIDList = new byte[0];
        lastRecoverTime = 0;
        campInfoDict.Clear();
        isOpenAuto = false;
    }
 
 
 
    void OnPlayerDataRefresh(PlayerDataType type)
    {
        //unLockMoneyType未赋值则不会刷新 减少运行
        if (type == unLockMoneyType)
        {
            UpdateRedpoint();
        }
        else if (type == PlayerDataType.GoldRush)
        {
            SetAutoWorking(isOpenAuto, UIHelper.GetMoneyCnt(52) > 0);
        }
    }
 
 
    public int GetRandommSkinID()
    {
        //从已解锁中随机
        return skinIDs[UnityEngine.Random.Range(0, skinIDs.Count)];
    }
 
    void RefreshUnLockSkinID()
    {
        skinIDs.Clear();
        foreach (var item in GoldRushWorkerConfig.GetValues())
        {
            if (IsWorkerUnLock(item.WorkerID))
            {
                skinIDs.Add(item.SkinID);
            }
        }
    }
 
    public void UpdateGoldRushInfo(HB036_tagSCGoldRushInfo netPack)
    {
        campUnlockState = (int)netPack.CampState;
        if (workerUnlockState != netPack.WorkerState)
        {
            workerUnlockState = (int)netPack.WorkerState;
            RefreshUnLockSkinID();
        }
        panningCnt = (int)netPack.PanningCnt;
        housekeeperEndTime = (int)netPack.HousekeeperEndTime;
        warehouseIDList = netPack.WarehouseIDList;
        lastRecoverTime = (int)netPack.LastRecoverTime;
        UpdateRedpoint();
        OnGoldRushInfoEvent?.Invoke();
    }
 
    public void UpdateGoldRushCampInfo(HB037_tagSCGoldRushCampInfo netPack)
    {
        for (int i = 0; i < netPack.CampCnt; i++)
        {
            campInfoDict[netPack.CampList[i].CampID] = netPack.CampList[i]; ;
            OnGoldRushCampEvent?.Invoke(netPack.CampList[i].CampID);
        }
        UpdateRedpoint();
 
    }
 
    //获取淘金仓库总量含正在执行的
    public int GetWarehouseCnt()
    {
        //排查0
        int cnt = 0;
        foreach (var item in warehouseIDList)
        {
            if (item != 0)
            {
                cnt++;
            }
        }
        foreach (var item in campInfoDict.Values)
        {
            if (item.GoldID != 0 && item.EndTime != 0)
            {
                cnt++;
            }
        }
        return cnt;
    }
 
    //获取淘金ID
    public int GetCampGoldID(int campID)
    {
        if (campInfoDict.ContainsKey(campID))
        {
            return campInfoDict[campID].GoldID;
        }
        return 0;
    }
 
    //获取营地工人
    public int GetCampWorkerCnt(int campID)
    {
        if (campInfoDict.ContainsKey(campID))
        {
            return campInfoDict[campID].WorkerCnt;
        }
        return 0;
    }
 
    public int GetEmptyWorkerCount()
    {
        int count = 0;
        foreach (var item in campInfoDict.Values)
        {
            count += item.WorkerCnt;
        }
        return maxWorkerCount - count;
    }
 
    //获取营地刷新次数
    public int GetCampRefreshCnt(int campID)
    {
        if (campInfoDict.ContainsKey(campID))
        {
            return campInfoDict[campID].RefreshCnt;
        }
        return 0;
    }
 
    //获取营地结束时间,0代表未开始
    public int GetCampEndTime(int campID)
    {
        if (campInfoDict.ContainsKey(campID))
        {
            if (campInfoDict[campID].GoldID == 0)
            {
                return 0;
            }
            return (int)campInfoDict[campID].EndTime;
        }
        return 0;
    }
 
 
    public string GetCampItemName(GoldRushItemConfig config)
    {
        return UIHelper.AppendColor(config.ItemLV, Language.Get("L1113", config.ItemLV) + " " + ItemConfig.Get(config.ItemID).ItemName);
    }
 
 
    //营地是否已解锁
    public bool IsCampUnLock(int campID)
    {
        return (campUnlockState & (1 << campID)) != 0;
    }
 
    //工人是否已解锁
    public bool IsWorkerUnLock(int workerID)
    {
        return (workerUnlockState & (1 << workerID)) != 0;
    }
 
    // 0-发布淘金(消耗淘金令);1-刷新淘金;2-开始淘金或调整监工数;3-取消淘金
    public void SendGoldRushOP(int opType, int campID, int workerCnt)
    {
        var pack = new CB036_tagCSGoldRushOP();
        pack.OPType = (byte)opType;
        pack.CampID = (byte)campID;
        pack.WorkerCnt = (byte)workerCnt;
        GameNetSystem.Instance.SendInfo(pack);
        if (opType <= 1)
        {
            OnRefreshItemEvent?.Invoke(campID);
        }
    }
 
    //解锁  0-营地;1-监工
    public void SendGoldRushUnlock(int unlockType, int id)
    {
        var pack = new CB037_tagCSGoldRushUnlock();
        pack.UnlockType = (byte)unlockType;
        pack.UnlockID = (byte)id;
        GameNetSystem.Instance.SendInfo(pack);
    }
 
    public void SendGoldRushWarehouseAward(int index, int isAll)
    {
        var pack = new CB038_tagCSGoldRushWarehouseAward();
        pack.AwardIndex = (byte)index;
        pack.IsAll = (byte)isAll;
        GameNetSystem.Instance.SendInfo(pack);
    }
 
    public void GetAllAward()
    {
        if (CheckHasFinishGoldRush())
        {
            SendGoldRushWarehouseAward(0, 1);
        }
    }
 
 
    //通知外出行为事件
    public void NotifyGoldRushEvent(int campID, int eventType, int leaderCount)
    {
        GoldRushEvent?.Invoke(campID, eventType, leaderCount);
    }
 
    //通知路径行为事件
    public void NotifyPathEvent(PosEvent posEvent, bool isBack, int tendID, int index, string content)
    {
        PathEvent?.Invoke(posEvent, isBack, tendID, index, content);
    }
 
 
    //红点:可领取,可解锁的监工
    Redpoint redpoint = new Redpoint(MainRedDot.MainAffairsRedpoint, MainRedDot.BlessedLandRedpoint);
 
    //可解锁的监工
    Redpoint workerRedpoint = new Redpoint(MainRedDot.BlessedLandRedpoint, MainRedDot.BlessedLandRedpoint * 10 + 1);
 
    //可领取的奖励
    Redpoint awardRedpoint = new Redpoint(MainRedDot.BlessedLandRedpoint, MainRedDot.BlessedLandRedpoint * 10 + 2);
    //营地解锁红点
    Redpoint campRedpoint = new Redpoint(MainRedDot.MainAffairsRedpoint, MainRedDot.BlessedLandRedpoint * 10);
 
    void UpdateRedpoint()
    {
        if (CheckCanUnLockWorker())
        {
            workerRedpoint.state = RedPointState.Simple;
        }
        else
        {
            workerRedpoint.state = RedPointState.None;
        }
 
        if (CheckHasFinishGoldRush())
        {
            awardRedpoint.state = RedPointState.Simple;
        }
        else
        {
            awardRedpoint.state = RedPointState.None;
        }
 
 
        campRedpoint.state = CheckCanUnLockCamp() ? RedPointState.Simple : RedPointState.None;
    }
 
    //玩家数据类型
    void InitUnlockMoney(int type)
    {
        unLockMoneyType = UIHelper.moneyTypeToPlayerDataType[type];
    }
 
    //检查是否有可解锁的监工
    bool CheckCanUnLockWorker()
    {
        foreach (var workerID in GoldRushWorkerConfig.GetKeys())
        {
            if (IsWorkerUnLock(workerID))
            {
                continue;
            }
            var config = GoldRushWorkerConfig.Get(workerID);
            if (config.MoneyUnlock.Length != 0)
            {
                InitUnlockMoney(config.MoneyUnlock[0]);
 
                if (UIHelper.GetMoneyCnt(config.MoneyUnlock[0]) < config.MoneyUnlock[1])
                {
                    continue;
                }
            }
 
            if (config.PlayerLVUnlock != 0 && PlayerDatas.Instance.baseData.LV < config.PlayerLVUnlock)
            {
                continue;
            }
 
            return true;
        }
        return false;
    }
 
    bool CheckHasFinishGoldRush()
    {
        //非0
        foreach (var id in warehouseIDList)
        {
            if (id != 0)
            {
                return true;
            }
        }
        return false;
    }
 
    //获取已完成的营地数量
    public int GetFinishGoldRushCount()
    {
        int cnt = 0;
        foreach (var id in warehouseIDList)
        {
            if (id != 0)
            {
                ++cnt;
            }
        }
        return cnt;
    }
 
    //检查是否有可解锁的营地
    bool CheckCanUnLockCamp()
    {
        foreach (var campID in GoldRushCampConfig.GetKeys())
        {
            if (IsCampUnLock(campID))
            {
                continue;
            }
 
            var config = GoldRushCampConfig.Get(campID);
            if (config.MoneyUnlock.Length != 0)
            {
                InitUnlockMoney(config.MoneyUnlock[0]);
 
                if (UIHelper.GetMoneyCnt(config.MoneyUnlock[0]) < config.MoneyUnlock[1])
                {
                    continue;
                }
            }
 
            if (config.PanningUnlock != 0 && panningCnt < config.PanningUnlock)
            {
                continue;
            }
 
 
            return true;
 
        }
        return false;
    }
 
 
    //0 已解锁 1 次数锁 2 金钱锁
    public int GetCampLockState(int campID)
    {
        if (IsCampUnLock(campID))
        {
            return 0;
        }
        var config = GoldRushCampConfig.Get(campID);
        if (config.PanningUnlock != 0)
        {
            return 1;
        }
 
        if (config.MoneyUnlock.Length != 0)
        {
            return 2;
        }
 
        return 0;
 
    }
 
    //0 已解锁 1 等级锁 2 金钱锁
    public int GetWorkerLockState(int workerID)
    {
        if (IsWorkerUnLock(workerID))
        {
            return 0;
        }
        var config = GoldRushWorkerConfig.Get(workerID);
        if (config.PlayerLVUnlock != 0)
        {
            return 1;
        }
 
        if (config.MoneyUnlock.Length != 0)
        {
            return 2;
        }
 
        return 0;
 
    }
 
 
    //自动淘金 先填充营地 再填充多个监工
 
    void SetAutoWorking(bool _isOpenAuto, bool _isAutoWorking)
    {
        isOpenAuto = _isOpenAuto;
        m_IsAutoWorking = _isAutoWorking;
        OnAutoWorkingEvent?.Invoke();
    }
 
 
    //自动淘金的物品,按物品id配置索引存储
    // 返回值0代表不勾选,数值代表等级,因默认是0,所以存储上 9代表不勾选,0代表等级1, 后续加1
    public int GetAutoItemLV(int index)
    {
        var value = QuickSetting.Instance.GetQuickSettingValue<int>(QuickSettingType.AutoGoldRush, index);
        if (value == 9)
        { 
            return 0;
        }
        return value + 1;
    }
 
    //设置自动淘金的物品,按物品id配置索引存储
    // 参数0代表不勾选,数值代表等级,因默认是0,所以存储上 9代表不勾选,0代表等级1, 后续加1
    public void SetAutoItemLV(int index, int value)
    {
        if (value == 0)
        { 
            value = 9;
        }
        else
        {
            value--;
        }
        QuickSetting.Instance.SetQuickSetting<int>(QuickSettingType.AutoGoldRush, value, index);
        QuickSetting.Instance.SendPackage();
    }
 
 
}