少年修仙传客户端代码仓库
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
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, September 08, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using vnxbqy.UI;
 
//灵兽魂石
namespace vnxbqy.UI
{
 
    public class PetStoneTipsWin : Window,SecondWindowInterface
    {
        [SerializeField] ScrollerController m_ScrollerController;
        [SerializeField] GameObject m_Text_Power;
        [SerializeField] Text m_PowerNum;
        private Dictionary<int, int> tag_Item = new Dictionary<int, int>();
        Dictionary<string, ItemConfig> tagCIM = new Dictionary<string, ItemConfig>();
 
        private List<int> ListID = new List<int>();
 
        PackModel _playerPack;
        PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); } }
 
        #region Built-in
        PetModel m_petModel;
        PetModel petmodel { get { return m_petModel ?? (m_petModel = ModelCenter.Instance.GetModel<PetModel>()); } }
 
        RoleParticularModel m_RoleParticularModel;
        RoleParticularModel roleParticularModel { get { return m_RoleParticularModel ?? (m_RoleParticularModel = ModelCenter.Instance.GetModel<RoleParticularModel>()); } }
 
        public Button close { get; set; }
 
        protected override void BindController()
        {
            if (this is SecondWindowInterface)
            {
                var frame = this.GetComponentInChildren<SecondFrameLoader2>();
                frame.Create();
                close = frame.GetComponentInChildren<Button>();
            }
 
            tag_Item = petmodel._TagPetItem;
        }
 
        protected override void AddListeners()
        {
            close.onClick.AddListener(CloseButtonHS);
        }
 
        protected override void OnPreOpen()
        {
            GetPetPower();
            ListId();
            ListSortId();//排序
            m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
            OnCreateGridLineCell(m_ScrollerController);
            m_ScrollerController.JumpIndex(JumpIndex());
        }
 
 
 
        protected override void OnAfterOpen()
        {
 
            PetModel.Event_Ha339 += HA339;
            roleParticularModel.PowerUpdate += PowerUpdate;
        }
 
        protected override void OnPreClose()
        {
            m_petModel.PetStoneItemId = 0;
            m_ScrollerController.OnRefreshCell -= OnRefreshGridCell;
            PetModel.Event_Ha339 -= HA339;
            roleParticularModel.PowerUpdate -= PowerUpdate;
        }
 
 
 
        protected override void OnAfterClose()
        {
 
        }
 
        private void PowerUpdate()
        {
            GetPetPower();
        }
        private void GetPetPower()
        {
            ulong PetPower = roleParticularModel.GetFuncFightPower((int)FuncPowerType.PetSoul);
            if (PetPower > 0)
            {
                m_Text_Power.SetActive(true);
                m_PowerNum.SetActive(true);
                m_PowerNum.text = "+" + PetPower;
            }
            else
            {
                m_Text_Power.SetActive(false);
                m_PowerNum.SetActive(false);
            }
        }
        #endregion
 
        private void OnCreateGridLineCell(ScrollerController gridCtrl)
        {
            gridCtrl.Refresh();
 
            for (int i = 0; i < ListID.Count; i++)
            {
                gridCtrl.AddCell(ScrollerDataType.Header, ListID[i]);
            }
            gridCtrl.Restart();
        }
 
        private void OnRefreshGridCell(ScrollerDataType type, CellView cell)
        {
            int _id = cell.index;
            MountStoneItem _MountStoneItem = cell.GetComponent<MountStoneItem>();
            ItemConfig _item = ItemConfig.Get(_id.ToString());
            if (ItemConfig.Get(_id) == null)
                return;
            _MountStoneItem.m_BGMItem.SetItemBackGround(_item.ItemColor);
            _MountStoneItem.Item.SetSprite(_item.IconKey);
            int hs_number = playerPack.GetItemCountByID(PackType.Item, _id);//魂石数量
            List<int> bagIndex = null;
            if (hs_number <= 0)
            {
                _MountStoneItem.UserBtn.interactable = false;
                _MountStoneItem.UserBtn.GetComponent<ImageEx>().gray = true;
                _MountStoneItem.m_UseTxt.color = UIHelper.GetUIColor(TextColType.White);
                _MountStoneItem.ItemNum.text = " <color=#ff2828>" + hs_number.ToString() + "</color>" + "/1";
            }
            else
            {
                _MountStoneItem.UserBtn.interactable = true;
                _MountStoneItem.UserBtn.GetComponent<ImageEx>().gray = false;
                _MountStoneItem.m_UseTxt.color = UIHelper.GetUIColor(TextColType.NavyBrown);
                _MountStoneItem.ItemNum.text = hs_number.ToString() + "/1";
                bagIndex = playerPack.GetSinglePack(PackType.Item).GetItemIndexsAppointedCount(_id, 1);
            }
            int _maxuse = AttrFruitConfig.Get(_id).basicUseLimit;
            _MountStoneItem.PetExpNum.text = tag_Item[_id].ToString() + "/" + _maxuse.ToString();
            _MountStoneItem.Slider.value = (float)Math.Round((float)tag_Item[_id] / _maxuse, 2, MidpointRounding.AwayFromZero);
            SpiritBeastsText(_id.ToString(), _MountStoneItem.Some_text, tag_Item[_id]);
            if (tag_Item[_id] >= _maxuse)
                _MountStoneItem.UserBtn.SetActive(false);
            else
                _MountStoneItem.UserBtn.SetActive(true);
            _MountStoneItem.ItemButton.GetComponent<Button>().RemoveAllListeners();
            _MountStoneItem.ItemButton.GetComponent<Button>().AddListener(() =>
            {
                ItemTipUtility.Show(_item.ID);
            });
 
            //一次使用物品多个,不算多格子
            int useCnt = 0;
            var item = playerPack.GetItemByID(PackType.Item, _id);
            if (item != null)
            {
                
                useCnt = Math.Min(_maxuse - tag_Item[_id], item.count);
            }
            _MountStoneItem.UserBtn.RemoveAllListeners();
            _MountStoneItem.UserBtn.AddListener(() =>
            {
                if (item == null || useCnt < 0)
                {
                    return;
                }
                ItemOperateUtility.Instance.UseItem(item.guid, useCnt);
            });
 
        }
 
        void CloseButtonHS()//灵兽魂石关闭
        {
            Close();
        }
 
        void SpiritBeastsText(string _id, Text _text, int _max)//兽魂文本的判定赋值
        {
            Dictionary<int, int> _dic = new Dictionary<int, int>();
            var config = ItemConfig.Get(_id);
 
            if (config.Effect1 != 0)
            {
                _dic.Add(config.Effect1, config.EffectValueA1);
            }
            if (config.Effect2 != 0)
            {
                _dic.Add(config.Effect2, config.EffectValueA2);
            }
            if (config.Effect3 != 0)
            {
                _dic.Add(config.Effect3, config.EffectValueA3);
            }
            if (config.Effect4 != 0)
            {
                _dic.Add(config.Effect4, config.EffectValueA4);
            }
            if (config.Effect5 != 0)
            {
                _dic.Add(config.Effect5, config.EffectValueA5);
            }
 
            if (_dic.Count == 0)
                return;
 
            int textNumber = 0;
            if (_dic.Count > 2)
            {
                string val = string.Empty;
                foreach (var item in _dic.Keys)
                {
                    textNumber += 1;
                    var propertyConfig = PlayerPropertyConfig.Get(item);
                    val += propertyConfig.Name;
 
                    switch (propertyConfig.ISPercentage)
                    {
                        case 0:
                            val += "<color=#109d06>  +" + (_dic[item] * _max) + "   </color>";
                            break;
                        case 1:
                            val += "<color=#109d06> +" + (_dic[item] * _max) / 100 + "%   </color>";
                            break;
                        case 2:
                            val += "<color=#109d06> +" + (_dic[item] * _max) + "%   </color>";
                            break;
                    }
 
                    if (textNumber == 2)
                    {
                        val += "\n";
                    }
 
                }
                _text.text = val;
            }
            else
            {
                string val = string.Empty;
                foreach (var item in _dic.Keys)
                {
                    var propertyConfig = PlayerPropertyConfig.Get(item);
                    val += propertyConfig.Name;
 
                    switch (propertyConfig.ISPercentage)
                    {
                        case 0:
                            val += "<color=#009f3c>  +" + (_dic[item] * _max) + "   </color>";
                            break;
                        case 1:
                            val += "<color=#009f3c> +" + (_dic[item] * _max) / 100 + "%   </color>";
                            break;
                        case 2:
                            val += "<color=#009f3c> +" + (_dic[item] * _max) + "%   </color>";
                            break;
                    }
                }
                _text.text = val;
            }
            _dic.Clear();
        }
 
        void HA339(HA339_tagMCAttrFruitEatCntList info)
        {
            tag_Item = petmodel._TagPetItem;
            m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
        }
 
 
        private void ListId()
        {
            if (ListID.Count <= 0)
            {
                foreach (var key in petmodel._TagPetItem.Keys)
                {
                    ListID.Add(key);
                }
            }
        }
        private int JumpIndex()
        {
            SuccessConfig successConfig = SuccessConfig.Get(AchievementGoto.guideAchievementId);
            if (successConfig != null)
            {
                int[] StoneId = successConfig.Condition;
                if (StoneId.Length > 0)
                {
                    if (ListID.Contains(StoneId[0]))
                    {
                        if (playerPack.GetItemCountByID(PackType.Item, StoneId[0]) <= 0)
                        {
                            SysNotifyMgr.Instance.ShowTip("PetStone_1");
                        }
                        return ListID.IndexOf(StoneId[0]);
                    }
                    else
                    {
                        return 0;
                    }
                }
                else
                {
                    if (ListID.Contains(m_petModel.PetStoneItemId))
                    {
                        return ListID.IndexOf(m_petModel.PetStoneItemId);
                    }
                    else
                    {
                        return 0;
                    }
                }
            }
            else
            {
                if (ListID.Contains(m_petModel.PetStoneItemId))
                {
                    return ListID.IndexOf(m_petModel.PetStoneItemId);
                }
                else
                {
                    return 0;
                }
            }
        }
 
        private void ListSortId()//排序
        {
            ListID.Sort(Compare);
        }
 
        private int Compare(int x, int y)
        {
            int index_x = MaxSortIndex(x);
            int index_y = MaxSortIndex(y);
            bool havex = IsUse(x);
            bool havey = IsUse(y);
            bool IsFull_x = IsFull(x);
            bool IsFull_y = IsFull(y);
            if (havex.CompareTo(havey) != 0)
            {
                return -havex.CompareTo(havey);
            }
            if (IsFull_x.CompareTo(IsFull_y) != 0)
            {
                return -IsFull_x.CompareTo(IsFull_y);
            }
            if (index_x.CompareTo(index_y) != 0)
            {
                return -index_x.CompareTo(index_y);
            }
            if (x.CompareTo(y) != 0)
            {
                return x.CompareTo(y);
            }
            return 1;
        }
        private int MaxSortIndex(int sortId)
        {
            int index = 0;
            var AttrFruitconfig = AttrFruitConfig.Get(sortId);
            if (AttrFruitconfig != null)
            {
                index = AttrFruitconfig.Sort;
            }
            return index;
        }
        private bool IsUse(int Id)
        {
            int hs_number = playerPack.GetItemCountByID(PackType.Item, Id);//魂石数量
            int _maxuse = AttrFruitConfig.Get(Id.ToString()).basicUseLimit;
            if (tag_Item.ContainsKey(Id))
            {
                if (hs_number > 0 && _maxuse > tag_Item[Id])
                {
                    return true;
                }
 
            }
            return false;
        }
        private bool IsFull(int Id)
        {
            bool IsBool = true;
            int _maxuse = AttrFruitConfig.Get(Id.ToString()).basicUseLimit;
            if (tag_Item.ContainsKey(Id))
            {
                if (tag_Item[Id] >= _maxuse)
                {
                    IsBool = false;
                }
            }
            return IsBool;
        }
    }
 
}