(define player-actions
(build-actions
- (init (wrap-apply player-init!))
+ (init (wrap-apply player-init))
(handle-input (wrap-apply player-handle-input))
(tell (wrap-apply player-tell))))
(define-class <player> (<gameobj>)
(username #:init-keyword #:username
- #:accessor player-username)
- ;; Connection id
- (client #:accessor player-client)
+ #:getter player-username)
(self-commands
#:init-value '()
- #:accessor player-self-commands)
+ #:getter player-self-commands)
(message-handler
#:init-value
;;; player message handlers
-(define-mhandler (player-init! player message)
- (player-look-around player))
+(define-mhandler (player-init player message)
+ ;; Look around the room we're in
+ (<- player (gameobj-loc player) 'look-room))
(define-mhandler (player-handle-input player message input)
#:text text))
-;;; player methods
-
-(define (player-look-around player)
- (define room-name
- (message-ref
- (<-wait player (gameobj-loc player) 'get-name)
- 'val))
- (define room-desc
- (message-ref
- (<-wait player (gameobj-loc player) 'get-desc)
- 'val))
- (define message-text
- (format #f "**~a**\n~a\n" room-name room-desc))
-
- (<- player (gameobj-gm player) 'write-home #:text message-text))
-
-
;;; Command handling
;;; ================
(define co-occupant-commands
;; TODO: Switch this to a fold. Ignore a result if it
;; returns false for in the command response
- (map
- (lambda (co-occupant)
- (let ((result (<-wait player co-occupant 'get-commands
- #:verb verb)))
- (list
- (message-ref result 'commands)
- (message-ref result 'goes-by)
- co-occupant)))
+ (fold
+ (lambda (co-occupant prev)
+ (display "pre-message\n")
+ (let* ((result (<-wait player co-occupant 'get-commands
+ #:verb verb))
+ (commands (message-ref result 'commands))
+ (goes-by (message-ref result 'goes-by)))
+ (display "post-message\n")
+ (append
+ (map (lambda (command)
+ (list command goes-by co-occupant))
+ commands)
+ prev)))
+ '()
co-occupants))
;; Append our own command handlers
(sort
actors-and-commands
(lambda (x y)
- (> (command-priority (car (pk 'x x)))
- (command-priority (car (pk 'y y)))))))
+ (pk 'x x)
+ (pk 'y y)
+ (> (command-priority (car x))
+ (command-priority (car y))))))
(define (find-command-winner sorted-candidates line)