少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
namespace vnxbqy.UI
{
    public class DungeonTargetBehaviour : MonoBehaviour
    {
        [SerializeField] Text descText;
        [SerializeField] List<Text> m_TargetDescs;
        [SerializeField] List<Text> m_TargetNums;
        private Dungeon dungeonInfo;
 
        DungeonModel m_Model;
        DungeonModel model
        {
            get
            {
                return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<DungeonModel>());
            }
        }
 
        public void Init(Dungeon dungeon)
        {
            dungeonInfo = dungeon;
            UpdateMissionEvent();
        }
 
        public void Init(int mapId, int lineId = 0)
        {
            Init(new Dungeon()
            {
                mapId = mapId,
                lineId = lineId,
            });
        }
 
        private void OnEnable()
        {
            model.updateMissionEvent += UpdateMissionEvent;
            model.onCollectNpcInfoRefresh += UpdateMissionEvent;
            model.onAttackNpcInfoRefresh += UpdateMissionEvent;
        }
 
        private void UpdateMissionEvent()
        {
            if (dungeonInfo.mapId == 0) return;
 
            var dateMapId = model.GetDataMapIdByMapId(dungeonInfo.mapId);
            var hintId = model.GetDungeonHintId(dateMapId, dungeonInfo.lineId);
            var config = DungeonHintConfig.Get(hintId);
 
            m_TargetDescs[0].SetActive(config.targetNum >= 1);
            m_TargetDescs[1].SetActive(config.targetNum >= 2);
            m_TargetDescs[2].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, config.NPC1ID);
            }
            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, config.NPC2ID);
            }
            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, config.NPC3ID);
            }
 
            switch (dateMapId)
            {
                case HazyGrassModel.FAIRY_DATAMAP:
                case HazyGrassModel.REIKI_DATAMAP:
                    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, int[] npcIds)
        {
            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;
                case DungeonTargetType.Collect:
                    var collectCount = 0;
                    for (int i = 0; i < npcIds.Length; i++)
                    {
                        collectCount += model.GetDugneonNpcCollectCount(npcIds[i]);
                    }
                    if (_targetValue > 0)
                    {
                        var label = UIHelper.AppendColor(collectCount >= _targetValue ?
                            TextColType.LightYellow : TextColType.Green
                            , collectCount.ToString());
                        m_TargetNums[_index].text = StringUtility.Contact(label, "/", _targetValue);
                        break;
                    }
                    m_TargetNums[_index].text = collectCount.ToString();
                    break;
                case DungeonTargetType.AttackCount:
                    var attackCount = model.GetDungeonNpcAttackCount(npcId);
                    if (_targetValue > 0)
                    {
                        var label = UIHelper.AppendColor(attackCount >= _targetValue ?
                            TextColType.LightYellow : TextColType.Green
                            , attackCount.ToString());
                        m_TargetNums[_index].text = StringUtility.Contact(label, "/", _targetValue);
                        break;
                    }
                    m_TargetNums[_index].text = attackCount.ToString();
                    break;
            }
        }
 
        private void OnDisable()
        {
            model.updateMissionEvent -= UpdateMissionEvent;
            model.onCollectNpcInfoRefresh -= UpdateMissionEvent;
            model.onAttackNpcInfoRefresh -= UpdateMissionEvent;
        }
    }
}