diff options
| author | El-BG-1970 <elouan.gros.fr@gmail.com> | 2022-08-26 09:21:14 +0200 |
|---|---|---|
| committer | El-BG-1970 <elouan.gros.fr@gmail.com> | 2022-08-26 09:21:14 +0200 |
| commit | 4198d1ae1d53b87ad0dfcc489b0e90b7f69c6b23 (patch) | |
| tree | 195aab75d3e10a65b07444de2dd63210e9eeeff4 /src/inventory.lisp | |
| parent | 2a8076782ac7786c26e18493fe407c7916b49254 (diff) | |
| download | transacc-4198d1ae1d53b87ad0dfcc489b0e90b7f69c6b23.tar.gz | |
added multipurpose panel (currently only displays player stats)
Diffstat (limited to 'src/inventory.lisp')
| -rw-r--r-- | src/inventory.lisp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/inventory.lisp b/src/inventory.lisp index 8aa590f..a8b7c59 100644 --- a/src/inventory.lisp +++ b/src/inventory.lisp @@ -1,7 +1,7 @@ (defpackage inventory (:use :cl) (:export :new-inventory - :filled + :how-filled :add-item :remove-item :find-item)) @@ -21,6 +21,10 @@ (when (> size 0) (make-instance 'inventory :size size))) +(defmethod how-filled ((inv inventory)) + (with-slots (size filled) inv + (cons filled size))) + (defmethod find-item ((inv inventory) name) (with-slots (items) inv (find-if @@ -36,15 +40,16 @@ (setq filled (- filled (cdr item))))) (defmethod update-item ((inv inventory) item qty old-item) + (delete-item inv old-item) (with-slots (filled items) inv - (delete-item inv old-item) (let ((total-quantity (+ qty (cdr old-item))) (item-name (commodities:name item)) (item-price (commodities:price item)) (old-qty (cdr old-item)) (old-item-price (commodities:price (car old-item)))) (let ((new-item (commodities:new-commodity item-name - (/ (+ (* qty item-price) (* old-qty old-item-price)) + (/ (+ (* qty item-price) + (* old-qty old-item-price)) total-quantity)))) (push (cons new-item |
