aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common/OpenSim.Framework/AgentInventory.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Common/OpenSim.Framework/AgentInventory.cs')
-rw-r--r--Common/OpenSim.Framework/AgentInventory.cs278
1 files changed, 0 insertions, 278 deletions
diff --git a/Common/OpenSim.Framework/AgentInventory.cs b/Common/OpenSim.Framework/AgentInventory.cs
deleted file mode 100644
index b36982a..0000000
--- a/Common/OpenSim.Framework/AgentInventory.cs
+++ /dev/null
@@ -1,278 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32using libsecondlife.Packets;
33using OpenSim.Framework.Types;
34using OpenSim.Framework.Utilities;
35
36namespace OpenSim.Framework.Inventory
37{
38 public class AgentInventory
39 {
40 //Holds the local copy of Inventory info for a agent
41 public Dictionary<LLUUID, InventoryFolder> InventoryFolders;
42 public Dictionary<LLUUID, InventoryItem> InventoryItems;
43 public InventoryFolder InventoryRoot;
44 public int LastCached; //maybe used by opensim app, time this was last stored/compared to user server
45 public LLUUID AgentID;
46 public AvatarWearable[] Wearables;
47
48 public AgentInventory()
49 {
50 InventoryFolders = new Dictionary<LLUUID, InventoryFolder>();
51 InventoryItems = new Dictionary<LLUUID, InventoryItem>();
52 this.Initialise();
53 }
54
55 public virtual void Initialise()
56 {
57 Wearables = new AvatarWearable[13]; //should be 12 of these
58 for (int i = 0; i < 13; i++)
59 {
60 Wearables[i] = new AvatarWearable();
61 }
62
63 }
64
65 public bool CreateNewFolder(LLUUID folderID, ushort type)
66 {
67 InventoryFolder Folder = new InventoryFolder();
68 Folder.FolderID = folderID;
69 Folder.OwnerID = this.AgentID;
70 Folder.DefaultType = type;
71 this.InventoryFolders.Add(Folder.FolderID, Folder);
72 return (true);
73 }
74
75 public void CreateRootFolder(LLUUID newAgentID, bool createTextures)
76 {
77 this.AgentID = newAgentID;
78 InventoryRoot = new InventoryFolder();
79 InventoryRoot.FolderID = LLUUID.Random();
80 InventoryRoot.ParentID = new LLUUID();
81 InventoryRoot.Version = 1;
82 InventoryRoot.DefaultType = 8;
83 InventoryRoot.OwnerID = this.AgentID;
84 InventoryRoot.FolderName = "My Inventory";
85 InventoryFolders.Add(InventoryRoot.FolderID, InventoryRoot);
86 InventoryRoot.OwnerID = this.AgentID;
87 if (createTextures)
88 {
89 this.CreateNewFolder(LLUUID.Random(), 0, "Textures", InventoryRoot.FolderID);
90 }
91 }
92
93 public bool CreateNewFolder(LLUUID folderID, ushort type, string folderName)
94 {
95 InventoryFolder Folder = new InventoryFolder();
96 Folder.FolderID = folderID;
97 Folder.OwnerID = this.AgentID;
98 Folder.DefaultType = type;
99 Folder.FolderName = folderName;
100 this.InventoryFolders.Add(Folder.FolderID, Folder);
101
102 return (true);
103 }
104
105 public bool CreateNewFolder(LLUUID folderID, ushort type, string folderName, LLUUID parent)
106 {
107 if (!this.InventoryFolders.ContainsKey(folderID))
108 {
109 Console.WriteLine("creating new folder called " + folderName + " in agents inventory");
110 InventoryFolder Folder = new InventoryFolder();
111 Folder.FolderID = folderID;
112 Folder.OwnerID = this.AgentID;
113 Folder.DefaultType = type;
114 Folder.FolderName = folderName;
115 Folder.ParentID = parent;
116 this.InventoryFolders.Add(Folder.FolderID, Folder);
117 }
118
119 return (true);
120 }
121
122 public bool HasFolder(LLUUID folderID)
123 {
124 if (this.InventoryFolders.ContainsKey(folderID))
125 {
126 return true;
127 }
128 return false;
129 }
130
131 public LLUUID GetFolderID(string folderName)
132 {
133 foreach (InventoryFolder inv in this.InventoryFolders.Values)
134 {
135 if (inv.FolderName == folderName)
136 {
137 return inv.FolderID;
138 }
139 }
140
141 return LLUUID.Zero;
142 }
143
144 public bool UpdateItemAsset(LLUUID itemID, AssetBase asset)
145 {
146 if(this.InventoryItems.ContainsKey(itemID))
147 {
148 InventoryItem Item = this.InventoryItems[itemID];
149 Item.AssetID = asset.FullID;
150 Console.WriteLine("updated inventory item " + itemID.ToStringHyphenated() + " so it now is set to asset " + asset.FullID.ToStringHyphenated());
151 //TODO need to update the rest of the info
152 }
153 return true;
154 }
155
156 public bool UpdateItemDetails(LLUUID itemID, UpdateInventoryItemPacket.InventoryDataBlock packet)
157 {
158 Console.WriteLine("updating inventory item details");
159 if (this.InventoryItems.ContainsKey(itemID))
160 {
161 Console.WriteLine("changing name to "+ Util.FieldToString(packet.Name));
162 InventoryItem Item = this.InventoryItems[itemID];
163 Item.Name = Util.FieldToString(packet.Name);
164 Console.WriteLine("updated inventory item " + itemID.ToStringHyphenated());
165 //TODO need to update the rest of the info
166 }
167 return true;
168 }
169
170 public LLUUID AddToInventory(LLUUID folderID, AssetBase asset)
171 {
172 if (this.InventoryFolders.ContainsKey(folderID))
173 {
174 LLUUID NewItemID = LLUUID.Random();
175
176 InventoryItem Item = new InventoryItem();
177 Item.FolderID = folderID;
178 Item.OwnerID = AgentID;
179 Item.AssetID = asset.FullID;
180 Item.ItemID = NewItemID;
181 Item.Type = asset.Type;
182 Item.Name = asset.Name;
183 Item.Description = asset.Description;
184 Item.InvType = asset.InvType;
185 this.InventoryItems.Add(Item.ItemID, Item);
186 InventoryFolder Folder = InventoryFolders[Item.FolderID];
187 Folder.Items.Add(Item);
188 return (Item.ItemID);
189 }
190 else
191 {
192 return (null);
193 }
194 }
195
196 public bool DeleteFromInventory(LLUUID itemID)
197 {
198 bool res = false;
199 if (this.InventoryItems.ContainsKey(itemID))
200 {
201 InventoryItem item = this.InventoryItems[itemID];
202 this.InventoryItems.Remove(itemID);
203 foreach (InventoryFolder fold in InventoryFolders.Values)
204 {
205 if (fold.Items.Contains(item))
206 {
207 fold.Items.Remove(item);
208 break;
209 }
210 }
211 res = true;
212
213 }
214 return res;
215 }
216 }
217
218 public class InventoryFolder
219 {
220 public List<InventoryItem> Items;
221 //public List<InventoryFolder> Subfolders;
222 public LLUUID FolderID;
223 public LLUUID OwnerID;
224 public LLUUID ParentID = LLUUID.Zero;
225 public string FolderName;
226 public ushort DefaultType;
227 public ushort Version;
228
229 public InventoryFolder()
230 {
231 Items = new List<InventoryItem>();
232 //Subfolders = new List<InventoryFolder>();
233 }
234
235 }
236
237 public class InventoryItem
238 {
239 public LLUUID FolderID;
240 public LLUUID OwnerID;
241 public LLUUID ItemID;
242 public LLUUID AssetID;
243 public LLUUID CreatorID;
244 public sbyte InvType;
245 public sbyte Type;
246 public string Name ="";
247 public string Description;
248
249 public InventoryItem()
250 {
251 this.CreatorID = LLUUID.Zero;
252 }
253
254 public string ExportString()
255 {
256 string typ = "notecard";
257 string result = "";
258 result += "\tinv_object\t0\n\t{\n";
259 result += "\t\tobj_id\t%s\n";
260 result += "\t\tparent_id\t"+ ItemID.ToString() +"\n";
261 result += "\t\ttype\t"+ typ +"\n";
262 result += "\t\tname\t" + Name+"|\n";
263 result += "\t}\n";
264 return result;
265 }
266 }
267
268 public class AvatarWearable
269 {
270 public LLUUID AssetID = new LLUUID("00000000-0000-0000-0000-000000000000");
271 public LLUUID ItemID = new LLUUID("00000000-0000-0000-0000-000000000000");
272
273 public AvatarWearable()
274 {
275
276 }
277 }
278}