using Cal; using System; using System.Collections.Generic; using System.IO; namespace ET { public static class SkillHelper { public static async ETTask GetSkillConfig() { string path = "../Config/Skill/SkillConfig.bytes"; return await File.ReadAllBytesAsync(path); } public static async ETTask GetSkillBuffConfig() { string path = "../Config/Skill/BuffConfig.bytes"; return await File.ReadAllBytesAsync(path); } public static async ETTask GetSkillLogicConfig() { string path = "../Config/Skill/SkillLogicConfig.bytes"; return await File.ReadAllBytesAsync(path); } /// /// 从一个迭代器中获取指定条件,指定数量的元素,返回数组类型 /// /// /// 源数据 /// 临时列表 /// 临时索引列表 /// 条件表达式 /// 需要的数量 /// public static T[] SelectTarget(IEnumerable source, List list, List indexList, Func match, int targetCount, T firstT = null) where T : class { if (firstT != null) { targetCount--; } T[] ret = new T[targetCount]; if (source == null) return null; list.Clear(); foreach (T item in source) { if (item != firstT) if (match(item)) { list.Add(item); } } int sourceCount = list.Count; if (sourceCount == 0) return null; if (sourceCount <= targetCount) { for (int i = 0; i < list.Count; i++) { ret[i] = list[i]; } return ret; } indexList.Clear(); for (int i = 0; i < sourceCount; i++) indexList.Add(i); int site = sourceCount;//设置下限 int id; for (int j = 0; j < targetCount; j++) { //返回0到site - 1之中非负的一个随机数 id = RandomHelper.RandomNumber(0, site); //在随机位置取出一个数,保存到结果数组 ret[j] = list[indexList[id]]; //最后一个数复制到当前位置 indexList[id] = indexList[site - 1]; //位置的下限减少一 site--; } return ret; } public static bool GetParam(SkillParam skillParam, int skillId, out float value) { value = 0; if (skillParam == null) return true; switch (skillParam.skillSourcetype) { case SkillSourcetype.Changable: skillParam.values.TryGetValue(skillId % 100, out value); return true; default: case SkillSourcetype.None: value = 0; return false; case SkillSourcetype.Constage: value = skillParam.value; return true; } } //private static readonly List indexList = new List(); //private static readonly List tempList = new List(); ///// ///// 从sourceList中选取count个随机目标 ///// //public static void SelectUnits(List sourceList, Unit selectUnit, int targetCount) //{ // if (sourceList == null || sourceList.Count == 0) return; // var sourceCount = sourceList.Count; // if (sourceCount <= targetCount) // { // return; // } // tempList.Clear(); // indexList.Clear(); // tempList.AddRange(sourceList); // sourceList.Clear(); // if (selectUnit != null) // { // targetCount--; // sourceList.Add(selectUnit); // } // for (int i = 0; i < sourceCount; i++) // indexList.Add(i); // int site = sourceCount;//设置下限 // for (int j = 0; j < targetCount; j++) // { // //返回0到site - 1之中非负的一个随机数 // int id = RandomHelper.RandomNumber(0, site); // //在随机位置取出一个数,保存到结果数组 // sourceList.Add(tempList[indexList[id]]); // //最后一个数复制到当前位置 // indexList[id] = indexList[site - 1]; // //位置的下限减少一 // site--; // } //} public static int RandomNumber(int skillId, SkillParam minCount, SkillParam maxCount, bool isRnadom = true) { if (!SkillHelper.GetParam(maxCount, skillId, out float max)) { Log.Error($"数据填写不完整,the id of skill is {skillId}"); return 1; } float min = 1; if(isRnadom && !SkillHelper.GetParam(minCount, skillId, out min)) { Log.Error($"数据填写不完整,the id of skill is {skillId}"); } return isRnadom ? RandomHelper.RandomNumber((int)min, (int)max + 1) : (int)max; } } }