少年修仙传客户端代码仓库
hch
2025-04-03 c154ac0832fe4379a00d3e1cda700e7d2a7383c7
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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using LitJson;
using UnityEngine;
 
class FlowerGiftModel : ILModel<FlowerGiftModel>
{
    public SelectPlayer jumpPlayer; //从外面点击的玩家信息
 
    public event Action OnSelectPlayer;
    //要赠送的对象(jumpPlayer + 列表)
    SelectPlayer m_SelectPlayer;
    public SelectPlayer selectPlayer {
 
        get {
            return m_SelectPlayer;
        }
 
        set {
            m_SelectPlayer = value;
            OnSelectPlayer?.Invoke();
        }
    }
 
    public bool giveToggle = false;
    public int charmValue = 0; //魅力值
    public Dictionary<string, int> charmSourceDict = new Dictionary<string, int>();
    public uint feedBackFlowerGiverID = 0;  //查看送花者ID
    
    FriendsModel friendsModel { get { return ModelCenter.Instance.GetModelEx<FriendsModel>();}}
 
    protected override void Init()
    {
        GameEvent.playerLoginOkEvent += OnPlayerLoginOkEvent;
        GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitializeEvent;
        GameEvent.playerDataRefreshEvent += OnPlayerDataRefreshEvent;
    }
 
    protected override void UnInit()
    {
        GameEvent.playerLoginOkEvent -= OnPlayerLoginOkEvent;
        GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitializeEvent;
        GameEvent.playerDataRefreshEvent -= OnPlayerDataRefreshEvent;
    }
 
 
    void OnBeforePlayerDataInitializeEvent()
    {
        charmValue = 0;
        charmSourceDict.Clear();
        flowersReceive.Clear();
        giveToggle = false;
    }
 
 
    public struct SelectPlayer
    {
        public int playerID;
        public string name;
        public int closeCnt; //亲密度
    }
 
    //!!!_socialPlayerDict 里存玩家信息没有sortvalue,_groupDict里只有sortvalue
    public int GetCloseCnt(int playerID)
    {
        var playerInfo = friendsModel.GetFriendDictByType(5);
        if (playerInfo == null)
            return 0;
 
        if (!playerInfo.ContainsKey((uint)playerID))
            return 0;
 
        return (int)playerInfo[(uint)playerID].SortValue;
    }
 
    public List<SelectPlayer> playerList = new List<SelectPlayer>();
    public void GetPlayerList()
    {
        playerList.Clear();
        if (WeddingModel.Instance.m_CoupleID != 0)
        { 
            playerList.Add(new SelectPlayer()
            {
                playerID = (int)WeddingModel.Instance.m_CoupleID,
                name = WeddingModel.Instance.m_CoupleName,
                closeCnt = GetCloseCnt((int)WeddingModel.Instance.m_CoupleID),
            });
        }
        var friendDict = friendsModel.GetFriendDictByType(2);
        if (friendDict == null)
            return;
        var keyList = friendDict.Keys.ToList();
        for (int i = 0; i < keyList.Count; i++)
        {
            uint playerID = keyList[i];
            var playerInfo = friendsModel.GetFirendInfo(playerID, 2);
            if (playerInfo == null)
                continue;
            if (playerID == WeddingModel.Instance.m_CoupleID)
                continue;
 
            var player = new SelectPlayer
            {
                playerID = (int)playerID,
                name = playerInfo.PlayerName.Trim().Replace("\0", ""),
                closeCnt = GetCloseCnt((int)playerID),
            };
            playerList.Add(player);
        }
 
        playerList.Sort(SortPlayer);
 
    }
 
    int SortPlayer(SelectPlayer friendA, SelectPlayer friendB)
    {
        bool ca = friendA.playerID == WeddingModel.Instance.m_CoupleID;
        bool cb = friendB.playerID == WeddingModel.Instance.m_CoupleID;
        if (ca != cb)
        {
            return cb.CompareTo(ca);
        }
        return friendB.closeCnt.CompareTo(friendA.closeCnt);
    }
 
