少年修仙传客户端代码仓库
client_Zxw
2018-12-20 0bbc8595fdc2cc2c06b9d461cf4d7d9db4ce2f8b
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TableConfig;
using LitJson;
 
namespace Snxxz.UI
{
    [XLua.Hotfix]
    [XLua.LuaCallCSharp]
    public class CrossServerModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, IPlayerLoginOk
    {
        public string PkResultLocalSaveKey { get; private set; }
        public List<PkResultInfo> localSaveResults { get; private set; }
 
        public override void Init()
        {
            ParseFuncConfig();
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            InitData();
        }
 
        public void OnAfterPlayerDataInitialize()
        {
            int playerId = (int)PlayerDatas.Instance.baseData.PlayerID;
            PkResultLocalSaveKey = StringUtility.Contact("PkResultLocalSaveKey", playerId);
            GetLocalSaveData();
        }
 
        public void OnPlayerLoginOk()
        {
 
        }
 
        public override void UnInit()
        {
 
        }
 
        private void InitData()
        {
            curWinRate = 0;
            sumBattleNum = 0;
            dayMatchNum = 0;
            alreadyBuyNum = 0;
            pkResultInfo = new PkResultInfo();
        }
 
        public bool TryGetMaxRank(out int upScore)
        {
            upScore = 0;
            if (pkResultInfo == null) return false;
            var arenaConfig = Config.Instance.Get<CrossServerArenaConfig>(pkResultInfo.DanLV);
            if(arenaConfig != null)
            {
                upScore = arenaConfig.LVUpScore;
            }
            return upScore == 0;
        }
 
        public int GetBuyMatchNumPrice()
        {
            Equation.Instance.Clear();
            Equation.Instance.AddKeyValue("buyCnt",alreadyBuyNum);
            return Equation.Instance.Eval<int>(priceFormula);
        }
 
        public bool TryGetWinStreakScore(out int score)
        {
            score = 0;
            if (pkResultInfo.WinStreak < 2) return false;
 
            Equation.Instance.Clear();
            Equation.Instance.AddKeyValue("cWinCount",pkResultInfo.WinStreak);
            score = Equation.Instance.Eval<int>(winStreakScoreFormula);
            return true;
        }
 
        public List<AwardType> sortDayAwardslist = new List<AwardType>();
        public void SortDayAwardsList()
        {
            sortDayAwardslist.Clear();
            sortDayAwardslist.AddRange(dayAwardTypelist);
            sortDayAwardslist.Sort(CompareByCompleteProgress);
        }
 
        public int CompareByCompleteProgress(AwardType start,AwardType end)
        {
            int x = (int)start.progress;
            int y = (int)end.progress;
            if (x.CompareTo(y) != 0) return x.CompareTo(y);
 
            x = dayAwardTypelist.IndexOf(start);
            y = dayAwardTypelist.IndexOf(end);
            if (x.CompareTo(y) != 0) return x.CompareTo(y);
 
            return 0;
        }
 
