Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added basic communication functions

  • Loading branch information...
commit 12a88c640f10738169a1049fd3b7f35f2f6c5113 1 parent 50e3ad2
@yasht yasht authored
Showing with 23 additions and 11 deletions.
  1. +16 −8 io.lisp
  2. +7 −3 structs.lisp
View
24 io.lisp
@@ -40,14 +40,16 @@
(flet ((quote-it (x)
(list 'quote x)))
(cons (car cmd) (mapcar #'quote-it (cdr cmd))))))
-
+(defparameter user-stream nil "The stream to the current user it's reading")
+(defun alist (what)
+ (ecase what (:keys (function car)) (:values (function cdr))))
(defun mulch-repl ()
(loop
- (dolist (users-i (mapcar #'username-variable (map 'list (alist :keys) *registered-usernames*)))
+ (dolist (users-i (mapcar #'username-variable (map 'list (alist :keys) *registered-usernames*)))
(if (player-stream users-i)
- (let ((cmd (mulch-read users-i)) (user-stream (player-stream users-i)))
- (mulch-print (eval cmd))
- ))))) ;I have no idea whether or not this will work.
+ (let ((cmd (mulch-read users-i)))
+ (setf user-stream (player-stream users-i))
+ (mulch-print (eval cmd))))))) ;I have no idea whether or not this will work.
;;Currently, we'll be using regular eval, but it should be replaced once we have a defcommand macro.
;;Now we must create a defcommand macro (in order to simplify the task of limiting certain commands to certain groups of players, e.g. level 40 and above or only Occultists... It will also be used for the basic communication commands: say, tell. We'll need to implement channels with this as well.
@@ -69,9 +71,15 @@
(if (or (equalp (player-gender player) ,@gender) (null ,@gender))
,@body
(mulch-print "I do not know that command"))))
-
-
-
+(defun say (words)
+ (let ((users-at-room (remove (find-player-from-stream user-stream) (locale-players (player-location (find-player-from-stream user-stream))))))
+ (dolist (users-i (users-at-room))
+ (mulch-print (concatenate 'string (find-player-from-stream user-stream) "says:""\"" words "\"") (player-stream users-i)))))
+(defun tell (player words)
+ (let ((recip-stream (player-stream (username-variable player))))
+ (mulch-print (concatenate 'string (find-player-from-stream user-stream) "tells you:" "\"" words "\"") recip-stream)))
+
+
View
10 structs.lisp
@@ -16,8 +16,8 @@
;;;; structs.lisp
;Rooms, people, objects...
-(defstruct room name light north east south west northeast southwest northwest southeast players objects )))) ;To prevent bugs with players and objects, create a "build-room" function that takes a name, setfs a var to the room, calls players-at and objects-at to define the objects and players....
-(defun players-at-aux (location-name) (defparameter `,@(players-at-aux-1 location-name) (list nil))) ;This needs an aux function itself due to being a list....Ugly, I know....
+(defstruct locale name light north east south west northeast southwest northwest southeast players objects)))) ;To prevent bugs with players and objects, create a "build-room" function that takes a name, setfs a var to the room, calls players-at and objects-at to define the objects and players....
+(defun players-at-aux (location-name) (defparameter (players-at-aux-1 location-name) (list nil))) ;This needs an aux function itself due to being a list....Ugly, I know....
(defun players-at-aux-1 (location-name) (concatenate 'string "players-" location-name))
(defun players-at (name-room list-players)
(dolist (players-i (mapcar #'username-variable *registered-usernames*))
@@ -25,4 +25,8 @@
(cons players-i (players-at-aux-1 name-room)))))
;Objects-at will probably have a cleaner design--I'll make an alist of objects and their locations, so it'll be easier to go through it...
(defstruct player name password gender species health mana level experience stream location saved-location) ;Set some default values for these, maybe change to defclass. ALSO: make int wis str dex cha etc....
-;Also, write a function that dolists through the players and if their experience is above, say, 100, then incf their level and setf the experience to their experience minus 100. Have this running at all times.
+;Also, write a function that dolists through the players and if their experience is above, say, 100, then incf their level and setf the experience to their experience minus 100. Have this running at all times.
+(defun find-player-from-stream (stream)
+ (dolist (players-i (mapcar #'username-variable *registered-usernames*))
+ (if (equalp (player-stream players-i) stream)
+ (username-variable *registered-usernames*))))
Please sign in to comment.
Something went wrong with that request. Please try again.