From 911a0b72e3415c9d3aba121bc532160da77c1afa Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期三, 22 十月 2025 21:05:02 +0800
Subject: [PATCH] 65 子 【公会】基础主体 / 【公会】基础主体-客户端

---
 Main/System/Guild/GuildManager.cs |  497 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 432 insertions(+), 65 deletions(-)

diff --git a/Main/System/Guild/GuildManager.cs b/Main/System/Guild/GuildManager.cs
index ef51011..f195061 100644
--- a/Main/System/Guild/GuildManager.cs
+++ b/Main/System/Guild/GuildManager.cs
@@ -1,4 +1,4 @@
-锘縰sing System;
+using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Text;
@@ -10,76 +10,62 @@
 {
     // 鐢宠鐨勫叕浼氬垪琛�
     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;
+    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 override void Init()
     {
         ParseConfig();
-        // PlayerDatas.Instance.fairyData.OnRefreshFairyMine += OnRefreshFairyMine;
         DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
     }
     public override void Release()
     {
-        // PlayerDatas.Instance.fairyData.OnRefreshFairyMine -= OnRefreshFairyMine;
         DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
     }
 
 
     public void OnBeforePlayerDataInitialize()
     {
+        ClearGuildData();
+    }
+
+    void ClearGuildData()
+    {
         m_FairyRequesteds.Clear();
         familyActions.Clear();
+        guildChanged = false;
+        applyList.Clear();
+        PlayerDatas.Instance.fairyData.ClearData();
     }
-
-
-
-    private void OnRefreshFairyMine()
+    
+    public void ClearGuildWhenQuit()
     {
-        if (!PlayerDatas.Instance.fairyData.HasFairy)
-        {
-            //閫�鍑哄叕浼�
-            familyActions.Clear();
-        }
+        //閫�鍑哄叕浼�
+        ClearGuildData();
+
+        //闇�瑕佽浆鍒癏omeWin鐣岄潰 涓斿叧闂叕浼氱浉鍏崇晫闈�(鐖跺瓙缁ф壙鍏抽棴)
+        UIManager.Instance.GetUI<MainWin>()?.ClickFunc(0);
     }
-
-
-    #region 鍙戝寘
-    public void SendKickFairy(uint playerID)
-    {
-        var pak = new CA605_tagCMDeleteFamilyMember();
-        pak.MemberID = playerID;
-        GameNetSystem.Instance.SendInfo(pak);
-    }
-
-
-
-    //鐢宠/鎾ら攢 鍔犲叆鍏細
-    public void SendApplyFairy(uint id, int type)
-    {
-        if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Fairy, true))
-        {
-            return;
-        }
-        if (PlayerDatas.Instance.fairyData.HasFairy)
-        {
-            ServerTipDetails.DisplayNormalTip(Language.Get("HasFairyTip"));
-            return;
-        }
-        CA602_tagCMRequesJoinFamily rqPack = new CA602_tagCMRequesJoinFamily();
-        rqPack.Type = (byte)type;
-        rqPack.TagFamilyID = id;
-        GameNetSystem.Instance.SendInfo(rqPack);
-    }
-    #endregion
-
 
 
 
     #region 閰嶇疆
- 
+
     public int createFairyCost
     {
         get;
@@ -94,8 +80,23 @@
     // 鑱屼綅锛� 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;
+
     void ParseConfig()
     {
+        DirtyWordConfig.DirtyWordInit();
+        DirtyNameConfig.DirtyNameInit();
+
         var config = FuncConfigConfig.Get("CreateFamily");
         createFairyCost = int.Parse(config.Numerical1);
         createMoneyType = int.Parse(config.Numerical2);
@@ -110,13 +111,27 @@
         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];
+
     }
 
 
     #endregion
 
 
-
+    //鎴戠殑璇锋眰鍔犲叆鍏細鐨勫垪琛�
+    public event Action MyRequestJoinEvent;
     public void UpdateFairyRequested(HA501_tagMCNotifyRequestJoinFamilyInfo _package)
     {
         m_FairyRequesteds.Clear();
@@ -124,10 +139,11 @@
         {
             m_FairyRequesteds.Add((int)_package.RequestJoinFamilyIDList[i]);
         }
+        MyRequestJoinEvent?.Invoke();
     }
 
 
