少年修仙传客户端代码仓库
hch
2025-03-03 28785d6ddf9c08e49527ede9405c7b6c93c6ed32
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, July 28, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using vnxbqy.UI;
using LitJson;
 
namespace vnxbqy.UI
{
 
    
    public class NewBieCenter : Singleton<NewBieCenter>
    {
        int m_CurrentGuide = 0;
        public int currentGuide
        {
            get { return m_CurrentGuide; }
            set { m_CurrentGuide = value; }
        }
 
        int m_GuideStep = 0;
        public int guideStep
        {
            get { return m_GuideStep; }
            private set { m_GuideStep = value; }
        }
 
        public bool inGuiding
        {
            get { return currentGuide != 0; }
        }
 
        List<int> allGuides = new List<int>();
        public List<int> completeGuidesBuf = new List<int>();
        List<int> unfoldAreas = new List<int>();
 
        Dictionary<int, Window> triggerWindows = new Dictionary<int, Window>();
 
        bool inited = false;
 
        TaskModel taskmodel { get { return ModelCenter.Instance.GetModel<TaskModel>(); } }
        BetterEquipGetModel betterItemGetModel { get { return ModelCenter.Instance.GetModel<BetterEquipGetModel>(); } }
        PreciousItemGetModel preciousItemGetModel { get { return ModelCenter.Instance.GetModel<PreciousItemGetModel>(); } }
        TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
        RuneModel runeModel { get { return ModelCenter.Instance.GetModel<RuneModel>(); } }
        ComposeWinModel composeModel { get { return ModelCenter.Instance.GetModel<ComposeWinModel>(); } }
        PrayerModel prayerModel { get { return ModelCenter.Instance.GetModel<PrayerModel>(); } }
        PlayerDeadModel playerDeadModel { get { return ModelCenter.Instance.GetModel<PlayerDeadModel>(); } }
        TeamModel teamModel { get { return ModelCenter.Instance.GetModel<TeamModel>(); } }
        DailyQuestModel dailyModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
 
        public event Action guideStepChangeEvent;
        public event Action guideBeginEvent;
        public event Action<int> guideCompletedEvent;
 
        public void Init()
        {
            playerDeadModel.playerDieEvent += OnPlayerDead;
        }
 
        public void UnInit()
        {
            playerDeadModel.playerDieEvent -= OnPlayerDead;
        }
 
        public bool IsGuideCompleted(int guideId)
        {
            return completeGuidesBuf.Contains(guideId);
        }
 
        public void ResetGuideRecords(uint[] _guideRecords)
        {
            completeGuidesBuf.Clear();
            if (_guideRecords == null || _guideRecords.Length == 0)
            {
                return;
            }
 
            for (int i = 0; i < _guideRecords.Length; i++)
            {
                var guideRecord = _guideRecords[i];
                for (ushort j = 0; j < 31; j++)
                {
                    if (MathUtility.GetBitValue(guideRecord, j))
                    {
                        completeGuidesBuf.Add(i * 31 + j);
                    }
                }
            }
        }
 
        public void CheckNewBieGuides(int[] _guides)
        {
            if (!inited)
            {
                var allGuideConfigs = GuideConfig.GetValues();
                foreach (var config in allGuideConfigs)
                {
                    if (config.Type == (int)GuideType.NewBie)
                    {
                        allGuides.Add(config.ID);
                    }
                }
 
                inited = true;
            }
 
            if (_guides == null)
            {
                return;
            }
 
            if (currentGuide != 0)
            {
                return;
            }
 
            var ok = false;
            for (int i = 0; i < _guides.Length; i++)
            {
                var guideId = _guides[i];
                if (completeGuidesBuf.Contains(guideId))
                {
                    continue;
                }
 
                ok = CheckGuideCondition(guideId);
                if (ok && currentGuide != guideId)
                {
                    StartNewBieGuideEx(guideId);
                    break;
                }
            }
 
        }
 
 
        public void StartNewBieGuideEx(int _id)
        {
            var config = GuideConfig.Get(_id);
            if (config == null)
            {
                return;
            }
            if (config.Type == (int)GuideType.NewBie)
            {
                StartNewBieGuide(_id);
            }
            else
            {
                FunctionalGuideCenter.Instance.StartGuide(_id);
            }
        }
 
