少年修仙传客户端代码仓库
hch
2 天以前 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
 
using LitJson;
 
 
namespace vnxbqy.UI
{
    
    public class PushCoinModel : Model, IBeforePlayerDataInitialize
    {
        public int[][] awardsTab; //推金币奖励面板
        public int[][] superAward; //超级大奖
        public int[][] redPackAward;    //红包奖励
        public int guideID; //引导ID
        public Dictionary<string, int> freeSuperPushRateInfo = new Dictionary<string, int>();   //免费超级大推金币概率
        public int ctgID;   //超级推
        public int limit90OffCardDays;  //90折卡限制免费获得的创角天数
        public int[] superPushGiftGoinInfo; //购买超级推持续登录金币奖励
 
        public const float pushEndPos = 11.5f;   //默认情况下推的位置
        public const float superPushEndPos = 9.8f; //超级推的最终位置
        public const string COINKEY = "MiniGameCoin"; //金币key
 
        public int stopIndex = 0; //抽中停止的位置
        public int lastStopIndex = 0;
 
        public Dictionary<int, int> modelCoinInfo = new Dictionary<int, int>(); // 台面模型币数量 类型: 1-金币;2-仙玉币
        public event Action<int> OnGetAwardResult;
 
 
        VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
        InSevenDayModel inSevenDayModel { get { return ModelCenter.Instance.GetModel<InSevenDayModel>(); } }
 
        public override void Init()
        {
            PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefreshEvent;
            GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
            ParseConfig();
        }
 
 
        void ParseConfig()
        {
            var config = FuncConfigConfig.Get("PushCoin");
            awardsTab = JsonMapper.ToObject<int[][]>(config.Numerical1);
 
            superAward = JsonMapper.ToObject<int[][]>(config.Numerical2);
            redPackAward = JsonMapper.ToObject<int[][]>(config.Numerical3);
            guideID = int.Parse(config.Numerical4);
            freeSuperPushRateInfo = JsonMapper.ToObject<Dictionary<string, int>>(config.Numerical5);
 
            config = FuncConfigConfig.Get("EnSuperDiscount");
            ctgID = int.Parse(config.Numerical1);
            limit90OffCardDays = int.Parse(config.Numerical2);
            superPushGiftGoinInfo = GeneralDefine.GetIntArray("EnSuperDiscount", 4);
 
        }
 
        //创角8天内或者还有次数
        public bool IsOpen()
        {
            if (!FuncOpen.Instance.IsFuncOpen(238))
            {
                return false;
            }
 
            if (!PlayerDatas.Instance.baseData.IsActive90Off)
            {
                return true;
            }
 
            if (TimeUtility.CreateDays <= 8)
            {
                return true;
            }
 
            if (UIHelper.GetMoneyCnt(48) > 0)
                return true;
            return false;
        }
 
 
 
        public override void UnInit()
        {
            PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefreshEvent;
            GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
        }
 
 
        public void OnBeforePlayerDataInitialize()
        {
            stopIndex = 0;
            lastStopIndex = 0;
            if (UI3DPushCoinStage.IsCreated() && !WindowCenter.Instance.IsOpen<PushCoinWin>())
            { 
                //如果是在界面打开的情况下 说明还是同一个账号的数据,此时不处理
                UI3DPushCoinStage.Instance?.DestroyCois();
            }
            modelCoinInfo.Clear();
        }
 
        void OnPlayerDataRefreshEvent(PlayerDataType type)
        {
            if (type == PlayerDataType.default40)
            {
                UpdateRedpoint();
            }
        }
 
 
 
        Redpoint redpoint = new Redpoint(MainRedDot.PushCoinRepoint);
        void UpdateRedpoint()
        {
            redpoint.state = RedPointState.None;
            if (UIHelper.GetMoneyCnt(48) > 0)
            {
                redpoint.state = RedPointState.Simple;
            }
        }
 
 
        //是否激活超级推金币 登录奖励第七天或者已购买
        public bool IsActiveSuperPush()
        {
            VipModel.RechargeCount rechargeCount;
            vipModel.TryGetRechargeCount(ctgID, out rechargeCount);
            if (rechargeCount.totalCount > 0)
            {
                return true;
            }
            int type = inSevenDayModel.RewardForDic[7];
            if (type == 1)
            {
                return true;
            }
 
            return false;
        }
 
        public bool IsActiveEnterEffect()
        {
            if (IsActiveSuperPush())
            {
                return false;
            }
 
            if (UIHelper.GetMoneyCnt(48) > 0 && PlayerDatas.Instance.baseData.LV < 100)
            {
                return true;
            }
            return false;
        }
 
 
        //public void ShowRedPackAwards()
        //{
        //    List<Item> items = new List<Item>();
 
        //    foreach (var arr in redPackAward)
        //    {
        //        var moneyType = arr[0];
        //        if (GeneralDefine.moneyDisplayIds.ContainsKey(moneyType))
        //        {
        //            items.Add(new Item()
        //            {
        //                id = GeneralDefine.moneyDisplayIds[moneyType],
        //                count = arr[1],
        //            });
 
        //            PushCoinPack(1, moneyType, arr[1]);
        //        }
        //    }
 
        //    ItemLogicUtility.Instance.ShowGetItem(items, "", 0);
        //}
 