-    public bool FairyRequested(int _fairyId)
+    public bool IsGuildRequested(int _fairyId)
     {
         return m_FairyRequesteds.Contains(_fairyId);
     }
@@ -145,7 +161,7 @@
 
 
 
-    #region 浠欑洘鍚嶉檺鍒�
+    #region 鍒涘缓鍏細 鏀瑰悕
     public bool CheckFairyNameLimit(string _name, out int errorCode)
     {
         errorCode = 0;
@@ -160,19 +176,30 @@
             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("FamilyNameChangeUnlegal");
+                // 鑴忓瓧
+                SysNotifyMgr.Instance.ShowTip("NameSensitive");
+                break;
+            case 2:
+                // 涓嶈兘绾暟瀛�
+                SysNotifyMgr.Instance.ShowTip("NameError3");
                 break;
         }
     }
@@ -190,9 +217,102 @@
     }
 
 
+
+
+    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 浠欑洘鍟嗗簵寮�鍚�
@@ -229,7 +349,7 @@
 
 
 
-
+    #region  鍏細鑷畾涔夎褰�
     public void UpdateFamilyAction(HA513_tagMCFamilyActionInfo _package)
     {
 
@@ -258,7 +378,17 @@
             return false;
         return true;
     }
-    
+
+    public void QueryFamilyAction(int familyID, int actionType)
+    {
+        var pack = new CA617_tagCMQueryFamilyAction();
+        pack.FamilyID = (ushort)familyID;
+        pack.ActionType = (byte)actionType;
+        GameNetSystem.Instance.SendInfo(pack);
+    }
+
+    #endregion
+
 
 
     #region 浠欑洘鍒楄〃
@@ -305,6 +435,11 @@
         }
         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;
@@ -317,15 +452,15 @@
     public static void SetFairyViewData(FairyData data, HA523_tagMCFamilyViewList.tagMCFamilyView view)
     {
         data.Rank = view.Rank;
-        data.FamilyID = view.FamilyID;
+        data.FamilyID = (int)view.FamilyID;
         data.FamilyName = view.FamilyName;
-        data.LeaderID = view.LeaderID;
+        data.LeaderID = (int)view.LeaderID;
         data.LeaderName = view.LeaderName;
         data.FamilyLV = view.FamilyLV;
         data.JoinReview = view.JoinReview;
         data.JoinLVMin = view.JoinLVMin;
-        data.ServerID = view.ServerID;
-        data.EmblemID = view.EmblemID;
+        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;
@@ -348,16 +483,16 @@
         {
             FairyApply apply = new FairyApply();
             apply.Name = vNetData.ReqJoinList[i].Name;
-            apply.PlayerID = vNetData.ReqJoinList[i].PlayerID;
-            apply.ReqTime = vNetData.ReqJoinList[i].ReqTime;
+            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 = vNetData.ReqJoinList[i].Face;
-            apply.FacePic = vNetData.ReqJoinList[i].FacePic;
-            apply.TitleID = vNetData.ReqJoinList[i].TitleID;
+            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 = vNetData.ReqJoinList[i].ServerID;
+            apply.ServerID = (int)vNetData.ReqJoinList[i].ServerID;
             apply.IsOnLine = vNetData.ReqJoinList[i].IsOnLine;
             applyList.Add(apply);
         }
@@ -384,7 +519,239 @@
     {
         return applyList;
     }
+
+    //type 0鐢宠/1鎾ら攢 鍔犲叆鍏細
+    //id 0 浠h〃涓�閿姞鍏�
+    public void SendApplyGuild(int id, int type)
+    {
+        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Fairy, 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;   //鎵撳紑鐣岄潰鎯呭喌涓嬮伩鍏嶇煭鏃堕棿澶氭绔嬪嵆璇锋眰锛孋/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 鍔犲瘑鏁板瓧
+
+    //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; // 鍙嶅悜鏄犲皠锛歮ap[i] -> i
+        }
+        return reverseMap;
+    }
+
+
+    #endregion
+
+}
+
+// 鏉冮檺ID: 1-鏀朵汉锛�2-鍙樻洿鑱屼綅锛�3-鍙戝竷鍏憡锛�4-韪汉
+public enum GuildFuncType
+{
+    Accept = 1,
+    ChangeJob = 2,
+    PublishNotice = 3,
+    Kick = 4,
 
 }
\ No newline at end of file

--
Gitblit v1.8.0