少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
using System;
using LitJson;
using System.Text.RegularExpressions;
using vnxbqy.UI;
 
namespace vnxbqy.UI
{
    
    public class PrayerModel : Model
    {
        public event Action OnCoinPrayerEvent;
        public event Action OnExpPrayerEvent;
 
        public event Action freeCoinPrayerStateChange;
 
        VipModel m_VipModel;
        VipModel vipModel
        {
            get
            {
                return m_VipModel ?? (m_VipModel = ModelCenter.Instance.GetModel<VipModel>());
            }
        }
 
        PackModel _playerPack;
        PackModel playerPack
        {
            get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
        }
 
        public override void Init()
        {
            lastCoinPrayerTime = 0;
            expPrayerCnt = 0;
            coinPrayerCnt = 0;
            ParseCfg();
 
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
            playerPack.refreshItemCountEvent += RefreshItemCountAct;
            TimeMgr.Instance.OnSyntonyEvent += OnSyntonyEvent;
            PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
        }
 
        private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
        {
            if (refreshType == PlayerDataType.LV)
            {
                UpdateRedPoint();
            }
        }
 
        private void RefreshItemCountAct(PackType _packType, int arg2, int _itemId)
        {
            if (_packType == PackType.Item && (_itemId == prayerExpRune || _itemId == prayerCoinRune))
            {
                UpdateRedPoint();
                if (_itemId == prayerCoinRune && freeCoinPrayerStateChange != null)
                {
                    freeCoinPrayerStateChange();
                }
            }
        }
 
        private void OnFuncStateChangeEvent(int func)
        {
            if (func == (int)FuncOpenEnum.CoinPray || func == (int)FuncOpenEnum.ExpPray)
            {
                UpdateRedPoint();
                if (func == (int)FuncOpenEnum.CoinPray && freeCoinPrayerStateChange != null)
                {
                    freeCoinPrayerStateChange();
                }
            }
        }
 
        public override void UnInit()
        {
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
            playerPack.refreshItemCountEvent -= RefreshItemCountAct;
            TimeMgr.Instance.OnSyntonyEvent -= OnSyntonyEvent;
        }
 
        public uint lastCoinPrayerTime { get; private set; }
        public uint expPrayerCnt { get; private set; }
        public uint coinPrayerCnt { get; private set; }
 
        #region 配置
        public string prayerCoinCostFormula { get; private set; }
        public string prayerExpFormula { get; private set; }
        public string prayerExpCostFormula { get; private set; }
        public int prayerGetCoin { get; private set; }
        public int prayerCoinFreeTime { get; private set; }
        public int prayerExpRune { get; private set; }
        public int prayerCoinRune { get; private set; }
        public int prayerSpecialCoinCount { get; private set; }
        public int prayerSpecialCoinValue { get; private set; }
        private void ParseCfg()
        {
            FuncConfigConfig cfg = FuncConfigConfig.Get("MoneyPray");
            if (cfg != null)
            {
                prayerCoinCostFormula = cfg.Numerical1;
                prayerGetCoin = int.Parse(cfg.Numerical2);
                prayerCoinFreeTime = int.Parse(cfg.Numerical3);
                var array = LitJson.JsonMapper.ToObject<int[]>(cfg.Numerical4);
                prayerSpecialCoinCount = array[0];
                prayerSpecialCoinValue = array[1];
            }
            cfg = FuncConfigConfig.Get("ExpPray");
            if (cfg != null)
            {
                prayerExpCostFormula = cfg.Numerical1;
                prayerExpFormula = cfg.Numerical2;
            }
            cfg = FuncConfigConfig.Get("FreeExpPrayItem");
            if (cfg != null)
            {
                prayerExpRune = int.Parse(cfg.Numerical1);
                prayerCoinRune = int.Parse(cfg.Numerical2);
            }
        }
        #endregion
 
        public int specialCoinPrayer { get; private set; }
 
        public void UpdateHistoryCoin(int _count)
        {
            specialCoinPrayer = _count;
        }
 
        public void SendCoinPrayer()
        {
            if (!CanFreeCoinPrayer())
            {
                if (coinPrayerCnt >= GetAllCoinPrayCnt())
                {
                    SysNotifyMgr.Instance.ShowTip("PrayerWin_2");
                    return;
                }
                if (PlayerDatas.Instance.baseData.diamond < GetCoinPrayerCost())
                {
                    if (VersionConfig.Get().isBanShu)
                    {
                        SysNotifyMgr.Instance.ShowTip("GoldErr");
                        return;
                    }
                    WindowCenter.Instance.Open<RechargeTipWin>();
                    return;
                }
            }
            CA530_tagCMBuySomething prayerpack = new CA530_tagCMBuySomething();
            prayerpack.Type = (int)VipPrivilegeType.GoldWish;
            GameNetSystem.Instance.SendInfo(prayerpack);
        }
        public void OnUpdatePrayerData(HA330_tagMCBuySomething vNetData)
        {
            for (int i = 0; i < vNetData.Cnt; i++)
            {
                HA330_tagMCBuySomething.tagMCSingleBuySomethingInfo data = vNetData.Infos[i];
                if (data.Type == (int)VipPrivilegeType.GoldWish)
                {
                    UpdateCoinPrayerCnt(data.BuyCnt);
                    UpdateCoinPrayerTime(data.LastFreeTime);
                    UpdateHistoryCoin(data.HistoryBuyCnt);
                    TimeSpan t = TimeUtility.ServerNow - TimeUtility.GetTime(lastCoinPrayerTime);
                    if (t.TotalSeconds < prayerCoinFreeTime)
                    {
                        TimeMgr.Instance.Register(TimeMgr.SyntonyType.PrayerRedpoint, prayerCoinFreeTime - (float)t.TotalSeconds);
                    }
                    if (OnCoinPrayerEvent != null)
                    {
                        OnCoinPrayerEvent();
                    }
                    if (freeCoinPrayerStateChange != null)
                    {
                        freeCoinPrayerStateChange();
                    }
                }
                else if (data.Type == (int)VipPrivilegeType.ExpWish)
                {
                    UpdateExpPrayerCnt(data.BuyCnt);
                }
            }
            UpdateRedPoint();
        }
 
