少年修仙传客户端代码仓库
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, July 18, 2018
//--------------------------------------------------------
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using LitJson;
using System.Linq;
 
public class DayPackageItemClassModel : Model, IPlayerLoginOk, IOpenServerActivity,  IBeforePlayerDataInitialize
{
    VipModel vipModel
    {
        get { return ModelCenter.Instance.GetModel<VipModel>(); }
    }
 
    StoreModel storeModel
    {
        get { return ModelCenter.Instance.GetModel<StoreModel>(); }
    }
 
    // 每日礼包由服务端通知,每周/月礼包取充值表和商城表
    // 0 每日礼包 1 每周礼包 2 每月礼包
    int m_SelectIndex = 0;
    public int selectIndex
    {
        get { return m_SelectIndex; }
        set
        {
            if (m_SelectIndex != value)
            {
                m_SelectIndex = value;
                if (selectUpdate != null)
                {
                    selectUpdate();
                }
            }
        }
    }
 
    public class DayGift
    {
        public int getCount; // 已获得次数
        public List<int[]> items;
        public float money; //orderInfo是数字字符串代表货币类型,否则代表充值 单位分
        public string orderInfo;
        public int buyCountLimit;
        public int onSalePer; //打折
    }
 
 
    public List<int> recordIDs = new List<int>();
    public Dictionary<int, DayGift> m_RechargeDict = new Dictionary<int, DayGift>();
    public Dictionary<int, DayGift> m_WeekRechargeDict = new Dictionary<int, DayGift>();
    public Dictionary<int, DayGift> m_MonthRechargeDict = new Dictionary<int, DayGift>();
 
    public int weekBuyType = 0;
    public int monthBuyType = 0;
    public List<int> weekStoreListSort = new List<int>();   //显示顺序
    public List<int> monthStoreListSort = new List<int>();
 
 
    public event Action selectUpdate;
    public event Action<int> onStateUpdate;
    public event Action onDayGoodsUpdate;
    public override void Init()
    {
        OpenServerActivityCenter.Instance.Register(23, this);
        ParseConfig();
    }
    private const int Redpoint_key1 = 20923;
    public Redpoint redPointStre1 = new Redpoint(209, Redpoint_key1); 
    public Redpoint redPoint1 = new Redpoint(Redpoint_key1, Redpoint_key1 * 10); //每日免费礼包
    public Redpoint redPoint2 = new Redpoint(Redpoint_key1, Redpoint_key1 * 10 + 1); //每周免费礼包
    public Redpoint redPoint3 = new Redpoint(Redpoint_key1, Redpoint_key1 * 10 + 2); //每月免费礼包
    public bool IsOpen
    {
        get
        {
            return FuncOpen.Instance.IsFuncOpen(185);
        }
    }
 
    public bool priorityOpen
    {
        get
        {
            return redPointStre1.state == RedPointState.Simple || redPointStre1.state == RedPointState.GetReward;
        }
    }
 
    public bool IsAdvance
    {
        get
        {
            return false;
        }
    }
 
    public void OnBeforePlayerDataInitialize()
    {
        m_RechargeDict.Clear();
        recordIDs.Clear();
 
        foreach (var item in m_WeekRechargeDict)
        {
            item.Value.getCount = 0;
        }
 
        foreach (var item in m_MonthRechargeDict)
        {
            item.Value.getCount = 0;
        }
    }
 
 
    public override void UnInit()
    {
    }
    public void OnPlayerLoginOk()
    {
        IsShowTip();
 
    }
 
    public DayGift GetDayGift(int index)
    {
        return m_RechargeDict[recordIDs[index]];
    }
 
 
    public void IsShowTip()
    {
        if (!FuncOpen.Instance.IsFuncOpen(185)) return;
 
        if (m_RechargeDict.ContainsKey(0) && m_RechargeDict[0].getCount == 0)
            redPointStre1.state = RedPointState.Simple;
        else
            redPointStre1.state = RedPointState.None;
 
    }
 
    
 
