57 lines
2.1 KiB
C#
57 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using cfg;
|
|
|
|
namespace Activity.Condition
|
|
{
|
|
/// <summary>
|
|
/// 条件检查器工厂 - 从配置表加载
|
|
/// </summary>
|
|
public class ConditionCheckerFactory
|
|
{
|
|
private static Dictionary<ConditionType, Type> _checkerTypeMap;
|
|
private static Dictionary<Type, IConditionChecker> _checkerMap;
|
|
public static void Initialize()
|
|
{
|
|
_checkerTypeMap = new Dictionary<ConditionType, Type>
|
|
{
|
|
{ ConditionType.AccountLevel, typeof(AccountLevelConditionChecker) },
|
|
{ ConditionType.GetFishCount, typeof(FishCountConditionChecker) },
|
|
// ... 更多条件类型映射
|
|
};
|
|
_checkerMap ??= new Dictionary<Type, IConditionChecker>();
|
|
}
|
|
|
|
public static IConditionChecker CreateCheckerByConditionType(ConditionType conditionType)
|
|
{
|
|
return !_checkerTypeMap.TryGetValue(conditionType, out var type) ? new DefaultConditionChecker() : CreateCheckerByType(type);
|
|
}
|
|
|
|
private static IConditionChecker CreateCheckerByType(Type type)
|
|
{
|
|
if (_checkerMap.TryGetValue(type, out var checker))
|
|
return checker;
|
|
_checkerMap[type] = checker=(IConditionChecker)Activator.CreateInstance(type);
|
|
return checker;
|
|
}
|
|
|
|
public static List<IConditionChecker> GetAllCommonCheckers()
|
|
{
|
|
// 从配置或约定加载所有通用检查器
|
|
var checkerTypes = new[]
|
|
{
|
|
typeof(TimeConditionChecker),
|
|
typeof(ABTestConditionChecker),
|
|
};
|
|
return checkerTypes.Select(CreateCheckerByType).Where(checker => checker != null).ToList();
|
|
}
|
|
public class DefaultConditionChecker : IConditionChecker
|
|
{
|
|
public int Priority => 999;
|
|
public bool CanOpen(FishingEvent @event) => true;
|
|
public List<Type> CareDataChangeWithType => null;
|
|
public bool NeedContinueListenAfterSatisfied => false;
|
|
}
|
|
}
|
|
} |