X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=mudsync%2Fgame-master.scm;h=8bc239bdb9bebedf6eebbe047879f8e495b218ab;hp=3424f12336bf2078f9b58c30d04230ebb6fe0184;hb=50cd2aba8f13ec7aecb58a683aa55ae665cf83ab;hpb=c4fbe0119751407183f541fa64f850e6b7404d97 diff --git a/mudsync/game-master.scm b/mudsync/game-master.scm index 3424f12..8bc239b 100644 --- a/mudsync/game-master.scm +++ b/mudsync/game-master.scm @@ -22,6 +22,7 @@ #:use-module (8sync agenda) #:use-module (oop goops) #:use-module (ice-9 match) + #:use-module (srfi srfi-26) #:export ( make-default-room-conn-handler)) @@ -56,7 +57,8 @@ (lookup-special (wrap-apply gm-lookup-special)) (new-client (wrap-apply gm-new-client)) (write-home (wrap-apply gm-write-home)) - (client-closed (wrap-apply gm-client-closed))))) + (client-closed (wrap-apply gm-client-closed)) + (inject-special! (wrap-apply gm-inject-special!))))) ;;; .. begin world init stuff .. @@ -74,6 +76,8 @@ ;; Set up the network (gm-setup-network gm)) + +;; @@: If you change this code, update gm-inject-special! if appropriate. (define (gm-init-game-spec gm game-spec) "Initialize the prebuilt special objects" (define set-locs '()) @@ -147,7 +151,7 @@ (define-mhandler (gm-lookup-special actor message symbol) (<-reply actor message - #:room-id (hash-ref (slot-ref actor 'special-dir) symbol))) + #:val (hash-ref (slot-ref actor 'special-dir) symbol))) (define-mhandler (gm-write-home actor message text) (define client-id (hash-ref (gm-reverse-client-dir actor) @@ -169,6 +173,40 @@ (gm-unregister-client! gm client))) +(define-mhandler (gm-inject-special! gm message + special-symbol gameobj-spec) + "Inject, possiibly replacing the original, special symbol +using the gameobj-spec." + (define existing-obj + (hash-ref (slot-ref gm 'special-dir) special-symbol)) + + ;; There's a lot of overlap here with gm-init-game-spec. + ;; We could try to union them? It seemed hard last time I looked, + ;; because things need to run in a different order. + (match gameobj-spec + (((? (cut eq? <> special-symbol) symbol) class loc args ...) + ;; initialize the special object + (let ((special-obj + (apply create-actor* gm class + ;; set cookie to be the object's symbol + (symbol->string symbol) + #:gm (actor-id gm) + args))) + ;; Set the location + (<-wait gm special-obj 'set-loc! + #:loc (hash-ref (gm-special-dir gm) loc)) + ;; Initialize the object, and depending on if an object + ;; already exists with this info, ask it to coordinate + ;; replacing with the existing object. + (if existing-obj + (<-wait gm special-obj 'init #:replace existing-obj) + (<-wait gm special-obj 'init)) + ;; Register the object + (hash-set! (gm-special-dir gm) symbol special-obj) + ;; Destroy the original, if it exists. + (if existing-obj + (<- gm existing-obj 'self-destruct #:why 'replaced)))))) + ;;; GM utilities (define (gm-register-client! gm client-id player) @@ -206,11 +244,13 @@ with an anonymous persona" #:name guest-name #:gm (actor-id gm) #:client client-id))) - (display "Are we broke yet?\n") ;; Register the player in our database of players -> connections (gm-register-client! gm client-id player) ;; Dump the player into the default room (<-wait gm player 'set-loc! #:loc room-id) ;; Initialize the player - (<- gm player 'init))))) - + (<-wait gm player 'init) + (<- gm room-id 'tell-room + #:text (format #f "You see ~a materialize out of thin air!\n" + guest-name) + #:exclude player)))))