Beispiel #1
0
        private static bool AttachTo(object from, object o, XmlAttachment attachment, bool first)
        {
            if (!(o is Item || o is Mobile) || attachment == null) return false;

            Hashtable attachments = null;
            if (o is Item)
            {
                if (ItemAttachments == null)
                {
                    ItemAttachments = new Hashtable();
                }
                attachments = ItemAttachments;

            }
            else
                if (o is Mobile)
                {
                    if (MobileAttachments == null)
                    {
                        MobileAttachments = new Hashtable();
                    }

                    attachments = MobileAttachments;
                }

            XmlAttach.Defrag(o);

            // see if there is already an attachment list for the object
            ArrayList attachmententry = FindAttachments(attachments, o, true);

            if (attachmententry != null)
            {
                // if an existing entry list was found then just add the attachment to that list after making sure there is not a duplicate
                foreach (XmlAttachment i in attachmententry)
                {
                    // and attachment is considered a duplicate if both the type and name match
                    if (i != null && !i.Deleted && i.GetType() == attachment.GetType() && i.Name == attachment.Name)
                    {
                        // duplicate found so replace it
                        i.Delete();
                    }
                }

                attachmententry.Add(attachment);
            }
            else
            {
                // otherwise make a new entry list
                attachmententry = new ArrayList(1);

                // containing the attachment
                attachmententry.Add(attachment);

                // and add it to the hash table
                attachments.Add(o, attachmententry);

            }

            attachment.AttachedTo = o;
            attachment.OwnedBy = o;

            if (from is Mobile)
            {
                attachment.SetAttachedBy(((Mobile)from).Name);
            }
            else
                if (from is Item)
                {
                    attachment.SetAttachedBy(((Item)from).Name);
                }

            // if this is being attached for the first time, then call the OnAttach method
            // if it is being reattached due to deserialization then dont
            if (first)
            {
                attachment.OnAttach();
            }
            else
            {
                attachment.OnReattach();
            }

            return !attachment.Deleted;
        }
Beispiel #2
0
		private static bool AttachTo(object from, IEntity o, XmlAttachment attachment, bool first)
		{
			if (o == null || attachment == null)
			{
				return false;
			}

			if (EntityAttachments == null)
			{
				EntityAttachments = new Dictionary<int, ArrayList>();
			}

			if (o is AddonComponent)
			{
				// add the attachment to the parent addon instead
				AddonComponent component = (AddonComponent)o;
				if (component.Addon != null)
				{
					o = component.Addon;
				}
			}

			Defrag(o.Serial);

			// see if there is already an attachment list for the object
			ArrayList attachmententry = FindAttachments(o, true);

			if (attachmententry != null)
			{
				// if an existing entry list was found then just add the attachment to that list after making sure there is not a duplicate
				foreach (XmlAttachment i in attachmententry)
				{
					// and attachment is considered a duplicate if both the type and name match
					if (i != null && !i.Deleted && i.GetType() == attachment.GetType() && i.Name == attachment.Name)
					{
						// duplicate found so replace it
						i.Delete();
					}
				}

				attachmententry.Add(attachment);
			}
			else
			{
				// otherwise make a new entry list
				attachmententry = new ArrayList(1);

				// containing the attachment
				attachmententry.Add(attachment);

				// and add it to the hash table
				EntityAttachments.Add(o.Serial.Value, attachmententry);
			}

			attachment.AttachedTo = o;
			attachment.OwnedBy = o;

			if (from is Mobile)
			{
				attachment.SetAttachedBy(((Mobile)from).Name);
			}
			else if (from is Item)
			{
				attachment.SetAttachedBy(((Item)from).Name);
			}

			// if this is being attached for the first time, then call the OnAttach method
			// if it is being reattached due to deserialization then dont
			if (first)
			{
				attachment.OnAttach();
			}
			else
			{
				attachment.OnReattach();
			}

			return !attachment.Deleted;
		}