using System.Collections.Generic; using System; using System.Xml; using libsecondlife; using libsecondlife.AssetSystem; using libsecondlife.Packets; namespace libsecondlife.InventorySystem { /// /// Base class for most inventory items, providing a lot of general inventory management functions. /// public class InventoryItem : InventoryBase { private const uint FULL_MASK_PERMISSIONS = 2147483647; public string Name { get { return base._Name; } set { _Name = value; UpdateItem(); } } internal LLUUID _FolderID = LLUUID.Zero; public LLUUID FolderID { get { return _FolderID; } set { InventoryFolder iTargetFolder = base.iManager.getFolder(value); if (iTargetFolder == null) { throw new Exception("Target Folder [" + value + "] does not exist."); } base.iManager.getFolder(this.FolderID)._Contents.Remove(this); iTargetFolder._Contents.Add(this); _FolderID = value; UpdateItem(); } } internal LLUUID _ItemID = null; public LLUUID ItemID { set { if (_ItemID == null) { _ItemID = value; } else { throw new Exception("You can not change an item's ID once it's been set."); } } get { return _ItemID; } } internal sbyte _InvType = 0; public sbyte InvType { get { return _InvType; } } internal sbyte _Type = 0; public sbyte Type { get { return _Type; } set { _Type = value; UpdateItem(); } } internal string _Description = ""; public string Description { get { return _Description; } set { _Description = value; UpdateItem(); } } internal uint _CRC = 0; public uint CRC { get { return _CRC; } set { _CRC = value; } } internal LLUUID _OwnerID = LLUUID.Zero; public LLUUID OwnerID { get { return _OwnerID; } } internal LLUUID _CreatorID = LLUUID.Zero; public LLUUID CreatorID { get { return _CreatorID; } } internal Asset _Asset; public Asset Asset { get { if (_Asset != null) { return _Asset; } else { if ((AssetID != null)) { AssetRequestDownload request = base.iManager.AssetManager.RequestInventoryAsset(this); if (request.Wait(AssetManager.DefaultTimeout) != AssetRequestDownload.RequestStatus.Success) { throw new Exception("Asset (" + AssetID.ToStringHyphenated() + ") unavailable (" + request.StatusMsg + ") for " + this.Name); } switch (Type) { case (sbyte)Asset.AssetType.Clothing: _Asset = new AssetWearable_Clothing(AssetID, request.GetAssetData()); break; case (sbyte)Asset.AssetType.Bodypart: _Asset = new AssetWearable_Body(AssetID, request.GetAssetData()); break; case (sbyte)Asset.AssetType.LSLText: _Asset = new AssetScript(AssetID, request.GetAssetData()); break; case (sbyte)Asset.AssetType.Notecard: _Asset = new AssetNotecard(AssetID, request.GetAssetData()); break; case (sbyte)Asset.AssetType.Texture: _Asset = new AssetImage(AssetID, request.GetAssetData()); break; default: _Asset = new Asset(AssetID, Type, request.GetAssetData()); break; } return Asset; } } return null; } } internal LLUUID _TransactionID = LLUUID.Zero; public LLUUID TransactionID { get { return _TransactionID; } } internal LLUUID _AssetID = LLUUID.Zero; public LLUUID AssetID { get { return _AssetID; } } internal LLUUID _GroupID = LLUUID.Zero; public LLUUID GroupID { get { return _GroupID; } set { _GroupID = value; UpdateItem(); } } internal bool _GroupOwned = false; public bool GroupOwned { get { return _GroupOwned; } set { _GroupOwned = value; UpdateItem(); } } internal int _CreationDate = (int)((TimeSpan)(DateTime.UtcNow - new DateTime(1970, 1, 1))).TotalSeconds; public int CreationDate { get { return _CreationDate; } } internal byte _SaleType = 0; public byte SaleType { get { return _SaleType; } set { _SaleType = value; UpdateItem(); } } internal uint _BaseMask = FULL_MASK_PERMISSIONS; public uint BaseMask { get { return _BaseMask; } } internal int _SalePrice = 0; public int SalePrice { get { return _SalePrice; } set { _SalePrice = value; UpdateItem(); } } internal uint _EveryoneMask = 0; public uint EveryoneMask { get { return _EveryoneMask; } set { _EveryoneMask = value; UpdateItem(); } } internal uint _Flags = 0; public uint Flags { get { return _Flags; } set { _Flags = value; UpdateItem(); } } internal uint _NextOwnerMask = FULL_MASK_PERMISSIONS; public uint NextOwnerMask { get { return _NextOwnerMask; } set { _NextOwnerMask = value; UpdateItem(); } } internal uint _GroupMask = 0; public uint GroupMask { get { return _GroupMask; } set { _GroupMask = value; UpdateItem(); } } internal uint _OwnerMask = FULL_MASK_PERMISSIONS; public uint OwnerMask { get { return _OwnerMask; } } internal InventoryItem(InventoryManager manager) : base(manager) { } internal InventoryItem(InventoryManager manager, InventoryDescendentsPacket.ItemDataBlock itemData) : base(manager) { _Name = System.Text.Encoding.UTF8.GetString(itemData.Name).Trim().Replace("\0", ""); _Description = System.Text.Encoding.UTF8.GetString(itemData.Description).Trim().Replace("\0", ""); _CreationDate = itemData.CreationDate; _InvType = itemData.InvType; _Type = itemData.Type; _ItemID = itemData.ItemID; _AssetID = itemData.AssetID; _FolderID = itemData.FolderID; _GroupOwned = itemData.GroupOwned; _GroupID = itemData.GroupID; _GroupMask = itemData.GroupMask; _CreatorID = itemData.CreatorID; _OwnerID = itemData.OwnerID; _OwnerMask = itemData.OwnerMask; _Flags = itemData.Flags; _BaseMask = itemData.BaseMask; _EveryoneMask = itemData.EveryoneMask; _NextOwnerMask = itemData.NextOwnerMask; _SaleType = itemData.SaleType; _SalePrice = itemData.SalePrice; _CRC = itemData.CRC; } internal InventoryItem(InventoryManager manager, string name, LLUUID folderID, sbyte invType, sbyte type, LLUUID uuidOwnerCreater) : base(manager) { _Name = name; _FolderID = folderID; _InvType = invType; _Type = type; _OwnerID = uuidOwnerCreater; _CreatorID = uuidOwnerCreater; UpdateCRC(); } internal InventoryItem(InventoryManager manager, string name, string description, LLUUID folderID, sbyte invType, sbyte type, LLUUID uuidOwnerCreater) : base(manager) { _Name = name; _Description = description; _FolderID = folderID; _InvType = invType; _Type = type; _OwnerID = uuidOwnerCreater; _CreatorID = uuidOwnerCreater; UpdateCRC(); } /// /// protected void SetAssetTransactionIDs(LLUUID assetID, LLUUID transactionID) { _AssetID = assetID; _TransactionID = transactionID; UpdateItem(); } /// /// /// public override bool Equals(object o) { if ((o is InventoryItem) == false) { return false; } return this._ItemID == ((InventoryItem)o)._ItemID; } /// /// public override int GetHashCode() { return this._ItemID.GetHashCode(); } /// /// CompareTo provided so that items can be sorted by name /// /// public int CompareTo(object obj) { if (obj is InventoryBase) { InventoryBase temp = (InventoryBase)obj; return this._Name.CompareTo(temp._Name); } throw new ArgumentException("object is not an InventoryItem"); } private void UpdateItem() { UpdateCRC(); base.iManager.ItemUpdate(this); } private void UpdateCRC() { _CRC = InventoryPacketHelper.InventoryUpdateCRC(this); } /// /// Move this item to the target folder /// /// public void MoveTo(InventoryFolder targetFolder) { this.FolderID = targetFolder.FolderID; } /// /// Move this item to the target folder /// /// public void MoveTo(LLUUID targetFolderID) { this.FolderID = targetFolderID; } /// /// If you have Copy permission, a copy is placed in the target folder /// /// public void CopyTo(LLUUID targetFolder) { base.iManager.ItemCopy(this.ItemID, targetFolder); } /// /// Give this item to another agent. If you have Copy permission, a copy will be given /// /// public void GiveTo(LLUUID ToAgentID) { base.iManager.ItemGiveTo(this, ToAgentID); } /// /// Delete this item from Second Life /// public void Delete() { iManager.getFolder(this.FolderID)._Contents.Remove(this); iManager.ItemRemove(this); } /// /// Attempt to rez this inventory item at the given point /// /// Region/Sim coordinates public void RezObject(LLVector3 TargetPos) { RezObject(TargetPos, null); } /// /// Attempt to rez this inventory item at the given point, in the given simulator /// /// Region/Sim coords /// public void RezObject(LLVector3 TargetPos, Simulator TargetSim) { iManager.ItemRezObject(this, TargetSim, TargetPos); } /// /// Attempt to attach this item /// public void Attach() { Attach(0); //Use default attach point. } /// /// Attempt to attach this item. /// /// Where to attach to public void Attach(ObjectManager.AttachmentPoint AttachmentPt) { iManager.ItemRezAttach(this, 0); } /// /// Attempt to detach this item /// public void Detach() { iManager.ItemDetach(this); } /// /// /// virtual internal void SetAssetData(byte[] assetData) { if (_Asset == null) { if (AssetID != null) { _Asset = new Asset(AssetID, Type, assetData); } else { _Asset = new Asset(LLUUID.Random(), Type, assetData); _AssetID = _Asset.AssetID; } } else { _Asset.SetAssetData(assetData); } } public override string GetDisplayType() { return "Unknown_Item"; } /// /// Output this item as XML /// /// Include an asset data as well, TRUE/FALSE override public string toXML(bool outputAssets) { string output = "