        void StartNewBieGuide(int _id)
        {
            if (_id == 0)
            {
                DebugEx.LogError("仅内网报错,请检查引导id = 0 的情况");
                return;
            }
            if (!PreFightMission.Instance.IsFinished())
            {
                if (_id == PreFightMission.Instance.SpecialGuideId)
                {
                    return;
                }
            }
 
            FunctionalGuideCenter.Instance.RemoveAllUnderWayGuide();
 
            currentGuide = _id;
            UpdateUnfoldAreas();
            if (PlayerDatas.Instance.hero != null)
            {
                HeroAIRecorder.Record();
                PlayerDatas.Instance.hero.Behaviour.StopHandupAI();
                PlayerDatas.Instance.hero.StopPathFind();
            }
 
            MapTransferUtility.Instance.Clear();
 
            var config = GuideConfig.Get(currentGuide);
            guideStep = config.Steps.Length > 0 ? config.Steps[0] : 0;
 
            if (guideBeginEvent != null)
            {
                guideBeginEvent();
            }
 
            WindowCenter.Instance.Open<NewBieWin>(true);
            WindowCenter.Instance.Close<ChatWin>();
 
            WindowJumpMgr.Instance.ClearJumpData();
 
            if (triggerWindows.ContainsKey(currentGuide))
            {
                var ignoreWindows = new List<string>();
                ignoreWindows.Add("NewBieWin");
                ignoreWindows.Add(triggerWindows[currentGuide].name);
 
                var parent = string.Empty;
                Window tmpWin = WindowCenter.Instance.Get(triggerWindows[currentGuide].name);
                if (tmpWin != null && !string.IsNullOrEmpty(tmpWin.fixParentName))
                {
                    ignoreWindows.Add(parent);
                }
                else if (WindowConfig.FindParentWindow(triggerWindows[currentGuide].name, out parent))
                {
                    ignoreWindows.Add(parent);
                }
 
                WindowCenter.Instance.CloseOthers(ignoreWindows, WindowCenter.CloseAllIgnoreType.BaseAndCustom);
            }
        }
 
        public void FinishNewBieGuide(int _id)
        {
            var guideRecord = currentGuide;
            currentGuide = 0;
            UpdateUnfoldAreas();
 
            WindowCenter.Instance.CloseImmediately("NewBieWin");
            if (!completeGuidesBuf.Contains(guideRecord))
            {
                completeGuidesBuf.Add(guideRecord);
            }
 
            var send = new CA222_tagCMSetGuideOK();
            send.GuideIndex = (byte)_id;
            send.IsOK = 1;
            GameNetSystem.Instance.SendInfo(send);
 
            if (guideCompletedEvent != null)
            {
                guideCompletedEvent(guideRecord);
            }
 
            Postprocessing(guideRecord);
 
            var jsonData = new JsonData();
            jsonData["af_success"] = true;
            jsonData["af_content_id"] = _id;
        }
 
        public void RemoveNewBieGuide(int _id)
        {
            if (!completeGuidesBuf.Contains(_id))
            {
                completeGuidesBuf.Add(_id);
            }
 
            var send = new CA222_tagCMSetGuideOK();
            send.GuideIndex = (byte)_id;
            send.IsOK = 1;
            GameNetSystem.Instance.SendInfo(send);
        }
 
        public void FinishCurrentGuideWithoutCloseWin()
        {
            var guideRecord = currentGuide;
            currentGuide = 0;
            UpdateUnfoldAreas();
            completeGuidesBuf.Add(guideRecord);
 
            var send = new CA222_tagCMSetGuideOK();
            send.GuideIndex = (byte)guideRecord;
            send.IsOK = 1;
            GameNetSystem.Instance.SendInfo(send);
 
            if (guideCompletedEvent != null)
            {
                guideCompletedEvent(guideRecord);
            }
        }
 
        public void ReportGuideStepComplete(int _step)
        {
            if (_step == guideStep)
            {
                var config = GuideConfig.Get(currentGuide);
                if (config == null)
                {
                    guideStep = 0;
                    FinishNewBieGuide(currentGuide);
                    return;
                }
 
                var stepIndex = Array.IndexOf(config.Steps, _step);
                if (stepIndex < config.Steps.Length - 1)
                {
                    guideStep = config.Steps[stepIndex + 1];
                    if (guideStepChangeEvent != null)
                    {
                        guideStepChangeEvent();
                    }
                }
                else
                {
                    guideStep = 0;
                    FinishNewBieGuide(currentGuide);
                }
            }
        }
 
