lispjam24/look.rkt

42 lines
1.6 KiB
Racket

#lang racket/gui
(require "structs.rkt"
"utils.rkt")
(provide look)
(define (look what where)
(if (empty? what)
(~a "In this area, there is: " (oxford-list (object-names where)))
(let* ([what-str (string-join what)]
[obj (find-object-by-name what-str where)])
(if obj
(~a "There is a " what-str " in the area."
(describe-obj obj))
(~a "The \"" what-str "\" you're looking for isn't in this area.")))))
(define (describe-obj obj)
(let ([output ""])
(when (player? obj)
(append-str! output "\nIt's you."))
(when (item? obj)
(append-str! output (~a "\nIt has a size of: " (item-size obj) "."))
(when (equipment? obj)
(append-str! output (~a "\nIt is a piece of equipment of type: " (equipment-type obj) "."))
(when (weapon? obj)
(append-str! output (~a "\nIt deals " (weapon-damage obj) " damage.")))
(when (armor? obj)
(append-str! output (~a "\nIt has a damage resistance of: " (armor-resistance obj) ".")))))
(cond
[(creature? obj)
(append-str! output (~a "\nIts species is: " (creature-species obj) "."))
(append-str! output (~a "\nIt's at " (creature-health obj) "HP."))
(if (empty? (creature-equipment obj))
(append-str! output (~a "\nIt doesn't look like it's carrying anything."))
(append-str! output (~a "\nIt looks like it's carrying: " (oxford-list (equipment-types obj)))))]
[else
(when (entity? obj)
(append-str! output (~a "\nInside is: " (oxford-list (object-names obj)))))]
)
output))