aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common/OpenSim.Framework/AgentInventory.cs
diff options
context:
space:
mode:
authorMW2007-05-24 12:35:32 +0000
committerMW2007-05-24 12:35:32 +0000
commitf95b6081cba084d1b067acea99c0effa2b3bf42c (patch)
tree7a7ab4aa037f75afa54f403c701a735acb101575 /Common/OpenSim.Framework/AgentInventory.cs
parentDie ServiceManager! (Not really Gareth, just the old directory, new directory... (diff)
downloadopensim-SC_OLD-f95b6081cba084d1b067acea99c0effa2b3bf42c.zip
opensim-SC_OLD-f95b6081cba084d1b067acea99c0effa2b3bf42c.tar.gz
opensim-SC_OLD-f95b6081cba084d1b067acea99c0effa2b3bf42c.tar.bz2
opensim-SC_OLD-f95b6081cba084d1b067acea99c0effa2b3bf42c.tar.xz
Renamed the new Directories. (removed the "-Source" from the end of them)
Diffstat (limited to 'Common/OpenSim.Framework/AgentInventory.cs')
-rw-r--r--Common/OpenSim.Framework/AgentInventory.cs251
1 files changed, 251 insertions, 0 deletions
diff --git a/Common/OpenSim.Framework/AgentInventory.cs b/Common/OpenSim.Framework/AgentInventory.cs
new file mode 100644
index 0000000..b28645e
--- /dev/null
+++ b/Common/OpenSim.Framework/AgentInventory.cs
@@ -0,0 +1,251 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5using libsecondlife.Packets;
6using OpenSim.Framework.Types;
7using OpenSim.Framework.Utilities;
8
9namespace OpenSim.Framework.Inventory
10{
11 public class AgentInventory
12 {
13 //Holds the local copy of Inventory info for a agent
14 public Dictionary<LLUUID, InventoryFolder> InventoryFolders;
15 public Dictionary<LLUUID, InventoryItem> InventoryItems;
16 public InventoryFolder InventoryRoot;
17 public int LastCached; //maybe used by opensim app, time this was last stored/compared to user server
18 public LLUUID AgentID;
19 public AvatarWearable[] Wearables;
20
21 public AgentInventory()
22 {
23 InventoryFolders = new Dictionary<LLUUID, InventoryFolder>();
24 InventoryItems = new Dictionary<LLUUID, InventoryItem>();
25 this.Initialise();
26 }
27
28 public virtual void Initialise()
29 {
30 Wearables = new AvatarWearable[13]; //should be 12 of these
31 for (int i = 0; i < 13; i++)
32 {
33 Wearables[i] = new AvatarWearable();
34 }
35
36 }
37
38 public bool CreateNewFolder(LLUUID folderID, ushort type)
39 {
40 InventoryFolder Folder = new InventoryFolder();
41 Folder.FolderID = folderID;
42 Folder.OwnerID = this.AgentID;
43 Folder.DefaultType = type;
44 this.InventoryFolders.Add(Folder.FolderID, Folder);
45 return (true);
46 }
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
66 public bool CreateNewFolder(LLUUID folderID, ushort type, string folderName)
67 {
68 InventoryFolder Folder = new InventoryFolder();
69 Folder.FolderID = folderID;
70 Folder.OwnerID = this.AgentID;
71 Folder.DefaultType = type;
72 Folder.FolderName = folderName;
73 this.InventoryFolders.Add(Folder.FolderID, Folder);
74
75 return (true);
76 }
77
78 public bool CreateNewFolder(LLUUID folderID, ushort type, string folderName, LLUUID parent)
79 {
80 if (!this.InventoryFolders.ContainsKey(folderID))
81 {
82 Console.WriteLine("creating new folder called " + folderName + " in agents inventory");
83 InventoryFolder Folder = new InventoryFolder();
84 Folder.FolderID = folderID;
85 Folder.OwnerID = this.AgentID;
86 Folder.DefaultType = type;
87 Folder.FolderName = folderName;
88 Folder.ParentID = parent;
89 this.InventoryFolders.Add(Folder.FolderID, Folder);
90 }
91
92 return (true);
93 }
94
95 public bool HasFolder(LLUUID folderID)
96 {
97 if (this.InventoryFolders.ContainsKey(folderID))
98 {
99 return true;
100 }
101 return false;
102 }
103
104 public LLUUID GetFolderID(string folderName)
105 {
106 foreach (InventoryFolder inv in this.InventoryFolders.Values)
107 {
108 if (inv.FolderName == folderName)
109 {
110 return inv.FolderID;
111 }
112 }
113
114 return LLUUID.Zero;
115 }
116
117 public bool UpdateItemAsset(LLUUID itemID, AssetBase asset)
118 {
119 if(this.InventoryItems.ContainsKey(itemID))
120 {
121 InventoryItem Item = this.InventoryItems[itemID];
122 Item.AssetID = asset.FullID;
123 Console.WriteLine("updated inventory item " + itemID.ToStringHyphenated() + " so it now is set to asset " + asset.FullID.ToStringHyphenated());
124 //TODO need to update the rest of the info
125 }
126 return true;
127 }
128
129 public bool UpdateItemDetails(LLUUID itemID, UpdateInventoryItemPacket.InventoryDataBlock packet)
130 {
131 Console.WriteLine("updating inventory item details");
132 if (this.InventoryItems.ContainsKey(itemID))
133 {
134 Console.WriteLine("changing name to "+ Util.FieldToString(packet.Name));
135 InventoryItem Item = this.InventoryItems[itemID];
136 Item.Name = Util.FieldToString(packet.Name);
137 Console.WriteLine("updated inventory item " + itemID.ToStringHyphenated());
138 //TODO need to update the rest of the info
139 }
140 return true;
141 }
142
143 public LLUUID AddToInventory(LLUUID folderID, AssetBase asset)
144 {
145 if (this.InventoryFolders.ContainsKey(folderID))
146 {
147 LLUUID NewItemID = LLUUID.Random();
148
149 InventoryItem Item = new InventoryItem();
150 Item.FolderID = folderID;
151 Item.OwnerID = AgentID;
152 Item.AssetID = asset.FullID;
153 Item.ItemID = NewItemID;
154 Item.Type = asset.Type;
155 Item.Name = asset.Name;
156 Item.Description = asset.Description;
157 Item.InvType = asset.InvType;
158 this.InventoryItems.Add(Item.ItemID, Item);
159 InventoryFolder Folder = InventoryFolders[Item.FolderID];
160 Folder.Items.Add(Item);
161 return (Item.ItemID);
162 }
163 else
164 {
165 return (null);
166 }
167 }
168
169 public bool DeleteFromInventory(LLUUID itemID)
170 {
171 bool res = false;
172 if (this.InventoryItems.ContainsKey(itemID))
173 {
174 InventoryItem item = this.InventoryItems[itemID];
175 this.InventoryItems.Remove(itemID);
176 foreach (InventoryFolder fold in InventoryFolders.Values)
177 {
178 if (fold.Items.Contains(item))
179 {
180 fold.Items.Remove(item);
181 break;
182 }
183 }
184 res = true;
185
186 }
187 return res;
188 }
189 }
190
191 public class InventoryFolder
192 {
193 public List<InventoryItem> Items;
194 //public List<InventoryFolder> Subfolders;
195 public LLUUID FolderID;
196 public LLUUID OwnerID;
197 public LLUUID ParentID = LLUUID.Zero;
198 public string FolderName;
199 public ushort DefaultType;
200 public ushort Version;
201
202 public InventoryFolder()
203 {
204 Items = new List<InventoryItem>();
205 //Subfolders = new List<InventoryFolder>();
206 }
207
208 }
209
210 public class InventoryItem
211 {
212 public LLUUID FolderID;
213 public LLUUID OwnerID;
214 public LLUUID ItemID;
215 public LLUUID AssetID;
216 public LLUUID CreatorID;
217 public sbyte InvType;
218 public sbyte Type;
219 public string Name ="";
220 public string Description;
221
222 public InventoryItem()
223 {
224 this.CreatorID = LLUUID.Zero;
225 }
226
227 public string ExportString()
228 {
229 string typ = "notecard";
230 string result = "";
231 result += "\tinv_object\t0\n\t{\n";
232 result += "\t\tobj_id\t%s\n";
233 result += "\t\tparent_id\t"+ ItemID.ToString() +"\n";
234 result += "\t\ttype\t"+ typ +"\n";
235 result += "\t\tname\t" + Name+"|\n";
236 result += "\t}\n";
237 return result;
238 }
239 }
240
241 public class AvatarWearable
242 {
243 public LLUUID AssetID = new LLUUID("00000000-0000-0000-0000-000000000000");
244 public LLUUID ItemID = new LLUUID("00000000-0000-0000-0000-000000000000");
245
246 public AvatarWearable()
247 {
248
249 }
250 }
251}