1 ;;; Mudsync --- Live hackable MUD
2 ;;; Copyright © 2016 Christopher Allan Webber <cwebber@dustycloud.org>
4 ;;; This file is part of Mudsync.
6 ;;; Mudsync is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or
9 ;;; (at your option) any later version.
11 ;;; Mudsync is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;; General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with Mudsync. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (mudsync player)
20 #:use-module (mudsync command)
21 #:use-module (mudsync gameobj)
22 #:use-module (mudsync game-master)
23 #:use-module (mudsync parser)
24 #:use-module (8sync systems actors)
25 #:use-module (8sync agenda)
26 #:use-module (ice-9 format)
27 #:use-module (oop goops)
28 #:use-module (srfi srfi-1)
30 player-self-commands))
35 (define player-actions
37 (init (wrap-apply player-init!))
38 (handle-input (wrap-apply player-handle-input))))
40 (define player-actions*
41 (append player-actions
44 (define-class <player> (<gameobj>)
45 (username #:init-keyword #:username
46 #:accessor player-username)
48 (client #:accessor player-client)
52 #:accessor player-self-commands)
56 ;; @@: We're gonna need action inheritance real awful soon, huh?
57 (simple-dispatcher player-actions*)))
60 ;;; player message handlers
62 (define-mhandler (player-init! player message)
63 (player-look-around player))
66 (define-mhandler (player-handle-input player message input)
67 (define split-input (split-verb-and-rest input))
68 (define input-verb (pk 'input-verb (car split-input)))
69 (define input-rest (pk 'input-rest (cdr split-input)))
71 (define command-candidates
73 (player-gather-command-handlers player input-verb)))
76 (pk 'winner (find-command-winner command-candidates input-rest)))
78 (<- player (gameobj-gm player) 'write-home
80 (format #f "<~a>: ~s\n"
81 (player-username player)
87 (define (player-look-around player)
90 (<-wait player (gameobj-loc player) 'get-name)
94 (<-wait player (gameobj-loc player) 'get-desc)
97 (format #f "**~a**\n~a\n" room-name room-desc))
99 (<- player (gameobj-gm player) 'write-home #:text message-text))