Class: GameMachine::Helpers::GameMessage
- Inherits:
-
Object
- Object
- GameMachine::Helpers::GameMessage
- Defined in:
- lib/game_machine/helpers/game_message.rb
Constant Summary collapse
- CHARS =
[*('a'..'z'),*('0'..'9')].flatten
- STR =
Array.new(100) {|i| CHARS.sample}.join
- STR2 =
Array.new(1000) {|i| CHARS.sample}.join
Instance Attribute Summary collapse
-
#client_message ⇒ Object
readonly
Returns the value of attribute client_message.
-
#player_id ⇒ Object
readonly
Returns the value of attribute player_id.
Instance Method Summary collapse
- #chat_channel(topic, flags = '') ⇒ Object
- #chat_channels(names) ⇒ Object
- #chat_message(type, message_text, topic) ⇒ Object
- #client_connection(client_id, gateway) ⇒ Object
- #client_disconnect(client_id, gateway) ⇒ Object
- #current_entity ⇒ Object
- #echo_test(value) ⇒ Object
- #entities ⇒ Object
- #entity(id) ⇒ Object
- #error_message(code, message) ⇒ Object
- #get_neighbors(search_radius = nil) ⇒ Object
- #has_entity?(id) ⇒ Boolean
-
#initialize(player_id, default_entity_id = nil) ⇒ GameMessage
constructor
A new instance of GameMessage.
- #join_chat(topic, flags = '') ⇒ Object
- #leave_chat(topic) ⇒ Object
- #neighbors(players, npcs) ⇒ Object
- #player_logout ⇒ Object
- #player_move(x, y) ⇒ Object
- #send_to_player ⇒ Object
- #to_byte_array ⇒ Object
- #to_entity ⇒ Object
- #track_entity ⇒ Object
Constructor Details
#initialize(player_id, default_entity_id = nil) ⇒ GameMessage
Returns a new instance of GameMessage.
10 11 12 13 14 |
# File 'lib/game_machine/helpers/game_message.rb', line 10 def initialize(player_id,default_entity_id=nil) @player_id = player_id @current_entity_id = default_entity_id || 'default' = (@player_id) end |
Instance Attribute Details
#client_message ⇒ Object (readonly)
Returns the value of attribute client_message.
8 9 10 |
# File 'lib/game_machine/helpers/game_message.rb', line 8 def end |
#player_id ⇒ Object (readonly)
Returns the value of attribute player_id.
8 9 10 |
# File 'lib/game_machine/helpers/game_message.rb', line 8 def player_id @player_id end |
Instance Method Details
#chat_channel(topic, flags = '') ⇒ Object
109 110 111 |
# File 'lib/game_machine/helpers/game_message.rb', line 109 def chat_channel(topic,flags='') MessageLib::ChatChannel.new.set_name(topic).set_flags(flags) end |
#chat_channels(names) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/game_machine/helpers/game_message.rb', line 101 def chat_channels(names) channels = MessageLib::ChatChannels.new names.each do |name| channels.add_chat_channel(chat_channel(name)) end current_entity.set_chat_channels(channels) end |
#chat_message(type, message_text, topic) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/game_machine/helpers/game_message.rb', line 113 def (type,,topic) = MessageLib::ChatMessage.new .set_chat_channel( chat_channel(topic) ) .() .set_type(type) current_entity.() end |
#client_connection(client_id, gateway) ⇒ Object
97 98 99 |
# File 'lib/game_machine/helpers/game_message.rb', line 97 def client_connection(client_id,gateway) MessageLib::ClientConnection.new.set_id(client_id).set_gateway(gateway) end |
#client_disconnect(client_id, gateway) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/game_machine/helpers/game_message.rb', line 54 def client_disconnect(client_id,gateway) .set_client_disconnect( MessageLib::ClientDisconnect.new.set_client_connection( client_connection(client_id,gateway) ) ) end |
#current_entity ⇒ Object
32 33 34 35 36 37 |
# File 'lib/game_machine/helpers/game_message.rb', line 32 def current_entity unless has_entity?(@current_entity_id) add_entity(@current_entity_id) end entities.select {|entity| entity.id == @current_entity_id}.first end |
#echo_test(value) ⇒ Object
135 136 137 |
# File 'lib/game_machine/helpers/game_message.rb', line 135 def echo_test(value) current_entity.set_echo_test(MessageLib::EchoTest.new.(value)) end |
#entities ⇒ Object
24 25 26 |
# File 'lib/game_machine/helpers/game_message.rb', line 24 def entities .get_entity_list.to_a end |
#entity(id) ⇒ Object
39 40 41 42 |
# File 'lib/game_machine/helpers/game_message.rb', line 39 def entity(id) @current_entity_id = id current_entity end |
#error_message(code, message) ⇒ Object
48 49 50 51 52 |
# File 'lib/game_machine/helpers/game_message.rb', line 48 def (code,) .( MessageLib::ErrorMessage.new.set_code(code).() ) end |
#get_neighbors(search_radius = nil) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/game_machine/helpers/game_message.rb', line 74 def get_neighbors(search_radius=nil) component = MessageLib::GetNeighbors.new component.set_value(true) if search_radius component.set_search_radius(search_radius) end current_entity.set_get_neighbors(component) end |
#has_entity?(id) ⇒ Boolean
28 29 30 |
# File 'lib/game_machine/helpers/game_message.rb', line 28 def has_entity?(id) entities.select {|entity| entity.id == id}.first ? true : false end |
#join_chat(topic, flags = '') ⇒ Object
123 124 125 126 127 |
# File 'lib/game_machine/helpers/game_message.rb', line 123 def join_chat(topic,flags='') current_entity.set_join_chat( MessageLib::JoinChat.new.add_chat_channel(chat_channel(topic,flags)) ) end |
#leave_chat(topic) ⇒ Object
129 130 131 132 133 |
# File 'lib/game_machine/helpers/game_message.rb', line 129 def leave_chat(topic) current_entity.set_leave_chat( MessageLib::LeaveChat.new.add_chat_channel(chat_channel(topic)) ) end |
#neighbors(players, npcs) ⇒ Object
83 84 85 86 87 |
# File 'lib/game_machine/helpers/game_message.rb', line 83 def neighbors(players,npcs) current_entity.set_neighbors( MessageLib::Neighbors.new.set_player_list(players).set_npc_list(npcs) ) end |
#player_logout ⇒ Object
62 63 64 65 66 |
# File 'lib/game_machine/helpers/game_message.rb', line 62 def player_logout .set_player_logout( MessageLib::PlayerLogout.new.set_player_id(@player_id) ) end |
#player_move(x, y) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/game_machine/helpers/game_message.rb', line 89 def player_move(x,y) current_entity.set_player_move( MessageLib::PlayerMove.new.set_target( MessageLib::Target.new.set_x(x).set_y(y) ) ) end |
#send_to_player ⇒ Object
20 21 22 |
# File 'lib/game_machine/helpers/game_message.rb', line 20 def send_to_player .send_to_player end |
#to_byte_array ⇒ Object
16 17 18 |
# File 'lib/game_machine/helpers/game_message.rb', line 16 def to_byte_array .to_byte_array end |
#to_entity ⇒ Object
44 45 46 |
# File 'lib/game_machine/helpers/game_message.rb', line 44 def to_entity current_entity.set_player(.player) end |
#track_entity ⇒ Object
68 69 70 71 72 |
# File 'lib/game_machine/helpers/game_message.rb', line 68 def track_entity current_entity.set_track_entity( MessageLib::TrackEntity.new.set_value(true) ) end |