-
-
Save irskep/f1d1baa496f91aa20aaebf3672bc5584 to your computer and use it in GitHub Desktop.
This file contains 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
let strengthFactor = ( | |
attacker.stats.strength - attacker.weapon.strengthRequirement) | |
if attacker.weapon.isMelee: | |
hitChance = (1 - defender.stats.reflex) * strengthFactor | |
else: | |
hitChance = ( | |
(1 - defender.stats.reflex) * | |
(1 - (attacker.weapon.rangeFalloff * distance)) | |
// too close for a ranged weapon to be accurate! | |
if distance <= 1: hitChance /= 2 | |
if random.random() > hitChance { return Outcome.miss() } | |
let armor = defender.armor[random.choice(ARMOR_TYPES)] | |
// there are 3 damage types: | |
// physical, heat/fire, and electric. | |
// each piece of armor has resistance values for each, | |
// which determines damage. | |
var total = 0 | |
if weapon.isMelee: | |
// physical weapon damage is affected by strength | |
total += ( | |
attacker.weapon.damagePhysical * | |
strengthFactor * | |
(1 - armor.physicalResistance)) | |
else: | |
total += attacker.weapon.damagePhysical * (1 - armor.physicalResistance) | |
total += attacker.weapon.damageElectric * (1 - armor.electricResistance) | |
total += attacker.weapon.damageHeat * (1 - armor.heatResistance) | |
// Result: A number roughly between 0 and 1 that I can multiply by an arbitrary scaling factor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment