Skip to content

Instantly share code, notes, and snippets.

@irskep irskep/combat.txt Secret
Created Mar 5, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.