Skip to content

Instantly share code, notes, and snippets.

@irskep
Created March 5, 2018 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irskep/f1d1baa496f91aa20aaebf3672bc5584 to your computer and use it in GitHub Desktop.
Save irskep/f1d1baa496f91aa20aaebf3672bc5584 to your computer and use it in GitHub Desktop.
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