61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Activity.Condition;
|
||
|
||
namespace cfg
|
||
{
|
||
public partial class FishingEvent
|
||
{
|
||
private List<IConditionChecker> _conditionCheckers;
|
||
private Dictionary<Type, List<IConditionChecker>> _checkersByDataType;
|
||
|
||
/// <summary>
|
||
/// 获取所有条件检查器
|
||
/// </summary>
|
||
public List<IConditionChecker> GetConditionCheckers()
|
||
{
|
||
if (_conditionCheckers != null) return _conditionCheckers;
|
||
_conditionCheckers=new List<IConditionChecker>();
|
||
_conditionCheckers.AddRange(ConditionCheckerFactory.GetAllCommonCheckers());
|
||
_conditionCheckers.AddRange(ConditionList.Select(condition =>
|
||
ConditionCheckerFactory.CreateCheckerByConditionType(condition.Condition))
|
||
.Where(checker => checker != null));
|
||
_conditionCheckers.Sort((x, y)=>x.Priority.CompareTo(y.Priority));
|
||
return _conditionCheckers;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取关心指定数据类型的检查器(按数据类型预先索引)
|
||
/// </summary>
|
||
public List<IConditionChecker> GetCheckersForDataType(Type dataType)
|
||
{
|
||
EnsureCheckersIndexed();
|
||
return _checkersByDataType.GetValueOrDefault(dataType);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 确保检查器已按数据类型索引
|
||
/// </summary>
|
||
private void EnsureCheckersIndexed()
|
||
{
|
||
if (_checkersByDataType != null) return;
|
||
|
||
_checkersByDataType = new Dictionary<Type, List<IConditionChecker>>();
|
||
|
||
foreach (var checker in GetConditionCheckers())
|
||
{
|
||
// 某些检查器(如时间、ABTest)不会关心任何数据类型,CareDataChangeWithType 可能为 null
|
||
if (checker.CareDataChangeWithType == null) continue;
|
||
|
||
foreach (var dataType in checker.CareDataChangeWithType)
|
||
{
|
||
if (!_checkersByDataType.ContainsKey(dataType))
|
||
_checkersByDataType[dataType] = new List<IConditionChecker>();
|
||
|
||
_checkersByDataType[dataType].Add(checker);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} |