Exemplo n.º 1
0
            protected override void OnTarget(Mobile from, object targ)
            {
                bool done = false;

                if (!(targ is Item))
                {
                    from.SendMessage("You can only dupe items.");
                    return;
                }

                CommandLogging.WriteLine(from, "{0} {1} duping {2} (inBag={3}; amount={4})", from.AccessLevel, CommandLogging.Format(from), CommandLogging.Format(targ), m_InBag, m_Amount);

                Item      copy = (Item)targ;
                Container pack;

                if (m_InBag)
                {
                    if (copy.Parent is Container)
                    {
                        pack = (Container)copy.Parent;
                    }
                    else if (copy.Parent is Mobile)
                    {
                        pack = ((Mobile)copy.Parent).Backpack;
                    }
                    else
                    {
                        pack = null;
                    }
                }
                else
                {
                    pack = from.Backpack;
                }

                Type t = copy.GetType();

                //ConstructorInfo[] info = t.GetConstructors();

                ConstructorInfo c = t.GetConstructor(Type.EmptyTypes);

                if (c != null)
                {
                    try
                    {
                        from.SendMessage("Duping {0}...", m_Amount);
                        for (int i = 0; i < m_Amount; i++)
                        {
                            object o = c.Invoke(null);

                            if (o != null && o is Item)
                            {
                                Item newItem = (Item)o;
                                CopyProperties(newItem, copy);                                  //copy.Dupe( item, copy.Amount );
                                copy.OnAfterDuped(newItem);
                                newItem.Parent = null;

                                if (pack != null)
                                {
                                    pack.DropItem(newItem);
                                    BaseContainer.DropItemFix(newItem, from, pack.ItemID, pack.GumpID);
                                }
                                else
                                {
                                    newItem.MoveToWorld(from.Location, from.Map);
                                }

                                newItem.InvalidateProperties();

                                CommandLogging.WriteLine(from, "{0} {1} duped {2} creating {3}", from.AccessLevel, CommandLogging.Format(from), CommandLogging.Format(targ), CommandLogging.Format(newItem));
                            }
                        }
                        from.SendMessage("Done");
                        done = true;
                    }
                    catch
                    {
                        from.SendMessage("Error!");
                        return;
                    }
                }

                if (!done)
                {
                    from.SendMessage("Unable to dupe.  Item must have a 0 parameter constructor.");
                }
            }
Exemplo n.º 2
0
        public static int Build(Mobile from, Point3D start, Point3D end, ConstructorInfo ctor, object[] values, string[,] props, PropertyInfo[] realProps, List <Container> packs)
        {
            try
            {
                Map map = from.Map;

                int objectCount = (packs == null ? (((end.X - start.X) + 1) * ((end.Y - start.Y) + 1)) : packs.Count);

                if (objectCount >= 20)
                {
                    from.SendMessage("Constructing {0} objects, please wait.", objectCount);
                }

                bool sendError = true;

                StringBuilder sb = new StringBuilder();
                sb.Append("Serials: ");

                if (packs != null)
                {
                    for (int i = 0; i < packs.Count; ++i)
                    {
                        IEntity built = Build(from, ctor, values, props, realProps, ref sendError);

                        sb.AppendFormat("0x{0:X}; ", built.Serial.Value);

                        if (built is Item)
                        {
                            Container pack = packs[i];
                            pack.DropItem((Item)built); BaseContainer.DropItemFix((Item)built, from, pack.ItemID, pack.GumpID);
                        }
                        else if (built is Mobile)
                        {
                            Mobile m = (Mobile)built;
                            m.MoveToWorld(new Point3D(start.X, start.Y, start.Z), map);
                            m.OnAfterSpawn();
                        }
                    }
                }
                else
                {
                    for (int x = start.X; x <= end.X; ++x)
                    {
                        for (int y = start.Y; y <= end.Y; ++y)
                        {
                            IEntity built = Build(from, ctor, values, props, realProps, ref sendError);

                            sb.AppendFormat("0x{0:X}; ", built.Serial.Value);

                            if (built is Item)
                            {
                                Item item = (Item)built;
                                item.MoveToWorld(new Point3D(x, y, start.Z), map);
                                item.OnAfterSpawn();
                            }
                            else if (built is Mobile)
                            {
                                Mobile m = (Mobile)built;
                                m.MoveToWorld(new Point3D(x, y, start.Z), map);
                                m.OnAfterSpawn();
                            }
                        }
                    }
                }

                CommandLogging.WriteLine(from, sb.ToString());

                return(objectCount);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(0);
            }
        }