少年修仙传客户端代码仓库
client_linchunjie
2018-09-19 aecb6a5a62d8a4cfc7b924ce957a9c7ea90c235d
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
using System;
using System.Collections;
using System.Collections.Generic;
using TableConfig;
using UnityEngine;
namespace Snxxz.UI
{
    public class GuardModel : Model, IAfterPlayerDataInitialize, IPlayerLoginOk
    {
        List<int> fairyLandGuardItems = new List<int>();
 
        public bool fairyLandGuard { get; set; }
        public ItemModel fairyLandItemModel { get; private set; }
 
        public event Action onDungeonEquipGuardEvent;
 
        PlayerPackModel pack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
        DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
        PackModelInterface packModelInterface { get { return ModelCenter.Instance.GetModel<PackModelInterface>(); } }
 
        public override void Init()
        {
            ParseConfig();
            StageManager.Instance.onStageLoadFinish += OnStageLoadFinish;
            pack.RefreshItemCountAct += RefreshItemCountAct;
            KnapsackTimeCDMgr.Instance.RefreshItemOverdueAct += RefreshItemOverdueTimeAct;
        }
 
        public void OnAfterPlayerDataInitialize()
        {
        }
 
        public void OnPlayerLoginOk()
        {
            SnxxzGame.Instance.StartCoroutine(Co_LoadGuard());
        }
 
        public override void UnInit()
        {
 
        }
 
        IEnumerator Co_LoadGuard()
        {
            yield return null;
            GA_Hero _hero = PlayerDatas.Instance.hero;
            if (_hero == null)
            {
                yield break;
            }
            PlayerPackModel _packModel = ModelCenter.Instance.GetModel<PlayerPackModel>();
            SinglePackModel _equipModel = _packModel.GetSinglePackModel(PackType.rptEquip);
            if (_equipModel == null)
            {
                yield break;
            }
            var _itemModel = _equipModel.GetItemModelByIndex((int)RoleEquipType.retSpiritAnimal);
            if (_itemModel != null && _itemModel.itemInfo != null)
            {
                _hero.SwitchGuard((uint)_itemModel.itemInfo.ItemID);
            }
        }
 
        private void RefreshItemCountAct(PackType type, int arg2, int _id)
        {
            if (fairyLandGuard)
            {
                if (type == PackType.rptEquip || fairyLandGuardItems.Contains(_id))
                {
                    CheckFairyLandGuard();
                }
            }
        }
 
        IEnumerator Co_DungeonDuardCheck()
        {
            yield return WaitingForSecondConst.WaitMS500;
            CheckFairyLandGuard();
        }
 
        private void OnStageLoadFinish()
        {
            var _mapId = dungeonModel.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID);
            if (_mapId == 31080)
            {
                SnxxzGame.Instance.StartCoroutine(Co_DungeonDuardCheck());
            }
        }
 
        private void RefreshItemOverdueTimeAct(string _guid)
        {
            if (fairyLandGuard)
            {
                var itemModel = pack.GetItemModelByGUID(_guid);
                if (itemModel != null && fairyLandItemModel != null && itemModel.itemId == fairyLandItemModel.itemId)
                {
                    CheckFairyLandGuard();
                }
            }
        }
 
        private void CheckFairyLandGuard()
        {
            fairyLandGuard = false;
            var itemModel = pack.GetItemModelByIndex(PackType.rptEquip, (int)RoleEquipType.retSpiritAnimal);
            if (itemModel == null || !fairyLandGuardItems.Contains(itemModel.itemId))
            {
                for (int i = 0; i < fairyLandGuardItems.Count; i++)
                {
                    List<ItemModel> list = null;
                    pack.GetSinglePackModel(PackType.rptItem).GetItemCountByID(fairyLandGuardItems[i], out list);
                    if (list != null && list.Count > 0)
                    {
                        for (int k = 0; k < list.Count; k++)
                        {
                            bool isOverdue = packModelInterface.IsOverdue(list[k].itemInfo.ItemGUID,
                                list[k].itemId, list[k].useDataDict);
 
                            if (!isOverdue)
                            {
                                fairyLandGuard = true;
                                fairyLandItemModel = list[k];
                                if (onDungeonEquipGuardEvent != null)
                                {
                                    onDungeonEquipGuardEvent();
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            if (onDungeonEquipGuardEvent != null)
            {
                onDungeonEquipGuardEvent();
            }
        }
 
        void ParseConfig()
        {
            var config = Config.Instance.Get<FuncConfigConfig>("XjmjGuardian");
            fairyLandGuardItems.AddRange(ConfigParse.GetMultipleStr<int>(config.Numerical1));
            fairyLandGuardItems.Sort(Compare);
        }
 
        int Compare(int x, int y)
        {
            return x.CompareTo(y);
        }
    }
}