        //public byte OpType;    // 操作类型: 0-抽奖;1-获得金币;2-激活至尊卡
        public void PushCoinPack(int opType, int moneyType = 0, int value = 0)
        {
            var pack = new CAA02_tagCMTuijinbi();
            pack.OpType = (byte)opType;
            pack.Value1 = (uint)moneyType;
            pack.Value2 = (uint)value;
            GameNetSystem.Instance.SendInfo(pack);
 
        }
 
        void OnSecondEvent()
        {
            if (dropCoins.Count == 0)
                return;
 
            foreach (var key in dropCoins.Keys)
            {
                PushCoinPack(1, key, dropCoins[key]);
            }
            NoteCoin();
            dropCoins.Clear();
        }
 
        Dictionary<int, int> dropCoins = new Dictionary<int, int>(); //推下去的币 汇总后汇报
 
        //public byte OpType;    // 操作类型: 0-抽奖;1-获得金币;2-激活至尊卡
        //moneyType 1 金币  2 仙玉币
        public void DropCoin(int opType, int moneyType = 0, int value = 0)
        {
            if (opType == 1)
            {
                if (dropCoins.ContainsKey(moneyType))
                {
                    dropCoins[moneyType] = dropCoins[moneyType] + value;
                }
                else
                {
                    dropCoins[moneyType] = value;
                }
            }
            else
            { 
                PushCoinPack(opType, moneyType, value);
                NoteCoin();
            }
            
            SoundPlayer.Instance.PlayUIAudio(854);
        }
 
        public void UpdateJinbiInfo(HAA05_tagMCTuijinbiInfo netPack)
        {
            modelCoinInfo.Clear();
 
            //登录后初始数量由 DrawNum = 0决定,其他情况为抽奖索引
            for (int i = 0; i < netPack.PoolPrizeCnt; i++)
            {
                var prize = netPack.PoolPrizeList[i];
                modelCoinInfo[prize.PrizeType] = (int)prize.PrizeCount;
            }
 
            OnGetAwardResult?.Invoke(netPack.DrawNum);
        }
 
 
        //记录所有币的位置, 下次同设备打开恢复,如果是不同设备则重新掉落
        public void NoteCoin()
        {
            if (UI3DPushCoinStage.Instance == null)
                return;
 
            if (UI3DPushCoinStage.Instance.coinParent == null)
                return;
 
            Dictionary<int, List<float>> coinsInfo = new Dictionary<int, List<float>>();
            //位置和数量
            var coins = UI3DPushCoinStage.Instance.coinParent.GetComponentsInChildren<Transform>();
            foreach (var coin in coins)
            {
                int key = 0;
                if (coin.name == COINKEY + 1)
                {
                    key = 1;
                }
                else if (coin.name == COINKEY + 2)
                {
                    key = 2;
                }
                else if (coin.name == COINKEY + 4)
                {
                    key = 4;
                }
                else
                {
                    continue;
                }
                //Debug.Log(coin.name + " " + coin.localRotation + " " + coin.localPosition);
                if (!coinsInfo.ContainsKey(key))
                {
                    coinsInfo[key] = new List<float>();
                }
 
                coinsInfo[key].Add(Mathf.Round(coin.localPosition.x * 100) / 100f);
                coinsInfo[key].Add(Mathf.Round(coin.localPosition.y * 100) / 100f);
                coinsInfo[key].Add(Mathf.Round(coin.localPosition.z * 100) / 100f);
                coinsInfo[key].Add(Mathf.Round(coin.localRotation.x * 100) / 100f);
                coinsInfo[key].Add(Mathf.Round(coin.localRotation.y * 100) / 100f);
                coinsInfo[key].Add(Mathf.Round(coin.localRotation.z * 100) / 100f);
            }
 
            List<int> ints = new List<int>() { 1, 2, 4};
            foreach (var key in ints)
            {
                int index = ints.IndexOf(key);
                if (coinsInfo.ContainsKey(key))
                { 
                    var list = coinsInfo[key];
                    var json = JsonMapper.ToJson(list);
                    LocalSave.SetString(PlayerDatas.Instance.baseData.PlayerID + COINKEY + key, json);
 
                    if (key == 4)
                    { 
                        int value = (int)Math.Abs(list[2]*100);
                        //Debug.Log(COINKEY + key + ":" + value + "-" + json);
                        //服务端只记录1折币的z距离位置
                        QuickSetting.Instance.SetQuickSetting(QuickSetting.QuickSettingType.PushCoin, string.Format("{0:D3}", value), index);
                        QuickSetting.Instance.SendPackage();
                    }
                }
                else
                {
                    LocalSave.DeleteKey(PlayerDatas.Instance.baseData.PlayerID + COINKEY + key);
                    if (key == 4)
                    { 
                        QuickSetting.Instance.SetQuickSetting(QuickSetting.QuickSettingType.PushCoin, "***", index);
                        QuickSetting.Instance.SendPackage();
                    }
                }
            }
        }
 
        //类型: 1-金币;2-仙玉币
        public int GetCoinCount(int type)
        {
            if (modelCoinInfo.ContainsKey(type))
            {
                return modelCoinInfo[type];
            }
            return 0;
        }
 
    }
 
}