        public void UpdateCoinPrayerTime(uint _time)
        {
            lastCoinPrayerTime = _time;
        }
 
        public void UpdateExpPrayerCnt(uint _cnt)
        {
            expPrayerCnt = _cnt;
            if (OnExpPrayerEvent != null) OnExpPrayerEvent();
        }
 
        public void UpdateCoinPrayerCnt(uint _cnt)
        {
            coinPrayerCnt = _cnt;
        }
 
        public void SendExpPrayer()
        {
            var _expRuneCnt = playerPack.GetItemCountByID(PackType.Item, prayerExpRune);
            if (_expRuneCnt <= 0)
            {
                if (expPrayerCnt >= GetAllExpPrayCnt())
                {
                    SysNotifyMgr.Instance.ShowTip("PrayerWin_2");
                    return;
                }
                if (PlayerDatas.Instance.baseData.diamond < GetExpPrayerCost())
                {
                    if (VersionConfig.Get().isBanShu)
                    {
                        SysNotifyMgr.Instance.ShowTip("GoldErr");
                        return;
                    }
                    WindowCenter.Instance.Open<RechargeTipWin>();
                    return;
                }
            }
            CA530_tagCMBuySomething prayerpack = new CA530_tagCMBuySomething();
            prayerpack.Type = (int)VipPrivilegeType.ExpWish;
            GameNetSystem.Instance.SendInfo(prayerpack);
        }
 
        public int GetCoinPrayerCost()
        {
            Equation.Instance.Clear();
            Equation.Instance.AddKeyValue("cnt", coinPrayerCnt + 1);
            return Equation.Instance.Eval<int>(prayerCoinCostFormula);
        }
        public string GetExpPrayerVal()
        {
            Equation.Instance.Clear();
            Equation.Instance.AddKeyValue("exp", PlayerLVConfig.GetExpByPlayerLv(PlayerDatas.Instance.baseData.LV));
            PlayerLVConfig cfg = PlayerLVConfig.Get(PlayerDatas.Instance.baseData.LV);
            if (cfg != null)
            {
                Equation.Instance.AddKeyValue("reExp", cfg.ReExp);
            }
            double _value = Equation.Instance.Eval<double>(prayerExpFormula);
            return _value.ToString();
        }
 
        public int GetExpPrayerCost()
        {
            Equation.Instance.Clear();
            Equation.Instance.AddKeyValue("cnt", expPrayerCnt + 1);
            return Equation.Instance.Eval<int>(prayerExpCostFormula);
        }
 
        public int GetAllCoinPrayCnt()
        {
            return ModelCenter.Instance.GetModel<VipModel>().GetVipPrivilegeCnt(VipPrivilegeType.GoldWish);
        }
 
        public int GetAllExpPrayCnt()
        {
            return ModelCenter.Instance.GetModel<VipModel>().GetVipPrivilegeCnt(VipPrivilegeType.ExpWish);
        }
 
        public bool CanFreeCoinPrayer()
        {
            var _coinRuneCnt = playerPack.GetItemCountByID(PackType.Item, prayerCoinRune);
            if (_coinRuneCnt > 0)
            {
                return true;
            }
            if (lastCoinPrayerTime == 0)
            {
                return true;
            }
            TimeSpan t = TimeUtility.ServerNow - TimeUtility.GetTime(lastCoinPrayerTime);
            if (t.TotalSeconds >= prayerCoinFreeTime)
            {
                return true;
            }
            return false;
        }
 
        public bool FreeCoinPrayerTime()
        {
            if (lastCoinPrayerTime == 0)
            {
                return true;
            }
            TimeSpan t = TimeUtility.ServerNow - TimeUtility.GetTime(lastCoinPrayerTime);
            if (t.TotalSeconds >= prayerCoinFreeTime)
            {
                return true;
            }
            return false;
        }
 
        private void OnSyntonyEvent(TimeMgr.SyntonyType type)
        {
            if (type == TimeMgr.SyntonyType.PrayerRedpoint)
            {
                UpdateRedPoint();
                if (freeCoinPrayerStateChange != null)
                {
                    freeCoinPrayerStateChange();
                }
            }
        }
 
        #region 红点
        public Redpoint redpoint = new Redpoint(201, 20102);
 
        public void UpdateRedPoint()
        {
            var redpointAble = false;
            if (PlayerDatas.Instance.baseData.LV >= GeneralDefine.prayerRedpointLimitLv)
            {
                if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.CoinPray))
                {
                    if (CanFreeCoinPrayer())
                    {
                        redpointAble = true;
                    }
                }
                if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.ExpPray))
                {
                    var _expRuneCnt = playerPack.GetItemCountByID(PackType.Item, prayerExpRune);
                    if (_expRuneCnt > 0)
                    {
                        redpointAble = true;
                    }
                }
            }
 
            redpoint.state = redpointAble ? RedPointState.GetReward : RedPointState.None;
        }
        #endregion
    }
}