        public void RegisterTrigger(int[] _guides, Window _window)
        {
            foreach (var guide in _guides)
            {
                triggerWindows[guide] = _window;
            }
        }
 
        private bool CheckGuideCondition(int _guideId)
        {
            var config = GuideConfig.Get(_guideId);
            if (config == null)
            {
                return false;
            }
 
            if (config.PreGuideId != 0 && !completeGuidesBuf.Contains(config.PreGuideId))
            {
                return false;
            }
 
            switch ((GuideTriggerType)config.TriggerType)
            {
                case GuideTriggerType.None:
                    return true;
                case GuideTriggerType.FunctionOpen:
                case GuideTriggerType.ManualFunctionOpen:
                    return FuncOpen.Instance.IsFuncOpen(config.Condition);
                case GuideTriggerType.RuneInlay:
                    return FuncOpen.Instance.IsFuncOpen(config.Condition) && runeModel.GetRuneTotalCount(RuneModel.RUNE_TYPE) > 0;
                case GuideTriggerType.Level:
                    return PlayerDatas.Instance.baseData.LV >= config.Condition;
                case GuideTriggerType.EquipQuality:
                    var equipPlace = betterItemGetModel.GetShowEquipPlace();
                    return (equipPlace == 1 || equipPlace == 2) && betterItemGetModel.GetShowItemQuality() >= config.Condition;
                case GuideTriggerType.Item:
                    return preciousItemGetModel.GetShowItemId() == config.Condition;
                case GuideTriggerType.TreasureDungeon:
                    Treasure treasure;
                    treasureModel.TryGetTreasure(config.Condition, out treasure);
                    return treasure != null && treasure.state == TreasureState.Collecting;
                case GuideTriggerType.Treasure:
                    if (!treasureModel.newGotShowing)
                    {
                        Treasure treasure1;
                        return treasureModel.TryGetTreasure(config.Condition, out treasure1) && treasure1.state == TreasureState.Collected;
                    }
                    else
                    {
                        return false;
                    }
                case GuideTriggerType.TreasureCollectSoul:
                    return IsTreasureCollectSoul(config.Condition);
                case GuideTriggerType.TreasureAwaken:
                    return false;
                case GuideTriggerType.QuestCanAccept:
                    return taskmodel.currentMission == config.Condition && taskmodel.currentMissionState == 0;
                case GuideTriggerType.MainLineQuestCanDo:
                    return taskmodel.currentMission == config.Condition && taskmodel.currentMissionState == 1;
                case GuideTriggerType.MainLineQuestCanAward:
                    return taskmodel.currentMission == config.Condition && taskmodel.currentMissionState == 2;
                case GuideTriggerType.MainLineQuestLimit:
                case GuideTriggerType.BranchQuestLimit:
                    return taskmodel.GetTaskStatus(config.Condition) == TaskModel.TaskStatus.CardLevel
                            || taskmodel.GetTaskStatus(config.Condition) == TaskModel.TaskStatus.TreasureCardLevel;
                case GuideTriggerType.MainLineQuestContinue:
                case GuideTriggerType.BranchQuestContinue:
                    return taskmodel.GetTaskStatus(config.Condition) == TaskModel.TaskStatus.Normal;
                case GuideTriggerType.Map:
                    return PlayerDatas.Instance.baseData.MapID == config.Condition;
                case GuideTriggerType.RealmSitDown:
                    return false;
                case GuideTriggerType.ItemCompound:
                    return IsComposeEnough(config.Condition);
                case GuideTriggerType.HangUpResult:
                    return true;
                case GuideTriggerType.BranchQuestCando:
                    return taskmodel.SideQuestState(config.Condition) == 1;
                case GuideTriggerType.BranchQuestCanAward:
                    return taskmodel.SideQuestState(config.Condition) == 2;
                case GuideTriggerType.Pray:
                    return taskmodel.currentMission == config.Condition &&
                                prayerModel.CanFreeCoinPrayer() &&
                                (taskmodel.GetTaskStatus(config.Condition) == TaskModel.TaskStatus.CardLevel || taskmodel.GetTaskStatus(config.Condition) == TaskModel.TaskStatus.TreasureCardLevel);
                case GuideTriggerType.VIPExperience:
                    return PlayerDatas.Instance.baseData.VIPLv <= 0;
                case GuideTriggerType.FairyLandBuyTimes:
                    var state = dailyModel.GetQuestState((int)DailyQuestType.FairyLand);
                    return state == DailyQuestModel.DailyQuestState.CanBuyTimes;
                case GuideTriggerType.TeamAutoAccept:
                    return !teamModel.myTeam.inTeam;
                case GuideTriggerType.TrialExchange:
                    var trialCompleteTimes = dailyModel.GetDailyQuestCompletedTimes((int)DailyQuestType.Trial);
                    return trialCompleteTimes >= 3;
                default:
                    return false;
            }
        }
 
