Class: LibSL::AgentManager
- Inherits:
-
Object
- Object
- LibSL::AgentManager
- Defined in:
- lib/agent.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#look_at ⇒ Object
Returns the value of attribute look_at.
-
#position ⇒ Object
Returns the value of attribute position.
-
#region_handle ⇒ Object
readonly
Returns the value of attribute region_handle.
-
#region_name ⇒ Object
readonly
Returns the value of attribute region_name.
Instance Method Summary collapse
-
#chat(message, type = :normal, channel = 0) ⇒ Object
Send a chat message to the simulator or >0 (for scripts listening on that channel).
- #first_name ⇒ Object
- #full_name ⇒ Object
-
#im(message, to, session = nil) ⇒ Object
Send an instant message to another agent.
-
#initialize(client) ⇒ AgentManager
constructor
New AgentManager.
- #last_name ⇒ Object
-
#move_to_sim(simulator) ⇒ Object
Complete a transfer to a sim (e.g. after login or teleport).
-
#send_money(amount, to, description = "") ⇒ Object
Send Linden$ to another agent.
-
#teleport(region_id, position = nil) ⇒ Object
Teleport somewhere to in region local coordinates.
Constructor Details
#initialize(client) ⇒ AgentManager
New AgentManager
10 11 12 13 14 15 16 17 18 |
# File 'lib/agent.rb', line 10 def initialize(client) @client = client @position = LLVector3.new(0, 0, 0) @look_at = LLVector3.new(0, 0, 0) @region_id = LLUUID.new @region_handle = LLU64.new(0) @region_name = "" init_handlers end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/agent.rb', line 5 def client @client end |
#look_at ⇒ Object
Returns the value of attribute look_at.
5 6 7 |
# File 'lib/agent.rb', line 5 def look_at @look_at end |
#position ⇒ Object
Returns the value of attribute position.
5 6 7 |
# File 'lib/agent.rb', line 5 def position @position end |
#region_handle ⇒ Object (readonly)
Returns the value of attribute region_handle.
6 7 8 |
# File 'lib/agent.rb', line 6 def region_handle @region_handle end |
#region_name ⇒ Object (readonly)
Returns the value of attribute region_name.
6 7 8 |
# File 'lib/agent.rb', line 6 def region_name @region_name end |
Instance Method Details
#chat(message, type = :normal, channel = 0) ⇒ Object
Send a chat message to the simulator or >0 (for scripts listening on that channel)
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/agent.rb', line 72 def chat(, type=:normal, channel=0) type = case type when :whisper then 0 when :shout then 2 else 1 end throw "Channel has to be >=0, #{channel} given!" if channel < 0 packet = ChatFromViewerPacket.new({ :AgentData => { :AgentID => @client.network_manager.agent_id, :SessionID => @client.network_manager.session_id }, :ChatData => { :Message => , :Type => type, :Channel => channel } }) @client.network_manager.send_packet packet end |
#first_name ⇒ Object
20 21 22 |
# File 'lib/agent.rb', line 20 def first_name @client.network_manager.first_name end |
#full_name ⇒ Object
28 29 30 |
# File 'lib/agent.rb', line 28 def full_name first_name + " " + last_name end |
#im(message, to, session = nil) ⇒ Object
Send an instant message to another agent
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/agent.rb', line 96 def im(, to, session=nil) session ||= LLUUID.new packet = ImprovedInstantMessagePacket.new({ :AgentData => { :AgentID => @client.network_manager.agent_id, :SessionID => @client.network_manager.session_id }, :MessageBlock => { :FromGroup => LLBool.new(false), :ToAgentID => to, :ParentEstateID => LLU32.new(0), :RegionID => @region_id, :Position => @position, :Offline => LLU8.new(1), :Dialog => LLU8.new(DIALOG[:IM]), :ID => session, :Timestamp => LLU32.new(Time.now.to_i), :FromAgentName => LLVariable1.new(full_name), :Message => LLVariable2.new(), :BinaryBucket => LLVariable2.new("") } }) @client.network_manager.send_packet packet end |
#last_name ⇒ Object
24 25 26 |
# File 'lib/agent.rb', line 24 def last_name @client.network_manager.last_name end |
#move_to_sim(simulator) ⇒ Object
Complete a transfer to a sim (e.g. after login or teleport)
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/agent.rb', line 34 def move_to_sim(simulator) # EventManager.register_handler(EventHandler.new(Proc.new do |type| # EventMachine::add_periodic_timer(2) do # packet = AgentUpdatePacket.new({ # :AgentData => { # :AgentID => @client.network_manager.agent_id, # :SessionID => @client.network_manager.session_id, # :BodyRotation => LLQuaternion.new(1, 1, 1), # :HeadRotation => LLQuaternion.new(1, 1, 1), # :State => LLU8.new(0), # :CameraCenter => @position, # :CameraAtAxis => LLVector3.new(), # :CameraLeftAxis => LLVector3.new(), # :CameraUpAxis => LLVector3.new(), # :Far => LLF32.new(64), # :ControlFlags => LLU32.new(0), # :Flags => LLU8.new(0) # } # }) # @client.network_manager.send_packet packet, true # end # end, :movement_complete)) packet = CompleteAgentMovementPacket.new({ :AgentData => { :AgentID => @client.network_manager.agent_id, :SessionID => @client.network_manager.session_id, :CircuitCode => @client.network_manager.circuit_code } }) simulator.send_packet(packet) end |
#send_money(amount, to, description = "") ⇒ Object
Send Linden$ to another agent
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/agent.rb', line 124 def send_money(amount, to, description="") packet = MoneyTransferRequestPacket.new({ :AgentData => { :AgentID => @client.network_manager.agent_id, :SessionID => @client.network_manager.session_id }, :Money => { :SourceID => @client.network_manager.agent_id, :DestID => to, :Flags => LLU8.new(0), :Amount => LLS32.new(amount), :AggregatePermNextOwner => LLU8.new(0), :AggregatePermInventory => LLU8.new(0), # see http://hg.secondlife.com/viewer-release/src/tip/indra/llinventory/lltransactiontypes.h#cl-77) :TransactionType => LLS32.new(5001), # Gift :Description => LLVariable1.new(description) } }) end |
#teleport(region_id, position = nil) ⇒ Object
Teleport somewhere to in region local coordinates
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/agent.rb', line 148 def teleport(region_id, position=nil) raise ArgumentError, "region_id has to be a LLUUID" unless region_id.is_a? LLUUID position = LLVector3.new(128, 128, 0) unless position.is_a? LLVector3 packet = TeleportRequestPacket.new({ :AgentData => { :AgentID => @client.network_manager.agent_id, :SessionID => @client.network_manager.session_id }, :Info => { :RegionID => region_id, :Position => position, :LookAt => LLVector3.new(1, 0, 0) } }) @client.network_manager.send_packet packet end |