diff options
author | Justin Clark-Casey (justincc) | 2012-07-06 22:07:19 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-07-06 22:07:19 +0100 |
commit | f6e5791ecd0b75ae4a6a85c66874af7047f6f55b (patch) | |
tree | 4e2a9a772b02bb8c2cc580076ab0c525dea82dd2 /OpenSim/Region/CoreModules | |
parent | Log MONO_THREADS_PER_CPU value on simulator startup, or "unset" if it is not set (diff) | |
download | opensim-SC_OLD-f6e5791ecd0b75ae4a6a85c66874af7047f6f55b.zip opensim-SC_OLD-f6e5791ecd0b75ae4a6a85c66874af7047f6f55b.tar.gz opensim-SC_OLD-f6e5791ecd0b75ae4a6a85c66874af7047f6f55b.tar.bz2 opensim-SC_OLD-f6e5791ecd0b75ae4a6a85c66874af7047f6f55b.tar.xz |
refactor: extract method UpdateUserInventoryWithAttachment() from AttachObject() for better code comprehension
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index af30a8e..9eb0e38 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | |||
@@ -292,31 +292,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
292 | 292 | ||
293 | group.AttachmentPoint = attachmentPt; | 293 | group.AttachmentPoint = attachmentPt; |
294 | group.AbsolutePosition = attachPos; | 294 | group.AbsolutePosition = attachPos; |
295 | 295 | ||
296 | // We also don't want to do any of the inventory operations for an NPC. | ||
297 | if (sp.PresenceType != PresenceType.Npc) | 296 | if (sp.PresenceType != PresenceType.Npc) |
298 | { | 297 | UpdateUserInventoryWithAttachment(sp, group, attachmentPt); |
299 | // Remove any previous attachments | ||
300 | List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); | ||
301 | |||
302 | // At the moment we can only deal with a single attachment | ||
303 | if (attachments.Count != 0) | ||
304 | { | ||
305 | if (attachments[0].FromItemID != UUID.Zero) | ||
306 | DetachSingleAttachmentToInvInternal(sp, attachments[0]); | ||
307 | else | ||
308 | m_log.WarnFormat( | ||
309 | "[ATTACHMENTS MODULE]: When detaching existing attachment {0} {1} at point {2} to make way for {3} {4} for {5}, couldn't find the associated item ID to adjust inventory attachment record!", | ||
310 | attachments[0].Name, attachments[0].LocalId, attachmentPt, group.Name, group.LocalId, sp.Name); | ||
311 | } | ||
312 | |||
313 | // Add the new attachment to inventory if we don't already have it. | ||
314 | UUID newAttachmentItemID = group.FromItemID; | ||
315 | if (newAttachmentItemID == UUID.Zero) | ||
316 | newAttachmentItemID = AddSceneObjectAsNewAttachmentInInv(sp, group).ID; | ||
317 | |||
318 | ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group); | ||
319 | } | ||
320 | 298 | ||
321 | AttachToAgent(sp, group, attachmentPt, attachPos, silent); | 299 | AttachToAgent(sp, group, attachmentPt, attachPos, silent); |
322 | } | 300 | } |
@@ -324,6 +302,30 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
324 | return true; | 302 | return true; |
325 | } | 303 | } |
326 | 304 | ||
305 | private void UpdateUserInventoryWithAttachment(IScenePresence sp, SceneObjectGroup group, uint attachmentPt) | ||
306 | { | ||
307 | // Remove any previous attachments | ||
308 | List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); | ||
309 | |||
310 | // At the moment we can only deal with a single attachment | ||
311 | if (attachments.Count != 0) | ||
312 | { | ||
313 | if (attachments[0].FromItemID != UUID.Zero) | ||
314 | DetachSingleAttachmentToInvInternal(sp, attachments[0]); | ||
315 | else | ||
316 | m_log.WarnFormat( | ||
317 | "[ATTACHMENTS MODULE]: When detaching existing attachment {0} {1} at point {2} to make way for {3} {4} for {5}, couldn't find the associated item ID to adjust inventory attachment record!", | ||
318 | attachments[0].Name, attachments[0].LocalId, attachmentPt, group.Name, group.LocalId, sp.Name); | ||
319 | } | ||
320 | |||
321 | // Add the new attachment to inventory if we don't already have it. | ||
322 | UUID newAttachmentItemID = group.FromItemID; | ||
323 | if (newAttachmentItemID == UUID.Zero) | ||
324 | newAttachmentItemID = AddSceneObjectAsNewAttachmentInInv(sp, group).ID; | ||
325 | |||
326 | ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group); | ||
327 | } | ||
328 | |||
327 | public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt) | 329 | public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt) |
328 | { | 330 | { |
329 | if (!Enabled) | 331 | if (!Enabled) |
@@ -652,11 +654,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
652 | // "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}", | 654 | // "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}", |
653 | // grp.Name, grp.LocalId, remoteClient.Name); | 655 | // grp.Name, grp.LocalId, remoteClient.Name); |
654 | 656 | ||
655 | InventoryItemBase newItem = m_invAccessModule.CopyToInventory( | 657 | InventoryItemBase newItem |
656 | DeRezAction.TakeCopy, | 658 | = m_invAccessModule.CopyToInventory( |
657 | m_scene.InventoryService.GetFolderForType(sp.UUID, AssetType.Object).ID, | 659 | DeRezAction.TakeCopy, |
658 | new List<SceneObjectGroup> { grp }, | 660 | m_scene.InventoryService.GetFolderForType(sp.UUID, AssetType.Object).ID, |
659 | sp.ControllingClient, true)[0]; | 661 | new List<SceneObjectGroup> { grp }, |
662 | sp.ControllingClient, true)[0]; | ||
660 | 663 | ||
661 | // sets itemID so client can show item as 'attached' in inventory | 664 | // sets itemID so client can show item as 'attached' in inventory |
662 | grp.FromItemID = newItem.ID; | 665 | grp.FromItemID = newItem.ID; |
@@ -782,7 +785,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
782 | item = m_scene.InventoryService.GetItem(item); | 785 | item = m_scene.InventoryService.GetItem(item); |
783 | bool changed = sp.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID); | 786 | bool changed = sp.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID); |
784 | if (changed && m_scene.AvatarFactory != null) | 787 | if (changed && m_scene.AvatarFactory != null) |
788 | { | ||
789 | // m_log.DebugFormat( | ||
790 | // "[ATTACHMENTS MODULE]: Queueing appearance save for {0}, attachment {1} point {2} in ShowAttachInUserInventory()", | ||
791 | // sp.Name, att.Name, AttachmentPt); | ||
792 | |||
785 | m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID); | 793 | m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID); |
794 | } | ||
786 | } | 795 | } |
787 | 796 | ||
788 | #endregion | 797 | #endregion |