X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=mudsync%2Fplayer.scm;h=844aaf96f031fbf4112a05b602a3bd5e0f4e5813;hp=d2fc76dd64d1cbb15a4cf079bb3c9de8317761e9;hb=6cff5b0062ef928204295ab4327bf2d417070421;hpb=7e11c67b59dc07a46576b2acaa4657ee533df7d5 diff --git a/mudsync/player.scm b/mudsync/player.scm index d2fc76d..844aaf9 100644 --- a/mudsync/player.scm +++ b/mudsync/player.scm @@ -71,12 +71,12 @@ ;;; player message handlers -(define-mhandler (player-init player message) +(define (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) +(define* (player-handle-input player message #:key input) (define split-input (split-verb-and-rest input)) (define input-verb (car split-input)) (define input-rest (cdr split-input)) @@ -89,16 +89,16 @@ (match winner ((cmd-action winner-id message-args) - (apply send-message player winner-id cmd-action message-args)) + (apply <- player winner-id cmd-action message-args)) (#f (<- player (gameobj-gm player) 'write-home #:text "Huh?\n")))) -(define-mhandler (player-tell player message text) +(define* (player-tell player message #:key text) (<- player (gameobj-gm player) 'write-home #:text text)) -(define-mhandler (player-disconnect-self-destruct player message) +(define (player-disconnect-self-destruct player message) "Action routine for being told to disconnect and self destruct." (define loc (gameobj-loc player)) (when loc @@ -108,13 +108,14 @@ (slot-ref player 'name)))) (gameobj-self-destruct player)) -(define-mhandler (player-cmd-inventory player message) +(define (player-cmd-inventory player message) "Display the inventory for the player" (define inv-names (map (lambda (inv-item) - (message-ref (<-wait player inv-item 'get-name) - 'val)) + (msg-receive (_ #:key val) + (<-wait player inv-item 'get-name) + val)) (gameobj-occupants player))) (define text-to-show (if (eq? inv-names '()) @@ -144,19 +145,19 @@ ;; Ask the room for its commands (define room-commands ;; TODO: Map room id and sort - (message-ref - (<-wait player player-loc + (msg-receive (_ #:key commands) + (<-wait player player-loc 'get-container-commands #:verb verb) - 'commands)) + commands)) ;; All the co-occupants of the room (not including ourself) (define co-occupants (remove (lambda (x) (equal? x (actor-id player))) - (message-ref - (<-wait player player-loc 'get-occupants) - 'occupants))) + (msg-receive (_ #:key occupants) + (<-wait player player-loc 'get-occupants) + occupants))) ;; @@: There's a race condition here if someone leaves the room ;; during this, heh... @@ -165,14 +166,11 @@ ;; Get all the co-occupants' commands (define co-occupant-commands - ;; TODO: Switch this to a fold. Ignore a result if it - ;; returns false for in the command response (fold (lambda (co-occupant prev) - (let* ((result (<-wait player co-occupant 'get-commands - #:verb verb)) - (commands (message-ref result 'commands)) - (goes-by (message-ref result 'goes-by))) + (msg-receive (_ #:key commands goes-by) + (<-wait player co-occupant 'get-commands + #:verb verb) (append (map (lambda (command) (list command goes-by co-occupant)) @@ -189,7 +187,23 @@ (val-or-run (slot-ref player 'self-commands)))) - ;; TODO: Append our inventory's relevant command handlers + ;; Append our inventory's relevant command handlers + (define inv-items + (gameobj-occupants player)) + (define inv-item-commands + (fold + (lambda (inv-item prev) + (msg-receive (_ #:key commands goes-by) + (<-wait player inv-item + 'get-contained-commands + #:verb verb) + (append + (map (lambda (command) + (list command goes-by inv-item)) + commands) + prev))) + '() + inv-items)) ;; Now return a big ol sorted list of ((actor-id . command)) (append @@ -197,7 +211,8 @@ player-loc '()) ; room doesn't go by anything (sort-commands-multi-actors co-occupant-commands) (sort-commands-append-actor our-commands - (actor-id player) '()))) ; nor does player + (actor-id player) '()) ; nor does player + (sort-commands-multi-actors inv-item-commands))) (define (sort-commands-append-actor commands actor-id goes-by) (sort-commands-multi-actors