AgentInventory.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using libsecondlife;
  5. using OpenSim.Framework.Assets;
  6. namespace OpenSim.Framework.Inventory
  7. {
  8. public class AgentInventory
  9. {
  10. //Holds the local copy of Inventory info for a agent
  11. public Dictionary<LLUUID, InventoryFolder> InventoryFolders;
  12. public Dictionary<LLUUID, InventoryItem> InventoryItems;
  13. public InventoryFolder InventoryRoot = new InventoryFolder();
  14. public int LastCached; //maybe used by opensim app, time this was last stored/compared to user server
  15. public LLUUID AgentID;
  16. public AvatarWearable[] Wearables;
  17. public AgentInventory()
  18. {
  19. InventoryFolders = new Dictionary<LLUUID, InventoryFolder>();
  20. InventoryItems = new Dictionary<LLUUID, InventoryItem>();
  21. this.Initialise();
  22. }
  23. public virtual void Initialise()
  24. {
  25. Wearables = new AvatarWearable[13]; //should be 12 of these
  26. for (int i = 0; i < 13; i++)
  27. {
  28. Wearables[i] = new AvatarWearable();
  29. }
  30. InventoryRoot = new InventoryFolder();
  31. InventoryRoot.FolderID = LLUUID.Random();
  32. InventoryRoot.ParentID = new LLUUID();
  33. InventoryRoot.Version = 1;
  34. InventoryRoot.DefaultType = 8;
  35. InventoryRoot.OwnerID = this.AgentID;
  36. InventoryRoot.FolderName = "My Inventory";
  37. InventoryFolders.Add(InventoryRoot.FolderID, InventoryRoot);
  38. }
  39. public bool CreateNewFolder(LLUUID folderID, ushort type)
  40. {
  41. InventoryFolder Folder = new InventoryFolder();
  42. Folder.FolderID = folderID;
  43. Folder.OwnerID = this.AgentID;
  44. Folder.DefaultType = type;
  45. this.InventoryFolders.Add(Folder.FolderID, Folder);
  46. return (true);
  47. }
  48. public void CreateRootFolder(LLUUID newAgentID, bool createTextures)
  49. {
  50. this.AgentID = newAgentID;
  51. /* InventoryRoot = new InventoryFolder();
  52. InventoryRoot.FolderID = LLUUID.Random();
  53. InventoryRoot.ParentID = new LLUUID();
  54. InventoryRoot.Version = 1;
  55. InventoryRoot.DefaultType = 8;
  56. InventoryRoot.OwnerID = this.AgentID;
  57. InventoryRoot.FolderName = "My Inventory-";
  58. InventoryFolders.Add(InventoryRoot.FolderID, InventoryRoot);*/
  59. InventoryRoot.OwnerID = this.AgentID;
  60. if (createTextures)
  61. {
  62. this.CreateNewFolder(LLUUID.Random(), 0, "Textures", InventoryRoot.FolderID);
  63. }
  64. }
  65. public bool CreateNewFolder(LLUUID folderID, ushort type, string folderName)
  66. {
  67. InventoryFolder Folder = new InventoryFolder();
  68. Folder.FolderID = folderID;
  69. Folder.OwnerID = this.AgentID;
  70. Folder.DefaultType = type;
  71. Folder.FolderName = folderName;
  72. this.InventoryFolders.Add(Folder.FolderID, Folder);
  73. return (true);
  74. }
  75. public bool CreateNewFolder(LLUUID folderID, ushort type, string folderName, LLUUID parent)
  76. {
  77. InventoryFolder Folder = new InventoryFolder();
  78. Folder.FolderID = folderID;
  79. Folder.OwnerID = this.AgentID;
  80. Folder.DefaultType = type;
  81. Folder.FolderName = folderName;
  82. Folder.ParentID = parent;
  83. this.InventoryFolders.Add(Folder.FolderID, Folder);
  84. return (true);
  85. }
  86. public bool HasFolder(LLUUID folderID)
  87. {
  88. if (this.InventoryFolders.ContainsKey(folderID))
  89. {
  90. return true;
  91. }
  92. return false;
  93. }
  94. public bool UpdateItem(LLUUID itemID, AssetBase asset)
  95. {
  96. if(this.InventoryItems.ContainsKey(itemID))
  97. {
  98. InventoryItem Item = this.InventoryItems[itemID];
  99. Item.AssetID = asset.FullID;
  100. Console.WriteLine("updated inventory item " + itemID.ToStringHyphenated() + " so it now is set to asset " + asset.FullID.ToStringHyphenated());
  101. //TODO need to update the rest of the info
  102. }
  103. return true;
  104. }
  105. public LLUUID AddToInventory(LLUUID folderID, AssetBase asset)
  106. {
  107. if (this.InventoryFolders.ContainsKey(folderID))
  108. {
  109. LLUUID NewItemID = LLUUID.Random();
  110. InventoryItem Item = new InventoryItem();
  111. Item.FolderID = folderID;
  112. Item.OwnerID = AgentID;
  113. Item.AssetID = asset.FullID;
  114. Item.ItemID = NewItemID;
  115. Item.Type = asset.Type;
  116. Item.Name = asset.Name;
  117. Item.Description = asset.Description;
  118. Item.InvType = asset.InvType;
  119. this.InventoryItems.Add(Item.ItemID, Item);
  120. InventoryFolder Folder = InventoryFolders[Item.FolderID];
  121. Folder.Items.Add(Item);
  122. return (Item.ItemID);
  123. }
  124. else
  125. {
  126. return (null);
  127. }
  128. }
  129. }
  130. public class InventoryFolder
  131. {
  132. public List<InventoryItem> Items;
  133. //public List<InventoryFolder> Subfolders;
  134. public LLUUID FolderID;
  135. public LLUUID OwnerID;
  136. public LLUUID ParentID = LLUUID.Zero;
  137. public string FolderName;
  138. public ushort DefaultType;
  139. public ushort Version;
  140. public InventoryFolder()
  141. {
  142. Items = new List<InventoryItem>();
  143. //Subfolders = new List<InventoryFolder>();
  144. }
  145. }
  146. public class InventoryItem
  147. {
  148. public LLUUID FolderID;
  149. public LLUUID OwnerID;
  150. public LLUUID ItemID;
  151. public LLUUID AssetID;
  152. public LLUUID CreatorID;
  153. public sbyte InvType;
  154. public sbyte Type;
  155. public string Name;
  156. public string Description;
  157. public InventoryItem()
  158. {
  159. this.CreatorID = LLUUID.Zero;
  160. }
  161. }
  162. public class AvatarWearable
  163. {
  164. public LLUUID AssetID = new LLUUID("00000000-0000-0000-0000-000000000000");
  165. public LLUUID ItemID = new LLUUID("00000000-0000-0000-0000-000000000000");
  166. public AvatarWearable()
  167. {
  168. }
  169. }
  170. }