Пример #1
0
        private static void DecreaseRemainingTime()
        {
            var entitySets = EcsManager.Get().GetEntitiesWithComponents <IImpartedEffect>();

            foreach (var entitySet in entitySets)
            {
                foreach (var component in entitySet.ComponentsOfType <IImpartedEffect>())
                {
                    component.TimeRemaining -= TimeSpan.FromSeconds(1 / 60.0);
                    if (component.TimeRemaining.TotalMilliseconds <= 0)
                    {
                        entitySet.Entity.RemoveComponent(component);
                    }
                }
            }
        }
Пример #2
0
        private IImpartedEffect ApplyAffect <TEffect>(object target) where TEffect : IImpartedEffect, new()
        {
            var affects = this.componentAffectsMap[typeof(TEffect)];
            var effect  = new TEffect();

            switch (target)
            {
            case Farmer _ when(affects& Affects.AllPlayers) == 0:
                throw new Exception($"Effect of type {typeof(TEffect).Name} cannot be applied to {nameof(Farmer)}.");

            case Monster _ when(affects& Affects.Monsters) == 0:
                throw new Exception($"Effect of type {typeof(TEffect).Name} cannot be applied to {nameof(Farmer)}.");
            }

            EcsManager.Get().AddComponent <TEffect, IImpartedEffect>(target, effect);
            return(effect);
        }
Пример #3
0
 public static EntityComponentSet[] GetComponents <T>(this IEffectRenderer <T> @this)
 {
     return(EcsManager.Get().GetEntitiesWithComponents <T>());
 }