少年修仙传客户端代码仓库
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
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
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
 
namespace vnxbqy.UI
{
    public class HolidayWishPoolModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
    {
        public event Action<int> onStateUpdate;
        public const int redPointID = 28002;
        public Redpoint redPoint = new Redpoint(MainRedDot.RedPoint_HolidayWishes, redPointID);
        Operation operationType = Operation.HolidayWish;
 
        //节日祝福 id从101开始和精彩活动区分
        public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_JRZF;
        public const int activityID = 102;
 
        //瓶子编号对应的int2<祝福值,领取情况>
        public Dictionary<byte, Int2> bottleDict = new Dictionary<byte, Int2>();
        public event Action UpdateBottleInfo; // 瓶子信息变更 祝福值和领奖情况
        public event Action UpdateLegendMsg;
        public event Action<int> UpdateWishNum;
 
        public byte bottleNumSelect;
        public List<WishLegend> wishLegends = new List<WishLegend>();
 
        public int wishItemID; //祝福需要的物品ID
        public int wishCount1; // 祝福次数
        public int wishSingleNeedNum = 1; //单次祝福需要的物品数量
        public int wishCount2;
 
        bool IsRequestLegend = false; //首次启动界面请求
        int viewType = 17;
 
        PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
        public override void Init()
        {
            playerPack.refreshItemCountEvent += RefreshItemCountEvent;
            DTCA003_tagUniversalGameRecInfo.onGetUniversalGameInfo += OnGetUniversalGameInfo;
            OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
            OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
            OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent;
            OpenServerActivityCenter.Instance.Register(activityID, this, activityType);
 
            var funcCfg = FuncConfigConfig.Get("FeastWishCfg");
            wishItemID = int.Parse(funcCfg.Numerical1);
            var _jsonDataC = LitJson.JsonMapper.ToObject(funcCfg.Numerical2);
            if (_jsonDataC.Count > 0)
            {
                wishCount1 = int.Parse(_jsonDataC[0].ToString());
                wishCount2 = int.Parse(_jsonDataC[1].ToString());
            }
        }
 
 
 
        public void OnBeforePlayerDataInitialize()
        {
            bottleDict.Clear();
            IsRequestLegend = false;
            wishLegends.Clear();
        }
 
        public void OnPlayerLoginOk()
        {
        }
 
        public override void UnInit()
        {
            playerPack.refreshItemCountEvent -= RefreshItemCountEvent;
            DTCA003_tagUniversalGameRecInfo.onGetUniversalGameInfo -= OnGetUniversalGameInfo;
            OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;
            OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent;
            OperationTimeHepler.Instance.operationAdvanceEvent -= OperationAdvanceEvent;
        }
 
        public bool IsOpen {
            get {
                return OperationTimeHepler.Instance.SatisfyOpenCondition(operationType);
            }
        }
 
        public bool priorityOpen {
            get {
                return redPoint.state == RedPointState.Simple;
            }
        }
 
        public bool IsAdvance {
            get {
                return OperationTimeHepler.Instance.SatisfyAdvanceCondition(operationType);
            }
        }
 
        private void OperationEndEvent(Operation type, int state)
        {
            if (type == operationType && state == 0)
            {
                if (onStateUpdate != null)
                {
                    onStateUpdate(activityID);
                }
                UpdateRedpoint();
            }
        }
 
        private void OperationAdvanceEvent(Operation type)
        {
            if (type == operationType)
            {
                if (onStateUpdate != null)
                {
                    onStateUpdate(activityID);
                }
            }
        }
 
        private void OperationStartEvent(Operation type, int state)
        {
            if (type == operationType && state == 0)
            {
 
                if (onStateUpdate != null)
                {
                    onStateUpdate(activityID);
                }
            }
        }
 
        //0 可领取  1 已领取
        public int GetBottleAwardState(byte bottleNum, int index)
        {
 
            OperationHolidayWish holiday;
            OperationTimeHepler.Instance.TryGetOperation(operationType, out holiday);
 
            int recordIndex = holiday.wishBottles[bottleNumSelect].ChoosePrizeList[index].RecordIndex;
            if (((int)Math.Pow(2, recordIndex) & bottleDict[bottleNum].y) == 0)
            {
                return 0;
            }
 
            return 1;
        }
 
