Skip to content

Commit

Permalink
serialize body
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingmachine committed May 8, 2012
1 parent 386c3c7 commit 16c1e98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions base-classes.lisp
Expand Up @@ -8,4 +8,5 @@
(defclass named-object ()
((name
:initarg :name
:initform nil
:reader name)))
2 changes: 1 addition & 1 deletion body-part.lisp
Expand Up @@ -27,7 +27,7 @@
(setf (latest-event (game-room body))
(list (id body)
(list 'body-parts
(serialize body-part))
(list (serialize body-part)))
(list 'current-health
(current-health body))))))

Expand Down
15 changes: 15 additions & 0 deletions body.lisp
Expand Up @@ -109,3 +109,18 @@

(defmethod current-health ((body body))
(- (max-health body) (reduce #'+ (mappend (lambda (bp) (hash-values (damage-received bp))) (body-parts body)))))

(defmethod player? ((body body))
(not (null (player body))))

;; TODO should this be a before method that doesn't do
;; call-next-method if the body belongs to a player?
(defmethod name ((body body))
(if (player? body)
(name (player body))
(call-next-method)))

(defmethod serialize ((body body))
(list (list 'name (name body))
(list 'current-health (current-health body))
(list 'body-parts (mapcar #'serialize (body-parts body)))))

0 comments on commit 16c1e98

Please sign in to comment.