summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/player.lisp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/player.lisp b/src/player.lisp
index d497fed..394cee9 100644
--- a/src/player.lisp
+++ b/src/player.lisp
@@ -5,7 +5,8 @@
:get-cash
:get-debt
:repay-debt
- :buy-item))
+ :buy-item
+ :sell-item))
(in-package :player)
@@ -33,11 +34,11 @@
:debt debt))
(defmethod get-debt ((p player))
- (with-slots (debt) player
+ (with-slots (debt) p
debt))
(defmethod get-cash ((p player))
- (with-slots (cash) player
+ (with-slots (cash) p
cash))
(defmethod buy-item ((p player) item quantity)
@@ -50,6 +51,16 @@
(setq cash (- cash cost))
t)))))
+(defmethod sell-item ((p player) item amount)
+ (with-slots (stock cash) p
+ (let ((stocked-item
+ (inventory:remove-item stock
+ (commodities:name item) amount)))
+ (when stocked-item
+ (setq cash
+ (+ cash (* (cdr stocked-item)
+ (commodities:price item))))))))
+
(defmethod repay-debt ((p player) amount)
(with-slots (debt cash) p
(when (and (<= amount debt)