Skip to content

Instantly share code, notes, and snippets.

@Dunkelheit
Created August 19, 2020 17:44
Show Gist options
  • Save Dunkelheit/f7349aabeaabf77ec628d5cfc05b5628 to your computer and use it in GitHub Desktop.
Save Dunkelheit/f7349aabeaabf77ec628d5cfc05b5628 to your computer and use it in GitHub Desktop.
Destructured function parameters and code maintainability: example 7
/**
* 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