少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
 
 
public class FaQiLVUPModel : ILModel<FaQiLVUPModel>
{
    public int faqiLVUPItemID;
    public int faqiLVUPStoreID;
    public int faqiLV;    //等阶
    public int eatItemCount;    //当前阶已吃丹个数
    public event Action onFaqiUpdateEvent;  //变化时
    public event Action onFaqiLVChangeEvent; //升级时
 
    public Dictionary<int, int> faqiLVUPAttr = new Dictionary<int, int>();
 
    public List<int> attrSort = new List<int>() { 6, 7, 8, 18, 49 }; //面板显示顺序
    public const int onceItemExp = 10; //一个材料的经验值
 
    PackModel packModel { get { return ModelCenter.Instance.GetModelEx<PackModel>(); } }
    protected override void Init()
    {
        ParseConfig();
        GameEvent.playerLoginOkEvent += OnPlayerLoginOk;
        packModel.refreshItemCountEvent += RefreshItemCount;
    }
 
    protected override void UnInit()
    {
        GameEvent.playerLoginOkEvent -= OnPlayerLoginOk;
        packModel.refreshItemCountEvent -= RefreshItemCount;
    }
 
 
    void ParseConfig()
    {
        faqiLVUPItemID = int.Parse(FuncConfigConfig.Get("FaQiUpItem").Numerical1);
        faqiLVUPStoreID = int.Parse(FuncConfigConfig.Get("FaQiUpItem").Numerical2);
    }
 
 
    public void UpdateFaQiInfo(IL_HA354_tagMCFaQiInfo netPack)
    {
        bool isLVUP = false;
        if (netPack.LV > faqiLV)
        {
            isLVUP = true;
        }
        faqiLV = netPack.LV;
        eatItemCount = (int)netPack.EatItemCount;
        RefreshFaQiLVUPAttr();
        if (isLVUP)
        {
            onFaqiLVChangeEvent?.Invoke();
            UpdateRedpoint();
        }
        onFaqiUpdateEvent?.Invoke();
    }
 
 
    private void RefreshItemCount(PackType type, int index, int id)
    {
        if (id == faqiLVUPItemID)
        {
            UpdateRedpoint();
        }
 
    }
 
    public void RefreshFaQiLVUPAttr()
    {
        faqiLVUPAttr.Clear();
        //丹经验属性
        for (int i = 1; i <= faqiLV; i++)
        {
            var config = ILFaQiLVUpConfig.Get(i);
            var eatCnt = 0;
            if (config.useCnt == 0)
            {
                //最高级不计算
                continue;
            }
            else if (i == faqiLV)
            {
                //当前等级取封包数量
                eatCnt = eatItemCount / config.useCnt;
            }
            else
            {
                eatCnt = config.NeedEatCount / config.useCnt;
            }
 
            for (int j = 0; j < config.UpItemAttrType.Length; j++)
            {
                var upKey = config.UpItemAttrType[j];
                if (!faqiLVUPAttr.ContainsKey(upKey))
                {
                    faqiLVUPAttr[upKey] = 0;
                }
 
                faqiLVUPAttr[upKey] = faqiLVUPAttr[upKey] + eatCnt * config.UpItemAttrValue[j];
            }
 
 
        }
 
        //升阶属性
        for (int k = 1; k <= faqiLV; k++)
        {
            var config = ILFaQiLVUpConfig.Get(k);
            for (int i = 0; i < config.LVAttrType.Length; i++)
            {
                var upKey = config.LVAttrType[i];
                if (!faqiLVUPAttr.ContainsKey(upKey))
                {
                    faqiLVUPAttr[upKey] = 0;
                }
 
                faqiLVUPAttr[upKey] = faqiLVUPAttr[upKey] + config.LVAttrValue[i];
            }
        }
    }
 
    //增加属性预览
    public Dictionary<int, int> GetNextTrainAttr()
    {
        Dictionary<int, int> nextTrainAttr = new Dictionary<int, int>();
        var NextTrainCount = GetTrainCount();
        if (NextTrainCount == 0)
        {
            return nextTrainAttr;
        }
        var config = ILFaQiLVUpConfig.Get(faqiLV);
        for (int i = 0; i < config.UpItemAttrType.Length; i++)
        {
            nextTrainAttr[config.UpItemAttrType[i]] = config.UpItemAttrValue[i];
        }
 
        if (eatItemCount + NextTrainCount >= config.NeedEatCount)
        {
            //有升阶的情况
            var Nextconfig = ILFaQiLVUpConfig.Get(faqiLV + 1);
 
            for (int i = 0; i < Nextconfig.LVAttrType.Length; i++)
            {
                if (!nextTrainAttr.ContainsKey(Nextconfig.LVAttrType[i]))
                {
                    nextTrainAttr[Nextconfig.LVAttrType[i]] = 0;
                }
                nextTrainAttr[Nextconfig.LVAttrType[i]] = nextTrainAttr[Nextconfig.LVAttrType[i]] + Nextconfig.LVAttrValue[i];
            }
        }
 
        return nextTrainAttr;
    }
 
    //单次培养所需个数
    public int GetTrainCount()
    {
        var config = ILFaQiLVUpConfig.Get(faqiLV);
        if (config.NeedEatCount == 0)
        {
            //已满级
            return 0;
        }
 
        //var nextConfig = ILFaQiLVUpConfig.Get(faqiLV + 1);
        //if (nextConfig.NeedEatCount == 0)
        //{
        //    // 下一阶满级,只扣剩余所需不超过单次的材料数量
        //    if (config.NeedEatCount - eatItemCount < config.useCnt)
        //    {
        //        return config.NeedEatCount - eatItemCount;
        //    }
        //}
 
        return config.useCnt;
    }
 
    public void UpgradeFaqi(int Number, bool IsAutoBuy = false)//是否自动购买
    {
        IL_CA532_tagCMFaQiLVUp pack = new IL_CA532_tagCMFaQiLVUp();//向服务端发包坐骑经验单
        pack.UseItemCnt = (ushort)Number;
        pack.IsAutoBuy = (byte)(IsAutoBuy ? 1 : 0);
        GameNetSystem.Instance.SendInfo(pack);
 
    }
 
    void OnPlayerLoginOk()
    {
        
        UpdateRedpoint();
    }
 
    public Redpoint redpoint = new Redpoint(MainRedDot.RedPoint_key, MainRedPoint.faqiRedPoint);
    public Redpoint redpoint1 = new Redpoint(MainRedPoint.faqiRedPoint, MainRedPoint.faqiRedPoint * 10 + 1);
    void UpdateRedpoint()
    {
        if (!FuncOpen.Instance.IsFuncOpen(199)) return;
        redpoint1.state = RedPointState.None;
        var count = packModel.GetItemCountByID(PackType.Item, faqiLVUPItemID);
        var onceCnt = GetTrainCount();
        if (onceCnt == 0)
        {
            return;
        }
        if (count >= onceCnt)
        {
            redpoint1.state = RedPointState.Simple;
        }
    }
}