bool BlockAttack(Damage damage) { // trigger the hitReaction animation if the character is blocking var defenseRangeConditions = meleeManager != null ? (meleeManager.CurrentMeleeDefense() != null ? meleeManager.CurrentMeleeDefense().AttackInDefenseRange(damage.sender) : false) : false; if (blocking && (animator != null && animator.enabled) && !damage.ignoreDefense && defenseRangeConditions) { var recoil_id = damage.recoil_id; var targetRecoil_id = (meleeManager.CurrentMeleeDefense() != null ? meleeManager.CurrentMeleeDefense().Recoil_ID : 0); var hitRecoilContidions = stepUp || climbUp || jumpOver || quickTurn || rolling; if (!hitRecoilContidions) { SendMessage("TriggerRecoil", recoil_id, SendMessageOptions.DontRequireReceiver); } if (meleeManager.CurrentMeleeDefense().breakAttack&& !hitRecoilContidions && damage.sender != null) { damage.sender.SendMessage("TriggerRecoil", targetRecoil_id, SendMessageOptions.DontRequireReceiver); } var damageResult = GetDamageResult(damage.value, meleeManager.CurrentMeleeDefense().defenseRate); currentHealth -= damageResult; meleeManager.CurrentMeleeDefense().PlayDEFSound(); if (damage.sender != null && damageResult > 0) { damage.sender.SendMessage("PlayHitSound", SendMessageOptions.DontRequireReceiver); } if (healthSlider != null) { healthSlider.Damage(damageResult); } currentHealthRecoveryDelay = healthRecoveryDelay; CheckHealth(); return(true); } return(false); }
bool BlockAttack(Damage damage) { // while the character is defending var defenceRangeConditions = (meleeManager != null && meleeManager.CurrentMeleeDefense() != null ? meleeManager.CurrentMeleeDefense().AttackInDefenseRange(damage.sender) : false); if (blocking && currentStamina > damage.value && !damage.ignoreDefense && defenceRangeConditions) { var recoil_id = damage.recoil_id; var targetRecoil_id = (meleeManager.CurrentMeleeDefense() != null ? meleeManager.CurrentMeleeDefense().Recoil_ID : 0); // trigger a recoil animation based on the ID set by the attack of the attacker SendMessage("TriggerRecoil", recoil_id, SendMessageOptions.DontRequireReceiver); if (meleeManager.CurrentMeleeDefense().breakAttack&& damage.sender != null) { damage.sender.SendMessage("TriggerRecoil", targetRecoil_id, SendMessageOptions.DontRequireReceiver); } // reduce the current stamina based on the damage of the attack ReduceStamina(damage.value); recoveryDelay = meleeManager.CurrentMeleeDefense().d_staminaRecoveryDelay; // reduce the current health if your defense rate is lower then 100 var damageResult = GetDamageResult(damage.value, meleeManager.CurrentMeleeDefense().defenseRate); currentHealth -= damageResult; // trigger the def sound of your defense weapon meleeManager.CurrentMeleeDefense().PlayDEFSound(); if (damage.sender != null && damageResult > 0) { // play the hit sound based on the weapon that attacked you - check the weapon sounds damage.sender.SendMessage("PlayHitSound", SendMessageOptions.DontRequireReceiver); } // reduce the current health based on the damage of the weapon currentHealth -= damageResult; currentHealthRecoveryDelay = healthRecoveryDelay; return(true); } return(false); }