        #region 表数据
        public int freeMaxMatchNum { get; private set; } //每日免费匹配次数
        public int buyMaxMatchNum { get; private set; } //每日可购买次数
        public string priceFormula { get;private set;} //购买匹配次数需要价格公式
        public string winStreakScoreFormula { get; private set; } //连胜积分公式
        public List<AwardType> dayAwardTypelist { get; private set; }
        private void ParseFuncConfig()
        {
            var CrossRealmPKAward = Config.Instance.Get<FuncConfigConfig>("CrossRealmPKAward");
            var dayMatchAwardData = JsonMapper.ToObject(CrossRealmPKAward.Numerical1);
            var dayWinAwardData = JsonMapper.ToObject(CrossRealmPKAward.Numerical2);
            dayAwardTypelist = new List<AwardType>();
            foreach (var num in dayWinAwardData.Keys)
            {
                int times = int.Parse(num);
                var items = dayWinAwardData[num];
                var awardType = new AwardType(times,1);
                dayAwardTypelist.Add(awardType);
                if (items.IsArray)
                {
                    for(int i = 0; i < items.Count; i++)
                    {
                        var itemInfo = items[i];
                        if(itemInfo.IsArray && itemInfo.Count >= 3)
                        {
                            int id = 0;
                            int.TryParse(itemInfo[0].ToString(), out id);
                            int count = 0;
                            int.TryParse(itemInfo[1].ToString(), out count);
                            int isBind = 0;
                            int.TryParse(itemInfo[2].ToString(), out isBind);
                            AwardItem awardItem = new AwardItem(id, count, isBind);
                            awardType.SetAwardItems(awardItem);
                        }
                    }
                }
            }
 
            foreach (var num in dayMatchAwardData.Keys)
            {
                int times = int.Parse(num);
                var items = dayMatchAwardData[num];
                var awardType = new AwardType(times,2);
                dayAwardTypelist.Add(awardType);
                if (items.IsArray)
                {
                    for(int i = 0;i < items.Count; i++)
                    {
                        var itemInfo = items[i];
                        if (itemInfo.IsArray && itemInfo.Count >= 3)
                        {
                            int id = 0;
                            int.TryParse(itemInfo[0].ToString(), out id);
                            int count = 0;
                            int.TryParse(itemInfo[1].ToString(), out count);
                            int isBind = 0;
                            int.TryParse(itemInfo[2].ToString(), out isBind);
                            AwardItem awardItem = new AwardItem(id, count, isBind);
                            awardType.SetAwardItems(awardItem);
                        }
                    }
                }
            }
 
            var CrossRealmPKMatchCount = Config.Instance.Get<FuncConfigConfig>("CrossRealmPKMatchCount");
            freeMaxMatchNum = int.Parse(CrossRealmPKMatchCount.Numerical1);
            buyMaxMatchNum = int.Parse(CrossRealmPKMatchCount.Numerical2);
            priceFormula = CrossRealmPKMatchCount.Numerical3;
 
            var CrossRealmPKScore = Config.Instance.Get<FuncConfigConfig>("CrossRealmPKScore");
            winStreakScoreFormula = CrossRealmPKScore.Numerical3;
        }
 
        public class AwardType
        {
            public int type { get; private set; } //1 胜利奖励 2 匹配奖励 
            public int num { get; private set;}
            public int curCompletedNum { get; private set; }
            public CompleteProgress progress { get; private set;}
            public bool IsReceived { get; set; }
            public List<AwardItem> awardItems = new List<AwardItem>();
            public AwardType(int _num,int _type)
            {
                type = _type;
                num = _num;
                curCompletedNum = 0;
                IsReceived = false;
                progress = CompleteProgress.Completed;
                awardItems.Clear();
            }
 
            public void SetAwardItems(AwardItem awardItem)
            {
                awardItems.Add(awardItem);
            }
 
            public void SetCompletedNum(int completedNum)
            {
                curCompletedNum = completedNum;
                if(IsReceived)
                {
                    curCompletedNum = num;
                    progress = CompleteProgress.AlreadyReceived;
                }
                else
                {
                    progress = curCompletedNum < num ? CompleteProgress.UnCompleted : CompleteProgress.Completed;
                }
            }
 
            public enum CompleteProgress
            {
                Completed = 0, //已达成
                UnCompleted = 1, //未达成
                AlreadyReceived = 2, //已领取
            }
        }
 
        public struct AwardItem
        {
            public int itemId;
            public int itemCount;
            public int isBind;
            public AwardItem(int _id,int _count,int _isBind)
            {
                itemId = _id;
                itemCount = _count;
                isBind = _isBind;
            }
        }
        #endregion
 
