чтобы обновлять данные, иначе придется плодить новые одинаковые поведения каждый раз
public interface IBotState
{
}
public interface IBotBehaviour
{
void Process();
bool TrySetup(IBotState state);
}
public interface IBotBehaviour<TState>
where TState : IBotState
{
bool TrySetup(TState state);
}
public interface IBot
{
void SetBehaviour(IBotBehaviour behaviour);
}
public class IdleBehaviour : IBotBehaviour
{
public void Process()
{
// wait 1s
}
public void Setup(IBotState state)
{
}
}
public class FollowState : IBotState
{
public Position myPosition;
public Position targetPosition;
}
public class FollowBehaviour : IBotBehaviour<FollowState>
{
private Position myPosition;
private Position targetPosition;
public void Process()
{
// move my pos to target pos
}
public bool TrySetup(IBotState state)
{
var followState = state as FollowState;
if (followState == null)
{
return false;
}
return this.TrySetup(followState);
}
public bool TrySetup(FollowState state)
{
this.myPosition = state.myPosition;
this.targetPosition = state.targetPosition;
return true;
}
}
public class BotTest : IBot
{
protected IBotBehaviour currentBehaviour;
public void SetBehaviour(IBotBehaviour behaviour)
{
this.currentBehaviour = behaviour;
}
// call currentBehaviour.Process() in game cycle
}
services.AddDbContext<StoreAppContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("StoreAppDatabase")));
И референсы на IoC-библиотеку будут только в одном проекте, а не в многих.
В данном случаи различия реально существены