少年修仙传客户端代码仓库
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, September 21, 2018
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
 
using System;
using System.Collections.Generic;
 
namespace vnxbqy.UI
{
 
    public class DungenWHYJ : MonoBehaviour
    {
 
        [SerializeField] Button m_WHYJButton;
        [SerializeField] GameObject m_Container_WHYJ;        
        [SerializeField] ItemCell[] m_Items;
        [SerializeField] Image m_Rating;//评级
        DungeonModel model { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
        List<int> ListRating = new List<int>();
        Dictionary<int, List<Item>> rewardItems = new Dictionary<int, List<Item>>();
        public void Init()
        {
            ListRating.Clear();
            var congfig = DungeonOpenTimeConfig.Get(51010).RewardRate;
            for (int i = 0; i < congfig.Length; i++)
            {
                ListRating.Add(congfig[i]);
            }           
            model.dungeonFightStageChangeEevent += dungeonFightStageChangeEevent;        
            model.updateMissionEvent += updateMissionEvent;
            if (model.dungeonFightStage == DungeonFightStage.Prepare)
            {
                m_Container_WHYJ.SetActive(true);
            }
            else
            {
                m_Container_WHYJ.SetActive(false);
            }
            SetRatingImage();
            SetTranItemCell();
        }
 
        public void Unit()
        {
            model.dungeonFightStageChangeEevent -= dungeonFightStageChangeEevent;
            model.updateMissionEvent -= updateMissionEvent;
        }
 
        private void updateMissionEvent()
        {
            SetRatingImage();
            SetTranItemCell();
        }
 
        private void Start()
        {
            m_WHYJButton.AddListener(OnClickButton);
        }
        private void OnEnable()
        {
           
        }
        private void OnDisable()
        {
          
        }
 
        private void dungeonFightStageChangeEevent(DungeonFightStage obj)
        {
            if (obj == DungeonFightStage.Prepare)
            {
                if (!m_Container_WHYJ.activeSelf)
                {
                    m_Container_WHYJ.SetActive(true);
                }
            }
            else if(obj == DungeonFightStage.Normal)
            {
                if (m_Container_WHYJ.activeSelf)
                {
                    m_Container_WHYJ.SetActive(false);
                }
            }
        }
 
        private void SetTranItemCell()
        {
            int lineID = model.mission.lineID;
 
            if (!rewardItems.ContainsKey(lineID + 1))
            {
                rewardItems.Add(lineID + 1, new List<Item>());
                var WHYJConfig = WHYJRewardConfig.Get(lineID + 1);
                for (int i = 0; i < WHYJConfig.Reward.Length; i++)
                {
                    rewardItems[lineID + 1].Add(new Item()
                    {
                        id = WHYJConfig.Reward[i],
                        count = WHYJConfig.Quantity[i],
                    });
                }
                rewardItems[lineID + 1].Sort(Compare);
            }
 
            List<Item> RewardList = rewardItems[lineID + 1];
 
            for (int i = 0; i < m_Items.Length; i++)
            {
                if (i < RewardList.Count)
                {
                    m_Items[i].SetActive(true);
                    float value = GetRating() * RewardList[i].count;
                    ItemCellModel cellModel = new ItemCellModel(RewardList[i].id, true, (ulong)Math.Round(value,0));
                    m_Items[i].Init(cellModel);
                }
                else
                {
                    m_Items[i].SetActive(false);
                }
            }
        }
 
        private int Compare(Item x, Item y)
        {
            var lhs_config = ItemConfig.Get(x.id);
            var rhs_config = ItemConfig.Get(y.id);
            if (lhs_config.ItemColor != rhs_config.ItemColor)
            {
                return -lhs_config.ItemColor.CompareTo(rhs_config.ItemColor);
            }
            return 0;
        }
 
        private void OnClickButton()
        {
            m_Container_WHYJ.SetActive(!m_Container_WHYJ.activeSelf);
        }
 
        private float GetRating()
        {
            float Value = 1f;
            if (ListRating.Count < 4)
            {
                return Value;
            }
            switch (model.mission.grade)
            {
                case 1:
                    Value =(float)Math.Round((double)ListRating[4] / 100, 1);                
                    return Value;
                case 2:
                    Value = (float)Math.Round((double)ListRating[3] / 100, 1);
                    return Value;
                case 3:
                    Value = (float)Math.Round((double)ListRating[2] / 100, 1);
                    return Value;
                case 4:
                    Value = (float)Math.Round((double)ListRating[1] / 100, 1);
                    return Value;
                case 5:
                    Value = (float)Math.Round((double)ListRating[0] / 100, 1);
                    return Value;
                default:
                    Value = (float)Math.Round((double)ListRating[0] / 100, 1);
                    return Value;
            }              
        }
        private void SetRatingImage()
        {
            if (model.mission.Equals(default(DungeonMissionData)))
            {
                return;
            }
            switch (model.mission.grade)
            {
                case 1:
                    m_Rating.SetSprite("Rating_D");
                    break;
                case 2:
                    m_Rating.SetSprite("Rating_C");
                    break;
                case 3:
                    m_Rating.SetSprite("Rating_B");
                    break;
                case 4:
                    m_Rating.SetSprite("Rating_A");
                    break;
                case 5:
                    m_Rating.SetSprite("Rating_S");
                    break;
                default:
                    m_Rating.SetSprite("Rating_S");
                    break;
            }
        }
    }
}