/// <summary> /// 执行注册到指定时间点的所有能力代码 /// </summary> /// <param name="timePoint">目标时间点</param> /// <param name="parameter">执行参数</param> /// <returns></returns> public static ExecuteInformation Execute(ExecuteTimePoint timePoint, params object[] parameter) { var answer = new ExecuteInformation(0, true, parameter); lock (CodeList) { var list = GenerateExexcuteList(timePoint); var count = list.Count - 1; for (var i = 0; i <= count; i++) { answer = list[i].Execute(i == 0 ? null : list[i - 1], i == count ? null : list[i + 1], answer); if (answer.RemoveAfterExecute) CodeList.Remove(list[i]); } } return answer; }
private static List<Code> GenerateExexcuteList(ExecuteTimePoint timePoint, List<Code> addedList = null) { if (addedList == null) addedList = new List<Code>(); var newCodeList = CodeList.Where(e => ((e.ExecuteMask & (int)timePoint) != 0) && !addedList.Contains(e)).ToList(); if (newCodeList.Count == 0) return addedList; foreach (var e in newCodeList) { if (e.CodeType == CodeType.FromCardPlay) GenerateExexcuteList(ExecuteTimePoint.AfterNormalCodeActive, addedList); if (e.CodeType == CodeType.WillSummon) GenerateExexcuteList(ExecuteTimePoint.AfterSummonActive, addedList); if (e.CodeType == CodeType.PutTrap) GenerateExexcuteList(ExecuteTimePoint.AfterTrapActive, addedList); if (e.CodeType == CodeType.MakeInterference) GenerateExexcuteList(ExecuteTimePoint.AfterInterferenceActive, addedList); if (e.CodeType == CodeType.FromServant) GenerateExexcuteList(ExecuteTimePoint.AfterServantUseCode, addedList); addedList.Add(e); if (e.CodeType == CodeType.FromCardPlay) GenerateExexcuteList(ExecuteTimePoint.BeforeNormalCodeActive, addedList); if (e.CodeType == CodeType.WillSummon) GenerateExexcuteList(ExecuteTimePoint.BeforeSummonActive, addedList); if (e.CodeType == CodeType.PutTrap) GenerateExexcuteList(ExecuteTimePoint.BeforeTrapActive, addedList); if (e.CodeType == CodeType.MakeInterference) GenerateExexcuteList(ExecuteTimePoint.BeforeInterferenceActive, addedList); if (e.CodeType == CodeType.FromServant) GenerateExexcuteList(ExecuteTimePoint.BeforeServantUseCode, addedList); } return addedList; }