少年修仙传客户端代码仓库
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
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
namespace Snxxz.UI
{
    [XLua.Hotfix]
    [XLua.LuaCallCSharp]
    public class GatherSoulComposeModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        Dictionary<int, Compose> composeDict = new Dictionary<int, Compose>();
        public List<ComposeCategory> composeCategories { get; private set; }
        public Dictionary<ComposeCategory, List<int>> categoryDict { get; private set; }
 
        public event Action onSelectComposeItemChange;
        public event Action onSelectCategoryChange;
 
        ComposeCategory m_SelectCategory;
        public ComposeCategory selectCategory
        {
            get { return m_SelectCategory; }
            set
            {
                if (!value.Equals(m_SelectCategory))
                {
                    m_SelectCategory = value;
                    if (onSelectCategoryChange != null)
                    {
                        onSelectCategoryChange();
                    }
                }
            }
        }
 
        int m_SelectItemId = 0;
        public int selectItemId
        {
            get { return m_SelectItemId; }
            set
            {
                if (value != m_SelectItemId)
                {
                    m_SelectItemId = value;
                    if (onSelectComposeItemChange != null)
                    {
                        onSelectComposeItemChange();
                    }
                }
            }
        }
 
        public VirtualItem jumpGatherSoulItem { get; set; }
 
        GatheringSoulModel soulModel
        {
            get { return ModelCenter.Instance.GetModel<GatheringSoulModel>(); }
        }
 
        public override void Init()
        {
            ParseConfig();
        }
 
        public void OnBeforePlayerDataInitialize()
        {
        }
 
        public void OnPlayerLoginOk()
        {
        }
 
        public override void UnInit()
        {
        }
 
        void ParseConfig()
        {
            categoryDict = new Dictionary<ComposeCategory, List<int>>();
            composeCategories = new List<ComposeCategory>();
            var configs = GatherSoulComposeConfig.GetValues();
            for (int i = 0; i < configs.Count; i++)
            {
                composeDict.Add(configs[i].TagItemID, new Compose(configs[i]));
 
                var itemConfig = ItemConfig.Get(configs[i].TagItemID);
                var gatherSoulConfig = GatherSoulConfig.Get(configs[i].TagItemID);
                if (gatherSoulConfig == null)
                {
                    continue;
                }
                var propertyCount = gatherSoulConfig.AttrType.Length;
                var quality = itemConfig.ItemColor;
                var category = new ComposeCategory()
                {
                    category = configs[i].category,
                    propertyCount = propertyCount,
                    quality = quality,
                };
                if (!composeCategories.Contains(category))
                {
                    composeCategories.Add(category);
                }
 
                List<int> list;
                if (!categoryDict.TryGetValue(category, out list))
                {
                    list = new List<int>();
                    categoryDict.Add(category, list);
                }
                list.Add(configs[i].TagItemID);
            }
        }
 
        public bool ExistInComposeMat(int itemId, out Compose outCompose)
        {
            outCompose = null;
            foreach (var compose in composeDict.Values)
            {
                if (compose.requireItems.Contains(itemId))
                {
                    outCompose = compose;
                    return true;
                }
            }
            return false;
        }
 
        public bool TryGetCompose(int itemId, out Compose compose)
        {
            return composeDict.TryGetValue(itemId, out compose);
        }
 
        public class Compose
        {
            public int itemId;
            public List<int> requireItems;
            public int requireLevel;
            public int requireSoulSplinters;
            public int requireSoulCore;
            public int category;
 
            public Compose(GatherSoulComposeConfig config)
            {
                itemId = config.TagItemID;
                requireItems = new List<int>(config.NeedItem);
                requireLevel = config.NeedLV;
                requireSoulSplinters = config.NeedSoulSplinters;
                requireSoulCore = config.NeedSoulCore;
                category = config.category;
            }
        }
 
        public struct ComposeCategory
        {
            public int category;
            public int quality;
            public int propertyCount;
 
            public override bool Equals(object obj)
            {
                var compare = (ComposeCategory)obj;
                return this.category == compare.category && this.quality == compare.quality
                    && this.propertyCount == compare.propertyCount;
            }
 
            public override int GetHashCode()
            {
                return (category * 100 + quality * 10 + propertyCount).GetHashCode();
            }
        }
    }
}