Skip to content

Instantly share code, notes, and snippets.

@vgaltes
Created July 4, 2016 21:15
Show Gist options
  • Save vgaltes/a64c9e36fcc21ea19800fe90dd406eb6 to your computer and use it in GitHub Desktop.
Save vgaltes/a64c9e36fcc21ea19800fe90dd406eb6 to your computer and use it in GitHub Desktop.
let interactWith characterFrom playerTo action distance =
let calculateDamage characterFrom playerTo action distance =
match action with
| Attack amount ->
match playerTo with
| Character c ->
let damage = calculateHealthDifference amount attackRules characterFrom c distance
let damage' = applyEnvironmentalRules damage environmentalAttackRules characterFrom distance
applyLimitRules damage' attackLimitRules c.Health
| Thing t ->
let damage = applyEnvironmentalRules amount environmentalAttackRules characterFrom distance
applyLimitRules damage attackLimitRules t.Health
| Heal amount ->
match playerTo with
| Character c ->
let healing = calculateHealthDifference amount healRules characterFrom c distance
applyLimitRules healing healLimitRules c.Health
| Thing t -> 0
let damage = calculateDamage characterFrom playerTo action distance
match action with
| Attack _ ->
match playerTo with
| Character c -> Player.Character {c with Health = c.Health - damage}
| Thing t -> Player.Thing {t with Health = t.Health - damage}
| Heal _ ->
match playerTo with
| Character c -> Player.Character {c with Health = c.Health + damage}
| Thing t -> Player.Thing t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment