少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
//--------------------------------------------------------
//    [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;
        [SerializeField] UIEffect m_Effect;
 
        TagType m_TagType;
        public TagType tagType {
            get { return m_TagType; }
            set { m_TagType = value; }
        }
 
        int npcId = 0;
        int index = 0;
        Vector3 jumpPoint = Vector3.zero;
 
        MapModel mapModel { get { return ModelCenter.Instance.GetModel<MapModel>(); } }
        TaskModel taskModel { get { return ModelCenter.Instance.GetModel<TaskModel>(); } }
        FairyLeagueModel fairyLeagueModel { get { return ModelCenter.Instance.GetModel<FairyLeagueModel>(); } }
 
        private void Start()
        {
            if (m_Moveto != null)
            {
                m_Moveto.SetListener(MoveTo);
            }
        }
 
        public void Display(int npcId, TextColType colorType)
        {
            this.npcId = npcId;
            var config = NPCConfig.Get(this.npcId);
            switch (m_TagType)
            {
                case TagType.Function:
                    var status = this.taskModel.StatusLightQuery(this.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;
 
                    OnSelectEvent(mapModel.selectedMapEventPoint);
                    mapModel.selectMapEventPointEvent -= OnSelectEvent;
                    mapModel.selectMapEventPointEvent += OnSelectEvent;
                    break;
                case TagType.WayPoint:
                    break;
                case TagType.Boss:
                    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);
                    break;
                case TagType.Elite:
                case TagType.Monster:
                    m_NpcName.text = config.charName;
                    m_NpcName.colorType = colorType;
                    break;
                case TagType.Crystal:
                    this.OnCrystalStateChange(this.npcId);
                    PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
                    PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshEvent;
                    fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange;
                    fairyLeagueModel.UpdateWarCrystalEvent += OnCrystalStateChange;
                    break;
            }
        }
 
        public void Display(Vector3 position)
        {
            jumpPoint = position;
        }
 
        public void Display(int index)
        {
            this.index = index;
        }
 
        public void Dispose()
        {
            mapModel.selectMapEventPointEvent += OnSelectEvent;
            TaskModel.Event_TaskResponse -= OnTaskStateChange;
            fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange;
            PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
        }
 
        private void OnSelectEvent(int eventId)
        {
            var config = MapEventPointConfig.Get(eventId);
 
            var isFunctionNpc = false;
            if (config != null && config.NPCID == this.npcId)
            {
                var npcConfig = NPCConfig.Get(config.NPCID);
                if (npcConfig.NPCType == 0)
                {
                    isFunctionNpc = true;
                }
            }
 
            if (isFunctionNpc)
            {
                if (!m_Effect.IsPlaying)
                {
                    m_Effect.Play();
                }
            }
            else
            {
                if (m_Effect.IsPlaying)
                {
                    m_Effect.Stop();
                }
            }
        }
 
        private void MoveTo()
        {
            switch (m_TagType)
            {
                case TagType.FairyLeagueBuff:
                    {
                        var buffPos = fairyLeagueModel.crystalPosList[index];
                        var hero = PlayerDatas.Instance.hero;
                        if (hero != null)
                        {
                            hero.MoveToPosition(new Vector3(buffPos.x, hero.Pos.y, buffPos.y));
                        }
                    }
                    break;
                case TagType.JumpPoint:
                    MapTransferUtility.Instance.MoveToLocalMapPosition(new Vector3(jumpPoint.x, jumpPoint.z, 0) );
                    break;
                default:
                    {
                        WindowCenter.Instance.Close<WorldMapWin>();
                        WindowCenter.Instance.Close<LocalMapWin>();
                        WindowCenter.Instance.Open<MainInterfaceWin>();
                        MapTransferUtility.Instance.MoveToNPC(npcId);
                        mapModel.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 PlayerDataRefreshEvent(PlayerDataType type)
        {
            if (type == PlayerDataType.Faction)
            {
                OnCrystalStateChange();
            }
        }
 
        private void OnCrystalStateChange(int npcId)
        {
            if (this.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;
            }
 
            var isBlue = (FairyCampType)camp == FairyCampType.Blue;
            m_TaskState.SetSprite(isBlue ? "BlueCrystal" : "RedCrystal");
            m_Moveto.image.SetSprite(isBlue ? "BlueBottom" : "RedBottom");
        }
 
        public enum TagType
        {
            Boss = 1,
            Elite = 2,
            Monster = 3,
            Function = 4,
            WayPoint = 5,
            Crystal = 6,
            FairyLeagueBuff = 7,
            JumpPoint = 8
        }
 
    }
 
    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 behaviour)
        {
            var pattern = behaviour.tagType;
            GameObjectPoolManager.GameObjectPool pool;
            if (pools.TryGetValue((int)pattern, out pool))
            {
                behaviour.enabled = false;
                pool.Release(behaviour.gameObject);
            }
        }
 
        public static void Clear()
        {
            foreach (var key in pools.Keys)
            {
                var pool = pools[key];
                if (pool != null)
                {
                    pool.Clear();
                }
            }
            pools.Clear();
        }
    }
 
}