Sha256: 81241b7dc12ff71d316f64cb0abf4314d8b6830ff7f8fa055063c3d68aaca02c

Contents?: true

Size: 1005 Bytes

Versions: 6

Compression:

Stored size: 1005 Bytes

Contents

module GameMachine
  module GameSystems
    class ChatTopic < Actor::Base
      include Commands

      attr_reader :chat_id, :registered_as
      def post_init(*args)
        @chat_id = args.first
        @registered_as = args.last
      end

      def on_receive(message)
        if message.is_a?(MessageLib::Entity) && message.has_chat_message
          receive_chat_message(message.chat_message)
        elsif message.is_a?(JavaLib::DistributedPubSubMediator::SubscribeAck)
        else
          unhandled(message)
        end
      end

      private

      def receive_chat_message(chat_message)
        GameMachine.logger.debug "Sending chat message #{chat_message.message} to #{chat_id}"
        if registered_as == 'player'
          commands.player.send_message(chat_message,chat_id)
        else
          message = MessageLib::Entity.new.set_id(chat_id).set_chat_message(chat_message)
          Actor::Base.find(registered_as).tell(message,get_self)
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
game_machine-1.0.4 lib/game_machine/game_systems/chat_topic.rb
game_machine-1.0.2 lib/game_machine/game_systems/chat_topic.rb
game_machine-0.0.11 lib/game_machine/game_systems/chat_topic.rb
game_machine-0.0.10 lib/game_machine/game_systems/chat_topic.rb
game_machine-0.0.9 lib/game_machine/game_systems/chat_topic.rb
game_machine-0.0.8 lib/game_machine/game_systems/chat_topic.rb