/// <summary> /// Instantly regenerates vitality and applies an adrenaline bonus. /// </summary> /// <param name="healthAmount">Amount of vitality to be healed.</param> /// <param name="bonus">Allow adrenaline bonus?</param> /// <param name="bonusDuration">Duration of the adrenaline bonus.</param> public virtual void Heal(float healthAmount, bool bonus = false, float bonusDuration = 10) { if (healthAmount > 0 && m_BodyParts.Count > 0) { for (int i = 0, bodyPartsCount = m_BodyParts.Count; i < bodyPartsCount; i++) { if (m_BodyParts[i]) { m_BodyParts[i].Heal(healthAmount / bodyPartsCount); // Heals each body part by the same amount. } } Invoke(nameof(SetNormalSnapshot), 0); m_PlayerBreathSource.Stop(); m_PlayerHealthSource.ForcePlay(m_HealSound, m_HealVolume); if (!bonus) { return; } Limping = false; Trembling = false; Bleeding = false; StartCoroutine(m_FPController.AdrenalineShot(bonusDuration)); } }
/// <summary> /// Play the animation and instantiates a grenade. /// </summary> protected virtual IEnumerator ThrowGrenade() { if (m_Animator) { m_Animator.CrossFadeInFixedTime(m_PullAnimation, 0.1f); } if (m_PlayerBodySource == null) { m_PlayerBodySource = AudioManager.Instance.RegisterSource("[AudioEmitter] CharacterBody", transform.root, spatialBlend: 0); } m_PlayerBodySource.ForcePlay(m_PullSound, m_PullVolume); yield return(m_PullDuration); if (m_Animator) { m_Animator.CrossFadeInFixedTime(m_ThrowAnimation, 0.1f); } m_PlayerBodySource.ForcePlay(m_ThrowSound, m_ThrowVolume); yield return(m_InstantiateDelay); InstantiateGrenade(); }
/// <summary> /// Play the animation, regenerate the character's vitality and apply a temporary speed bonus. /// </summary> protected virtual IEnumerator AdrenalineShot() { if (m_Animator) { m_Animator.CrossFadeInFixedTime(m_ShotAnimation, 0.1f); } if (m_PlayerBodySource == null) { m_PlayerBodySource = AudioManager.Instance.RegisterSource("[AudioEmitter] CharacterBody", transform.root, spatialBlend: 0); } m_PlayerBodySource.ForcePlay(m_ShotSound, m_ShotVolume); yield return(new WaitForSeconds(m_DelayToInject)); m_HealthController.Heal(m_HealAmount, m_StaminaBonusDuration > 0, m_StaminaBonusDuration); if (!m_InfiniteShots) { m_Amount--; } yield return(m_ShotDuration); }
/// <summary> /// Plays the draw animation. /// </summary> public void Draw() { if (!m_Animator) { return; } if (!m_Draw) { return; } if (m_DrawAnimation.Length == 0) { return; } // Normalizes the playing speed. m_Animator.speed = 1; m_Animator.Play(m_DrawAnimation); m_PlayerBodySource = AudioManager.Instance.RegisterSource("[AudioEmitter] CharacterBody", m_FPController.transform.root, spatialBlend: 0); m_PlayerBodySource.ForcePlay(m_DrawSound, m_DrawVolume); }
/// <summary> /// Checks the target object to analyze if it is a weapon. /// </summary> private void SearchForWeapons() { if (Target) { // Try to convert the target for a gun pickup. GunPickup target = Target.GetComponent <GunPickup>(); // If the gun pickup is not null means that the target is actually a weapon. if (target) { IWeapon weapon = GetWeaponByID(target.ID); if (weapon == null) { return; } if (m_CurrentWeapon != null) { if (!m_CurrentWeapon.CanSwitch) { return; } if (IsEquipped(weapon)) { return; } if (HasFreeSlot) { if (InputManager.GetButtonDown(m_UseButton)) { EquipWeapon(GetWeaponIndexOnList(weapon.Identifier)); Destroy(target.transform.gameObject); StartCoroutine(Change(m_CurrentWeapon, weapon)); m_PlayerBodySource.ForcePlay(m_ItemPickupSound, m_ItemPickupVolume); CalculateWeight(); } } else { if (InputManager.GetButtonDown(m_UseButton)) { UnequipWeapon(GetEquippedWeaponIndexOnList(m_CurrentWeapon.Identifier)); EquipWeapon(GetWeaponIndexOnList(weapon.Identifier)); StartCoroutine(DropAndChange(m_CurrentWeapon, weapon, target)); if (m_FastChangeWeapons) { m_PlayerBodySource.ForcePlay(m_ItemPickupSound, m_ItemPickupVolume); } CalculateWeight(); } } } else { if (HasFreeSlot) { if (InputManager.GetButtonDown(m_UseButton)) { EquipWeapon(GetWeaponIndexOnList(weapon.Identifier)); Destroy(target.transform.gameObject); Select(weapon); CalculateWeight(); } } } } } }
/// <summary> /// Executes an attack using the left arm. /// </summary> internal void LeftAttack() { if (!m_Animator) { return; } if (!m_Attack) { return; } // Normalizes the playing speed. m_Animator.speed = 1; // Choose an animation from the list according to the defined selection method. if (m_LeftAttackAnimationList.Count > 0) { switch (m_AttackAnimationType) { case AnimationType.Sequential: { if (m_LastIndex == m_LeftAttackAnimationList.Count || m_LastIndex > m_LeftAttackAnimationList.Count) { m_LastIndex = 0; } string currentAnim = m_LeftAttackAnimationList[m_LastIndex++]; if (currentAnim.Length > 0) { m_Animator.CrossFadeInFixedTime(currentAnim, 0.1f); } break; } case AnimationType.Random: { string currentAnim = m_LeftAttackAnimationList[Random.Range(0, m_LeftAttackAnimationList.Count)]; if (currentAnim.Length > 0) { m_Animator.CrossFadeInFixedTime(currentAnim, 0.1f); } break; } default: throw new ArgumentOutOfRangeException(); } } // Attack sound. if (m_AttackSoundList.Count > 0) { if (m_AttackSoundList.Count > 1) { int i = Random.Range(1, m_AttackSoundList.Count); AudioClip a = m_AttackSoundList[i]; m_AttackSoundList[i] = m_AttackSoundList[0]; m_AttackSoundList[0] = a; m_PlayerBodySource.ForcePlay(a, m_AttackVolume); } else { m_PlayerBodySource.ForcePlay(m_AttackSoundList[0], m_AttackVolume); } } }