Exemplo n.º 1
0
        /// <summary>
        /// Return best matching parent region for our new region or return an interferring region if found
        /// Check for Cover to make sure the returning region is not crossing edges
        /// </summary>
        public static WorldRegion GetBaseRegion(List <WorldRegion> list, Region reg, Dimensions dimension)
        {
            foreach (WorldRegion r in list)
            {
                if ((int)dimension != r.Dimension)
                {
                    continue;
                }
                if (reg.Overlap(r) == false)
                {
                    continue;
                }

                if (r.Cover(reg) == false)
                {
                    return(r); // we will catch this later
                }
                if (r.SubRegions == null)
                {
                    return(r);
                }

                WorldRegion w = GetBaseRegion(r.SubRegions, reg, dimension);

                if (w == null)
                {
                    return(r);
                }
                else
                {
                    return(w);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public void Resize(int minX, int maxX, int minY, int maxY, int minZ, int maxZ, Client player)
        {
            RegionList regions = player.Session.World.Regions;

            Region      test   = new Region(minX, maxX, minY, maxY, minZ, maxZ);
            WorldRegion parent = RegionCrossing.GetParentRegion(regions.List, this);

            if (parent == null)
            {
                player.TellSystem(Chat.Red, "parent not found");
                return;
            }

            if (player.Admin() == false)
            {
                if ((Donors.IsDonor(player) == false))
                {
                    player.TellSystem(Chat.Aqua, "Only for donors and admins may resize a region");
                    return;
                }
                //Useless since when only donors get this far:
                if (minY < 50 && (!player.Donor))
                {
                    player.TellSystem(Chat.Red, "Only admins and donors may make regions below Y=50");
                    return;
                }
                if (ResidentPermissions(player) == false)
                {
                    player.TellSystem(Chat.Yellow, "You are not a resident of this region");
                    return;
                }

                if (parent.ResidentPermissions(player) == false)
                {
                    player.TellSystem(Chat.Yellow, "You are not a resident of the parent region");
                    return;
                }
            }

            List <WorldRegion> list;

            if (parent == this)
            {
                list = player.Session.World.Regions.List;
            }
            else
            {
                list = parent.SubRegions;
            }

            //Make sure the new size overlaps the old one so we don't make huge mistakes
            if (test.Overlap(this) == false)
            {
                player.TellSystem(Chat.Red, "New size must overlap old one");
                player.TellSystem(Chat.Red, "New size " + test);
                player.TellSystem(Chat.Red, "Old size " + this.Coords());
                return;
            }

            //Check that the new size fits in the parent
            if (parent != this)
            {
                if (parent.Cover(test) == false)
                {
                    player.TellSystem(Chat.Red, "parent " + parent.Name + " is too small " + parent.Coords());
                    return;
                }
            }
            //else we are in the top level, no limit there

            //Make sure new size does not collide with siblings
            foreach (WorldRegion w in list)
            {
                if (w.Dimension != Dimension) //If toplevel "siblings" are all toplevel regions
                {
                    continue;
                }
                if (w == this)
                {
                    continue;
                }
                if (w.Overlap(test))
                {
                    player.TellSystem(Chat.Red, "new size overlap sibling " + w);
                    return;
                }
            }

            //Chech that subregions still fit into the new size
            if (SubRegions != null)
            {
                foreach (WorldRegion w in SubRegions)
                {
                    if (test.Cover(w) == false)
                    {
                        player.TellSystem(Chat.Red, "New size does not cover subregion:");
                        player.TellSystem(Chat.Red, w.ToString());
                        return;
                    }
                }
            }

            Log.WritePlayer(player, "Region Resized: from " + this + " to " + test);
            MinX = test.MinX;
            MaxX = test.MaxX;
            MinY = test.MinY;
            MaxY = test.MaxY;
            MinZ = test.MinZ;
            MaxZ = test.MaxZ;
            RegionLoader.Save(regions);
            player.TellSystem(Chat.Purple, "Region resized: " + this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Return best matching parent region for our new region or return an interferring region if found
        /// Check for Cover to make sure the returning region is not crossing edges
        /// </summary>
        public static WorldRegion GetBaseRegion(List<WorldRegion> list, Region reg, Dimensions dimension)
        {
            foreach (WorldRegion r in list)
            {
                if ((int)dimension != r.Dimension)
                    continue;
                if (reg.Overlap(r) == false)
                    continue;   
                
                if (r.Cover(reg) == false)
                    return r; // we will catch this later
                        
                if (r.SubRegions == null) 
                    return r;

                WorldRegion w = GetBaseRegion(r.SubRegions, reg, dimension);
                        
                if (w == null)
                    return r;
                else
                    return w;
            }
            return null;
        }