refactor: Make logic in AM.AttachObject() clearer by not reusing existing variables in different contexts

remove-scene-viewer
Justin Clark-Casey (justincc) 2011-09-06 02:40:19 +01:00
parent 5beee42809
commit 1a8f5b97b9
1 changed files with 19 additions and 14 deletions

View File

@ -285,26 +285,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
group.AttachmentPoint = attachmentPt; group.AttachmentPoint = attachmentPt;
group.AbsolutePosition = attachPos; group.AbsolutePosition = attachPos;
// Remove any previous attachments
UUID itemID = UUID.Zero;
List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt);
// At the moment we can only deal with a single attachment
// We also don't want to do any of the inventory operations for an NPC. // We also don't want to do any of the inventory operations for an NPC.
if (sp.PresenceType != PresenceType.Npc) if (sp.PresenceType != PresenceType.Npc)
{ {
// Remove any previous attachments
List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt);
// At the moment we can only deal with a single attachment
if (attachments.Count != 0) if (attachments.Count != 0)
itemID = attachments[0].GetFromItemID(); {
UUID oldAttachmentItemID = attachments[0].GetFromItemID();
if (itemID != UUID.Zero) if (oldAttachmentItemID != UUID.Zero)
DetachSingleAttachmentToInv(itemID, sp); DetachSingleAttachmentToInv(oldAttachmentItemID, sp);
else
m_log.WarnFormat(
"[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!",
attachments[0].Name, attachments[0].LocalId, attachmentPt, group.Name, group.LocalId, sp.Name);
}
// Add the new attachment to inventory if we don't already have it.
UUID newAttachmentItemID = group.GetFromItemID();
if (newAttachmentItemID == UUID.Zero)
newAttachmentItemID = AddSceneObjectAsNewAttachmentInInv(sp.ControllingClient, group).ID;
itemID = group.GetFromItemID(); ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group);
if (itemID == UUID.Zero)
itemID = AddSceneObjectAsNewAttachmentInInv(sp.ControllingClient, group).ID;
ShowAttachInUserInventory(sp, attachmentPt, itemID, group);
} }
AttachToAgent(sp, group, attachmentPt, attachPos, silent); AttachToAgent(sp, group, attachmentPt, attachPos, silent);