Example #1
0
        public static Item DupeItem(Mobile from, object item, bool RecurseContainers)
        {
            Type   t = item.GetType();
            object o = Construct(t);

            if (o == null)
            {
                if (from != null)
                {
                    from.SendMessage("Unable to dupe {0}. Item must have a 0 parameter constructor.", t.Name);
                }

                return(null);
            }

            if (o is Item)
            {
                Item newItem = (Item)o;
                Item srcItem = (Item)item;
                CopyProperties(o, item, t, "Parent");

                if ((o is Container) && RecurseContainers)
                {
                    Container srcContainer = (Container)item;
                    Container newContainer = (Container)o;

                    newContainer.Items.Clear(); // if container object type adds items in its constructor, we need to remove them.
                    for (int i = 0; i < srcContainer.Items.Count; i++)
                    {
                        Item a = DupeItem(from, srcContainer.Items[i], true);

                        if (a != null)
                        {
                            newContainer.AddItem(a);
                            newContainer.UpdateTotals();
                        }
                    }
                }

                if ((o is KeyRing) && RecurseContainers)
                {
                    KeyRing srcRing = (KeyRing)item;
                    KeyRing newRing = new KeyRing();

                    int count = srcRing.Keys.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Key newkey = new Key(srcRing.Keys[i].KeyValue);
                        newRing.Add(newkey);
                    }
                    return(newRing);
                }

                newItem.UpdateTotals();
                return(newItem);
            }

            return(null);
        }