Пример #1
0
 private void OnAnyEpisodeComplete(Episode episode)
 {
     foreach (var behaviour in Behaviours.Where(behaviour => behaviour.IsPreventsMovement()).ToList())
     {
         RemoveStack(behaviour, behaviour.StackCount);
     }
 }
Пример #2
0
        private void OnAnySkillUsed(SkillUseEventData data)
        {
            var behaviours = Behaviours.Where(b => b.Flags.HasFlag(BehaviourFlags.BreaksOnCast) &&
                                              b.Caster == data.Caster).ToList();

            foreach (var behaviour in behaviours)
            {
                if (!behaviour.CanBeRemovedOnCast)
                {
                    continue;
                }

                RemoveStack(behaviour, behaviour.StackCount);
            }

            // Skills triggering "AnySkillUsed" event right after behaviour is applied.

            Timer.Instance.WaitForEndOfFrame(() =>
            {
                foreach (var behaviour in behaviours)
                {
                    if (behaviour.CanBeRemovedOnCast)
                    {
                        continue;
                    }

                    behaviour.CanBeRemovedOnCast = true;
                }
            });
        }
Пример #3
0
        private void OnDealDamage(EntityDamagedEventData data)
        {
            if (data.Damage.Amount < 1)
            {
                return;
            }

            Timer.Instance.WaitForFixedUpdate(() =>
            {
                foreach (var behaviour in Behaviours.Where(
                             behaviour => behaviour.Flags.HasFlag(BehaviourFlags.BreaksOnDealDamage)).ToList())
                {
                    RemoveStack(behaviour, behaviour.StackCount);
                }

                if (!data.Damage.Flags.HasFlag(DamageFlags.DOT))
                {
                    foreach (var behaviour in Behaviours.Where(
                                 behaviour => behaviour.Flags.HasFlag(BehaviourFlags.BreaksOnDealDirectDamage)).ToList())
                    {
                        RemoveStack(behaviour, behaviour.StackCount);
                    }
                }
            });
        }
Пример #4
0
 private void RemoveBehaviours(Func <Behaviour, bool> predicate = null)
 {
     Behaviours
     .Where(behaviour => predicate?.Invoke(behaviour) ?? true)
     .ToList()
     .ForEach(behaviour => behaviour.Remove(behaviour.StackCount));
 }
Пример #5
0
 public int GetStackCount(int behaviourId)
 {
     return(Behaviours
            .Where(b => b.Id == behaviourId)
            .Select(b => b.StackCount)
            .DefaultIfEmpty(0)
            .Sum());
 }
Пример #6
0
 private void OnAnyEntityDied(EntityDiedEventData data)
 {
     foreach (var behaviour in Behaviours.Where(behaviour =>
                                                behaviour.Flags.HasFlag(BehaviourFlags.BreaksOnCasterDeath) &&
                                                behaviour.Caster == data.Victim).ToList())
     {
         RemoveStack(behaviour, behaviour.StackCount);
     }
 }
Пример #7
0
        private void BeforeBehaviourApplied(Behaviour applied)
        {
            if (!applied.IsPreventsActions())
            {
                return;
            }

            foreach (var behaviour in Behaviours.Where(behaviour => behaviour.Flags.HasFlag(BehaviourFlags.BreaksOnCrowdControl)).ToList())
            {
                RemoveAllStacks(behaviour.Id);
            }
        }
Пример #8
0
        private void UpdateFrameProcessors()
        {
            var requiredTypes  = new List <Type>();
            var fb             = Behaviours.Count();
            var requestedTypes = Behaviours.Where(b => b.RequestedFrameProcessors != null).SelectMany(b => b.RequestedFrameProcessors);

            if (requestedTypes != null)
            {
                requiredTypes.AddRange(requestedTypes.Distinct());
            }

            var presentTypes = FrameProcessors.Select(p => p.GetType()).Distinct();

            var toRemove = presentTypes.Where(t => !requiredTypes.Contains(t)).ToList();
            var toAdd    = requiredTypes.Where(t => !presentTypes.Contains(t));

            FrameProcessors.Where(p => toRemove.Contains(p.GetType())).ToList().ForEach(p => p.Dispose());
            FrameProcessors.RemoveAll(p => toRemove.Contains(p.GetType()));
            FrameProcessors.AddRange(toAdd.Select(t => (ICameraFrameProcessor)Activator.CreateInstance(t)));
        }
Пример #9
0
        public async Task RemoveBehaviourAsync(string reference)
        {
            var found = Behaviours.Where(b => b.UniqueReference == reference).ToList();

            Behaviours.RemoveAll(b => b.UniqueReference == reference);
            UpdateFrameProcessors();
            if (Connection == ConnectedState.Connected)
            {
                foreach (var behaviour in found)
                {
                    if (behaviour.ActionOnRemoved != null)
                    {
                        EnqueueAction(behaviour.ActionOnRemoved);
                    }
                }
                await ActOnAnyBehaviourPermanentRequirements();
                await UnregisterBehavioursAsync(found);
            }

            OnBehaviourEvent?.Invoke(Behaviours, BehaviourEvent.Remove);
        }
Пример #10
0
 private List <Behaviour> GetBehavioursByType(EBehaviourType type) => Behaviours.Where(_ => _.BehaviourType == type).ToList();
Пример #11
0
 public IEnumerable <BaseBehaviour> GetBehavioursByType(Type behType)
 => Behaviours.Where(b => b.GetType() == behType);
Пример #12
0
 private List <Behaviour> GetBehavioursByType(EBehaviourType type) => Behaviours.Where(_ => _.BehaviourType.Equals(type)).ToList();