少年修仙传客户端代码仓库
client_Wu Xijin
2019-04-16 fc714208ff3a320c3bb52bddd5ea3d91f647a206
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, November 07, 2017
//--------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
 
    public class LocalMapTag : MonoBehaviour
    {
        [SerializeField] TextEx m_NpcName;
        [SerializeField] TextEx m_Level;
        [SerializeField] Button m_Moveto;
        [SerializeField] Image m_TaskState;
 
        TagType m_TagType;
        public TagType tagType {
            get {
                return m_TagType;
            }
            set {
                m_TagType = value;
            }
        }
 
        LocalMapFindPath localMapFindPath;
        Vector3 worldPosition = Vector3.zero;
        int npcId = 0;
        int index = 0;
        TaskModel taskmodel {
            get {
                return ModelCenter.Instance.GetModel<TaskModel>();
            }
        }
 
        FairyLeagueModel fairyLeagueModel {
            get {
                return ModelCenter.Instance.GetModel<FairyLeagueModel>();
            }
        }
 
        public void Display(int _npcId, TextColType _colorType)
        {
            npcId = _npcId;
            switch (m_TagType)
            {
                case TagType.Function:
                    var status = taskmodel.StatusLightQuery(npcId);
                    if (status > 0)
                    {
                        m_TaskState.SetSprite(StringUtility.Contact("LocalMapTaskState_", status));
                    }
                    else
                    {
                        m_TaskState.SetSprite("LocalMapTaskState_0");
                    }
 
                    m_TaskState.SetNativeSize();
                    TaskModel.Event_TaskResponse -= OnTaskStateChange;
                    TaskModel.Event_TaskResponse += OnTaskStateChange;
                    break;
                case TagType.WayPoint:
                    break;
                case TagType.Boss:
                    break;
                case TagType.Elite:
                case TagType.Monster:
                    var config = NPCConfig.Get(npcId);
                    m_NpcName.text = config.charName;
                    m_NpcName.colorType = _colorType;
                    break;
                case TagType.Crystal:
                    OnCrystalStateChange(npcId);
                    m_Moveto.RemoveAllListeners();
                    m_Moveto.AddListener(MoveTo);
                    PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
                    PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
                    fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange;
                    fairyLeagueModel.UpdateWarCrystalEvent += OnCrystalStateChange;
                    break;
            }
        }
 
        public void Display(int _npcId, TextColType _colorType, Vector3 _position)
        {
            worldPosition = _position;
            npcId = _npcId;
 
            switch (m_TagType)
            {
                case TagType.Boss:
                    var config = NPCConfig.Get(npcId);
                    m_NpcName.text = config.charName;
                    m_Level.text = Language.Get("HeadUpName_Monster", config.NPCLV);
                    m_NpcName.colorType = _colorType;
                    var dangerous = PlayerDatas.Instance.baseData.LV <= config.NPCLV;
                    m_Level.color = UIHelper.GetUIColor(dangerous ? TextColType.Red : TextColType.Green, false);
                    m_Moveto.RemoveAllListeners();
                    m_Moveto.AddListener(MoveTo);
                    break;
                default:
                    break;
            }
        }
 
        public void Display(int _index)
        {
            index = _index;
            switch (m_TagType)
            {
                case TagType.FairyLeagueBuff:
                    m_Moveto.RemoveAllListeners();
                    m_Moveto.AddListener(MoveTo);
                    break;
            }
        }
 
        public void Dispose()
        {
            TaskModel.Event_TaskResponse -= OnTaskStateChange;
            fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange;
            PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
        }
 
        private void MoveTo()
        {
            switch (m_TagType)
            {
                case TagType.FairyLeagueBuff:
                    {
                        var _help = fairyLeagueModel.fairyLeagueHelp;
                        Vector2 _buffPos = fairyLeagueModel.crystalPosList[index];
                        var _hero = PlayerDatas.Instance.hero;
                        if (_hero != null)
                        {
                            _hero.MoveToPosition(new Vector3(_buffPos.x, _hero.Pos.y, _buffPos.y));
                        }
                    }
                    break;
                default:
                    {
                        var model = ModelCenter.Instance.GetModel<MapModel>();
                        WindowCenter.Instance.Close<WorldMapWin>();
                        WindowCenter.Instance.Close<LocalMapWin>();
                        WindowCenter.Instance.Open<MainInterfaceWin>();
                        MapTransferUtility.Instance.MoveToNPC(npcId);
                        model.selectedMapEventPoint = -1;
                    }
                    break;
            }
        }
 
        private void OnTaskStateChange(int _nowNPCid, int _nPCLamp, Dictionary<int, int> _dic)
        {
            if (npcId == _nowNPCid)
            {
                var status = taskmodel.StatusLightQuery(npcId);
                if (status > 0)
                {
                    m_TaskState.SetSprite(StringUtility.Contact("LocalMapTaskState_", status));
                }
                else
                {
                    m_TaskState.SetSprite("LocalMapTaskState_0");
                }
                m_TaskState.SetNativeSize();
            }
        }
 
        private void OnCrystalStateChange()
        {
            OnCrystalStateChange(npcId);
        }
 
        private void PlayerDataRefreshInfoEvent(PlayerDataType _type)
        {
            if (_type == PlayerDataType.Faction)
            {
                OnCrystalStateChange();
            }
        }
 
        private void OnCrystalStateChange(int _npcId)
        {
            if (npcId != _npcId)
            {
                return;
            }
            var _index = fairyLeagueModel.GetCrystalIndex(_npcId);
            m_NpcName.text = (_index + 1).ToString();
            var _camp = fairyLeagueModel.fairyLeagueHelp.GetCrystalBelongCamp(_npcId);
            if (_camp == 0)
            {
                m_TaskState.SetSprite("GrayCrystal");
                m_Moveto.image.SetSprite("GreyBottom");
                return;
            }
            m_TaskState.SetSprite((FairyCampType)_camp == FairyCampType.Blue ? "BlueCrystal" : "RedCrystal");
            m_Moveto.image.SetSprite((FairyCampType)_camp == FairyCampType.Blue ? "BlueBottom" : "RedBottom");
        }
 
        public enum TagType
        {
            Boss = 1,
            Elite = 2,
            Monster = 3,
            Function = 4,
            WayPoint = 5,
            Crystal = 6,
            FairyLeagueBuff = 7,
        }
 
    }
 
    public class LocalMapTagPool
    {
        static Dictionary<int, GameObjectPoolManager.GameObjectPool> pools = new Dictionary<int, GameObjectPoolManager.GameObjectPool>();
 
        public static LocalMapTag Require(LocalMapTag.TagType _pattern)
        {
            GameObjectPoolManager.GameObjectPool pool = null;
            var poolKey = (int)_pattern;
            if (!pools.ContainsKey(poolKey))
            {
                var prefab = UILoader.LoadPrefab(StringUtility.Contact("LocalMap_", _pattern));
                if (prefab != null)
                {
                    pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                    pools[poolKey] = pool;
                }
            }
            else
            {
                pool = pools[poolKey];
            }
 
            if (pool != null)
            {
                var instance = pool.Request();
                var npcBehaviour = instance.GetComponent<LocalMapTag>();
                npcBehaviour.tagType = _pattern;
                npcBehaviour.enabled = true;
                return npcBehaviour;
            }
            else
            {
                return null;
            }
        }
 
        public static void Recycle(LocalMapTag _npcBehaviour)
        {
            var pattern = _npcBehaviour.tagType;
            GameObjectPoolManager.GameObjectPool pool;
            if (pools.TryGetValue((int)pattern, out pool))
            {
                _npcBehaviour.enabled = false;
                pool.Release(_npcBehaviour.gameObject);
            }
        }
 
        public static void Clear()
        {
            foreach (var key in pools.Keys)
            {
                var pool = pools[key];
                if (pool != null)
                {
                    pool.Clear();
                }
            }
            pools.Clear();
        }
    }
 
}