/// <inheritdoc />
 public bool CommitAbility(IGameplayAbilitySystem AbilitySystem)
 {
     ActivateAbility(AbilitySystem);
     AbilitySystem.OnGameplayAbilityActivated.Invoke(this);
     ApplyCost(AbilitySystem);
     return(true);
 }
 /// <summary>
 /// Applies cooldown.  Cooldown is applied even if the  ability is already
 /// on cooldown
 /// </summary>
 protected void ApplyCooldown(IGameplayAbilitySystem abilitySystem)
 {
     foreach (var cooldownEffect in this.CooldownsToApply)
     {
         abilitySystem.ApplyGameEffectToTarget(cooldownEffect, abilitySystem);
     }
 }
示例#3
0
        public override async void ActivateAbility(IGameplayAbilitySystem AbilitySystem, IGameplayAbility Ability)
        {
            var abilitySystemActor            = AbilitySystem.GetActor();
            var animationEventSystemComponent = abilitySystemActor.GetComponent <AnimationEventSystem>();
            var animatorComponent             = abilitySystemActor.GetComponent <Animator>();

            // Make sure we have enough resources.  End ability if we don't

            (_, var gameplayEventData) = await AbilitySystem.OnGameplayEvent.WaitForEvent((gameplayTag, eventData) => gameplayTag == WaitForEventTag);

            animatorComponent.SetTrigger(AnimationTriggerName);
            animatorComponent.SetTrigger(AnimationCompleteTriggerName);

            if (ExecuteEffectEvent != null)
            {
                await animationEventSystemComponent.CustomAnimationEvent.WaitForEvent((x) => x == ExecuteEffectEvent);
            }
            _ = AbilitySystem.ApplyGameEffectToTarget(TargetGameplayEffect, gameplayEventData.Target);


            var beh = animatorComponent.GetBehaviour <AnimationBehaviourEventSystem>();
            await beh.StateEnter.WaitForEvent((animator, stateInfo, layerIndex) => stateInfo.fullPathHash == Animator.StringToHash(CompletionAnimatorStateFullHash));

            // End Ability
            Ability.EndAbility(AbilitySystem);
        }
示例#4
0
 /// <summary>
 /// Applies cooldown.  Cooldown is applied even if the  ability is already
 /// on cooldown
 /// </summary>
 protected void ApplyCooldown(IGameplayAbilitySystem abilitySystem)
 {
     foreach (var cooldown in this.GameplayCooldowns)
     {
         abilitySystem.ActiveGameplayEffectsContainer.ApplyCooldownEffect(new ActiveGameplayEffectData(cooldown.CooldownGameplayEffect, abilitySystem, abilitySystem));
     }
 }
示例#5
0
        public override async void ActivateAbility(IGameplayAbilitySystem AbilitySystem, IGameplayAbility Ability)
        {
            var abilitySystemActor            = AbilitySystem.GetActor();
            var animationEventSystemComponent = abilitySystemActor.GetComponent <AnimationEventSystem>();
            var animatorComponent             = abilitySystemActor.GetComponent <Animator>();

            // Make sure we have enough resources.  End ability if we don't

            (_, var gameplayEventData) = await AbilitySystem.OnGameplayEvent.WaitForEvent((gameplayTag, eventData) => gameplayTag == WaitForEventTag);

            animatorComponent.SetTrigger(AnimationTriggerName);
            List <GameObject> objectsSpawned = new List <GameObject>();

            // projectile.transform.position = abilitySystemActor.transform.position + abilitySystemActor.transform.forward * 1.2f + new Vector3(0, 1.5f, 0);
            await animationEventSystemComponent.CustomAnimationEvent.WaitForEvent((x) => x == FireProjectile);

            AbilitySystem.ApplyGameEffectToTarget(TargetGameplayEffect, gameplayEventData.Target);

            var beh = animatorComponent.GetBehaviour <AnimationBehaviourEventSystem>();
            await beh.StateEnter.WaitForEvent((animator, stateInfo, layerIndex) => stateInfo.fullPathHash == Animator.StringToHash(CompletionAnimatorStateFullHash));

            // Commit ability cost
            // TODO: ApplyCost();

            // Wait for some specific gameplay event
            // Not applicable for base activate

            // Commit ability cooldown
            //TODO: ApplyCooldown();

            // Apply game effect(s)

            // End Ability
            Ability.EndAbility(AbilitySystem);
        }
