Skip to content
Browse files

can simulate an attack sequence

  • Loading branch information...
1 parent 748e072 commit 90388279b13decaf7e8fe33536f8480df391aa13 @flyingmachine committed Apr 25, 2012
Showing with 57 additions and 5 deletions.
  1. +17 −2 body-classes.lisp
  2. +21 −3 combat.lisp
  3. +18 −0 engagement.lisp
  4. +1 −0 master.lisp
View
19 body-classes.lisp
@@ -173,7 +173,7 @@
(agility
:documentation "Used to determine:
-* Swiftness of blows
+* Swiftness of blows - AP
* Dodge
* Damage dealt with agility-favoring weapons"
:initarg :agility
@@ -189,7 +189,13 @@
* Manual tasks..."
:initarg :dexterity
:initform 1
- :accessor dexterity)))
+ :accessor dexterity)
+
+ (player
+ :documentation "Used to determine whether to prompt for action during combat"
+ :initarg :player
+ :initform nil
+ :reader player)))
(defmethod body-parts ((body body))
(mappend (lambda (layer) (body-parts (cdr layer))) (body-layers body)))
@@ -200,6 +206,15 @@
(defmethod max-health ((body body))
(* 20 (stamina body)))
+(defmethod max-ap ((body body))
+ (agility body))
+
+(defmethod dead? ((body body))
+ (<= (current-health body) 0))
+
+(defun current-weapon (body)
+ (select-item "dagger"))
+
(defmethod current-health ((body body))
(- (max-health body) (reduce #'+ (mappend (lambda (bp) (hash-values (damage-received bp))) (body-parts body)))))
View
24 combat.lisp
@@ -1,9 +1,11 @@
;; Target is the string name of a specific body part
+;; returns # of AP points expended
(defun attack (attacker defender weapon &optional target)
(let ((thing-hit (attempt-hit attacker defender weapon target)))
(if thing-hit
(apply-damage attacker defender weapon thing-hit)
- (format t "You missed! How sad.~%"))))
+ (format t "You missed! How sad.~%"))
+ 3))
(defun attempt-hit (attacker defender weapon &optional target)
(let ((miss (= (random (chance-to-miss attacker defender weapon target)) 0)))
@@ -44,7 +46,7 @@
;;
;; TODO make this skill / attribute based
(defun body-parts-for-target-selection (attacker defender weapon &optional target)
- (let ((reach (+ (item-length weapon) (height attacker))))
+ (let1 reach (+ (item-length weapon) (height attacker))
(labels ((build (layers acc acc-height)
(if (null layers)
acc
@@ -72,7 +74,23 @@
;; wonder if it's good style to include "function" when returning function
(defun target-hit-function ()
- (let ((current-position 0))
+ (let1 current-position 0
(lambda (target increment)
(incf current-position increment)
(> current-position target))))
+
+;;---
+;; Combat actions
+;;---
+
+;; Must return number of AP expended, including negative AP for
+;; spells, item usage that increase AP
+;; current is a body
+(defun combat-action (current engagees)
+ (if (player current)
+ (player-combat-action current engagees)
+ (mob-combat-action current engagees)))
+
+(defun mob-combat-action (current engagees)
+ (let1 first-target (find current engagees :test (lambda (a b) (not (eql a b))))
+ (attack current first-target (current-weapon current))))
View
18 engagement.lisp
@@ -0,0 +1,18 @@
+;; Figure out who's in the engagement?
+(defun begin-engagement ())
+
+(defun turn (engagees)
+ (if (engagement-ended engagees)
+ nil
+ (let1 current (car engagees)
+ (if (dead? current)
+ (turn (cdr engagees))
+ (progn
+ (do ((ap (max-ap current) (- ap (combat-action current engagees)))
+ (i 0 (1+ i)))
+ ((or (<= ap 0) (> i 10))))
+ (turn (append1 (cdr engagees) current)))))))
+
+;; For now, end engagement when just one user is left
+(defun engagement-ended (engagees)
+ (not (cdr engagees)))
View
1 master.lisp
@@ -6,4 +6,5 @@
(load 'describe-body)
(load 'items)
(load 'combat)
+(load 'engagement)
(load 'tests)

0 comments on commit 9038827

Please sign in to comment.
Something went wrong with that request. Please try again.