少年修仙传客户端代码仓库
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
    public class AlchemyUseDrugCell : CellView
    {
        [SerializeField] ItemCell m_Item;
        [SerializeField] Slider m_Slider;
        [SerializeField] Text m_UseCount;
        [SerializeField] PropertyBehaviour[] m_Propertys;
        [SerializeField] Button m_Func;
        [SerializeField] Text m_FuncLabel;
 
        static Dictionary<int, int> propertys = new Dictionary<int, int>();
 
        AlchemyModel model { get { return ModelCenter.Instance.GetModel<AlchemyModel>(); } }
 
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
        public void Display(int itemId, int displayIndex)
        {
            this.gameObject.name = "AlchemyUseDrugCell_" + displayIndex;
 
            var count = packModel.GetItemCountByID(PackType.Item, itemId);
            var itemModel = new ItemCellModel(itemId, true, (ulong)count);
            m_Item.Init(itemModel);
            m_Item.button.SetListener(() =>
            {
                ItemTipUtility.Show(itemId);
            });
 
            m_Item.countText.SetActive(count > 0);
            m_Item.countText.text = count.ToString();
 
            var eatTimes = 0;
 
            AlchemyDrugUseLimit drugUseLimit;
            if (model.TryGetAlchemyUseLimit(itemId, out drugUseLimit))
            {
                var useLimit = drugUseLimit.GetUseLimit();
                m_UseCount.text = StringUtility.Contact(drugUseLimit.eatTimes, "/", useLimit);
                m_Slider.value = Mathf.Clamp01((float)drugUseLimit.eatTimes / useLimit);
                eatTimes = drugUseLimit.eatTimes;
            }
 
            GetProperty(itemId, ref propertys);
 
            var index = 0;
            foreach (var key in propertys.Keys)
            {
                if (index < m_Propertys.Length)
                {
                    m_Propertys[index].SetActive(true);
                    m_Propertys[index].DisplayUpper(key, propertys[key] * eatTimes);
                    index++;
                }
            }
            for (int i = index; i < m_Propertys.Length; i++)
            {
                m_Propertys[i].SetActive(false);
            }
 
            var state = model.GetAlchemyDrugState(itemId);
            m_Func.SetInteractable(m_FuncLabel, state == 0 || state == 1);
 
            if (state == 1)
            {
                m_Func.image.SetSprite("TY_AN_31");
            }
            else
            {
                m_Func.image.SetSprite("TY_AN_32");
            }
 
            switch (state)
            {
                case 0:
                case 2:
                    m_FuncLabel.text = Language.Get("AlchemyDrugState_1");
                    break;
                case 1:
                case 3:
                    m_FuncLabel.text = Language.Get("AlchemyDrugState_2");
                    break;
            }
 
            m_Func.SetListener(() =>
            {
                OnFunc(itemId);
            });
        }
 
        private void OnFunc(int itemId)
        {
            var state = model.GetAlchemyDrugState(itemId);
            switch (state)
            {
                case 0:
                    var itemCount = packModel.GetItemCountByID(PackType.Item, itemId);
                    var list = packModel.GetItemsById(PackType.Item, itemId);
                    if (list != null && list.Count > 0)
                    {
                        int maxValue = itemCount;
                        AlchemyDrugUseLimit drugUseLimit;
                        if (model.TryGetAlchemyUseLimit(itemId, out drugUseLimit))
                        {
                            maxValue = Mathf.Min(itemCount, drugUseLimit.GetUseLimit() - drugUseLimit.eatTimes);
                        }
 
                        //if (maxValue > 1)
                        //{
                        //    AlchemyDrugBatchUseWin.itemId = itemId;
                        //    WindowCenter.Instance.Open<AlchemyDrugBatchUseWin>();
                        //}
                        //else 
                        if (ItemOperateUtility.Instance.CheckItemUselimit(itemId))
                        {
                            var config = ItemConfig.Get(itemId);
                            if (config != null && config.Effect1 == 200)
                            {
                                ModelCenter.Instance.GetModel<ReikiRootModel>().reikiPointPromoteSymbol = true;
                            }
                            ItemOperateUtility.Instance.UseItem(list[0].guid, maxValue);
                        }
                    }
                    break;
                case 1:
                    AlchemyDrugLimitWin.drugId = itemId;
                    WindowCenter.Instance.Open<AlchemyDrugLimitWin>();
                    break;
            }
        }
 
        static void GetProperty(int itemId, ref Dictionary<int, int> dict)
        {
            dict.Clear();
            var itemConfig = ItemConfig.Get(itemId);
            if (itemConfig == null)
            {
                return;
            }
            if (itemConfig.Effect1 != 0)
            {
                dict.Add(itemConfig.Effect1, itemConfig.EffectValueA1);
            }
            if (itemConfig.Effect2 != 0)
            {
                dict.Add(itemConfig.Effect2, itemConfig.EffectValueA2);
            }
            if (itemConfig.Effect3 != 0)
            {
                dict.Add(itemConfig.Effect3, itemConfig.EffectValueA3);
            }
            if (itemConfig.Effect4 != 0)
            {
                dict.Add(itemConfig.Effect4, itemConfig.EffectValueA4);
            }
            if (itemConfig.Effect5 != 0)
            {
                dict.Add(itemConfig.Effect5, itemConfig.EffectValueA5);
            }
        }
    }
}