示例#6
0
        private async void SeekTargetAndDestroy(IGameplayAbilitySystem AbilitySystem, GameplayEventData gameplayEventData, GameObject projectile)
        {
            await projectile.GetComponent <Projectile>().SeekTarget(gameplayEventData.Target.TargettingLocation.gameObject, gameplayEventData.Target.gameObject);

            _ = AbilitySystem.ApplyGameEffectToTarget(TargetGameplayEffect, gameplayEventData.Target);
            DestroyImmediate(projectile);
        }
        private bool TagRequirementsMet(IGameplayAbilitySystem AbilitySystem)
        {
            // Checks to make sure Source ability system doesn't have prohibited tags
            var activeTags = AbilitySystem.ActiveTags;
            var hasActivationRequiredTags = true;
            var hasActivationBlockedTags  = false;
            var hasSourceRequiredTags     = false;
            var hasSourceBlockedTags      = false;


            if (this.Tags.ActivationRequiredTags.Added.Count > 0)
            {
                hasActivationRequiredTags = !this.Tags.ActivationRequiredTags.Added.Except(activeTags).Any();
            }

            if (this.Tags.ActivationBlockedTags.Added.Count > 0)
            {
                hasActivationBlockedTags = activeTags.Any(x => this.Tags.ActivationBlockedTags.Added.Contains(x));
            }

            if (this.Tags.SourceRequiredTags.Added.Count > 0)
            {
                hasSourceRequiredTags = !this.Tags.SourceRequiredTags.Added.Except(activeTags).Any();
            }

            if (this.Tags.SourceBlockedTags.Added.Count > 0)
            {
                hasSourceBlockedTags = activeTags.Any(x => this.Tags.SourceBlockedTags.Added.Contains(x));
            }

            return(!hasActivationBlockedTags && hasActivationRequiredTags);
        }
 /// <summary>
 /// Applies cooldown.  Cooldown is applied even if the  ability is already
 /// on cooldown
 /// </summary>
 protected void ApplyCooldown(IGameplayAbilitySystem abilitySystem)
 {
     for (var i = 0; i < this.GameplayCooldowns.Count; i++)
     {
         abilitySystem.AddGameplayEffectToActiveList(this.GameplayCooldowns[i].CooldownGameplayEffect);
     }
 }
        /// <summary>
        /// Applies the ability cost, decreasing the specified cost resource from the player.
        /// If player doesn't have the required resource, the resource goes to negative (or clamps to 0)
        /// </summary>
        protected void ApplyCost(IGameplayAbilitySystem AbilitySystem)
        {
            var modifiers             = this.GameplayCost.CostGameplayEffect.CalculateModifierEffect();
            var attributeModification = this.GameplayCost.CostGameplayEffect.CalculateAttributeModification(AbilitySystem, modifiers);

            this.GameplayCost.CostGameplayEffect.ApplyInstantEffect(AbilitySystem);
        }
 /// <inheritdoc />
 public GameplayEffect ApplyGameEffectToTarget(GameplayEffect Effect, IGameplayAbilitySystem Target, float Level = 0)
 {
     if (Effect.ExecuteEffect(Target))
     {
         this.AddGameplayEffectToActiveList(Effect);
     }
     return(Effect);
 }
 /// <inheritdoc />
 public virtual bool IsAbilityActivatable(IGameplayAbilitySystem AbilitySystem)
 {
     // Player must be "Idle" to begin ability activation
     if (AbilitySystem.Animator.GetCurrentAnimatorStateInfo(0).fullPathHash != Animator.StringToHash("Base.Idle"))
     {
         return(false);
     }
     return(PlayerHasResourceToCast(AbilitySystem) && AbilityOffCooldown(AbilitySystem) && TagRequirementsMet(AbilitySystem));
 }
 /// <inheritdoc />
 public bool CommitAbility(IGameplayAbilitySystem AbilitySystem)
 {
     if (!IsAbilityActivatable(AbilitySystem))
     {
         return(false);
     }
     // this.abilitySystem.OnGameplayAbilityActivated.Invoke(this);
     ApplyCost();
     return(true);
 }
 public ActiveGameplayEffectData(GameplayEffect effect, IGameplayAbilitySystem instigator, IGameplayAbilitySystem target)
 {
     this._gameplayEffect = effect;
     this._startWorldTime = Time.time;
     this.Instigator      = instigator;
     this.Target          = target;
     if (!this.Effect.Period.ExecuteOnApplication)
     {
         this._timeOfLastPeriodicApplication = Time.time;
     }
 }