    void ParseConfig()
    {
        // 礼包数据包含了价格 购买数量等动态信息 切换账号和打折时刷新
        weekStoreListSort.Clear();
        monthStoreListSort.Clear();
        m_MonthRechargeDict.Clear();
        m_WeekRechargeDict.Clear();
 
 
        var config = FuncConfigConfig.Get("BuyPackage");
        var weekStoreList = JsonMapper.ToObject<int[]>(config.Numerical1);
        var monthStoreList = JsonMapper.ToObject<int[]>(config.Numerical2);
        weekBuyType = int.Parse(config.Numerical3);
        monthBuyType = int.Parse(config.Numerical4);
 
        // 商店购买也存入充值 orderInfo存储货币类型
        foreach (var id in weekStoreList)
        {
            weekStoreListSort.Add(id + 100000000);
            StoreConfig storeCfg = StoreConfig.Get(id);
            m_WeekRechargeDict[id + 100000000] = new DayGift()
            {
                money = storeCfg.MoneyNumber,
                orderInfo = storeCfg.MoneyType.ToString(),
                items = storeModel.GetShopItemlistEx(storeCfg),
                buyCountLimit = storeCfg.GoumaiNumber[0],
            };
        }
        foreach (var id in monthStoreList)
        {
            monthStoreListSort.Add(id + 100000000);
            StoreConfig storeCfg = StoreConfig.Get(id);
            m_MonthRechargeDict[id + 100000000] = new DayGift()
            {
                money = storeCfg.MoneyNumber,
                orderInfo = storeCfg.MoneyType.ToString(),
                items = storeModel.GetShopItemlistEx(storeCfg),
                buyCountLimit = storeCfg.GoumaiNumber[0],
            };
        }
 
        var list = vipModel.GetCTGConfigs(VersionConfig.Get().appId);
        for (int i = 0; i < list.Count; i++)
        {
            var ctgConfig = CTGConfig.Get(list[i]);
            if (ctgConfig.PayType == weekBuyType)
            {
                OrderInfoConfig orderCfg;
                vipModel.TryGetOrderInfo(ctgConfig.RecordID, out orderCfg);
 
                m_WeekRechargeDict[ctgConfig.RecordID] = new DayGift()
                {
                    money = orderCfg.m_PayRMBNum,
                    orderInfo = orderCfg.OrderInfo,
                    items = JsonMapper.ToObject<int[][]>(ctgConfig.GainItemList).ToList(),
                    buyCountLimit = ctgConfig.WeekBuyCount,
                    onSalePer = ctgConfig.Percentage,
                };
                weekStoreListSort.Add(ctgConfig.RecordID);
            }
            else if (ctgConfig.PayType == monthBuyType)
            {
                OrderInfoConfig orderCfg;
                vipModel.TryGetOrderInfo(ctgConfig.RecordID, out orderCfg);
                m_MonthRechargeDict[ctgConfig.RecordID] = new DayGift()
                {
                    money = orderCfg.m_PayRMBNum,
                    orderInfo = orderCfg.OrderInfo,
                    items = JsonMapper.ToObject<int[][]>(ctgConfig.GainItemList).ToList(),
                    buyCountLimit = ctgConfig.MonthBuyCount,
                    onSalePer = ctgConfig.Percentage,
                };
                monthStoreListSort.Add(ctgConfig.RecordID);
            }
        }
 
        monthStoreListSort.Sort(SortMonthList);
        weekStoreListSort.Sort(SortWeekList);
    }
 
 
    int SortMonthList(int a, int b)
    {
        int ida = a > 100000000 ? 0 : 1;
        int idb = b > 100000000 ? 0 : 1;
        if (ida != idb)
            return ida.CompareTo(idb);
 
        return m_MonthRechargeDict[a].money.CompareTo(m_MonthRechargeDict[b].money);
 
    }
 
    int SortWeekList(int a, int b)
    {
        int ida = a > 100000000 ? 0 : 1;
        int idb = b > 100000000 ? 0 : 1;
        if (ida != idb)
            return ida.CompareTo(idb);
 
        return m_WeekRechargeDict[a].money.CompareTo(m_WeekRechargeDict[b].money);
 
    }
 
 
    public void DayGoodsInfo(HAA25_tagMCDailyGiftbagInfo pack)
    {
        recordIDs = new List<int>();
        foreach (var goods in pack.GiftbagInfo)
        {
            recordIDs.Add((int)goods.GiftID);
            List<int[]> tmpItems = new List<int[]>();
            foreach (var itemInfo in goods.ItemInfo)
            {
                tmpItems.Add(new int[] { (int)itemInfo.ItemID, itemInfo.ItemCount });
            }
 
            int count = 0;
            if (m_RechargeDict.ContainsKey((int)goods.GiftID))
            {
                count = m_RechargeDict[(int)goods.GiftID].getCount;
            }
 
            m_RechargeDict[(int)goods.GiftID] = new DayGift()
            {
                getCount = count,
                money = UIHelper.GetRealCoin((int)goods.RMB),
                orderInfo = goods.OrderInfo,
                items = tmpItems,
                buyCountLimit = (int)goods.BuyCountLimit,
                onSalePer = PlayerDatas.Instance.baseData.IsActive90Off ? goods.Discount * 100 : goods.Discount,
            };
 
            
        }
 
        recordIDs.Sort();
 
        if (onDayGoodsUpdate != null) onDayGoodsUpdate();
    }
 
 
    public void DayGoodsPurchasing(HAA26_tagMCDailyGiftbagPlayerInfo pack)
    {
        //每次回报都会把所有已购买物品下发,先清空购买数量,再赋值
        foreach(int giftID in m_RechargeDict.Keys)
        {
            m_RechargeDict[giftID].getCount = 0;
        }
        foreach (var goods in pack.BuyCountList)
        {
            if (m_RechargeDict.ContainsKey((int)goods.GiftbagID))
            {
                m_RechargeDict[(int)goods.GiftbagID].getCount = goods.BuyCount;
            }
            else
            {
                m_RechargeDict[(int)goods.GiftbagID] = new DayGift()
                {
                    getCount = goods.BuyCount,
                };
            }
        }
 
        if (onDayGoodsUpdate != null) onDayGoodsUpdate();
 
        IsShowTip();
    }
 
 
    public void RequestReward()
    {
        var sendInfo = new CA504_tagCMPlayerGetReward();
        sendInfo.RewardType = (int)GotServerRewardType.Def_RewardType_DayPackageFree;
        sendInfo.DataEx = 0;
        sendInfo.DataExStrLen = 0;
        sendInfo.DataExStr = string.Empty;
        GameNetSystem.Instance.SendInfo(sendInfo);
    }
 
 
}