lib/gamefic/character.rb in gamefic-1.3.2 vs lib/gamefic/character.rb in gamefic-1.4.0

- old
+ new

@@ -26,29 +26,34 @@ end # Disconnect the current User. # def disconnect - # TODO: We might need some cleanup here. Like, move the character out of the game, or set a timeout to allow dropped users to reconnect... figure it out. @user = nil end # Perform a command. # The command can be specified as a String or a set of tokens. Either form # should yield the same result, but using tokens can yield better - # performance since it doesn't need to parse the command first. + # performance since it bypasses the parser. # # The command will be executed immediately regardless of game state. # + # If the from_user argument is true, the command is assumed to have come + # directly from user input. The character's last_order and last_object + # will be updated with the result. + # # @example Send a command as a string # character.perform "take the key" # # @example Send a command as a set of tokens # character.perform :take, @key # - def perform(*command) - Director.dispatch(self, *command) + def perform(*command, from_user: false) + o = Director.dispatch(self, *command) + last_order = o if from_user + o end # Quietly perform a command. # This method executes the command exactly as #perform does, except it # buffers the resulting output instead of sending it to the user. @@ -77,28 +82,29 @@ message = "<p>#{message.strip}</p>" # This method uses String#gsub instead of String#gsub! for # compatibility with Opal. message = message.gsub(/[ \t\r]*\n[ \t\r]*\n[ \t\r]*/, '</p><p>') message = message.gsub(/[ \t]*\n[ \t]*/, ' ') - user.stream.send message + user.send message end end end # Send a message to the Character as raw text. # Unlike #tell, this method will not wrap the message in HTML paragraphs. # # @param message [String] def stream(message) - user.stream.send message.strip if !user.nil? + user.send message.strip unless user.nil? end - - def destroy - if @user != nil - @user.quit - end - super - end + + # TODO This might not be necessary. The User#quit method was a noop anyway. + #def destroy + # if @user != nil + # @user.quit + # end + # super + #end # Proceed to the next Action in the current stack. # This method is typically used in Action blocks to cascade through # multiple implementations of the same verb. #