public DateTime llGiveInventory(string destination, string inventory)
{
if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID)) return DateTime.Now;
bool found = false;
UUID destId = UUID.Zero;
UUID objId = UUID.Zero;
int assetType = 0;
string objName = String.Empty;
if (!UUID.TryParse(destination, out destId))
{
llSay(0, "Could not parse key " + destination);
return DateTime.Now;
}
// move the first object found with this inventory name
lock (m_host.TaskInventory)
{
foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
{
if (inv.Value.Name == inventory)
{
found = true;
objId = inv.Key;
assetType = inv.Value.Type;
objName = inv.Value.Name;
break;
}
}
}
if (!found)
{
llSay(0, String.Format("Could not find object '{0}'", inventory));
throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
}
// check if destination is an avatar
if (World.GetScenePresence(destId) != null || m_host.ParentEntity.Scene.RequestModuleInterface<IAgentInfoService>().GetUserInfo(destId.ToString()) != null)
{
// destination is an avatar
InventoryItemBase agentItem = null;
ILLClientInventory inventoryModule = World.RequestModuleInterface<ILLClientInventory>();
if (inventoryModule != null)
agentItem = inventoryModule.MoveTaskInventoryItemToUserInventory(destId, UUID.Zero, m_host, objId, false);
if (agentItem == null)
return DateTime.Now;
byte[] bucket = new byte[17];
bucket[0] = (byte)assetType;
byte[] objBytes = agentItem.ID.GetBytes();
Array.Copy(objBytes, 0, bucket, 1, 16);
GridInstantMessage msg = new GridInstantMessage(World,
m_host.UUID, m_host.Name + ", an object owned by " +
resolveName(m_host.OwnerID) + ",", destId,
(byte)InstantMessageDialog.InventoryOffered,
false, objName + "'\n'" + m_host.Name + "' is located at " +
m_host.AbsolutePosition.ToString() + " in '" + World.RegionInfo.RegionName,
agentItem.ID, true, m_host.AbsolutePosition,
bucket);
if (m_TransferModule != null)
m_TransferModule.SendInstantMessage(msg);
}
else
{
// destination is an object
ILLClientInventory inventoryModule = World.RequestModuleInterface<ILLClientInventory>();
if (inventoryModule != null)
inventoryModule.MoveTaskInventoryItemToObject(destId, m_host, objId);
}
return PScriptSleep(3000);
}