        #region 协议
        public int curWinRate { get; private set; } //当前胜率
        public int sumBattleNum { get; private set; } //对战总场数
        public int dayMatchNum { get; private set; } //今日匹配次数
        public int alreadyBuyNum { get; private set;} //今日购买匹配次数
        public PkResultInfo pkResultInfo { get; private set;}
        public event Action UpdatePkResultEvent;
        public void UpdatePKResultInfo(HC003_tagGCCrossRealmPKOverInfo pKOverInfo)
        {
            pkResultInfo = new PkResultInfo();
            pkResultInfo.PkEndTime = pKOverInfo.TimeStr;
            pkResultInfo.OverType = pKOverInfo.OverType;
            pkResultInfo.WinnerID = (int)pKOverInfo.WinnerID;
            pkResultInfo.RoundCount = pKOverInfo.RoundCount;
            pkResultInfo.RoundWinnerIDs = pKOverInfo.RoundWinnerID;
            pkResultInfo.AddScore = pKOverInfo.AddScore;
            pkResultInfo.CurScore = pKOverInfo.Score;
            pkResultInfo.DanLV = pKOverInfo.DanLV;
            pkResultInfo.WinStreak = pKOverInfo.CWinCnt;
            pkResultInfo.VsPlayerName = pKOverInfo.TagName;
            SetPkInfoLocalSave(pkResultInfo);
            if(UpdatePkResultEvent != null)
            {
                UpdatePkResultEvent();
            }
        }
 
        public class PkResultInfo
        {
            public string PkEndTime;    // 结算时间,格式 yyyy-MM-dd HH:mm:ss
 
            public int OverType;    // 0-正常,1-有人离线
 
            public int WinnerID;    // 胜方ID(本次战斗结束,不是回合结束)
 
            public int RoundCount;    // PK回合数
 
            public uint[] RoundWinnerIDs;    // 回合获胜ID列表
 
            public int AddScore;    // 本场加分
 
            public int CurScore;    // 当前积分
 
            public int DanLV;    // 当前段位
 
            public int WinStreak;    // 当前连胜数
 
            public string VsPlayerName; //对手名字
        }
 
        public void GetWinAndFailNum(out int winNum,out int failNum)
        {
            winNum = 0;
            failNum = 0;
            int playerId = (int)PlayerDatas.Instance.baseData.PlayerID;
            for(int i = 0; i < pkResultInfo.RoundCount; i++)
            {
                var winnerId = pkResultInfo.RoundWinnerIDs[i];
                if(winnerId == playerId)
                {
                    winNum += 1;
                }
                else
                {
                    failNum += 1;
                }
            }
        }
 
        /// <summary>
        /// 1 自己离线 2 对手离线
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public bool TryGetOffLine(out int type)
        {
            type = 0;
            int playerId = (int)PlayerDatas.Instance.baseData.PlayerID;
            if(pkResultInfo.OverType != 0)
            {
                type = playerId == pkResultInfo.WinnerID ? 2 : 1;
            }
            return pkResultInfo.OverType != 0;
        }
 
        /// <summary>
        ///0-取消匹配; 1-进行匹配
        /// </summary>
        /// <param name="type"></param>
        public void SendCrossMatch(int type)
        {
            CC101_tagCMCrossRealmPKMatch match = new CC101_tagCMCrossRealmPKMatch();
            match.Type = (byte)type;
            GameNetSystem.Instance.SendInfo(match);
        }
        #endregion
 
        #region 匹配记录
    
        private void GetLocalSaveData()
        {
            localSaveResults = new List<PkResultInfo>();
            string[] localJsons = LocalSave.GeStringArray(PkResultLocalSaveKey);
            if(localJsons != null)
            {
                for(int i = 0; i < localJsons.Length; i++)
                {
                    PkResultInfo resultInfo = JsonMapper.ToObject<PkResultInfo>(localJsons[i]);
                    localSaveResults.Add(resultInfo);
                }
            }
        }
 
        public void SetPkInfoLocalSave(PkResultInfo resultInfo)
        {
            if (localSaveResults.Count >= 30)
            {
                localSaveResults.RemoveAt(localSaveResults.Count - 1);
            }
            localSaveResults.Insert(0,resultInfo);
            string[] localJsons = new string[localSaveResults.Count];
            for(int i = 0; i < localJsons.Length; i++)
            {
                string json = JsonMapper.ToJson(localSaveResults[i]);
                localJsons[i] = json;
            }
            LocalSave.SetStringArray(PkResultLocalSaveKey,localJsons);
        }
 
        #endregion
 
        #region 红点
        #endregion
 
    }
}