X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=mudsync%2Fplayer.scm;h=1063955b6d4ba56371d82b5952ca84943d7d3991;hp=844aaf96f031fbf4112a05b602a3bd5e0f4e5813;hb=754bd427883ab189433fad90293e05d9aced2f70;hpb=6cff5b0062ef928204295ab4327bf2d417070421 diff --git a/mudsync/player.scm b/mudsync/player.scm index 844aaf9..1063955 100644 --- a/mudsync/player.scm +++ b/mudsync/player.scm @@ -21,7 +21,7 @@ #:use-module (mudsync gameobj) #:use-module (mudsync game-master) #:use-module (mudsync parser) - #:use-module (8sync systems actors) + #:use-module (8sync actors) #:use-module (8sync agenda) #:use-module (ice-9 control) #:use-module (ice-9 format) @@ -35,21 +35,6 @@ ;;; Players ;;; ======= -(define player-actions - (build-actions - (init (wrap-apply player-init)) - (handle-input (wrap-apply player-handle-input)) - (tell (wrap-apply player-tell)) - (disconnect-self-destruct (wrap-apply player-disconnect-self-destruct)) - (cmd-inventory (wrap-apply player-cmd-inventory)))) - -(define player-actions* - (append player-actions - gameobj-actions)) - -(define player-dispatcher - (simple-dispatcher player-actions*)) - (define player-self-commands (list (empty-command "inventory" 'cmd-inventory) @@ -64,16 +49,21 @@ (self-commands #:init-value player-self-commands) - (message-handler - #:init-value - (wrap-apply player-dispatcher))) + (actions #:allocation #:each-subclass + #:init-value + (build-actions + (init player-init) + (handle-input player-handle-input) + (tell player-tell) + (disconnect-self-destruct player-disconnect-self-destruct) + (cmd-inventory player-cmd-inventory)))) ;;; player message handlers (define (player-init player message) ;; Look around the room we're in - (<- player (gameobj-loc player) 'look-room)) + (<- (gameobj-loc player) 'look-room)) (define* (player-handle-input player message #:key input) @@ -89,20 +79,20 @@ (match winner ((cmd-action winner-id message-args) - (apply <- player winner-id cmd-action message-args)) + (apply <- winner-id cmd-action message-args)) (#f - (<- player (gameobj-gm player) 'write-home + (<- (gameobj-gm player) 'write-home #:text "Huh?\n")))) (define* (player-tell player message #:key text) - (<- player (gameobj-gm player) 'write-home + (<- (gameobj-gm player) 'write-home #:text text)) (define (player-disconnect-self-destruct player message) "Action routine for being told to disconnect and self destruct." (define loc (gameobj-loc player)) (when loc - (<- player loc 'tell-room + (<- loc 'tell-room #:exclude (actor-id player) #:text (format #f "~a disappears in a puff of entropy!\n" (slot-ref player 'name)))) @@ -113,9 +103,7 @@ (define inv-names (map (lambda (inv-item) - (msg-receive (_ #:key val) - (<-wait player inv-item 'get-name) - val)) + (msg-val (<-wait inv-item 'get-name))) (gameobj-occupants player))) (define text-to-show (if (eq? inv-names '()) @@ -125,7 +113,7 @@ (map (lambda (item-name) (string-append " * " item-name "\n")) inv-names)))) - (<- player (actor-id player) 'tell #:text text-to-show)) + (<- (actor-id player) 'tell #:text text-to-show)) ;;; Command handling @@ -146,9 +134,8 @@ (define room-commands ;; TODO: Map room id and sort (msg-receive (_ #:key commands) - (<-wait player player-loc - 'get-container-commands - #:verb verb) + (<-wait player-loc 'get-container-commands + #:verb verb) commands)) ;; All the co-occupants of the room (not including ourself) @@ -156,7 +143,7 @@ (remove (lambda (x) (equal? x (actor-id player))) (msg-receive (_ #:key occupants) - (<-wait player player-loc 'get-occupants) + (<-wait player-loc 'get-occupants) occupants))) ;; @@: There's a race condition here if someone leaves the room @@ -169,8 +156,8 @@ (fold (lambda (co-occupant prev) (msg-receive (_ #:key commands goes-by) - (<-wait player co-occupant 'get-commands - #:verb verb) + (<-wait co-occupant 'get-commands + #:verb verb) (append (map (lambda (command) (list command goes-by co-occupant)) @@ -194,8 +181,7 @@ (fold (lambda (inv-item prev) (msg-receive (_ #:key commands goes-by) - (<-wait player inv-item - 'get-contained-commands + (<-wait inv-item 'get-contained-commands #:verb verb) (append (map (lambda (command)