src/caves/entities/aspects/attacker.clj @ 88091919d482

Messages!
author Steve Losh <steve@stevelosh.com>
date Tue, 17 Jul 2012 23:41:09 -0400
parents 811f328099c6
children f57db9d7ccff
(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!"
                      [(:glyph target) damage])
        (send-message target "The %s strikes you for %d damage!"
                      [(:glyph target) 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))