少年修仙传客户端代码仓库
xingchen Qiu
2019-04-10 b45f84d1a84cb768d0b136fe37ad18364d74af1f
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
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
namespace Snxxz.UI
{
    public class DungeonTargetBehaviour : MonoBehaviour
    {
        [SerializeField] Text descText;
        [SerializeField] List<Text> m_TargetDescs;
        [SerializeField] List<Text> m_TargetNums;
        private int currentDungeonId=0;
 
        DungeonModel m_Model;
        DungeonModel model {
            get {
                return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<DungeonModel>());
            }
        }
 
        public void Init(int mapID)
        {
            currentDungeonId = mapID;
            UpdateMissionEvent();
        }
 
        private void OnEnable()
        {
            model.updateMissionEvent += UpdateMissionEvent;
        }
 
        private void UpdateMissionEvent()
        {
            if (currentDungeonId == 0) return;
 
            var dateMapId = model.GetDataMapIdByMapId(currentDungeonId);
            var hintId = model.GetDungeonHintId(dateMapId, 0);
            var config = DungeonHintConfig.Get(hintId);
 
            m_TargetDescs[0].gameObject.SetActive(config.targetNum >= 1);
            m_TargetDescs[1].gameObject.SetActive(config.targetNum >= 2);
            m_TargetDescs[2].gameObject.SetActive(config.targetNum >= 3);
 
            var step = Mathf.Clamp(model.mission.step, 1, int.MaxValue) - 1;
            if (config.targetNum >= 1)
            {
                var desc = config.targetDescription1[step < config.targetDescription1.Length ? step : 0];
                var npcId = config.NPC1ID.Length == 0 ? 0 : config.NPC1ID[step < config.NPC1ID.Length ? step : 0];
                var targetValue = config.targetValue1.Length == 0 ? 0 : config.targetValue1[step < config.targetValue1.Length ? step : 0];
                GetTargetInfo(0, desc, targetValue, step, config.targetType1, npcId);
            }
            if (config.targetNum >= 2)
            {
                var desc = config.targetDescription2[step < config.targetDescription2.Length ? step : 0];
                var npcId = config.NPC2ID.Length == 0 ? 0 : config.NPC2ID[step < config.NPC2ID.Length ? step : 0];
                var targetValue = config.targetValue2.Length == 0 ? 0 : config.targetValue2[step < config.targetValue2.Length ? step : 0];
                GetTargetInfo(1, desc, targetValue, step, config.targetType2, npcId);
            }
            if (config.targetNum >= 3)
            {
                var desc = config.targetDescription3[step < config.targetDescription2.Length ? step : 0];
                var npcId = config.NPC3ID.Length == 0 ? 0 : config.NPC3ID[step < config.NPC3ID.Length ? step : 0];
                var targetValue = config.targetValue3.Length == 0 ? 0 : config.targetValue3[step < config.targetValue3.Length ? step : 0];
                GetTargetInfo(2, desc, targetValue, step, config.targetType3, npcId);
            }
 
            switch (dateMapId)
            {
                case GatherSoulDungeonModel.DUNGEON_MAPID:
                    var weel = Mathf.Clamp(model.mission.wheel, 1, int.MaxValue) - 1;
                    descText.text = config.Info.Length > weel ? config.Info[weel] : config.Info[0];
                    break;
                default:
                    descText.text = config.Info.Length > step ? config.Info[step] : config.Info[0];
                    break;
            }
        }
 
        private void GetTargetInfo(int _index,string desc,int _targetValue,int _targetStep,int _targetType,int npcId=0)
        {
            m_TargetDescs[_index].text = desc;
            m_TargetNums[_index].text = string.Empty;
            switch ((DungeonTargetType)_targetType) {
                case DungeonTargetType.NPC:
                    int killCnt = 0;
                    if (npcId != 0) {
                        var npcConfig = NPCConfig.Get(npcId);
                        desc = desc.Replace("@NPCName@", npcConfig.charName);
                        if (model.mission.npc != null) {
                            for (int i = 0; i < model.mission.npc.Length; i++) {
                                var npcInfo = model.mission.npc[i];
                                if (npcInfo.NPCID == npcId) {
                                    killCnt = npcInfo.killCnt;
                                    break;
                                }
                            }
                        }
                    }
                    if (_targetValue > 0) {
                        m_TargetNums[_index].text= StringUtility.Contact(killCnt, "/", _targetValue);
                        break;
                    }
                    m_TargetNums[_index].text = killCnt.ToString();
                    break;
                case DungeonTargetType.Exp:
                    if (_targetValue > 0) {
                        m_TargetNums[_index].text=StringUtility.Contact(UIHelper.ReplaceLargeNum((ulong)model.mission.totalExp), "/", UIHelper.ReplaceLargeNum((ulong)_targetValue));
                        break;
                    }
                    m_TargetNums[_index].text = StringUtility.Contact(UIHelper.ReplaceLargeNum((ulong)model.mission.totalExp),
                        model.mission.isFullExp == 1 ? StringUtility.Contact("  ", Language.Get("FullExp")) : string.Empty);
                    break;
                case DungeonTargetType.Score:
                    if (_targetValue > 0) {
                        m_TargetNums[_index].text= StringUtility.Contact(model.mission.score, "/", _targetValue);
                        break;
                    }
                    m_TargetNums[_index].text = model.mission.score.ToString();
                    break;
                case DungeonTargetType.Money:
                    if (_targetValue > 0) {
                        m_TargetNums[_index].text = StringUtility.Contact(model.mission.money, "/", _targetValue);
                        break;
                    }
                    m_TargetNums[_index].text = model.mission.money.ToString();
                    break;
                case DungeonTargetType.Wave:
                    if (_targetValue > 0) {
                        m_TargetNums[_index].text = StringUtility.Contact(model.mission.wheel, "/", _targetValue);
                        break;
                    }
                    m_TargetNums[_index].text = model.mission.wheel.ToString();
                    break;
                case DungeonTargetType.NpcTotal:
                    if (_targetValue > 0) {
                        m_TargetNums[_index].text = StringUtility.Contact(model.mission.npcTotal, "/", _targetValue);
                        break;
                    }
                    m_TargetNums[_index].text = model.mission.npcTotal.ToString();
                    break;
                case DungeonTargetType.Stage:
                    if (_targetValue > 0) {
                        m_TargetNums[_index].text = StringUtility.Contact(model.mission.step, "/", _targetValue);
                        break;
                    }
                    m_TargetNums[_index].text = model.mission.step.ToString();
                    break;
            }
        }
 
        private void OnDisable()
        {
            model.updateMissionEvent -= UpdateMissionEvent;
        }
    }
}