hch
2025-11-24 df658f77726c8f2079644fff7e7e1e1350d247f5
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
using System;
using LitJson;
 
using System.Collections.Generic;
using System.Linq;
 
public class HorseManager : GameSystemManager<HorseManager>
{
    public int classLV;    //当前阶级,从0开始
    public int horseLV;    //当前阶等级,从1开始
    public int exp;    //当前阶等级经验,每级从0开始
    public event Action OnHorseUpdateEvent;
 
 
    Dictionary<int, HorseSkin> skinDic = new Dictionary<int, HorseSkin>();
    public event Action OnSkinUpdateEvent;
 
    //升级/升阶属性
    public Dictionary<int, long> specialAttrDic = new Dictionary<int, long>();
    public Dictionary<int, long> attrDic = new Dictionary<int, long>();
    public Dictionary<int, long> skinAttrDic = new Dictionary<int, long>();
 
    int m_selectSkinID;
    public event Action OnSelectEvent;
    public int selectSkinID
    {
        get { return m_selectSkinID; }
        set
        {
            m_selectSkinID = value;
            OnSelectEvent?.Invoke();
        }
    }
    //配置
    public int lvUPItemID;
    public int rankUPItemID;
    public int quickRankLV;
 
    public override void Init()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitialize;
        PackManager.Instance.RefreshItemEvent += OnRefreshItemEvent;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
 