    public void UpdateCharm(IL_HB325_tagGCPlayerCharmValueInfo netData)
    {
        charmValue = (int)netData.CharmValueTotal;
        UpdateCharmRedPoint();
    }
 
    private Redpoint charmRedpoint = new Redpoint(10101, MainRedPoint.CharmRedPoint);
    void UpdateCharmRedPoint()
    {
        charmRedpoint.state = RedPointState.None;
        var charmLV = (int)PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.default11);
        var config = ILLoveCharmConfig.Get(charmLV);
        var nextConfig = ILLoveCharmConfig.Get(charmLV + 1);
        if (charmValue >= config.UpNeedCharm && nextConfig != null)
        { 
            charmRedpoint.state = RedPointState.Simple;
        }
    }
 
    void OnPlayerDataRefreshEvent(PlayerDataType dataType)
    {
        if (dataType != PlayerDataType.default11)
        {
            return;
        }
        UpdateCharmRedPoint();
    }
    public void QueryCharm(uint playerID, byte queryType)
    {
        var pack = new IL_CB309_tagCGCharmOfferBillboardQuery();
        pack.PlayerID = playerID;
        pack.QueryType = queryType;
        pack.QueryCount = 5;
        GameNetSystem.Instance.SendInfo(pack);
    }
 
    public void UpdateCharmSource(IL_HB319_tagGCCharmOfferBillboardDataList netPack)
    {
        charmSourceDict.Clear();
        for (int i = 0; i < netPack.DataCount; i++)
        {
            var info = netPack.OfferBillboardDataList[i];
            charmSourceDict[info.PlayerName] = (int)info.CharmValue;
        }
 
        if (netPack.PlayerID == PlayerDatas.Instance.baseData.PlayerID)
        {
            WindowCenter.Instance.OpenIL<CharmLVUPWin>();
            return;
        }
 
        if (!WindowCenter.Instance.IsOpen("CharmSourceWin"))
        {
            WindowCenter.Instance.OpenIL<CharmSourceWin>();
        }
    }
 
    public event Action OnReceiveFlower;
    public Dictionary<uint, List<FlowersReceive>> flowersReceive = new Dictionary<uint, List<FlowersReceive>>();
    public void UpdateReceiveFlowers(IL_HB320_tagGCSendGiftsOKList netPack)
    {
        for (int i = 0; i < netPack.SendGiftsOKList.Length; i++)
        {
 
            if (!flowersReceive.ContainsKey(netPack.SendGiftsOKList[i].PlayerID))
            {
                flowersReceive[netPack.SendGiftsOKList[i].PlayerID] = new List<FlowersReceive>();
            }
 
            flowersReceive[netPack.SendGiftsOKList[i].PlayerID].Add(new FlowersReceive() {
                Name = netPack.SendGiftsOKList[i].Name.Trim().Replace("\0", ""),
                GiftNum = netPack.SendGiftsOKList[i].GiftNum,
                GiftCount = netPack.SendGiftsOKList[i].GiftCount,
                SendTime = netPack.SendGiftsOKList[i].SendTime
            });
        }
 
        SaveFlowerReceive();
        OnReceiveFlower?.Invoke();
    }
 
    string bigSplit = "<&>";
    string nameSplit = "<@>";
    string listSplit = "<#>";
    string smallSplit = "<->";
    //id(|=|)name(|=|)GiftNum(|-)GiftCount(|-)SendTime(|@|)GiftNum(|-)GiftCount(|-)SendTime(|@|)(|&|)
    //id2(|=|)name2(|=|)GiftNum(|-)GiftCount(|-)SendTime(|@|)GiftNum(|-)GiftCount(|-)SendTime(|@|)
    void SaveFlowerReceive()
    {
        var fullString = string.Empty;
        var keyList = flowersReceive.Keys.ToList();
        for (int i = 0; i < keyList.Count; i++)
        {
            if (fullString != string.Empty)
            {
                fullString += bigSplit;
            }
            var info = flowersReceive[keyList[i]];
            if (info.Count > 0)
            {
                fullString += (keyList[i] + nameSplit + info[0].Name + nameSplit);
            }
            for (int j = 0; j < info.Count; j++)
            {
 
                fullString += info[j].GiftNum.ToString() + smallSplit;
                fullString += info[j].GiftCount.ToString() + smallSplit;
                fullString += info[j].SendTime.ToString() + listSplit;
            }
        }
 
        DebugEx.Log("IL_HB320_tagGCSendGiftsOKList " + fullString);
        LocalSave.SetString("FlowerReceive" + PlayerDatas.Instance.PlayerId, fullString);
 
    }
 
 
    void RestoreFlowerReceive()
    {
        try
        {
            var result = LocalSave.GetString("FlowerReceive" + PlayerDatas.Instance.PlayerId);
            if (result == string.Empty) return;
            string[] info1 = CommonFunc.Instance.StringSplit(result, bigSplit);
 
            for (int i = 0; i < info1.Length; i++)
            {
                if (info1[i] == string.Empty) continue;
                var info2 = CommonFunc.Instance.StringSplit(info1[i], nameSplit);
                uint playerID = uint.Parse(info2[0]);
                string name = info2[1];
 
                if (!flowersReceive.ContainsKey(playerID))
                {
                    flowersReceive[playerID] = new List<FlowersReceive>();
                }
                var info3 = CommonFunc.Instance.StringSplit(info2[2], listSplit);
                for (int j = 0; j < info3.Length; j++)
                {
                    if (info3[j] == string.Empty) continue;
                    var info4 = CommonFunc.Instance.StringSplit(info3[j], smallSplit);
                    flowersReceive[playerID].Add(new FlowersReceive()
                    {
                        Name = name,
                        GiftNum = (ushort)int.Parse(info4[0]),
                        GiftCount = (uint)int.Parse(info4[1]),
                        SendTime = (uint)int.Parse(info4[2])
                    });
                }
            }
        }
        catch
        {
            Debug.Log("RestoreFlowerReceive faile");
        }
    }
 
    void OnPlayerLoginOkEvent()
    {
        RestoreFlowerReceive();
    }
 
 
    //获取记录的送花玩家信息
    public List<FlowersReceive> GetOncPlayerFlowersInfo()
    {
        if (flowersReceive.Count == 0)
            return null;
 
        var playerID = flowersReceive.Keys.ToList()[0];
        var flowers = flowersReceive[playerID];
 
        flowersReceive.Remove(playerID);
        feedBackFlowerGiverID = playerID;
        SaveFlowerReceive();
        return flowers;
    }
 
 
    //赠送鲜花者信息 需要查询
    public byte FeedBackJob;
    public ushort FeedBackLV;    //等级
    public ushort FeedBackRealmLV;    //境界
    public byte FeedBackOnlineType;    //在线状态, 0 不在线 1在线
    public int FeedBackFace;    //基本脸型
    public void UpdatePlayerShortInfo(HB309_tagGCAnswerPlayerShortInfo netPack)
    {
        if (netPack.PlayerID != 0 && netPack.PlayerID == feedBackFlowerGiverID)
        {
            FeedBackJob = netPack.Job;
            FeedBackLV = netPack.LV;
            FeedBackRealmLV = netPack.RealmLV;
            FeedBackOnlineType = netPack.OnlineType;
            FeedBackFace = (int)netPack.Face;
        }
    }
 
 
    public struct FlowersReceive
    {
        public string Name;        // 赠送方玩家名
        public ushort GiftNum;        // 赠送礼物编号
        public uint GiftCount;        // 赠送礼物数量
        public uint SendTime;        // 赠送时间戳
    }
 
 
}