chenxin
2020-11-18 2ef9a95def81f3f47f302c86a5709140a6f39ce6
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
using System.Collections.Generic;
using UnityEngine;
 
/**
 * 无尽模式buff数据表处理类
 * @Author: chenxin
 * @Date: 2020-10-15 17:24:10
 */
namespace KTGMGemClient
{
    /// <summary>
    /// 自定义数据结构,用于管理buff的生命周期
    /// </summary>
    public class EndlessBuffConfig
    {
        /// <summary>
        /// 表配置数据
        /// </summary>
        public endless_buff Config;
 
        /// <summary>
        /// 作用对象类型
        /// </summary>
        public EndlessBuffUseTarget UseTarget;
 
        /// <summary>
        /// buff效果类型
        /// </summary>
        public EndlessBuffEffectType EffectType;
 
        /// <summary>
        /// buff生命周期类型
        /// </summary>
        public EndlessBuffLifeCycleType LifeCycleType;
 
        /// <summary>
        /// buff已经生效的波次数,以波为单位
        /// </summary>
        public int TackEffectWaves;
 
        /// <summary>
        /// 可生效总波数,生命周期类型为n波内生效才有作用,否则没有意义
        /// </summary>
        public int TotalEffectWaves;
 
        /// <summary>
        /// 记录玩家选择该buff的次数
        /// </summary>
        public int SelectCount;
    }
 
    public class EndlessBuffData
    {
        /// <summary>
        /// 无尽模式buff配置表
        /// </summary>
        private static List<endless_buff> endlessBuffList;
 
        /// <summary>
        /// 所有的配置,不管关卡等级的限制
        /// </summary>
        private static List<EndlessBuffConfig> allEndlessConfig;
 
        /// <summary>
        /// 当前关卡可用的buff池,需要使用关卡等级来初始化,随机buff数据使用这个
        /// </summary>
        private static List<EndlessBuffConfig> endlessBuffPool;
 
        private static System.Random random;
 
        /// <summary>
        /// 保存随机出来的buff列表
        /// </summary>
        private static List<EndlessBuffConfig> randomBuffList;
 
        /// <summary>
        /// 颜色品阶
        /// </summary>
        /// <typeparam name="Color"></typeparam>
        /// <returns></returns>
        private static List<Color> rareColorList = new List<Color>()
        {
            new Color(118 / 255f, 1, 118 / 255f),
            new Color(131 / 255f, 181 / 255f, 1),
            new Color(220 / 255f, 112 / 255f, 1),
        };
 
        public static void Init()
        {
            endlessBuffList = JsonDataCenter.GetList<endless_buff>();
            allEndlessConfig = new List<EndlessBuffConfig>();
            randomBuffList = new List<EndlessBuffConfig>();
            random = new System.Random();
 
            foreach (endless_buff data in endlessBuffList)
            {
                EndlessBuffConfig newConfig = new EndlessBuffConfig();
                newConfig.Config = data;
                newConfig.UseTarget = (EndlessBuffUseTarget)data.target_type[0];
                newConfig.EffectType = (EndlessBuffEffectType)data.buff_effect[0];
 
                if (data.scope == -1)
                    // 从游戏开始始终生效
                    newConfig.LifeCycleType = EndlessBuffLifeCycleType.Always;
                else if (data.scope == 0)
                    // 只会生效一次,而且是立即生效
                    newConfig.LifeCycleType = EndlessBuffLifeCycleType.Once;
                else if (data.scope > 0)
                {
                    // 生效 n 波
                    newConfig.LifeCycleType = EndlessBuffLifeCycleType.LimitedWave;
                    newConfig.TotalEffectWaves = data.scope;
                }
                allEndlessConfig.Add(newConfig);
            }
        }
 
        /// <summary>
        /// 初始化当前关卡的buff池
        /// </summary>
        /// <param name="level">关卡等级</param>
        public static void InitEndlessBuffPool(int level)
        {
            if (level <= 0)
            {
                Debug.LogError("--------------------- 错误的关卡等级 ---------------------");
                return;
            }
 
            endlessBuffPool = new List<EndlessBuffConfig>();
 
            for (int i = 0; i < allEndlessConfig.Count; ++i)
            {
                if (level >= allEndlessConfig[i].Config.down_level && level <= allEndlessConfig[i].Config.upper_level)
                    endlessBuffPool.Add(allEndlessConfig[i]);
            }
        }
 
        /// <summary>
        /// 从buff池中删除以后都不会再出现的buff
        /// </summary>
        /// <param name="id"></param>
        public static void RemoveFromBuffPool(int id)
        {
            for (int i = 0; i < endlessBuffPool.Count; ++i)
            {
                if (endlessBuffPool[i].Config.id == id)
                {
                    endlessBuffPool.Remove(endlessBuffPool[i]);
                    break;
                }
            }
        }
 
        /// <summary>
        /// 获取随机数量的buff列表
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public static List<EndlessBuffConfig> GetRandomBuffList(int num = 3)
        {
            List<EndlessBuffConfig> ret = new List<EndlessBuffConfig>();
 
            if (num > endlessBuffPool.Count)
            {
                Debug.LogError("--------------------- 数量超出了buff池中的数量 ---------------------");
                return ret;
            }
 
            while (num > 0)
            {
                int index = random.Next(endlessBuffPool.Count);
                ret.Add(endlessBuffPool[index]);
                endlessBuffPool.Remove(endlessBuffPool[index]);
                --num;
            }
 
            for (int i = 0; i < ret.Count; ++i)
            {
                endlessBuffPool.Add(ret[i]);
            }
 
            randomBuffList = ret;
 
            return ret;
        }
 
        /// <summary>
        /// 根据点击的索引获得buff数据
        /// </summary>
        /// <param name="index"></param>
        public static EndlessBuffConfig GetBuffByIndex(int index)
        {
            return randomBuffList[index];
        }
 
        /// <summary>
        /// 根据buff配置表id获取buff数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static EndlessBuffConfig GetBuffById(int id)
        {
            for (int i = 0; i < endlessBuffPool.Count; ++i)
            {
                if (endlessBuffPool[i].Config.id == id)
                    return endlessBuffPool[i];
            }
 
            return null;
        }
 
        /// <summary>
        /// 根据品质获得颜色值
        /// </summary>
        /// <param name="rare"></param>
        /// <returns></returns>
        public static Color GetColorByRare(int rare)
        {
            return rareColorList[rare - 1];
        }
    }
}