        public void CompleteAllGuides()
        {
            var send = new CA222_tagCMSetGuideOK();
            send.GuideIndex = 255;
            send.IsOK = 1;
            GameNetSystem.Instance.SendInfo(send);
 
            currentGuide = 0;
            WindowCenter.Instance.CloseImmediately("NewBieWin");
 
            var allGuideKeys = GuideConfig.GetKeys();
            for (int i = 0; i < allGuideKeys.Count; i++)
            {
                completeGuidesBuf.Add(int.Parse(allGuideKeys[i]));
            }
 
        }
 
        public void ResetAllGuides()
        {
            var send = new CA222_tagCMSetGuideOK();
            send.GuideIndex = 255;
            send.IsOK = 0;
            GameNetSystem.Instance.SendInfo(send);
 
            currentGuide = 0;
            WindowCenter.Instance.CloseImmediately("NewBieWin");
 
            completeGuidesBuf.Clear();
        }
 
        public void ResetGuide(int _guide)
        {
            var send = new CA222_tagCMSetGuideOK();
            send.GuideIndex = (byte)_guide;
            send.IsOK = 0;
            GameNetSystem.Instance.SendInfo(send);
 
            completeGuidesBuf.Remove(_guide);
        }
 
        private bool IsTreasureCollectSoul(int _treasureId)
        {
            return false;
        }
 
        private bool IsComposeEnough(int _secondType)
        {
            var itemId = composeModel.GetTicketId((int)ComposeFuncType.Ticket, _secondType, 0);
            var lackItem = dungeonModel.GetLackItem(DungeonSuppliesLackWin.lackType);
            if (lackItem.id != itemId || itemId == 0)
            {
                return false;
            }
            var singlepack = packModel.GetSinglePack(PackType.Item);
            var count = singlepack != null ? singlepack.GetCountById(itemId) : 0;
            return composeModel.IsComposeTicketByType(_secondType) && count == 0;
        }
 
        private void OnPlayerDead()
        {
            if (currentGuide != 0)
            {
                FinishNewBieGuide(currentGuide);
            }
        }
 
        private void Postprocessing(int guideId)
        {
            var guideConfig = GuideConfig.Get(guideId);
            if (guideConfig == null)
            {
                return;
            }
 
            var functionOpenConfig = FuncOpenLVConfig.Get(guideConfig.Condition);
            if (functionOpenConfig != null && functionOpenConfig.ContinueTask == 1)
            {
                taskmodel.AutomaticTripToTask(taskmodel.currentMission);
            }
            else
            {
                if (HeroAIRecorder.autoHandupRecord)
                {
                    if (PlayerDatas.Instance.hero != null)
                    {
                        PlayerDatas.Instance.hero.Behaviour.StartHandupAI();
                    }
                }
 
                if (MapTransferUtility.Instance.NpcID == 0 && HeroAIRecorder.moveToNPCRecord != 0)
                {
                    MapTransferUtility.Instance.MoveToNPC(HeroAIRecorder.moveToNPCRecord);
                }
 
                HeroAIRecorder.ClearRecord();
            }
        }
 
        public bool IsAreaNeedUnflod(int area)
        {
            return unfoldAreas.Contains(area);
        }
 
        private void UpdateUnfoldAreas()
        {
            unfoldAreas.Clear();
            if (currentGuide != 0)
            {
                var config = GuideConfig.Get(currentGuide);
                if (config != null)
                {
                    unfoldAreas.AddRange(config.UnfoldAreas);
                }
            }
        }
    }
 
}