diff --git a/ATL/Pooh/objects.atl b/ATL/Pooh/objects.atl index 04c4b69..f89ddcc 100644 --- a/ATL/Pooh/objects.atl +++ b/ATL/Pooh/objects.atl @@ -205,6 +205,7 @@ proof-item "Hunny" experience 5 money 5 + infinite define-quest "Reading material" say-before "I feel in dire need of intellectual stimulation, yet I fear that diff --git a/ATL/Pooh/objects.atl b/ATL/Pooh/objects.atl index 04c4b69..f89ddcc 100644 --- a/ATL/Pooh/objects.atl +++ b/ATL/Pooh/objects.atl @@ -205,6 +205,7 @@ proof-item "Hunny" experience 5 money 5 + infinite define-quest "Reading material" say-before "I feel in dire need of intellectual stimulation, yet I fear that diff --git a/ATL/Pooh/pooh.atl b/ATL/Pooh/pooh.atl index b2c3a45..bf0ffa7 100644 --- a/ATL/Pooh/pooh.atl +++ b/ATL/Pooh/pooh.atl @@ -20,4 +20,4 @@ strength 1 dexterity 4 constitution 4 - + \ No newline at end of file diff --git a/ATL/Pooh/objects.atl b/ATL/Pooh/objects.atl index 04c4b69..f89ddcc 100644 --- a/ATL/Pooh/objects.atl +++ b/ATL/Pooh/objects.atl @@ -205,6 +205,7 @@ proof-item "Hunny" experience 5 money 5 + infinite define-quest "Reading material" say-before "I feel in dire need of intellectual stimulation, yet I fear that diff --git a/ATL/Pooh/pooh.atl b/ATL/Pooh/pooh.atl index b2c3a45..bf0ffa7 100644 --- a/ATL/Pooh/pooh.atl +++ b/ATL/Pooh/pooh.atl @@ -20,4 +20,4 @@ strength 1 dexterity 4 constitution 4 - + \ No newline at end of file diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index 8b276b9..51c6b94 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -28,6 +28,7 @@ (description "") (says "") (sells NIL) + (buys NIL) (quest "") (interaction-hook "")) @@ -71,7 +72,8 @@ (proof-item NIL) (reward-item NIL) (money 0) - (experience 0)) + (experience 0) + (infinite)) (defun set-object-attribute (game-object property value) diff --git a/ATL/Pooh/objects.atl b/ATL/Pooh/objects.atl index 04c4b69..f89ddcc 100644 --- a/ATL/Pooh/objects.atl +++ b/ATL/Pooh/objects.atl @@ -205,6 +205,7 @@ proof-item "Hunny" experience 5 money 5 + infinite define-quest "Reading material" say-before "I feel in dire need of intellectual stimulation, yet I fear that diff --git a/ATL/Pooh/pooh.atl b/ATL/Pooh/pooh.atl index b2c3a45..bf0ffa7 100644 --- a/ATL/Pooh/pooh.atl +++ b/ATL/Pooh/pooh.atl @@ -20,4 +20,4 @@ strength 1 dexterity 4 constitution 4 - + \ No newline at end of file diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index 8b276b9..51c6b94 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -28,6 +28,7 @@ (description "") (says "") (sells NIL) + (buys NIL) (quest "") (interaction-hook "")) @@ -71,7 +72,8 @@ (proof-item NIL) (reward-item NIL) (money 0) - (experience 0)) + (experience 0) + (infinite)) (defun set-object-attribute (game-object property value) diff --git a/lisp/ui.lisp b/lisp/ui.lisp index 5859726..9f7442e 100644 --- a/lisp/ui.lisp +++ b/lisp/ui.lisp @@ -243,38 +243,61 @@ (format t "~&~%Quest complete. You gain:") (format t "~&Money: ~A Experience: ~A~&Items: ~A" (quest-money quest) (quest-experience quest) - (string-from-list (quest-reward-item quest))))))))) + (string-from-list (quest-reward-item quest))) + (unless (quest-infinite quest) + (remove-object-attribute npc 'quest npc)))))))) (defun trade (player npc) "The player trades with this NPC" - ;; TODO Implement player-sells-to-npc feature (when (and (stringp npc) (member npc (place-npc (get-game-object 'place (player-place player))) :test #'equalp)) (setf npc (get-game-object 'npc npc)) - (unless (npc-sells npc) - (format t "~&This NPC doesn't sell anything!") + (unless (or (npc-sells npc) (npc-buys npc)) + (format t "~&This NPC doesn't buy or sell anything!") (return-from trade))) - (format t "~&~%What do you want to buy? Your money: ~S" - (player-money player)) - (let* ((choice (choose-option (append (npc-sells npc) (list "None")))) - (item (get-game-object 'item choice)) - (cost (if item (item-cost item) NIL))) - ;; TODO The cost should be displayed alongside every item. - (cond ((equalp choice "None") NIL) - ((not item) - (format t "~&This object does not exist!") - (format t "~&(This is a bug in the game world.)") - NIL) - ((< (player-money player) cost) - (format t "~&This costs ~S. You do not have enough money!" - cost)) - ((y-or-n-p "Buy ~A for ~S?" choice cost) - (decf (player-money player) cost) - (set-object-attribute player 'item choice) - (format t "~&Bought ~A for ~A." choice cost)))) - (if (y-or-n-p "Buy something else?") + (if (and (npc-sells npc) (npc-buys npc)) + (setf trade (choose-option '("Buy" "Sell" "None"))) + (if (npc-sells npc) (setf trade "Buy") (setf trade "Sell"))) + (cond ((equalp trade "None") (return-from trade)) + ((equalp trade "Buy") + (format t "~&What do you want to buy? Your money: ~S" + (player-money player)) + (let* ((choice (choose-option (append (npc-sells npc) (list "None")))) + (item (get-game-object 'item choice)) + (cost (if item (item-cost item) NIL))) + ;; TODO If possible, the cost should be displayed alongside every item. + (cond ((equalp choice "None") NIL) + ((not item) + (format t "~&This object does not exist!") + (format t "~&(This is a bug in the game world.)") + NIL) + ((< (player-money player) cost) + (format t "~&This costs ~S. You do not have enough money!" + cost)) + ((y-or-n-p "Buy ~A for ~S?" choice cost) + (decf (player-money player) cost) + (set-object-attribute player 'item choice) + (format t "~&Bought ~A for ~A." choice cost))))) + ((equalp trade "Sell") + (format t "~&~A will buy:" (npc-name npc)) + (let* ((choice (choose-option (append (npc-buys npc) (list "None")))) + (item (get-game-object 'item choice)) + (cost (if item (item-cost item) NIL))) + (cond ((equalp choice "None") NIL) + ((not (member choice (player-item player) :test #'equalp)) + (format t "~&You cannot sell an item you don't have!") + NIL) + ((not item) + (format t "~&This object does not exist!") + (format t "~&(This is a bug in the game world.)") + NIL) + ((y-or-n-p "Sell ~A for ~S?" choice cost) + (incf (player-money player) cost) + (remove-object-attribute player 'item choice) + (format t "~&Sold ~A for ~S." choice cost)))))) + (if (y-or-n-p "Continue trading?") (trade player npc) (clear player))) (defun take (player &optional item-name)