using System.Collections.Generic; using UnityEngine; /** * 无尽模式buff数据表处理类 * @Author: chenxin * @Date: 2020-10-15 17:24:10 */ namespace KTGMGemClient { /// /// 自定义数据结构,用于管理buff的生命周期 /// public class EndlessBuffConfig { /// /// 表配置数据 /// public endless_buff Config; /// /// 作用对象类型 /// public EndlessBuffUseTarget UseTarget; /// /// buff效果类型 /// public EndlessBuffEffectType EffectType; /// /// buff生命周期类型 /// public EndlessBuffLifeCycleType LifeCycleType; /// /// buff已经生效的波次数,以波为单位 /// public int TackEffectWaves; /// /// 可生效总波数,生命周期类型为n波内生效才有作用,否则没有意义 /// public int TotalEffectWaves; } public class EndlessBuffData { /// /// 无尽模式buff配置表 /// private static List endlessBuffList; /// /// 所有的配置,不管关卡等级的限制 /// private static List allEndlessConfig; /// /// 当前关卡可用的buff池,需要使用关卡等级来初始化,随机buff数据使用这个 /// private static List endlessBuffPool; private static System.Random random; /// /// 保存随机出来的buff列表 /// private static List randomBuffList; /// /// 颜色品阶 /// /// /// private static List rareColorList = new List() { 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(); allEndlessConfig = new List(); randomBuffList = new List(); 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); } } /// /// 初始化当前关卡的buff池 /// /// 关卡等级 public static void InitEndlessBuffPool(int level) { if (level <= 0) { Debug.LogError("--------------------- 错误的关卡等级 ---------------------"); return; } endlessBuffPool = new List(); 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]); } } /// /// 获取随机数量的buff列表 /// /// /// public static List GetRandomBuffList(int num = 3) { List ret = new List(); 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; } /// /// 根据点击的索引获得buff数据 /// /// public static EndlessBuffConfig GetBuffByIndex(int index) { return randomBuffList[index]; } /// /// 根据品质获得颜色值 /// /// /// public static Color GetColorByRare(int rare) { return rareColorList[rare - 1]; } } }