Esempio n. 1
0
        public void StackReset(AbilitySystem baseAbility)
        {
            SetStackedSystem();

            IsStacked          = true;
            CurrentEffectIndex = baseAbility.CurrentEffectIndex;

            for (int i = 0; i < CurrentEffectIndex; i++)
            {
                EffectSystems[i].End();
            }

            StartAbility();

            void SetStackedSystem()
            {
                SetEffects();
            }
        }
Esempio n. 2
0
        public void UpdateSystem()
        {
            if (owner is EnemySystem)
            {
                InitEnemyAbilities();
            }
            else
            {
                if (!isOwnedByPlayer)
                {
                    return;
                }

                InitSpiritAbilities();
            }

            void InitEnemyAbilities()
            {
                abilitySystems.ForEach(system =>
                {
                    if (owner.CheckHaveMana(system.Ability.ManaCost))
                    {
                        system.Init();
                    }
                });
            }

            void InitSpiritAbilities()
            {
                abilitySystems.ForEach(abilitySystem =>
                {
                    if (owner.CheckHaveMana(abilitySystem.Ability.ManaCost))
                    {
                        if (!abilitySystem.Ability.IsUsedWhenShoot)
                        {
                            if (owner.Targets.Count > 0)
                            {
                                abilitySystem.SetTarget(owner.Targets[0] as IAppliedEffectsComponent);
                                Init(abilitySystem, CheckTargetInRange(abilitySystem.Target));
                            }
                            else
                            {
                                abilitySystem.SetTarget(null);
                                Init(abilitySystem, !abilitySystem.CheckAllEffectsEnded());
                            }

                            if (abilitySystem.IsNeedStack)
                            {
                                abilityStacks.Add(CreateStack(abilitySystem));
                                abilitySystem.IsNeedStack = false;
                            }
                        }
                    }
                });

                InitStacks();

                void InitStacks()
                {
                    for (int i = 0; i < abilityStacks.Count; i++)
                    {
                        Init(abilityStacks[i], !abilityStacks[i].CheckAllEffectsEnded());
                    }
                }
            }

            AbilitySystem CreateStack(AbilitySystem baseAbilitySystem)
            {
                var stack = new AbilitySystem(baseAbilitySystem.Ability, owner);

                stack.SetTarget(baseAbilitySystem.Target);
                stack.StackReset(baseAbilitySystem);

                return(stack);
            }

            bool CheckTargetInRange(IAppliedEffectsComponent target) =>
            owner.Targets.Find(targetInRange => target == targetInRange) != null;

            void Init(AbilitySystem abilitySystem, bool condition)
            {
                if (abilitySystem.Target != null && condition)
                {
                    abilitySystem.Init();
                    AbilityUsed?.Invoke(abilitySystem);
                }
                else if (abilitySystem.IsStacked && abilitySystem.CheckAllEffectsEnded())
                {
                    abilityStacks.Remove(abilitySystem);
                }
            }
        }