hch
1 天以前 cfe2a2d5bc6fe9a85488542597d4f73dddbfeee8
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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cysharp.Threading.Tasks;
using LitJson;
using UnityEngine;
 
 
public class GuildManager : GameSystemManager<GuildManager>
{
    // 申请的公会列表
    private List<int> m_FairyRequesteds = new List<int>();
    // 公会自定义记录附加数据,按类型存储
    // 公会ID, 类型ID, 数据
    public Dictionary<int, Dictionary<int, HA513_tagMCFamilyActionInfo.tagMCFamilyAction[]>> familyActions = new Dictionary<int, Dictionary<int, HA513_tagMCFamilyActionInfo.tagMCFamilyAction[]>>();
    public event Action<int, int> FamilyActionInfoEvent;    //公会自定义记录, 其他功能从这获取
 
    //要操作哪个成员的索引
    int m_MemberOPIndex = -1;
    public event Action MemberOPIndexEvent;
    public int memberOPIndex
    {
        get { return m_MemberOPIndex; }
        set
        {
            m_MemberOPIndex = value;
            MemberOPIndexEvent?.Invoke();
        }
    }
 
    public byte[] donateCntList;
    public event Action DonateCntListEvent;
    public event Action<bool> EnterOrQuitGuildEvent;   //进入或退出公会事件
 
 
    public override void Init()
    {
        ParseConfig();
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
        PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshEvent;
    }
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
        PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
    }
 
 
    void OnBeforePlayerDataInitialize()
    {
        ClearGuildData();
    }
 
    void OnPlayerLoginOk()
    {
        UpdateDonateRedPoint();
        QueryZBGFamilyInfo();
    }
    
    void PlayerDataRefreshEvent(PlayerDataType type)
    {
        if(type == PlayerDataType.default33)
        {
            UpdateDonateRedPoint();
        }
    }
 
    void ClearGuildData()
    {
        m_FairyRequesteds.Clear();
        familyActions.Clear();
        guildChanged = false;
        applyList.Clear();
        PlayerDatas.Instance.fairyData.ClearData();
    }
    
    //退出公会
    public void AfterQuitGuild()
    {
        //退出公会
        ClearGuildData();
        //需要转到HomeWin界面 且关闭公会相关界面(父子继承关闭)
        UIManager.Instance.GetUI<MainWin>()?.ClickFunc(0);
 
 
        isQueryZBGYet = false;
        zhenbaogeCutState = 0;
        familyZBGActions.Clear();
        sortPlayerCut.Clear();
        
        UpdateZBGRedpoint();
        UpdateDonateRedPoint();
        EnterOrQuitGuildEvent?.Invoke(false);
    }
 
    //注意上线通知公会数据时也会触发
    public async UniTask AfterEnterGuild()
    {
        //这里还没有公会数据, 后续的包会更新公会数据
        await UniTask.Delay(100);
        UpdateDonateRedPoint();
        UpdateZBGRedpoint();
        EnterOrQuitGuildEvent?.Invoke(true);
    }
 
 
    #region 配置
 
    public int createFairyCost
    {
        get;
        private set;
    }
    public int createMoneyType;
 
    public int requestPlayerCount;  //每个仙盟最大可接受申请加入玩家数
    public int requestGuildCount;   //每个玩家最大可同时申请加入仙盟数
 
    // 权限ID: 1-收人,2-变更职位,3-发布公告,4-踢人
    // 职位: 0-成员,1-精英,2-副盟主,3-盟主
    public Dictionary<int, int> guildWorkToLevel = new Dictionary<int, int>();
 
    //退出惩罚
    public int[] quitGuildPunishTime;
    public int[] beQuitGuildPunishTime;
    public int quitGuildPunishMoneyType;
    public int[] quitGuildPunishMoney;
    public int[] beQuitGuildPunishMoney;
 
    //改名
    public int renameFairyNameCD;
    public int renameFairyNameCost;
    public int renameFairyNameMoneyType;
 
 
    
 
    //珍宝阁(行商)
    public int zhenbaogeCutState = 0;
    public int zhenbaogeBuyState = 0;
    public bool needCheckCutCD = false;
    public event Action UpdateZhenbaogeEvent;
    public bool isQueryZBGYet = false;
    public float lastZBGStartTime = 0; //过天刷新用
    public const int ZBGFamilyActionType = 16;
    //{id:数据} 砍价行为,value1为玩家ID,特殊约定为1时为家族的数据
    public Dictionary<int, HA513_tagMCFamilyActionInfo.tagMCFamilyAction> familyZBGActions = new Dictionary<int, HA513_tagMCFamilyActionInfo.tagMCFamilyAction>();
    public List<int> sortPlayerCut = new List<int>();
    public event Action<bool> UpdateFamilyActionEvent;
    public int zbgPriceType;
    public int zbgOrgPriceValue;
    public int zbgChangFamilyCD;
    public List<int> cutCntListForTalk = new List<int>();
 
 
    void ParseConfig()
    {
        DirtyWordConfig.DirtyWordInit();
        DirtyNameConfig.DirtyNameInit();
 
        var config = FuncConfigConfig.Get("CreateFamily");
        createFairyCost = int.Parse(config.Numerical1);
        createMoneyType = int.Parse(config.Numerical2);
 
        // config = FuncConfigConfig.Get("FamilyMatchSet");
        // fairyLeagueLimit = int.Parse(config.Numerical1);
 
        config = FuncConfigConfig.Get("FamilyReqJoin");
        requestPlayerCount = int.Parse(config.Numerical1);
        requestGuildCount = int.Parse(config.Numerical2);
 
        config = FuncConfigConfig.Get("FamilyPower");
        guildWorkToLevel = ConfigParse.ParseIntDict(config.Numerical1);
 
        config = FuncConfigConfig.Get("FamilyLeave");
        quitGuildPunishTime = JsonMapper.ToObject<int[]>(config.Numerical1);
        beQuitGuildPunishTime = JsonMapper.ToObject<int[]>(config.Numerical2);
        quitGuildPunishMoneyType = int.Parse(config.Numerical3);
        quitGuildPunishMoney = JsonMapper.ToObject<int[]>(config.Numerical4);
        beQuitGuildPunishMoney = JsonMapper.ToObject<int[]>(config.Numerical5);
 
        config = FuncConfigConfig.Get("FamilyRename");
        renameFairyNameCD = int.Parse(config.Numerical2);
        var arr = ConfigParse.GetMultipleStr<int>(config.Numerical1);
        renameFairyNameMoneyType = arr[0];
        renameFairyNameCost = arr[1];
 
        config = FuncConfigConfig.Get("Zhenbaoge");
        zbgPriceType = int.Parse(config.Numerical1);
        zbgOrgPriceValue = int.Parse(config.Numerical2);
        zbgChangFamilyCD = int.Parse(config.Numerical3);
        cutCntListForTalk = JsonMapper.ToObject<List<int>>(config.Numerical4);
    }
 
 
    #endregion
 
 
    //我的请求加入公会的列表
    public event Action MyRequestJoinEvent;
    public void UpdateFairyRequested(HA501_tagMCNotifyRequestJoinFamilyInfo _package)
    {
        m_FairyRequesteds.Clear();
        for (int i = 0; i < _package.RequestCount; i++)
        {
            m_FairyRequesteds.Add((int)_package.RequestJoinFamilyIDList[i]);
        }
        MyRequestJoinEvent?.Invoke();
    }
 
 
    public bool IsGuildRequested(int _fairyId)
    {
        return m_FairyRequesteds.Contains(_fairyId);
    }
 
 
 
    public bool InSameFairy(int playerId)
    {
        if (!PlayerDatas.Instance.fairyData.HasFairy)
        {
            return false;
        }
        return PlayerDatas.Instance.fairyData.GetMember(playerId) != null;
    }
 
 
 
    #region 创建公会 改名
    public bool CheckFairyNameLimit(string _name, out int errorCode)
    {
        errorCode = 0;
        if (string.IsNullOrEmpty(_name))
        {
            errorCode = 0;
            return false;
        }
        if (DirtyWordConfig.IsDirtWord(_name) || UIHelper.HasSpecialCharac(_name)
            || DirtyNameConfig.IsDirtName(_name))
        {
            errorCode = 1;
            return false;
        }
        if (UIHelper.IsNumeric(_name))
        {
            errorCode = 2;
            return false;
        }
        return true;
    }
 
 
    public void ShowFairyNameErrorTip(int _errorCode)
    {
        switch (_errorCode)
        {
            case 0:
                //空
                SysNotifyMgr.Instance.ShowTip("FamilyNameChangeNoNull");
                break;
            case 1:
                // 脏字
                SysNotifyMgr.Instance.ShowTip("NameSensitive");
                break;
            case 2:
                // 不能纯数字
                SysNotifyMgr.Instance.ShowTip("NameError3");
                break;
        }
    }
 
    public void SendChangeFairyName(string _name, int _itemIndex)
    {
        LanguageVerify.Instance.VerifyFairy(_name, 2, PlayerDatas.Instance.fairyData.fairy.FamilyName, PlayerDatas.Instance.fairyData.mine.FmLV, (bool ok, string content) =>
        {
            CA611_tagCMRenameFamily _pak = new CA611_tagCMRenameFamily();
            _pak.NewName = content;
            _pak.ItemIndex = (byte)_itemIndex;
            _pak.NewNameLen = (byte)Encoding.UTF8.GetBytes(content).Length;
            GameNetSystem.Instance.SendInfo(_pak);
        });
    }
 
 
 
 
    int GetJoinCD()
    {
        if (PlayerDatas.Instance.baseData.leaveFamilyTime == 0)
            return 0;
        var quitType = PlayerDatas.Instance.baseData.leaveGuildInfo % 10;
        int quitCount = 0;
        int punishTime = 0;
        if (quitType == 0)
        {
            //被踢
            quitCount = PlayerDatas.Instance.baseData.leaveGuildInfo / 10 % 10 - 1;
            if (quitCount < 0) return 0;
            if (beQuitGuildPunishTime.Length != 0)
                punishTime = beQuitGuildPunishTime[Math.Min(quitCount, beQuitGuildPunishTime.Length - 1)];
        }
        else if (quitType == 1)
        {
            //主动退出
            quitCount = PlayerDatas.Instance.baseData.leaveGuildInfo / 100 - 1;
            if (quitCount < 0) return 0;
            if (quitGuildPunishTime.Length != 0)
                punishTime = quitGuildPunishTime[Math.Min(quitCount, quitGuildPunishTime.Length - 1)];
        }
 
        return punishTime * 60 - (TimeUtility.AllSeconds - PlayerDatas.Instance.baseData.leaveFamilyTime);
    }
 
 
    // 创建公会
    public void CreateGuild(string name, int emblemID, string emblemWord)
    {
        var cdSeconds = GetJoinCD();
        if (cdSeconds > 0)
        {
            SysNotifyMgr.Instance.ShowTip("GuildSys4", TimeUtility.SecondsToHMSEx(cdSeconds));
            return;
        }
 
        if (!UIHelper.CheckMoneyCount(createMoneyType, createFairyCost, 2))
        {
            return;
        }
 
        if (emblemWord.Length > 1)
        {
            //预制体输入框限制,不限任意字符都只能输入1个字
            return;
        }
 
        if (!CheckName(name))
        {
            return;
        }
 
        var pack = new CA604_tagCMCreateFamily();
        pack.Name = name;
        pack.EmblemID = (ushort)emblemID;
        pack.EmblemWord = emblemWord;
        GameNetSystem.Instance.SendInfo(pack);
 
    }
 
    public bool CheckName(string name)
    {
        int error;
 
        //获取name的字节长度,name可能是中文 或者其他占用3个字符的符号
        if (!UIHelper.SatisfyNameLength(name, out error))
        {
            // TODO 暂时按中文长度提示, 不同语言可根据情况修改
            if (error == 1)
            {
                SysNotifyMgr.Instance.ShowTip("NameError2", 7);
                return false;
            }
            else if (error == 2)
            {
                SysNotifyMgr.Instance.ShowTip("NameError1", 2);
                return false;
            }
        }
 
        if (!CheckFairyNameLimit(name, out error))
        {
            ShowFairyNameErrorTip(error);
            return false;
        }
 
        return true;
    }
 
    #endregion
 
 
 
 
    #region 仙盟商店开启
    public int fairyStoreLimit = 0;
    public bool fairyStoreOpen
    {
        get
        {
            if (PlayerDatas.Instance.fairyData.HasFairy)
            {
                var fairy = PlayerDatas.Instance.fairyData.fairy;
                if (fairy != null && fairy.FamilyLV >= fairyStoreLimit)
                {
                    return true;
                }
            }
            return false;
        }
    }
 
    public void ProcessErrorTip()
    {
        if (!PlayerDatas.Instance.fairyData.HasFairy)
        {
            SysNotifyMgr.Instance.ShowTip("DailyQuestwinUnionLimit");
        }
        else if (PlayerDatas.Instance.fairyData.fairy.FamilyLV < fairyStoreLimit)
        {
            SysNotifyMgr.Instance.ShowTip("FairyStoreOpenLimit", fairyStoreLimit);
        }
    }
    #endregion
 
 
 
 
    #region  公会自定义记录
    public void UpdateFamilyAction(HA513_tagMCFamilyActionInfo _package)
    {
        if (PlayerDatas.Instance.fairyData == null ||
            PlayerDatas.Instance.fairyData.fairy == null ||
            PlayerDatas.Instance.fairyData.fairy.FamilyID != _package.FamilyID)
        {
            return;
        }
 
        if (!familyActions.ContainsKey((int)_package.FamilyID))
        {
            familyActions.Add((int)_package.FamilyID, new Dictionary<int, HA513_tagMCFamilyActionInfo.tagMCFamilyAction[]>());
        }
 
        familyActions[(int)_package.FamilyID][_package.ActionType] = _package.FamilyActionList;
 
        UpdateHawkerAction(_package);
 
        FamilyActionInfoEvent?.Invoke((int)_package.FamilyID, _package.ActionType);
    }
 
    public bool TryGetFamilyActions(int actionType, out HA513_tagMCFamilyActionInfo.tagMCFamilyAction[] familyAction)
    {
        familyAction = null;
        if (!PlayerDatas.Instance.fairyData.HasFairy)
        {
            return false;
        }
        if (!familyActions.ContainsKey((int)PlayerDatas.Instance.fairyData.fairy.FamilyID))
        {
            return false;
        }
 
        if (!familyActions[(int)PlayerDatas.Instance.fairyData.fairy.FamilyID].TryGetValue(actionType, out familyAction))
            return false;
        return true;
    }
 
    public void QueryFamilyAction(int familyID, int actionType)
    {
        var pack = new CA617_tagCMQueryFamilyAction();
        pack.FamilyID = (uint)familyID;
        pack.ActionType = (byte)actionType;
        GameNetSystem.Instance.SendInfo(pack);
    }
 
    #endregion
 
 
 
    #region 仙盟列表
 
    public event Action OnRefreshFairyList;
 
    // 查找的公会ID:公会数据
    public Dictionary<int, FairyData> guildsDict = new Dictionary<int, FairyData>();
    // 按查询页存储
    public List<int> pageIndexList = new List<int>();  //正常是按页查询,顺序添加即可
    public int curPageIndex;
    public int totalPageCount;
 
    //查找公会列表
    public void OnRefreshGuildViewList(HA523_tagMCFamilyViewList vNetData)
    {
        curPageIndex = vNetData.PageIndex;
        totalPageCount = vNetData.TotalPage;
 
        foreach (var guildInfo in vNetData.FamilyList)
        {
            FairyData data = new FairyData();
            guildsDict[(int)guildInfo.FamilyID] = data;
            SetFairyViewData(data, guildInfo);
            pageIndexList.Add((int)guildInfo.FamilyID);
        }
 
 
        if (OnRefreshFairyList != null)
        {
            OnRefreshFairyList();
        }
    }
 
 
    //查找公会
    public void SendFindGuild(string msg, int pageIndex = 0, int pageSize = 20)
    {
        if (pageIndex == 0)
        {
            //默认查询第一页即代表重新开始查询,清空之前的数据
            guildsDict.Clear();
            pageIndexList.Clear();
        }
        var pack = new CA620_tagCMViewFamilyPage();
 
        if (!string.IsNullOrEmpty(msg) && UIHelper.IsNumeric(msg))
        {
            msg = DecryptGuildID(msg);
        }
 
        pack.Msg = msg;
        pack.MsgLen = (byte)msg.Length;
        pack.PageIndex = (byte)pageIndex;
        pack.ShowCount = (byte)pageSize;
 
        GameNetSystem.Instance.SendInfo(pack);
    }
 
 
    public static void SetFairyViewData(FairyData data, HA523_tagMCFamilyViewList.tagMCFamilyView view)
    {
        data.Rank = view.Rank;
        data.FamilyID = (int)view.FamilyID;
        data.FamilyName = view.FamilyName;
        data.LeaderID = (int)view.LeaderID;
        data.LeaderName = view.LeaderName;
        data.FamilyLV = view.FamilyLV;
        data.JoinReview = view.JoinReview;
        data.JoinLVMin = view.JoinLVMin;
        data.ServerID = (int)view.ServerID;
        data.EmblemID = (int)view.EmblemID;
        data.EmblemWord = view.EmblemWord;
        data.totalFightPower = view.FightPowerEx * Constants.ExpPointValue + view.FightPower;
        data.MemberCount = view.MemberCount;
 
    }
 
    #endregion
 
    #region 申请列表
    public event Action OnRefreshApplyList;
    private List<FairyApply> applyList = new List<FairyApply>();
    private Redpoint memberRedpoint = new Redpoint(107, 10702);
    private Redpoint applyRedpoint = new Redpoint(10702, 1070201);
 
    //申请加入的玩家信息
    public void OnRefreshRequestJoinPlayerInfo(HA522_tagMCFamilyReqJoinInfo vNetData)
    {
        applyList.Clear();
        for (int i = 0; i < vNetData.ReqCnt; i++)
        {
            FairyApply apply = new FairyApply();
            apply.Name = vNetData.ReqJoinList[i].Name;
            apply.PlayerID = (int)vNetData.ReqJoinList[i].PlayerID;
            apply.ReqTime = (int)vNetData.ReqJoinList[i].ReqTime;
            apply.LV = vNetData.ReqJoinList[i].LV;
            apply.Job = vNetData.ReqJoinList[i].Job;
            apply.RealmLV = vNetData.ReqJoinList[i].RealmLV;
            apply.Face = (int)vNetData.ReqJoinList[i].Face;
            apply.FacePic = (int)vNetData.ReqJoinList[i].FacePic;
            apply.TitleID = (int)vNetData.ReqJoinList[i].TitleID;
            apply.FightPower = vNetData.ReqJoinList[i].FightPower + vNetData.ReqJoinList[i].FightPowerEx * Constants.ExpPointValue;
            apply.ServerID = (int)vNetData.ReqJoinList[i].ServerID;
            apply.IsOnLine = vNetData.ReqJoinList[i].IsOnLine;
            applyList.Add(apply);
        }
        if (OnRefreshApplyList != null)
        {
            OnRefreshApplyList();
        }
        UpdateRequestRedpoint();
    }
 
    void UpdateRequestRedpoint()
    {
        if (PlayerDatas.Instance.fairyData.HasFairy && PlayerDatas.Instance.fairyData.IsCanFunc(LimitFunc.CanCall))
        {
            applyRedpoint.state = applyList.Count > 0 ? RedPointState.Simple : RedPointState.None;
        }
        else
        {
            applyRedpoint.state = RedPointState.None;
        }
    }
 
    public List<FairyApply> GetApplyList()
    {
        return applyList;
    }
 
    //type 0申请/1撤销 加入公会
    //id 0 代表一键加入
    public void SendApplyGuild(int id, int type)
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Guild, true))
        {
            return;
        }
 
        if (PlayerDatas.Instance.fairyData.HasFairy)
        {
            SysNotifyMgr.Instance.ShowTip("GeRen_chenxin_85890");
            return;
        }
 
        if (type == 0)
        {
            if (m_FairyRequesteds.Count >= requestGuildCount)
            {
                SysNotifyMgr.Instance.ShowTip("GuildSys9");
                return;
            }
 
            var cdSeconds = GetJoinCD();
            if (cdSeconds > 0)
            {
                SysNotifyMgr.Instance.ShowTip("GuildSys2", TimeUtility.SecondsToHMSEx(cdSeconds));
                return;
            }
 
            if (id != 0 && guildsDict.ContainsKey(id))
            {
                if (guildsDict[id].MemberCount >= FamilyConfig.Get(guildsDict[id].FamilyLV).MemberMax)
                {
                    SysNotifyMgr.Instance.ShowTip("jiazu_lhs_202580");
                    return;
                }
            }
        }
 
        CA602_tagCMRequesJoinFamily rqPack = new CA602_tagCMRequesJoinFamily();
        rqPack.Type = (byte)type;
        rqPack.TagFamilyID = (uint)id;
        GameNetSystem.Instance.SendInfo(rqPack);
    }
 
 
 
    //0 加入,1 申请 2 已申请
    public int GetRequestState(FairyData guildInfo)
    {
        if (IsGuildRequested(guildInfo.FamilyID))
        {
            return 2;
        }
 
        if (guildInfo.JoinReview != 0)
        {
            return 1;
        }
 
        return 0;
    }
 
 
 
    #endregion
 
    float lastChangeMarkTime = 0;   //打开界面情况下避免短时间多次立即请求,C/S通信也是有时间间隔
    public bool guildChanged = false;
    //Type:0-无;1-成员加入;2-成员退出;3-收人设置修改;4-公告修改;5-徽章修改;6-盟主变更;7-成员职位变更;8-成员上线;9-成员离线;
    //公会数据变化,请求新的公会信息,如在打开公会列表时请求,其他功能根据自身情况请求
    public void UpdateGuildDataChangeMark(HA521_tagMCFamilyChange netPack)
    {
        guildChanged = true;
        if (Time.time - lastChangeMarkTime < 0.2f)
        {
            //小优化 如果有问题也可以去除
            return;
        }
        lastChangeMarkTime = Time.time;
        if (UIManager.Instance.IsOpened<GuildHallWin>())
        {
            RequestGuildData();
        }
    }
 
    public void RequestGuildData()
    {
        if (guildChanged)
        {
            guildChanged = false;
            var pack = new CA626_tagCMGetFamilyInfo();
            GameNetSystem.Instance.SendInfo(pack);
 
        }
    }
 
    public void SendKickFairy(uint playerID)
    {
        var pak = new CA605_tagCMDeleteFamilyMember();
        pak.MemberID = playerID;
        GameNetSystem.Instance.SendInfo(pak);
    }
 
 
    //获取需要公会职位等级
    public int GetNeedGuildJobLV(int guildFuncID)
    {
        if (guildWorkToLevel.ContainsKey(guildFuncID))
        {
            return guildWorkToLevel[guildFuncID];
        }
        return 0;
    }
 
 
    public void SendChangeMemberLV(int playerID, int lv)
    {
        var pack = new CA625_tagCMChangeFamilyMemLV();
        pack.PlayerID = (uint)playerID;
        pack.FmLV = (byte)lv;
        GameNetSystem.Instance.SendInfo(pack);
    }
 
    public void KickMember(int playerID)
    {
        var pack = new CA605_tagCMDeleteFamilyMember();
        pack.MemberID = (uint)playerID;
        GameNetSystem.Instance.SendInfo(pack);
    }
 
    public void QuitGuild()
    {
 
        ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
        Language.Get("Guild_46"), (bool isOK) =>
            {
                if (isOK)
                {
                    if (PlayerDatas.Instance.fairyData.fairy.MemberCount > 1 &&
                    PlayerDatas.Instance.fairyData.mine.FmLV == 3)
                    {
                        SysNotifyMgr.Instance.ShowTip("GuildSys15");
                        return;
                    }
                    var pack = new CA603_tagCMLeaveFamily();
                    GameNetSystem.Instance.SendInfo(pack);
                }
            });
 
 
    }
 
    #region 捐赠
 
    public void UpdateDonateInfo(HA502_tagSCDonateCntInfo netPack)
    {
        donateCntList = netPack.DonateCntList;
        DonateCntListEvent?.Invoke();
        UpdateDonateRedPoint();
    }
    #endregion
 
    #region 珍宝阁
        
 
    public void UpdateZhenbaogeInfo(HA512_tagMCFamilyZhenbaogeInfo netPack)
    {
        //砍价状态:仙盟里记录已砍价才是真的已砍价状态,封包中的砍价状态用于判断cd间隔使用
        needCheckCutCD = netPack.CutState == 1;
        zhenbaogeBuyState = netPack.BuyState;
        UpdateZhenbaogeEvent?.Invoke();
        UpdateZBGRedpoint();
    }
 
 
 
 
    //登录后首次打开查询,换新仙盟查询
    public void QueryZBGFamilyInfo()
    {
        if (isQueryZBGYet)
            return;
 
        QueryFamilyAction((int)PlayerDatas.Instance.baseData.FamilyId, 16);
 
        isQueryZBGYet = true;
    }
 
 
 
    //更新砍价信息
    public void UpdateHawkerAction(HA513_tagMCFamilyActionInfo vNetData)
    {
        if (vNetData.ActionType != ZBGFamilyActionType)
        {
            return;
        }
        bool restart = false;
        if (vNetData.FamilyActionList.Length == 1 && vNetData.FamilyActionList[0].Value1 == 1)
        {
            if (familyZBGActions.ContainsKey(1) && familyZBGActions[1].Time != vNetData.FamilyActionList[0].Time)
            {
                familyZBGActions.Clear();
                sortPlayerCut.Clear();
                restart = true;
            }
        }
 
        for (int i = 0; i < vNetData.FamilyActionList.Length; i++)
        {
            int playerID = (int)vNetData.FamilyActionList[i].Value1;
            familyZBGActions[playerID] = vNetData.FamilyActionList[i];
 
        }
 
        if (familyZBGActions.ContainsKey((int)PlayerDatas.Instance.baseData.PlayerID))
        {
            //自己是否已砍价 从列表中查找
            zhenbaogeCutState = 1;
        }
        else
        {
            zhenbaogeCutState = 0;
        }
 
 
        sortPlayerCut = familyZBGActions.Keys.ToList();
        if (sortPlayerCut.Contains(1))
            sortPlayerCut.Remove(1);
        sortPlayerCut.Sort((a, b) => { return familyZBGActions[a].Time.CompareTo(familyZBGActions[b].Time); });
 
        UpdateFamilyActionEvent?.Invoke(restart);
        UpdateZBGRedpoint();
    }
 
    //砍价人数
    public int GetZBGFamilyActionCount()
    {
        return Math.Max(0, familyZBGActions.Count - 1);
    }
 
    public int GetTalkState()
    {
        int cnt = GetZBGFamilyActionCount();
        for (int i = 0; i < cutCntListForTalk.Count; i++)
        {
            if (cnt < cutCntListForTalk[i])
            {
                return i;
            }
        }
        return 0;
    }
 
    public int[][] GetZBGItems()
    {
        if (!familyZBGActions.ContainsKey(1))
            return null;
 
        return JsonMapper.ToObject<int[][]>(familyZBGActions[1].UseData);
    }
 
    public void OnZhenbaogeOP(byte type)
    {
        var pack = new CA616_tagCMZhenbaogeOP();
        pack.OpType = type;
        GameNetSystem.Instance.SendInfo(pack);
    }
 
 
    public Dictionary <int, FairyMember> tmpNoCutMembers = new Dictionary<int, FairyMember>();
 
    //未议价成员
    public void CalcNoCutMembers()
    {
        tmpNoCutMembers.Clear();
        var fairy = PlayerDatas.Instance.fairyData;
        if (fairy == null)
        {
            return;
        }
 
        foreach(var playerID in fairy.memberIDList)
        {
            if (!familyZBGActions.ContainsKey(playerID))
            {
                tmpNoCutMembers[playerID] = fairy.GetMember(playerID);
            }
        }
    }
 
    #endregion
 
 
    #region 红点
    Redpoint hallRedpoint = new Redpoint(MainRedDot.MainGuildRedpoint, MainRedDot.guildHallRedpointID);
    Redpoint donateRedpoint = new Redpoint(MainRedDot.guildHallRedpointID, MainRedDot.guildHallRedpointID * 10);
    //珍宝阁(行商)
    Redpoint zbgRedpoint = new Redpoint(MainRedDot.MainGuildRedpoint, MainRedDot.MainGuildRedpoint * 100 + 1);
 
    void UpdateDonateRedPoint()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Guild))
        {
            return;
        }
        donateRedpoint.state = RedPointState.None;
        if (PlayerDatas.Instance.fairyData.fairy == null)
        {
            return;
        }
 
        //只有第一档的才需要红点
        var config = FamilyDonateConfig.Get(1);
        if (donateCntList == null)
        {
            if (UIHelper.CheckMoneyCount(config.MoneyType, config.MoneyValue))
                donateRedpoint.state = RedPointState.Simple;
            return;
        }
        if (donateCntList != null && donateCntList.Length > 0)
        {
            if (donateCntList[0] < config.DailyCnt)
            {
                if (UIHelper.CheckMoneyCount(config.MoneyType, config.MoneyValue))
                    donateRedpoint.state = RedPointState.Simple;
            }
        }
    }
    
    public void UpdateZBGRedpoint()
    {
        zbgRedpoint.state = RedPointState.None;
 
        if (!PlayerDatas.Instance.fairyData.HasFairy)
        {
            return;
        }
 
        if (zhenbaogeCutState == 0)
        {
            zbgRedpoint.state = RedPointState.Simple;
        }
        else if (zhenbaogeBuyState == 0)
        {
            if (familyZBGActions[1].Value3 > 0)
            {
                zbgRedpoint.state = RedPointState.Simple;
            }
        }
    }
 
    #endregion
 
    #region 加密数字
 
    //1. 将数字补充到10位,不足补0
    //2. 将每个位的数字结合索引 映射到映射表中
    //3. 将映射后的数字拼接成字符串
    //4. 另外一个解密函数,将字符串还原成数字
 
    int[] map = { 5, 2, 9, 1, 8, 3, 7, 0, 6, 4 };
    int[] reverseMap;
 
    public string EncryptGuildID(int num)
    {
        if (num < 0)
        {
            Debug.LogError("Invalid number: " + num);
            return "";
        }
 
        string str = num.ToString().PadLeft(10, '0');
        StringBuilder result = new StringBuilder();
 
        for (int i = 0; i < str.Length; i++)
        {
            int digit = int.Parse(str[i].ToString());
            int encryptedDigit = map[(digit + i) % 10]; // 结合位置查表
            result.Append(encryptedDigit);
        }
        return "6" + result.ToString();
    }
 
    public string DecryptGuildID(string encryptedStr)
    {
        if (string.IsNullOrEmpty(encryptedStr) || encryptedStr.Length != 11)
        {
            // Debug.LogError("Invalid encrypted string: " + encryptedStr);
            SysNotifyMgr.Instance.ShowTip("GuildSys6");
            return "";
        }
 
        encryptedStr = encryptedStr.Substring(1);
 
        if (reverseMap.IsNullOrEmpty())
        {
            reverseMap = new int[10];
            reverseMap = GenerateReverseMap(map);
        }
        StringBuilder originalStr = new StringBuilder();
 
        for (int i = 0; i < encryptedStr.Length; i++)
        {
            int encryptedDigit = int.Parse(encryptedStr[i].ToString());
            int originalDigit = (reverseMap[encryptedDigit] - i + 10) % 10; // 反向查表并调整位置
            originalStr.Append(originalDigit);
        }
        return originalStr.ToString().TrimStart('0'); // 去除前导零
    }
 
 
    int[] GenerateReverseMap(int[] map)
    {
        for (int i = 0; i < map.Length; i++)
        {
            reverseMap[map[i]] = i; // 反向映射:map[i] -> i
        }
        return reverseMap;
    }
 
 
    #endregion
 
}
 
// 权限ID: 1-收人,2-变更职位,3-发布公告,4-踢人
public enum GuildFuncType
{
    Accept = 1,
    ChangeJob = 2,
    PublishNotice = 3,
    Kick = 4,
 
}