示例#14
0
        /// <inheritdoc />
        public bool AbilityOffCooldown(IGameplayAbilitySystem AbilitySystem)
        {
            var cooldownTags = this.GetAbilityCooldownTags();

            // Check if we have the cooldown effect
            var cooldownEffectsMatched = AbilitySystem.ActiveGameplayEffectsContainer.ActiveCooldowns.Select(x => x.Effect)
                                         .Intersect(this.GameplayCooldowns.Select(x => x.CooldownGameplayEffect)).Count();



            return(cooldownEffectsMatched == 0);
        }
示例#15
0
        /// <inheritdoc />
        public void EndAbility(IGameplayAbilitySystem AbilitySystem)
        {
            _onGameplayAbilityEnded.Invoke(this);

            // Ability finished.  Remove all listeners.
            _onGameplayAbilityEnded.RemoveAllListeners();



            // Tell ability system ability has ended
            AbilitySystem.NotifyAbilityEnded(this);
        }
        /// <inheritdoc />
        public bool PlayerHasResourceToCast(IGameplayAbilitySystem AbilitySystem)
        {
            // Check the modifiers on the ability cost GameEffect
            var modifiers             = this.GameplayCost.CostGameplayEffect.CalculateModifierEffect();
            var attributeModification = this.GameplayCost.CostGameplayEffect.CalculateAttributeModification(AbilitySystem, modifiers, operateOnCurrentValue: true);

            foreach (var attribute in attributeModification)
            {
                if (attribute.Value.NewAttribueValue < 0)
                {
                    return(false);
                }
            }
            return(true);
        }
        /// <inheritdoc />
        public bool AbilityOffCooldown(IGameplayAbilitySystem AbilitySystem)
        {
            var cooldownTags = this.GetAbilityCooldownTags();

            // Check if the ability system has any of these tags.  Since tags are provided
            // by game effects, that means we need to iterate through all active game effects
            // and check if any of them provide these tags

            // Check each active gameplay effect.  If we have a match, store the reference
            foreach (var gameplayEffect in AbilitySystem.ActiveGameplayEffects)
            {
                if (gameplayEffect.Effect.GetOwningTags().Intersect(cooldownTags).Count() > 0)
                {
                    return(false);
                }
            }

            return(true);
        }
        public override async void ActivateAbility(IGameplayAbilitySystem AbilitySystem, IGameplayAbility Ability)
        {
            var abilitySystemActor            = AbilitySystem.GetActor();
            var animationEventSystemComponent = abilitySystemActor.GetComponent <AnimationEventSystem>();
            var animatorComponent             = abilitySystemActor.GetComponent <Animator>();

            // Make sure we have enough resources.  End ability if we don't

            (_, var gameplayEventData) = await AbilitySystem.OnGameplayEvent.WaitForEvent((gameplayTag, eventData) => gameplayTag == WaitForEventTag);

            animatorComponent.SetTrigger(AnimationTriggerName);

            List <GameObject> objectsSpawned = new List <GameObject>();

            GameObject instantiatedProjectile = null;

            await animationEventSystemComponent.CustomAnimationEvent.WaitForEvent((x) => x == CastingInitiated);

            if (Projectile != null)
            {
                instantiatedProjectile = Instantiate(Projectile);
                instantiatedProjectile.transform.position = abilitySystemActor.transform.position + this.ProjectilePositionOffset + abilitySystemActor.transform.forward * 1.2f;
            }

            animatorComponent.SetTrigger(ProjectileFireTriggerName);


            await animationEventSystemComponent.CustomAnimationEvent.WaitForEvent((x) => x == FireProjectile);



            // Animation complete.  Spawn and send projectile at target
            if (instantiatedProjectile != null)
            {
                SeekTargetAndDestroy(AbilitySystem, gameplayEventData, instantiatedProjectile);
            }


            var beh = animatorComponent.GetBehaviour <AnimationBehaviourEventSystem>();
            await beh.StateEnter.WaitForEvent((animator, stateInfo, layerIndex) => stateInfo.fullPathHash == Animator.StringToHash(CompletionAnimatorStateFullHash));

            Ability.EndAbility(AbilitySystem);
        }
        /// <inheritdoc />
        public void EndAbility(IGameplayAbilitySystem AbilitySystem)
        {
            _onGameplayAbilityEnded.Invoke(this);

            // Ability finished.  Remove all listeners.
            _onGameplayAbilityEnded.RemoveAllListeners();

            // TODO: Remove tags added by this ability

            // TODO: Cancel all tasks?

            // TODO: Remove gameplay cues

            // TODO: Cancel ability

            // TODO: Remove blocking/cancelling Gameplay Tags

            // Tell ability system ability has ended
            AbilitySystem.NotifyAbilityEnded(this);
        }
示例#20
0
        public (float CooldownElapsed, float CooldownTotal) CalculateCooldown(IGameplayAbilitySystem AbilitySystem)
        {
            var dominantCooldown = this.GameplayCooldowns
                                   .Select(abilityCooldown => abilityCooldown.CooldownGameplayEffect)
                                   .Select(abilityCooldown =>
                                           AbilitySystem.ActiveGameplayEffectsContainer.ActiveCooldowns
                                           .FirstOrDefault(activeCooldownOnCharacter => activeCooldownOnCharacter.Effect == abilityCooldown))

                                   .Where(x => x != null && x.Effect != null)
                                   .DefaultIfEmpty()
                                   .OrderByDescending(activeEffect => activeEffect?.CooldownTimeRemaining)
                                   .FirstOrDefault();

            if (dominantCooldown == null)
            {
                return(0f, 0f);
            }

            return(dominantCooldown.CooldownTimeElapsed, dominantCooldown.CooldownTimeTotal);
        }
        public (float CooldownElapsed, float CooldownTotal) CalculateCooldown(IGameplayAbilitySystem AbilitySystem)
        {
            var cooldownTags = this.GetAbilityCooldownTags();

            // Iterate through all gameplay effects on the ability system and find all effects which grant these cooldown tags
            var dominantCooldownEffect = AbilitySystem.ActiveGameplayEffectsContainer
                                         .ActiveEffectAttributeAggregator
                                         .GetActiveEffects()
                                         .Where(x => x.Effect.GrantedTags.Intersect(cooldownTags).Any())
                                         .DefaultIfEmpty()
                                         .OrderByDescending(x => x?.CooldownTimeRemaining)
                                         .FirstOrDefault();

            if (dominantCooldownEffect == null)
            {
                return(0f, 0f);
            }

            return(dominantCooldownEffect.CooldownTimeElapsed, dominantCooldownEffect.CooldownTimeTotal);
        }
示例#22
0
 public GameplayCueParameters(IGameplayAbilitySystem Instigator, GameObject EffectCauser, GameObject SourceObject)
 {
     this.Instigator   = Instigator;
     this.EffectCauser = EffectCauser;
     this.SourceObject = SourceObject;
 }
示例#23
0
 public ActiveGameplayEffectsContainer(IGameplayAbilitySystem AbilitySystem)
 {
     this.AbilitySystem = AbilitySystem;
 }
示例#24
0
 public abstract List <IGameplayAbilitySystem> InitiateTargetting(IGameplayAbilitySystem AbilitySystem, IGameplayAbility Ability);
示例#25
0
 public override List <IGameplayAbilitySystem> InitiateTargetting(IGameplayAbilitySystem AbilitySystem, IGameplayAbility Ability)
 {
     return(new List <IGameplayAbilitySystem>());
 }
示例#26
0
 public abstract void ActivateAbility(IGameplayAbilitySystem AbilitySystem, IGameplayAbility Ability);
 /// <inheritdoc />
 public bool AbilityOffCooldown(IGameplayAbilitySystem AbilitySystem)
 {
     (var elapsed, var total) = this.CalculateCooldown(AbilitySystem);
     return(total == 0f);
 }
 /// <inheritdoc />
 public virtual bool IsAbilityActivatable(IGameplayAbilitySystem AbilitySystem)
 {
     return(PlayerHasResourceToCast(AbilitySystem) && AbilityOffCooldown(AbilitySystem));
 }
 /// <inheritdoc />
 public virtual void ActivateAbility(IGameplayAbilitySystem AbilitySystem)
 {
     _abilityLogic.ActivateAbility(AbilitySystem, this);
     ApplyCooldown(AbilitySystem);
 }
 /// <inheritdoc />
 public bool PlayerHasResourceToCast(IGameplayAbilitySystem AbilitySystem)
 {
     return(true);
 }