Class: LibSL::AgentManager

Inherits:
Object
  • Object
show all
Defined in:
lib/agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ AgentManager

New AgentManager

Parameters:

  • client (Client)

    The client



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

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/agent.rb', line 5

def client
  @client
end

#look_atObject

Returns the value of attribute look_at.



5
6
7
# File 'lib/agent.rb', line 5

def look_at
  @look_at
end

#positionObject

Returns the value of attribute position.



5
6
7
# File 'lib/agent.rb', line 5

def position
  @position
end

#region_handleObject (readonly)

Returns the value of attribute region_handle.



6
7
8
# File 'lib/agent.rb', line 6

def region_handle
  @region_handle
end

#region_nameObject (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)

Parameters:

  • type (Symbol) (defaults to: :normal)

    The chat type (:normal, :whisper or :shout)

  • channel (Integer) (defaults to: 0)

    (optional) should be 0 (public)



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(message, 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 => message,
			:Type => type,
			:Channel => channel
		}
	})
	@client.network_manager.send_packet packet
end

#first_nameObject



20
21
22
# File 'lib/agent.rb', line 20

def first_name
	@client.network_manager.first_name
end

#full_nameObject



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

Parameters:

  • message (String)

    the message to send

  • to (LLUUID)

    The recepients id



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(message, 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(message),
			:BinaryBucket => LLVariable2.new("")
		}
	})
	@client.network_manager.send_packet packet
end

#last_nameObject



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)

Parameters:

  • sim (Simulator)

    The sim you have been transfered to



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

Parameters:

  • amount (Integer)

    The amount of L$ to send

  • to (LLUUID)

    The recepient



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

Parameters:

  • region_id (LLUUID)

    The ID of the region to teleport to

  • position (LLVector3) (defaults to: nil)

    (optional) The position to teleport

Raises:

  • (ArgumentError)


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