Last active
August 19, 2020 17:32
-
-
Save Dunkelheit/f368585a9382ba683d0d90589484a932 to your computer and use it in GitHub Desktop.
Destructured function parameters and code maintainability: example 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Calculates the damage of a melee attack. | |
* | |
* @param {object} weapon - Weapon used in the attack. | |
* @param {object} interactives - Interactive creatures involved in the melee attack. | |
* @param {object} interactives.attacker - Player who inflicts the attack. | |
* @param {object} [interactives.defender] - Player who inflicts the attack. | |
* @param {object} options - Options of this function. | |
* @param {boolean} [options.inflictInDefender=false] - Whether to actually inflict the damage on <code>defender</code>. | |
* @param {boolean} [options.ignoreMagicalResistance=false] - If <code>true</code> magical resistances will be ignored in the calculations. | |
* @param {boolean} [options.ignorePhysicalDefence=false] - If <code>true</code> physical defenses will be ignored in the calculations. | |
* @param {boolean} [options.criticalHitsAllowed=true - Whether to allow critical hit values in the calculations. | |
* @returns {number} Damage inflicted by <code>weapon</code> of <code>attacker</code> on <code>defender</code>. | |
*/ | |
function calculateWeaponDamage(weapon, { attacker, defender }, | |
{ inflictInDefender = true, ignoreMagicalResistance = true, | |
ignorePhysicalDefence = true, criticalHitsAllowed = true }) { | |
// Do your magic here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment