少年修仙传客户端代码仓库
client_linchunjie
2019-04-18 f624ba05077458b476f76cb8d666029a2fb56807
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    public class AlchemyStudyBehaviour : MonoBehaviour
    {
        [SerializeField] ItemBehaviour m_Item;
        [SerializeField] Text m_StoveCondition;
        [SerializeField] Text m_PropertyCondition;
        [SerializeField] Button m_Func;
        [SerializeField] Text m_FuncLabel;
 
        AlchemyModel model { get { return ModelCenter.Instance.GetModel<AlchemyModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
        private void Awake()
        {
            m_Func.SetListener(Learn);
        }
 
        public void Display()
        {
            DisplayItem();
            DisplayStoveCondition();
            DisplayPropertyCondition();
            DisplayFuncState();
        }
 
        void DisplayItem()
        {
            var config = AlchemyConfig.Get(model.selectAlchemy);
            m_Item.SetItem(config.LearnNeedItemID, 1);
        }
 
        void DisplayStoveCondition()
        {
            var config = AlchemyConfig.Get(model.selectAlchemy);
            m_StoveCondition.gameObject.SetActive(config.LearnNeedAlchemLV > 0);
            if (config.LearnNeedAlchemLV > 0)
            {
                var satisfy = model.stoveLevel >= config.LearnNeedAlchemLV;
                m_StoveCondition.text = string.Format("炼丹炉达到{0}级", config.LearnNeedAlchemLV);
                m_StoveCondition.color = UIHelper.GetUIColor(satisfy ? TextColType.Green : TextColType.Red, true);
            }
        }
 
        void DisplayPropertyCondition()
        {
            var config = AlchemyConfig.Get(model.selectAlchemy);
            m_PropertyCondition.gameObject.SetActive(config.LearnNeedLuck > 0);
            if (config.LearnNeedLuck > 0)
            {
                var satisfy = PlayerDatas.Instance.extersion.luckValue >= config.LearnNeedLuck;
                var propertyConfig = PlayerPropertyConfig.Get((int)PropertyType.Luck);
                m_PropertyCondition.text = string.Format("{0}达到{1}级", propertyConfig.Name, config.LearnNeedLuck);
                m_PropertyCondition.color = UIHelper.GetUIColor(satisfy ? TextColType.Green : TextColType.Red, true);
            }
        }
 
        void DisplayFuncState()
        {
            var error = 0;
            var satisfyLearn = TryLearn(out error);
            m_Func.SetColorful(m_FuncLabel, satisfyLearn);
        }
 
        private void Learn()
        {
            var error = 0;
            if (TryLearn(out error))
            {
                var pak = new CA576_tagCMPlayerRefine();
                pak.AlchemyID = (uint)model.selectAlchemy;
                pak.DoType = 0;
                GameNetSystem.Instance.SendInfo(pak);
            }
            else
            {
                DisplayErrorTip(error);
            }
        }
 
        bool TryLearn(out int error)
        {
            error = 0;
            var config = AlchemyConfig.Get(model.selectAlchemy);
            var count = packModel.GetItemCountByID(PackType.Item, config.LearnNeedItemID);
            if (count <= 0)
            {
                error = 1;
                return false;
            }
            if (model.stoveLevel < config.LearnNeedAlchemLV)
            {
                error = 2;
                return false;
            }
            if (PlayerDatas.Instance.extersion.luckValue < config.LearnNeedLuck)
            {
                error = 3;
                return false;
            }
            return true;
        }
 
        void DisplayErrorTip(int error)
        {
            switch (error)
            {
                case 1:
                    SysNotifyMgr.Instance.ShowTip("AlchemyLearnError_1");
                    break;
                case 2:
                    SysNotifyMgr.Instance.ShowTip("AlchemyLearnError_2");
                    break;
                case 3:
                    SysNotifyMgr.Instance.ShowTip("AlchemyLearnError_3");
                    break;
            }
        }
 
        public void Dispose()
        {
        }
    }
}