少年修仙传客户端代码仓库
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    public enum ItemCellformat
    {
        Format_84x84,
        Format_80x80,
        Format_70x70,
        Format_64x64,
        None,
    }
 
    public class CommonItemBaisc : MonoBehaviour
    {
        [SerializeField] ItemCellformat m_Format;
        public ItemCellformat format { get { return m_Format; } set { m_Format = value; } }
 
        Image m_BgIcon;
        public Image bgIcon {
            get {
                if (m_BgIcon == null)
                {
                    LoadPrefab();
                    m_BgIcon = this.transform.GetComponent<Image>("Container_ItemCell/Img_BackGround");
                }
                return m_BgIcon;
            }
        }
 
        Image m_ItemIcon;
        public Image itemIcon {
            get {
                if (m_ItemIcon == null)
                {
                    LoadPrefab();
                    m_ItemIcon = this.transform.GetComponent<Image>("Container_ItemCell/Img_Icon");
                }
                return m_ItemIcon;
            }
        }
 
 
        Image m_StateIcon;
        public Image stateIcon {
            get {
                if (m_StateIcon == null)
                {
                    LoadPrefab();
                    m_StateIcon = this.transform.GetComponent<Image>("Container_ItemCell/Img_State");
                }
                return m_StateIcon;
            }
        }
 
        Text m_CountText;
        public Text countText {
            get {
                if (m_CountText == null)
                {
                    LoadPrefab();
                    m_CountText = this.transform.GetComponent<Text>("Container_ItemCell/Txt_Count");
                }
                return m_CountText;
            }
        }
 
        Button m_Button;
        public Button button {
            get {
                if (m_Button == null)
                {
                    LoadPrefab();
                    m_Button = this.GetComponent<Button>("Container_ItemCell");
                }
                return m_Button;
            }
        }
 
        EquipSuitEffect m_SuitEffect;
        EquipSuitEffect suitEffect
        {
            get
            {
                if (m_SuitEffect == null)
                {
                    LoadPrefab();
                    m_SuitEffect = EquipSuitEffect.Create(transform as RectTransform);
                }
                return m_SuitEffect;
            }
        }
 
        public bool suitEffectDirty { get; set; }
 
        GameObject cellContainer;
        protected void LoadPrefab()
        {
            if (cellContainer == null)
            {
                switch (format)
                {
                    case ItemCellformat.Format_64x64:
                        cellContainer = UIUtility.CreateWidget("ItemCell_64", "Container_ItemCell");
                        break;
                    case ItemCellformat.Format_70x70:
                        cellContainer = UIUtility.CreateWidget("ItemCell_70", "Container_ItemCell");
                        break;
                    case ItemCellformat.Format_80x80:
                        cellContainer = UIUtility.CreateWidget("ItemCell_80", "Container_ItemCell");
                        break;
                    case ItemCellformat.Format_84x84:
                        cellContainer = UIUtility.CreateWidget("ItemCell_84", "Container_ItemCell");
                        break;
                }
 
                if (cellContainer != null)
                {
                    cellContainer.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
                    cellContainer.transform.SetAsFirstSibling();
                }
            }
        }
 
        public int itemId { get; private set; }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
 
        /// <summary>
        /// 初始化数据 bool值用来判断是否需要展示评分高低或者职业限制
        /// </summary>
        /// <param name="model"></param>
        /// <param name="isCompare"></param>
        public virtual void Init(ItemModel model, bool isCompare = false)
        {
            itemId = model.itemId;
            InitUI(model.guid, model.itemId, (ulong)model.count, model.score, model.isAuction, model.packType, isCompare, model.useDataDict);
        }
 
        /// <summary>
        ///  初始化数据(预览)
        /// </summary>
        /// <param name="model"></param>
        public virtual void Init(ItemCellModel model)
        {
            itemId = model.itemId;
            InitUI(model.guid, model.itemId, model.count, model.score, false, model.packType, model.isCompare, model.useDataDic);
        }
 
        private void InitUI(string guid, int itemId, ulong count, int score, bool isAuction, PackType type, bool isCompare, Dictionary<int, List<int>> useDataDic)
        {
            var config = ItemConfig.Get(itemId);
            if (config == null) return;
 
            itemIcon.gameObject.SetActive(true);
            bgIcon.gameObject.SetActive(true);
            itemIcon.SetSprite(config.IconKey);
            bgIcon.SetItemBackGround(ItemLogicUtility.Instance.GetItemQuality(itemId, useDataDic));
 
            countText.gameObject.SetActive(count > 1);
            if (count > 1)
            {
                countText.text = UIHelper.ReplaceLargeNum((double)count);
            }
 
            suitEffect.Display(itemId, suitEffectDirty);
            suitEffectDirty = false;
 
            var compareReslut = isCompare ? Compare(type, itemId, score, guid) : 0;
            switch (compareReslut)
            {
                case -1:
                    stateIcon.gameObject.SetActive(true);
                    stateIcon.SetSprite("EquipDownIcon");
                    break;
                case 0:
                    stateIcon.gameObject.SetActive(false);
                    break;
                case 1:
                    stateIcon.gameObject.SetActive(true);
                    stateIcon.SetSprite("EquipUpIcon");
                    break;
                case 99:
                    stateIcon.gameObject.SetActive(true);
                    stateIcon.SetSprite("EquipForbidIcon");
                    break;
            }
        }
 
        /// <summary>
        /// 0 相等 99 禁止比较 1 高评分 -1 低评分
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="score"></param>
        /// <param name="isCompare"></param>
        /// <param name="compareSocre"></param>
        /// <returns></returns>
        int Compare(PackType type, int itemId, int score, string guid)
        {
            if (type == PackType.Equip || type == PackType.DogzEquip)
            {
                return 0;
            }
 
            if (!ItemLogicUtility.Instance.IsJobCompatibleItem(itemId))
            {
                return 99;
            }
 
            var config = ItemConfig.Get(itemId);
            if (config == null || config.EquipPlace == 0)
            {
                return 0;
            }
 
            var item = packModel.GetItemByGuid(guid);
            if (item != null && item.isAuction)
            {
                return 0;
            }
 
            if (item != null && ItemLogicUtility.Instance.IsOverdue(guid))
            {
                return 99;
            }
 
            switch (type)
            {
                case PackType.DogzItem:
                    var compareSocre = GetDogzEquipSocre(config.EquipPlace);
                    return score.CompareTo(compareSocre);
                default:
                    return equipModel.CompareToCurrent(guid);
            }
        }
 
        int GetDogzEquipSocre(int equipPlace)
        {
            var dogzModel = ModelCenter.Instance.GetModel<DogzModel>();
            ItemModel putOnModel = null;
            dogzModel.TryGetDogzEquip(dogzModel.presentSelectDogz, equipPlace, out putOnModel);
            return putOnModel == null ? 0 : putOnModel.score;
        }
 
    }
 
    public class ItemCellModel
    {
        public string guid { get; private set; }
        public int itemId { get; private set; }
        public ulong count { get; private set; }
        public int score { get; private set; }
        public bool isCompare { get; private set; }
        public ItemConfig itemConfig { get { return ItemConfig.Get(itemId); } }
        public PackType packType { get; private set; }
        public Dictionary<int, List<int>> useDataDic { get; private set; }
 
        public ItemCellModel(int itemId, bool isPreview = false, ulong count = 0, string guid = "", PackType type = PackType.Deleted, bool isCompare = false, Dictionary<int, List<int>> useDataDic = null)
        {
            this.itemId = AdjustItemId(itemId);
            this.guid = guid;
            this.count = count;
            this.isCompare = isCompare;
            this.useDataDic = useDataDic;
            this.packType = type;
 
            this.score = ItemLogicUtility.Instance.GetEquipScore(type, itemId, useDataDic, isPreview);
        }
 
        public ItemCellModel(int itemId)
        {
            this.itemId = AdjustItemId(itemId);
            this.guid = "";
            this.count = 0;
            this.isCompare = false;
            this.useDataDic = null;
            this.packType = PackType.Deleted;
            this.score = 0;
        }
 
        public ItemCellModel(int itemId, bool isPreview, ulong count)
        {
            this.itemId = AdjustItemId(itemId);
            this.guid = "";
            this.count = count;
            this.isCompare = false;
            this.useDataDic = null;
            this.packType = PackType.Deleted;
 
            this.score = ItemLogicUtility.Instance.GetEquipScore(PackType.Deleted, itemId, null, isPreview);
        }
 
        int AdjustItemId(int itemId)
        {
            var config = ItemConfig.Get(itemId);
            if (config != null && config.Effect1 == 220)
            {
                return config.EffectValueA1;
            }
            else
            {
                return itemId;
            }
        }
 
    }
 
 
}