Code: Select all
[ImplementationName(EffectName)]
public class TestImplementation : Effect, IUniqueEffect
{
public TestImplementation(EffectContext context) : base(context) { }
public override void OnCreate() => UnityEngine.Debug.Log("Test message");
float IUniqueEffect.GetAttrubuteBonus(SomeData data) => EffectOwner.BaseAttributeValue - 1f;
}
public class Effect
{
public Effect(EffectContext context)
{
EffectOwner = context.EffectOwner;
}
//Unit here is a facade for set of entities
public Unit EffectOwner { get; }
}
public class EffectFactory
{
private readonly IConstructorRepository _constructorRepository;
private readonly object[] _args;
private int _nextId;
public Effect Create(EffectName name, UnitId target)
{
if (_constructorRepository.TryGet(name, out ConstructorInfo constructorInfo) == false)
{
return null;
}
int effectId = _nextId++;
EffectContext context = new(effectId, name, _unitRepository.Get(parentId));
_args[0] = context;
return (Effect) constructorInfo.Invoke(_args);
}
}