Пример #1
0
        /// <summary> Checks how zones affect the given player's ability to affect
        /// a block at given coordinates. </summary>
        /// <param name="coords"> Block coordinates. </param>
        /// <param name="player"> Player to check. </param>
        /// <returns> None if no zones affect the coordinate.
        /// Allow if ALL affecting zones allow the player.
        /// Deny if ANY affecting zone denies the player. </returns>
        /// <exception cref="ArgumentNullException"> If player is null. </exception>
        public PermissionOverride Check(Vector3I coords, [NotNull] Player player)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }

            PermissionOverride result = PermissionOverride.None;

            if (Cache.Length == 0)
            {
                return(result);
            }

            Zone[] zoneListCache = Cache;
            bool   anyDeny       = false;

            for (int i = 0; i < zoneListCache.Length; i++)
            {
                Zone zone = zoneListCache[i];
                if (!zone.Bounds.Contains(coords))
                {
                    continue;
                }
                // want to be able to interact with special zones, even if can't affect zoned region
                if (SpecialZone.IsSpecialAffect(zone.Name))
                {
                    return(PermissionOverride.Allow);
                }

                if (zone.Controller.Check(player.Info))
                {
                    result = PermissionOverride.Allow;
                }
                else
                {
                    anyDeny = true;
                }
            }
            return(anyDeny ? PermissionOverride.Deny : result);
        }
Пример #2
0
        /// <summary> Checks how zones affect the given player's ability to affect
        /// a block at given coordinates, in detail. </summary>
        /// <param name="coords"> Block coordinates. </param>
        /// <param name="player"> Player to check. </param>
        /// <param name="allowedZones"> Array of zones that allow the player to build. </param>
        /// <param name="deniedZones"> Array of zones that deny the player from building. </param>
        /// <returns> True if any zones were found. False if none affect the given coordinate. </returns>
        /// <exception cref="ArgumentNullException"> If player is null. </exception>
        public bool CheckDetailed(Vector3I coords, [NotNull] Player player,
                                  out Zone[] allowedZones, out Zone[] deniedZones)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            var  allowedList = new List <Zone>();
            var  deniedList  = new List <Zone>();
            bool found       = false;

            Zone[] zoneListCache = Cache;
            for (int i = 0; i < zoneListCache.Length; i++)
            {
                Zone zone = zoneListCache[i];
                if (!zone.Bounds.Contains(coords))
                {
                    continue;
                }

                found = true;
                if (SpecialZone.IsSpecialAffect(zone.Name))
                {
                    allowedList.Add(zone);
                }
                else if (zone.Controller.Check(player.Info))
                {
                    allowedList.Add(zone);
                }
                else
                {
                    deniedList.Add(zone);
                }
            }
            allowedZones = allowedList.ToArray();
            deniedZones  = deniedList.ToArray();
            return(found);
        }