You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.3 KiB
59 lines
1.3 KiB
namespace CMSGame
|
|
{
|
|
public class Goal<TContext> where TContext : IGoalContext
|
|
{
|
|
public string Name = string.Empty;
|
|
|
|
public int BasePriority;
|
|
|
|
public List<GoalValidityModifier<TContext>> ValidityModifiers = new();
|
|
|
|
public List<GoalPriorityModifier<TContext>> PriorityModifiers = new();
|
|
|
|
public bool IsValid()
|
|
{
|
|
return ValidityModifiers.All(modifier => modifier.Execute());
|
|
}
|
|
|
|
public int Priority()
|
|
{
|
|
return BasePriority + PriorityModifiers.Sum(modifier => modifier.Execute());
|
|
}
|
|
}
|
|
|
|
public interface IGoalContext
|
|
{
|
|
IList<Action> ListActions();
|
|
}
|
|
|
|
public abstract class GoalModifier<TContext>
|
|
{
|
|
public string Name = string.Empty;
|
|
|
|
public TContext Context;
|
|
|
|
protected GoalModifier(TContext context)
|
|
{
|
|
Context = context;
|
|
}
|
|
}
|
|
|
|
public abstract class GoalValidityModifier<TContext> : GoalModifier<TContext>
|
|
{
|
|
protected GoalValidityModifier(TContext context) : base(context)
|
|
{
|
|
}
|
|
|
|
public abstract bool Execute();
|
|
}
|
|
|
|
public abstract class GoalPriorityModifier<TContext> : GoalModifier<TContext>
|
|
{
|
|
protected GoalPriorityModifier(TContext context) : base(context)
|
|
{
|
|
}
|
|
|
|
public abstract int Execute();
|
|
}
|
|
}
|