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
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;
 
    public Dictionary<int, HorseSkin> skinDic = new Dictionary<int, HorseSkin>();
 
    //升级/升阶属性
    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>();
 
    //配置
    public int lvUPItemID;
    public int rankUPItemID;
    public int quickRankLV;
 
    public override void Init()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitialize;
        PackManager.Instance.RefreshItemEvent += OnRefreshItemEvent;
 
        ParseConfig();
    }
 
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize;
        PackManager.Instance.RefreshItemEvent -= OnRefreshItemEvent;
    }
 
    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 OnRefreshItemEvent(PackType type, int index, int itemID)
    {
        if (type == PackType.Item)
        {
            if (itemID == lvUPItemID || itemID == rankUPItemID)
            {
                UpdateRedpoint();
            }
        }
    }
 
    public int GetHorseSkinID()
    {
        return (int)PlayerDatas.Instance.baseData.equipShowSwitch%100;
    }
 
    public void UpdateHorseInfo(HA303_tagSCHorseClassInfo netPack)
    {
        classLV = netPack.ClassLV;
        horseLV = netPack.HorseLV;
        exp = netPack.Exp;
        UpdateRedpoint();
        RefreshAttr();
        OnHorseUpdateEvent?.Invoke();
    }
 
 
    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();
        UpdateRedpoint();
        OnHorseUpdateEvent?.Invoke();
    }
 
    Redpoint redpoint = new Redpoint(MainRedDot.RedPoint_HorseKey);
    void UpdateRedpoint()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Horse))
        {
            return;
        }
 
        redpoint.state = RedPointState.None;
        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;
            }
        }
    }
 
    //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;
 
    }
 
 
    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;
    }
}
 
public class HorseSkin {
    public int State;        //是否已激活
    public int EndTime;        //到期时间戳,0为永久
    public int Star;        //星级
}