src/caves/entities/aspects/attacker.clj @ 1a3a4f8d5d85
Refactor the world code into separate files.
This pulls out the world generation code into its own file. It was
getting a bit crowded in there.
author |
Steve Losh <steve@stevelosh.com> |
date |
Wed, 01 Aug 2012 21:13:37 -0400 |
parents |
f57db9d7ccff |
children |
(none) |
(ns caves.entities.aspects.attacker
(:use [caves.entities.aspects.receiver :only [send-message]]
[caves.entities.aspects.destructible :only [Destructible take-damage
defense-value]]
[caves.entities.core :only [defaspect]]))
(declare get-damage)
(defaspect Attacker
(attack [this target world]
{:pre [(satisfies? Destructible target)]}
(let [damage (get-damage this target world)]
(->> world
(take-damage target damage)
(send-message this "You strike the %s for %d damage!"
[(:name target) damage])
(send-message target "The %s strikes you for %d damage!"
[(:name this) damage]))))
(attack-value [this world]
(get this :attack 1)))
(defn get-damage [attacker target world]
(let [attack (attack-value attacker world)
defense (defense-value target world)
max-damage (max 0 (- attack defense))
damage (inc (rand-int max-damage))]
damage))