Exemple #1
0
 private void OnAbilityActiveRPC(int abilityIndex, bool active)
 {
     if (active)
     {
         m_CharacterLocomotion.TryStartAbility(m_CharacterLocomotion.Abilities[abilityIndex]);
     }
     else
     {
         m_CharacterLocomotion.TryStopAbility(m_CharacterLocomotion.Abilities[abilityIndex], true);
     }
 }
        /// <summary>
        /// Tries to start the ItemSet ability.
        /// </summary>
        /// <returns>Success if the ability was started.</returns>
        public override TaskStatus OnUpdate()
        {
            if (m_ItemSetAbility == null)
            {
                return(TaskStatus.Failure);
            }

            // The ability is not null - try to start the ability.
            return(m_CharacterLocomotion.TryStartAbility(m_ItemSetAbility) ? TaskStatus.Success : TaskStatus.Failure);
        }
        /// <summary>
        /// Tries to start or stop the specified ability.
        /// </summary>
        /// <returns>Success if the ability was started or stopped.</returns>
        public override TaskStatus OnUpdate()
        {
            if (m_Ability == null)
            {
                return(TaskStatus.Failure);
            }

            // The ability is not null - try to start or stop the ability.
            if (m_Start.Value)
            {
                var abilityStarted = m_CharacterLocomotion.TryStartAbility(m_Ability);
                return((abilityStarted || m_AlwaysReturnSuccess.Value) ? TaskStatus.Success : TaskStatus.Failure);
            }
            else
            {
                var abilityStopped = m_CharacterLocomotion.TryStopAbility(m_Ability);
                return((abilityStopped || m_AlwaysReturnSuccess.Value) ? TaskStatus.Success : TaskStatus.Failure);
            }
        }
Exemple #4
0
        /// <summary>
        /// Attacks the target when within distance.
        /// </summary>
        public void Update()
        {
            var attack   = false;
            var distance = (m_LocalLookSource.Target.position - m_Transform.position).sqrMagnitude;

            if (m_AttackTime + m_ImmediateAttackDelay < Time.time && distance < m_ImmediateAttackDistance * m_ImmediateAttackDistance)
            {
                attack = true;
            }
            else if (m_NextAttackTime < Time.time && distance < m_TargetDistance * m_TargetDistance)
            {
                attack = true;
            }

            if (attack)
            {
                m_CharacterLocomotion.TryStartAbility(m_UseAbility);
                m_AttackTime     = Time.time;
                m_NextAttackTime = Time.time + m_AttackInterval.RandomValue;
            }
        }
Exemple #5
0
 /// <summary>
 /// Tries to start the specified ability.
 /// </summary>
 /// <param name="ability">The ability to try to start.</param>
 /// <returns>True if the ability was started.</returns>
 protected virtual bool TryStartAbility(Ability ability)
 {
     return(m_CharacterLocomotion.TryStartAbility(ability));
 }
Exemple #6
0
        /// <summary>
        /// Tries to start or stop the use of the current item.
        /// </summary>
        /// <returns>Success if the item was used.</returns>
        public override TaskStatus OnUpdate()
        {
            if (m_UseAbility == null)
            {
                return(TaskStatus.Failure);
            }

            // Return a status of running for as long as the character is using the item.
            if (m_WaitForUse)
            {
                for (int i = 0; i < m_UseAbility.UsableItems.Length; ++i)
                {
                    if (m_UseAbility.UsableItems[i] != null)
                    {
                        return(TaskStatus.Running);
                    }
                }
                m_WaitForUse     = false;
                m_WaitForStopUse = true;
            }

            // The item has been used. Return success as soon as the ability is stopped.
            if (m_WaitForStopUse)
            {
                m_CharacterLocomotion.TryStopAbility(m_UseAbility);
                if (!m_UseAbility.IsActive)
                {
                    return(TaskStatus.Success);
                }
                return(TaskStatus.Running);
            }

            // The item should be used in the direction of the target.
            if (m_LocalLookSource != null)
            {
                if (m_AimTarget.Value != null)
                {
                    m_LocalLookSource.Target = m_AimTarget.Value.transform;
                }
                else
                {
                    m_LocalLookSource.Target = null;
                }
            }

            // The Use ability has been found - try to start or stop the ability.
            if (m_Start.Value)
            {
                var abilityStarted = m_CharacterLocomotion.TryStartAbility(m_UseAbility);
                // The ability should wait to end until the Use ability is complete.
                if (m_WaitForUseComplete.Value)
                {
                    m_WaitForUse = true;
                    return(TaskStatus.Running);
                }
                return((abilityStarted || m_AlwaysReturnSuccess.Value) ? TaskStatus.Success : TaskStatus.Failure);
            }
            else
            {
                var abilityStopped = m_CharacterLocomotion.TryStopAbility(m_UseAbility, true);
                return((abilityStopped || m_AlwaysReturnSuccess.Value) ? TaskStatus.Success : TaskStatus.Failure);
            }
        }