Exemplo n.º 1
0
        /// <summary>
        /// Starts the item use.
        /// </summary>
        /// <param name="itemAbility">The item ability that is using the item.</param>
        public virtual void StartItemUse(ItemAbility useAbility)
        {
            // The use AnimatorAudioState is starting.
            m_UseAnimatorAudioStateSet.StartStopStateSelection(true);
            m_InUse = m_UseAnimatorAudioStateSet.NextState();
            if (m_InUse && m_PlayAudioOnStartUse)
            {
                var visibleObject = m_Item.GetVisibleObject() != null?m_Item.GetVisibleObject() : m_Character;

                m_UseAnimatorAudioStateSet.PlayAudioClip(visibleObject);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Damages the shield.
        /// </summary>
        /// <param name="source">The object that is trying to damage the shield.</param>
        /// <param name="amount">The amount of damage to apply/</param>
        /// <returns>The amount of damage remaining which should be applied to the character.</returns>
        public float Damage(object source, float amount)
        {
            // The shield can't absorb damage if it requires the character to be aiming and the character isn't aiming.
            if (!m_Aiming && m_RequireAim)
            {
                return(amount);
            }

            // The shield may not be able to absorb damage caused by explosions.
            if ((source is Objects.Explosion) && !m_AbsorbExplosions)
            {
                return(amount);
            }

            if (m_ApplyImpact)
            {
                m_HasImpact = true;
                m_ImpactAnimatorAudioStateSet.StartStopStateSelection(true);
                m_ImpactAnimatorAudioStateSet.NextState();
                EventHandler.ExecuteEvent(m_Character, "OnShieldImpact", this, source);
            }

            // If the shield is invincible then no damage is applied to it and the resulting absorption factor should be returned.
            if (m_DurabilityAttribute == null)
            {
                return(0);
            }

            // If the shield's durability is depleted then the entire damage amount should be applied to the character.
            if (m_DurabilityAttribute.Value == m_DurabilityAttribute.MinValue)
            {
                return(amount);
            }

            // Damage the shield and amount of damage which be applied to the character.
            var damageAmount = Mathf.Min(amount * m_AbsorptionFactor, m_DurabilityAttribute.Value);

            m_DurabilityAttribute.Value -= damageAmount;

            // The shield may be dropped if the damage reaches the minimum value.
            if (m_DurabilityAttribute.Value == m_DurabilityAttribute.MinValue && m_DropWhenDurabilityDepleted)
            {
                m_Inventory.RemoveItem(m_Item.ItemIdentifier, m_Item.SlotID, 1, false);
                m_Item.Drop(0, true);
            }

            // The remaining damage should be applied to the character.
            return(amount - damageAmount);
        }