示例#1
0
        public static int Build(Mobile from, Point3D start, Point3D end, ConstructorInfo ctor, object[] values, string[,] props, PropertyInfo[] realProps, ArrayList 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;

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

                        if (built is Item)
                        {
                            Container pack = (Container)packs[i];

                            pack.DropItem((Item)built);
                        }
                        else if (built is Mobile)
                        {
                            Mobile m = (Mobile)built;

                            m.MoveToWorld(new Point3D(start.X, start.Y, start.Z), map);
                        }
                    }
                }
                else
                {
                    for (int x = start.X; x <= end.X; ++x)
                    {
                        for (int y = start.Y; y <= end.Y; ++y)
                        {
                            object built = Build(from, ctor, values, props, realProps, ref sendError);

                            if (built is Item)
                            {
                                Item item = (Item)built;
                                item.MoveToWorld(new Point3D(x, y, start.Z), map);
                                AddItemEventArgs e = new AddItemEventArgs(built as Item, from);
                                EventSink.InvokeAddItem(e);

                                // erl: stores person adding it if Spawner
                                // or ChestItemSpawner type + calls change log

                                if (built is Spawner)
                                {
                                    Spawner sp = (Spawner)built;
                                    sp.LastProps = from;
                                    sp.LogChange("Spawner added");
                                }
                                else if (built is ChestItemSpawner)
                                {
                                    ChestItemSpawner sp = (ChestItemSpawner)built;
                                    sp.LastProps = from;
                                    sp.LogChange("ChestItemSpawner added");
                                }
                                else if (built is ChestLootPackSpawner)
                                {
                                    ChestLootPackSpawner sp = (ChestLootPackSpawner)built;
                                    sp.LastProps = from;
                                    sp.LogChange("ChestLootPackSpawner added");
                                }
                            }
                            else if (built is Mobile)
                            {
                                Mobile m = (Mobile)built;

                                m.MoveToWorld(new Point3D(x, y, start.Z), map);
                            }
                        }
                    }
                }

                return(objectCount);
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                Console.WriteLine(ex);
                return(0);
            }
        }
示例#2
0
        // Searches for spawners and returns struct list containing
        // relevant detail

        public static ArrayList FindMobSpawners(string searchtext, int x, int y, int tilerange)
        {
            ArrayList SpawnerList   = new ArrayList();
            Regex     SearchPattern = new Regex(searchtext.ToLower());

            // Loop through mobiles and check for Spawners

            foreach (Item item in World.Items.Values)
            {
                if (item is Server.Mobiles.Spawner)
                {
                    Spawner sp = (Spawner)item;

                    // Now check range / ignore range accordingly

                    int spX = sp.Location.X - x;
                    int spY = sp.Location.Y - y;

                    if ((tilerange == 0) || (
                            (sqr(sp.Location.X - x) <= sqr(tilerange) &&
                             sqr(sp.Location.Y - y) <= sqr(tilerange))
                            ))
                    {
                        // Loop through spawners' creature list and match
                        // against search text

                        foreach (string CreatureName in sp.CreaturesName)
                        {
                            if (SearchPattern.IsMatch(CreatureName.ToLower()))
                            {
                                SpawnerMatch ms = new SpawnerMatch();

                                ms.Item = false;
                                ms.Sp   = sp;

                                // Check if item type

                                Type   TestType = SpawnerType.GetType(CreatureName);
                                string strTest  = TestType.ToString();

                                Regex InvalidPatt = new Regex("^Server.Item");

                                if (InvalidPatt.IsMatch(strTest))
                                {
                                    ms.Item = true;
                                }
                                // We have a match! Create new match struct
                                // and add to return reference list

                                if (sp.Running == true)
                                {
                                    ms.Status = "on";
                                }
                                else
                                {
                                    ms.Status = "off";
                                }

                                ms.Matched  = CreatureName;
                                ms.Distance = (int)Math.Sqrt(sqr(spX) + sqr(spY));

                                SpawnerList.Add(ms);
                            }
                        }
                    }
                }

                if (item is Server.Items.ChestItemSpawner)
                {
                    ChestItemSpawner sp = (ChestItemSpawner)item;

                    // Now check range / ignore range accordingly

                    int spX = sp.Location.X - x;
                    int spY = sp.Location.Y - y;

                    if ((tilerange == 0) || (
                            (sqr(sp.Location.X - x) <= sqr(tilerange) &&
                             sqr(sp.Location.Y - y) <= sqr(tilerange))
                            ))
                    {
                        // Loop through spawners' creature list and match
                        // against search text

                        foreach (string ItemName in sp.ItemsName)
                        {
                            if (SearchPattern.IsMatch(ItemName.ToLower()))
                            {
                                SpawnerMatch ms = new SpawnerMatch();

                                ms.Item = false;
                                ms.Sp   = sp;

                                // Check if item type

                                Type   TestType = SpawnerType.GetType(ItemName);
                                string strTest  = TestType.ToString();

                                Regex InvalidPatt = new Regex("^Server.Item");

                                if (InvalidPatt.IsMatch(strTest))
                                {
                                    ms.Item = true;
                                }
                                // We have a match! Create new match struct
                                // and add to return reference list

                                if (sp.Running == true)
                                {
                                    ms.Status = "on";
                                }
                                else
                                {
                                    ms.Status = "off";
                                }

                                ms.Matched  = ItemName;
                                ms.Distance = (int)Math.Sqrt(sqr(spX) + sqr(spY));

                                SpawnerList.Add(ms);
                            }
                        }
                    }
                }
            }

            return(SpawnerList);
        }