        ParseConfig();
    }
 
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize;
        PackManager.Instance.RefreshItemEvent -= OnRefreshItemEvent;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
    }
 
    void ParseConfig()
    {
        var config = FuncConfigConfig.Get("HorseUpItem");
        lvUPItemID = int.Parse(config.Numerical1);
        rankUPItemID = int.Parse(config.Numerical2);
        quickRankLV = int.Parse(config.Numerical3);
    }
 
    void OnBeforePlayerDataInitialize()
    {
        classLV = 0;
        horseLV = 0;
        exp = 0;
        skinDic.Clear();
    }
 
    void OnPlayerLoginOk()
    {
        UpdateSkinRedpoint();
    }
 
    void OnRefreshItemEvent(PackType type, int index, int itemID)
    {
        if (type == PackType.Item)
        {
            if (itemID == lvUPItemID || itemID == rankUPItemID)
            {
                UpdateRedpoint();
            }
 
            if (HorseSkinConfig.itemsList.Contains(itemID))
            {
                UpdateSkinRedpoint();
            }
        }
    }
 
    //获取当前使用坐骑皮肤ID
    public int GetUsingHorseSkinID(bool useDefault = false)
    {
        var id = (int)PlayerDatas.Instance.baseData.equipShowSwitch % 1000;
        if (id == 0)
        {
            if (useDefault)
            {
                return 1;
            }
        }
        return id;
    }
 
    //获取其他玩家使用坐骑皮肤ID
    public int GetOtherPlayerHorseSkinID(int value)
    {
        return value % 1000;
    }
 
 
    public void UpdateHorseInfo(HA303_tagSCHorseClassInfo netPack)
    {
        bool isOpenSuccess = false;
        if (classLV != netPack.ClassLV && DTC0403_tagPlayerLoginLoadOK.finishedLogin)
        {
            isOpenSuccess = true;
        }
        classLV = netPack.ClassLV;
        horseLV = netPack.HorseLV;
        exp = netPack.Exp;
        UpdateRedpoint();
        UpdateSkinRedpoint();
        RefreshAttr();
        OnHorseUpdateEvent?.Invoke();
        if (isOpenSuccess)
        {
            UIManager.Instance.OpenWindow<HorseSuccessWin>();
        }
 
    }
 
 
    public void UpdateHorseSkinInfo(HA304_tagSCHorseSkinInfo netPack)
    {
        for (int i = 0; i < netPack.HorseSkinList.Length; i++)
        {
            skinDic[netPack.HorseSkinList[i].HorseSkinID] = new HorseSkin()
            {
                State = netPack.HorseSkinList[i].State,
                EndTime = (int)netPack.HorseSkinList[i].EndTime,
                Star = netPack.HorseSkinList[i].Star
            };
        }
 
        RefreshSkinAttr();
        UpdateSkinRedpoint();
        OnSkinUpdateEvent?.Invoke();
 
        if (DTC0403_tagPlayerLoginLoadOK.finishedLogin && netPack.HorseSkinList[0].Star == 0)
        {
            UIManager.Instance.OpenWindow<HorseSkinGetWin>(netPack.HorseSkinList[0].HorseSkinID);
        }
 
    }
 
    #region 红点
    Redpoint redpoint = new Redpoint(MainRedDot.RedPoint_HorseKey, MainRedDot.RedPoint_HorseKey * 10 + 1);
    Redpoint skinRedpoint = new Redpoint(MainRedDot.RedPoint_HorseKey, MainRedDot.RedPoint_HorseKey * 10 + 2);
 
 
    void UpdateRedpoint()
    {
        redpoint.state = RedPointState.None;
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Horse))
        {
            return;
        }
 
        var state = GetHorseState();
        if (state == 0)
        {
            if (PackManager.Instance.GetItemCountByID(PackType.Item, lvUPItemID) > 0)
            {
                redpoint.state = RedPointState.Simple;
                return;
            }
        }
        else if (state == 1)
        {
            var config = HorseClassConfig.Get(classLV);
            if (PackManager.Instance.GetItemCountByID(PackType.Item, rankUPItemID) >= config.ClassUPItemCnt)
            {
                redpoint.state = RedPointState.Simple;
                return;
            }
        }
    }
 
    //皮肤红点
    void UpdateSkinRedpoint()
    {
        skinRedpoint.state = RedPointState.None;
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Horse))
        {
            return;
        }
 
        if (!DTC0403_tagPlayerLoginLoadOK.finishedLogin)
        {
            return;
        }
 
 
        //升星/解锁红点
        foreach (var skin in HorseSkinConfig.GetValues())
        {
            if (IsSkinActive(skin.SkinID))
            {
                if (skin.StarMax > 0)
                {
                    //皮肤升星红点
                    int itemID = skin.UnlockValue;
                    var count = PackManager.Instance.GetItemCountByID(PackType.Item, itemID);
                    if (count >= skin.UpNeedCnt && skinDic[skin.SkinID].Star < skin.StarMax)
                    {
                        skinRedpoint.state = RedPointState.Simple;
                        return;
                    }
                }
            }
            else
            {
 
                if (skin.UnlockWay == 1)
                {
                    if (classLV >= skin.UnlockValue &&  skin.UnlockValue > 0)
                    {
                        skinRedpoint.state = RedPointState.Simple;
                        return;
                    }
                }
                else
                {
                    //皮肤解锁红点
                    int itemID = skin.UnlockValue;
                    var count = PackManager.Instance.GetItemCountByID(PackType.Item, itemID);
                    if (count >= skin.UnlockNeedCnt)
                    {
                        skinRedpoint.state = RedPointState.Simple;
                        return;
                    }
                }
            }
 
        }
    }
 
    public bool IsSkinActive(int id)
    {
        if (skinDic.TryGetValue(id, out var skin))
        {
            if (skin.State == 1 && skin.EndTime == 0)
            {
                return true;
            }
            else if (skin.State == 1 && skin.EndTime > 0 && skin.EndTime > TimeUtility.AllSeconds)
            {
                return true;
            }
        }
        var config = HorseSkinConfig.Get(id);
        if (config.UnlockWay == 1 && config.UnlockValue == 0)
        {
            return true;
        }
 
        return false;
    }
 
    public bool IsShowTheHorseRedImg(int skinID)
    {
        var skin = HorseSkinConfig.Get(skinID);
 
        if (IsSkinActive(skin.SkinID))
        {
            if (skin.StarMax > 0)
            {
                //皮肤升星红点
                int itemID = skin.UnlockValue;
                var count = PackManager.Instance.GetItemCountByID(PackType.Item, itemID);
                if (count >= skin.UpNeedCnt && skinDic[skinID].Star < skin.StarMax)
                {
                    return true;
                }
            }
        }
        else
        {
 
            if (skin.UnlockWay == 1)
            {
                if (classLV >= skin.UnlockValue && skin.UnlockValue > 0)
                {
                    return true;
                }
            }
            else
            {
                //皮肤解锁红点
                int itemID = skin.UnlockValue;
                var count = PackManager.Instance.GetItemCountByID(PackType.Item, itemID);
                if (count >= skin.UnlockNeedCnt)
                {
                    return true;
                }
            }            
        }
        return false;
    }
 
 
 
    //0 升级 1 升阶 2 满级
    public int GetHorseState()
    {
        if (HorseClassConfig.maxLVDict.TryGetValue(classLV, out int maxLV))
        {
            if (horseLV < maxLV)
            {
                return 0;
            }
            else if (horseLV >= maxLV)
            {
                if (classLV == HorseClassConfig.maxLVDict.Count - 1)
                {
                    //从0阶级开始
                    return 2;
                }
                return 1;
            }
        }
 
        return 2;
 
    }
    #endregion
 
    #region 属性
    public void RefreshAttr()
    {
        specialAttrDic.Clear();
        attrDic.Clear();
        for (int lv = 0; lv <= classLV; lv++)
        {
            //按阶加成
            var config = HorseClassConfig.Get(lv);
            if (!config.ClassSpecAttrIDList.IsNullOrEmpty())
            {
                for (int i = 0; i < config.ClassSpecAttrIDList.Length; i++)
                {
                    if (!specialAttrDic.ContainsKey(config.ClassSpecAttrIDList[i]))
                    {
                        specialAttrDic[config.ClassSpecAttrIDList[i]] = 0;
                    }
                    specialAttrDic[config.ClassSpecAttrIDList[i]] += config.ClassSpecAttrValueList[i];
                }
            }
 
            if (!config.ClassAttrValueList.IsNullOrEmpty())
            {
                for (int i = 0; i < config.AttrIDList.Length; i++)
                {
                    if (!attrDic.ContainsKey(config.AttrIDList[i]))
                    {
                        attrDic[config.AttrIDList[i]] = 0;
                    }
                    attrDic[config.AttrIDList[i]] += config.ClassAttrValueList[i];
                }
            }
 
            //按等级加成
            if (!config.PerLVAttrValueList.IsNullOrEmpty())
            {
                for (int i = 0; i < config.AttrIDList.Length; i++)
                {
                    if (!attrDic.ContainsKey(config.AttrIDList[i]))
                    {
                        attrDic[config.AttrIDList[i]] = 0;
                    }
                    var tmpHorseLV = lv != classLV ? config.MaxLV : horseLV;
 
                    attrDic[config.AttrIDList[i]] += config.PerLVAttrValueList[i] * tmpHorseLV;
                }
            }
        }
    }
 
    //刷新皮肤属性
    void RefreshSkinAttr()
    {
        skinAttrDic.Clear();
        foreach (var skinID in skinDic.Keys)
        {
            var skin = skinDic[skinID];
            if (skin.State != 1)
            {
                continue;
            }
 
            var config = HorseSkinConfig.Get(skinID);
 
            if (config.AttrIDList.IsNullOrEmpty())
            {
                continue;
            }
            if (!config.InitAttrValueList.IsNullOrEmpty())
            {
                for (int i = 0; i < config.AttrIDList.Length; i++)
                {
                    if (!skinAttrDic.ContainsKey(config.AttrIDList[i]))
                    {
                        skinAttrDic[config.AttrIDList[i]] = 0;
                    }
                    skinAttrDic[config.AttrIDList[i]] += config.InitAttrValueList[i];
                }
            }
 
            if (!config.AttrPerStarAddList.IsNullOrEmpty())
            {
                for (int i = 0; i < config.AttrIDList.Length; i++)
                {
                    if (!skinAttrDic.ContainsKey(config.AttrIDList[i]))
                    {
                        skinAttrDic[config.AttrIDList[i]] = 0;
                    }
                    skinAttrDic[config.AttrIDList[i]] += config.AttrPerStarAddList[i] * skin.Star;
                }
            }
        }
    }
 
    public long GetAttrValue(int attrID)
    {
        attrDic.TryGetValue(attrID, out long value);
        specialAttrDic.TryGetValue(attrID, out long specialValue);
        skinAttrDic.TryGetValue(attrID, out long skinValue);
        return value + specialValue + skinValue;
    }
 
    public int GetAttrPer(int attrID)
    {
        if (PlayerPropertyConfig.baseAttr2perDict.ContainsKey(attrID))
        {
            var pertype = PlayerPropertyConfig.baseAttr2perDict[attrID];
            attrDic.TryGetValue(pertype, out long value);
            specialAttrDic.TryGetValue(pertype, out long specialValue);
            skinAttrDic.TryGetValue(pertype, out long skinValue);
 
            return (int)(value + specialValue + skinValue);
        }
 
        return 0;
    }
    #endregion
 
    public List<int> sortSkinList = new List<int>();
    public void SortHorseSkinList()
    {
        sortSkinList = HorseSkinConfig.GetKeys();
        sortSkinList.Sort((a, b) =>
        {
            var isActiveA = IsSkinActive(a);
            var isActiveB = IsSkinActive(b);
            if (isActiveA != isActiveB)
            {
                return isActiveA ? -1 : 1;
            }
            var skinA = HorseSkinConfig.Get(a);
            var skinB = HorseSkinConfig.Get(b);
            return skinA.SkinID - skinB.SkinID;
        });
    }
 
    public Dictionary<int, long> GetAttrBySkinID(HorseSkinConfig config)
    {
        Dictionary<int, long> tmpDict = new Dictionary<int, long>();
 
        if (!config.InitAttrValueList.IsNullOrEmpty())
        {
            for (int i = 0; i < config.AttrIDList.Length; i++)
            {
                if (!tmpDict.ContainsKey(config.AttrIDList[i]))
                {
                    tmpDict[config.AttrIDList[i]] = 0;
                }
                tmpDict[config.AttrIDList[i]] += config.InitAttrValueList[i];
            }
        }
 
        if (!config.AttrPerStarAddList.IsNullOrEmpty())
        {
            var star = 0;
            if (skinDic.TryGetValue(config.SkinID, out var skin))
            {
                star = skin.Star;
            }
            for (int i = 0; i < config.AttrIDList.Length; i++)
            {
                if (!tmpDict.ContainsKey(config.AttrIDList[i]))
                {
                    tmpDict[config.AttrIDList[i]] = 0;
                }
                tmpDict[config.AttrIDList[i]] += config.AttrPerStarAddList[i] * star;
            }
        }
        return tmpDict;
    }
 
    public HorseSkin GetSkinData(int skinID)
    {
        skinDic.TryGetValue(skinID, out var skin);
        return skin;
    }
 
    //// 操作 1-激活;2-佩戴;3-升星
    public void SendSkinOP(int opType, int skinID)
    {
        var pack = new CB203_tagCSHorseSkinOP();
        pack.OPType = (byte)opType;
        pack.SkinID = (ushort)skinID;
        GameNetSystem.Instance.SendInfo(pack);
    }
}
 
public class HorseSkin {
    public int State;        //是否已激活
    public int EndTime;        //到期时间戳,0为永久
    public int Star;        //星级
}