        void UpdateRedpoint()
        {
            OperationHolidayWish holiday;
            OperationTimeHepler.Instance.TryGetOperation(operationType, out holiday);
            redPoint.state = RedPointState.None;
 
            if (holiday == null) return; //封包顺序如果有问题 此处为空
 
            // 瓶子的祝福值满 和 有祝福值可祈愿的情况 增加红点
            foreach (var bottle in bottleDict)
            {
                var state = GetBottleProcessState(bottle.Key, holiday);
                if (state >= 1)
                {
                    redPoint.state = RedPointState.Simple;
                }
            }
 
            if (playerPack.GetItemCountByID(PackType.Item, wishItemID) >= wishCount1)
            {
                redPoint.state = RedPointState.Simple;
            }
 
        }
 
        //瓶子进度0到1, -1代表已领完
        public float GetBottleProcessState(byte bottleNum, OperationHolidayWish holiday)
        {
            if (holiday == null) return 0;
            if (!bottleDict.ContainsKey(bottleNum) || !holiday.wishBottles.ContainsKey(bottleNum)) return 0;
 
            if (NumberOf1(bottleDict[bottleNum].y) >= holiday.wishBottles[bottleNum].ChooseTimeMax)
                return -1;
 
            return bottleDict[bottleNum].x / (float)holiday.wishBottles[bottleNum].NeedWishValue;
        }
 
        //遍历每次消除一个1,有多少次就多少个1
        private int NumberOf1(int n)
        {
            int count = 0;
            while (n != 0)
            {
                count++;
                n &= n - 1;
            }
            return count;
        }
 
        public void UpdateInfo(HAA44_tagMCFeastWishPlayerInfo netPack)
        {
            for (int i = 0; i < netPack.PlayerBottleInfo.Length; i++)
            {
                byte bottleNum = netPack.PlayerBottleInfo[i].BottleNum;
                if (bottleDict.ContainsKey(bottleNum))
                {
                    bottleDict[bottleNum] = new Int2(netPack.PlayerBottleInfo[i].WishValue, (int)netPack.PlayerBottleInfo[i].ChooseRecord);
                }
                else
                {
                    bottleDict.Add(bottleNum, new Int2(netPack.PlayerBottleInfo[i].WishValue, (int)netPack.PlayerBottleInfo[i].ChooseRecord));
                }
            }
 
            if (UpdateBottleInfo != null)
                UpdateBottleInfo();
 
            UpdateRedpoint();
        }
 
        public void SendWish(byte wishCount)
        {
            CAA11_tagCMFeastWishPoolWish wish = new CAA11_tagCMFeastWishPoolWish();
            wish.WishCount = wishCount;
            GameNetSystem.Instance.SendInfo(wish);
        }
 
        private void RefreshItemCountEvent(PackType packType, int index, int itemId)
        {
            if (itemId != wishItemID) return;
            UpdateRedpoint();
        }
 
 
        //每次启动游戏 只在打开界面做一次请求,后续会收到服务端单条通知
        public void RequestLegend()
        {
            if (IsRequestLegend) return;
            IsRequestLegend = true;
            CA001_tagViewUniversalGameRec legend = new CA001_tagViewUniversalGameRec();
            legend.ViewType = (byte)viewType;
            GameNetSystem.Instance.SendInfo(legend);
        }
 
        public void OnAddWish(HAA45_tagMCFeastWishResult netPack)
        {
            if (UpdateWishNum != null)
            {
                UpdateWishNum((int)netPack.AddWishValue);
            }
        }
 
        private void OnGetUniversalGameInfo(HA003_tagUniversalGameRecInfo package)
        {
            if (!IsRequestLegend)
            {
                //界面首次启动后会获取一次总信息
                return;
            }
 
            if (package.Type != viewType) return;
            for (int i = 0; i < package.Count; i++)
            {
                WishLegend msg = new WishLegend()
                {
                    name = package.UniversalGameRec[i].StrValue1,
                    itemID = (int)package.UniversalGameRec[i].Value1,
                    itemCount = (int)package.UniversalGameRec[i].Value2,
                    source = (int)package.UniversalGameRec[i].Value3,
                };
 
                wishLegends.Add(msg);
            }
            if (wishLegends.Count > 35)
            wishLegends.RemoveRange(0, 5);
 
            if (UpdateLegendMsg != null)
                UpdateLegendMsg();
 
        }
 
        public struct WishLegend
        {
            public string name;
            public int itemID;
            public int itemCount;
            public int source;
        }
    }
}