From 4198d1ae1d53b87ad0dfcc489b0e90b7f69c6b23 Mon Sep 17 00:00:00 2001 From: El-BG-1970 Date: Fri, 26 Aug 2022 09:21:14 +0200 Subject: added multipurpose panel (currently only displays player stats) --- src/inventory.lisp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/inventory.lisp') 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 -- cgit v1.2.3