aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/AvatarAppearance.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/AvatarAppearance.cs')
-rw-r--r--OpenSim/Framework/AvatarAppearance.cs138
1 files changed, 70 insertions, 68 deletions
diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs
index 55646dd..ba0cad2 100644
--- a/OpenSim/Framework/AvatarAppearance.cs
+++ b/OpenSim/Framework/AvatarAppearance.cs
@@ -51,7 +51,7 @@ namespace OpenSim.Framework
51 protected byte[] m_visualparams; 51 protected byte[] m_visualparams;
52 protected Primitive.TextureEntry m_texture; 52 protected Primitive.TextureEntry m_texture;
53 protected AvatarWearable[] m_wearables; 53 protected AvatarWearable[] m_wearables;
54 protected Dictionary<int, AvatarAttachment> m_attachments; 54 protected Dictionary<int, List<AvatarAttachment>> m_attachments;
55 protected float m_avatarHeight = 0; 55 protected float m_avatarHeight = 0;
56 protected float m_hipOffset = 0; 56 protected float m_hipOffset = 0;
57 57
@@ -85,11 +85,6 @@ namespace OpenSim.Framework
85 set { m_wearables = value; } 85 set { m_wearables = value; }
86 } 86 }
87 87
88 public virtual Dictionary<int, AvatarAttachment> Attachments
89 {
90 get { return m_attachments; }
91 }
92
93 public virtual UUID BodyItem { 88 public virtual UUID BodyItem {
94 get { return m_wearables[AvatarWearable.BODY].ItemID; } 89 get { return m_wearables[AvatarWearable.BODY].ItemID; }
95 set { m_wearables[AvatarWearable.BODY].ItemID = value; } 90 set { m_wearables[AvatarWearable.BODY].ItemID = value; }
@@ -246,7 +241,7 @@ namespace OpenSim.Framework
246 SetDefaultParams(); 241 SetDefaultParams();
247 SetHeight(); 242 SetHeight();
248 243
249 m_attachments = new Dictionary<int, AvatarAttachment>(); 244 m_attachments = new Dictionary<int, List<AvatarAttachment>>();
250 } 245 }
251 246
252 public AvatarAppearance(UUID avatarID, OSDMap map) 247 public AvatarAppearance(UUID avatarID, OSDMap map)
@@ -284,7 +279,7 @@ namespace OpenSim.Framework
284 279
285 SetHeight(); 280 SetHeight();
286 281
287 m_attachments = new Dictionary<int, AvatarAttachment>(); 282 m_attachments = new Dictionary<int, List<AvatarAttachment>>();
288 } 283 }
289 284
290 public AvatarAppearance(AvatarAppearance appearance) 285 public AvatarAppearance(AvatarAppearance appearance)
@@ -302,7 +297,7 @@ namespace OpenSim.Framework
302 SetDefaultParams(); 297 SetDefaultParams();
303 SetHeight(); 298 SetHeight();
304 299
305 m_attachments = new Dictionary<int, AvatarAttachment>(); 300 m_attachments = new Dictionary<int, List<AvatarAttachment>>();
306 301
307 return; 302 return;
308 } 303 }
@@ -329,9 +324,10 @@ namespace OpenSim.Framework
329 if (appearance.VisualParams != null) 324 if (appearance.VisualParams != null)
330 m_visualparams = (byte[])appearance.VisualParams.Clone(); 325 m_visualparams = (byte[])appearance.VisualParams.Clone();
331 326
332 m_attachments = new Dictionary<int, AvatarAttachment>(); 327 // Copy the attachment, force append mode since that ensures consistency
333 foreach (KeyValuePair<int, AvatarAttachment> kvp in appearance.Attachments) 328 m_attachments = new Dictionary<int, List<AvatarAttachment>>();
334 m_attachments[kvp.Key] = new AvatarAttachment(kvp.Value); 329 foreach (AvatarAttachment attachment in appearance.GetAttachments())
330 AppendAttachment(new AvatarAttachment(attachment));
335 } 331 }
336 332
337 protected virtual void SetDefaultWearables() 333 protected virtual void SetDefaultWearables()
@@ -487,12 +483,41 @@ namespace OpenSim.Framework
487 } 483 }
488// DEBUG OFF 484// DEBUG OFF
489 485
490 public void SetAttachments(AvatarAttachment[] data) 486 /// <summary>
487 /// Get a list of the attachments, note that there may be
488 /// duplicate attachpoints
489 /// </summary>
490 public List<AvatarAttachment> GetAttachments()
491 {
492 List<AvatarAttachment> alist = new List<AvatarAttachment>();
493 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
494 {
495 foreach (AvatarAttachment attach in kvp.Value)
496 alist.Add(new AvatarAttachment(attach));
497 }
498
499 return alist;
500 }
501
502 internal void AppendAttachment(AvatarAttachment attach)
491 { 503 {
492 foreach (AvatarAttachment attach in data) 504 if (! m_attachments.ContainsKey(attach.AttachPoint))
493 m_attachments[attach.AttachPoint] = new AvatarAttachment(attach); 505 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
506 m_attachments[attach.AttachPoint].Add(attach);
494 } 507 }
495 508
509 internal void ReplaceAttachment(AvatarAttachment attach)
510 {
511 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
512 m_attachments[attach.AttachPoint].Add(attach);
513 }
514
515 /// <summary>
516 /// Add an attachment, if the attachpoint has the
517 /// 0x80 bit set then we assume this is an append
518 /// operation otherwise we replace whatever is
519 /// currently attached at the attachpoint
520 /// </summary>
496 public void SetAttachment(int attachpoint, UUID item, UUID asset) 521 public void SetAttachment(int attachpoint, UUID item, UUID asset)
497 { 522 {
498 if (attachpoint == 0) 523 if (attachpoint == 0)
@@ -505,67 +530,47 @@ namespace OpenSim.Framework
505 return; 530 return;
506 } 531 }
507 532
508 m_attachments[attachpoint] = new AvatarAttachment(attachpoint,item,asset); 533 // check if this is an append or a replace, 0x80 marks it as an append
509 } 534 if ((attachpoint & 0x80) > 0)
510
511 public Hashtable GetAttachments()
512 {
513 if (m_attachments.Count == 0)
514 return null;
515
516 Hashtable ret = new Hashtable();
517
518 foreach (KeyValuePair<int, AvatarAttachment> kvp in m_attachments)
519 { 535 {
520 Hashtable data = new Hashtable(); 536 // strip the append bit
521 data["item"] = kvp.Value.ItemID.ToString(); 537 int point = attachpoint & 0x7F;
522 data["asset"] = kvp.Value.AssetID.ToString(); 538 AppendAttachment(new AvatarAttachment(point, item, asset));
523 539 }
524 ret[kvp.Key] = data; 540 else
541 {
542 ReplaceAttachment(new AvatarAttachment(attachpoint,item,asset));
525 } 543 }
526
527 return ret;
528 }
529
530 public List<int> GetAttachedPoints()
531 {
532 return new List<int>(m_attachments.Keys);
533 }
534
535 public UUID GetAttachedItem(int attachpoint)
536 {
537 if (!m_attachments.ContainsKey(attachpoint))
538 return UUID.Zero;
539
540 return m_attachments[attachpoint].ItemID;
541 }
542
543 public UUID GetAttachedAsset(int attachpoint)
544 {
545 if (!m_attachments.ContainsKey(attachpoint))
546 return UUID.Zero;
547
548 return m_attachments[attachpoint].AssetID;
549 } 544 }
550 545
551 public int GetAttachpoint(UUID itemID) 546 public int GetAttachpoint(UUID itemID)
552 { 547 {
553 foreach (KeyValuePair<int, AvatarAttachment> kvp in m_attachments) 548 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
554 { 549 {
555 if (kvp.Value.ItemID == itemID) 550 int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
556 { 551 if (index >= 0)
557 return kvp.Key; 552 return kvp.Key;
558 }
559 } 553 }
554
560 return 0; 555 return 0;
561 } 556 }
562 557
563 public void DetachAttachment(UUID itemID) 558 public void DetachAttachment(UUID itemID)
564 { 559 {
565 int attachpoint = GetAttachpoint(itemID); 560 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
561 {
562 int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
563 if (index >= 0)
564 {
565 // Remove it from the list of attachments at that attach point
566 m_attachments[kvp.Key].RemoveAt(index);
566 567
567 if (attachpoint > 0) 568 // And remove the list if there are no more attachments here
568 m_attachments.Remove(attachpoint); 569 if (m_attachments[kvp.Key].Count == 0)
570 m_attachments.Remove(kvp.Key);
571 return;
572 }
573 }
569 } 574 }
570 575
571 public void ClearAttachments() 576 public void ClearAttachments()
@@ -607,8 +612,8 @@ namespace OpenSim.Framework
607 612
608 // Attachments 613 // Attachments
609 OSDArray attachs = new OSDArray(m_attachments.Count); 614 OSDArray attachs = new OSDArray(m_attachments.Count);
610 foreach (KeyValuePair<int, AvatarAttachment> kvp in m_attachments) 615 foreach (AvatarAttachment attach in GetAttachments())
611 attachs.Add(kvp.Value.Pack()); 616 attachs.Add(attach.Pack());
612 data["attachments"] = attachs; 617 data["attachments"] = attachs;
613 618
614 return data; 619 return data;
@@ -675,15 +680,12 @@ namespace OpenSim.Framework
675 } 680 }
676 681
677 // Attachments 682 // Attachments
678 m_attachments = new Dictionary<int, AvatarAttachment>(); 683 m_attachments = new Dictionary<int, List<AvatarAttachment>>();
679 if ((data != null) && (data["attachments"] != null) && (data["attachments"]).Type == OSDType.Array) 684 if ((data != null) && (data["attachments"] != null) && (data["attachments"]).Type == OSDType.Array)
680 { 685 {
681 OSDArray attachs = (OSDArray)(data["attachments"]); 686 OSDArray attachs = (OSDArray)(data["attachments"]);
682 for (int i = 0; i < attachs.Count; i++) 687 for (int i = 0; i < attachs.Count; i++)
683 { 688 AppendAttachment(new AvatarAttachment((OSDMap)attachs[i]));
684 AvatarAttachment attach = new AvatarAttachment((OSDMap)attachs[i]);
685 m_attachments[attach.AttachPoint] = attach;
686 }
687 } 689 }
688 } 690 }
689 catch (Exception e) 691 catch (Exception e)