Exemplo n.º 1
0
        /// <summary>
        /// Adds to the whitelist.
        /// </summary>
        public bool AddToWhiteList(IAttributeCollection attributes, Whitelist whitelist, bool filter = true)
        {
            IAttributeCollection filtered = attributes;

            if (filter)
            {
                filtered = new AttributeCollection();

                foreach (var attribute in attributes)
                {
                    if (_vehicles.IsOnProfileWhiteList(attribute.Key))
                    {
                        filtered.AddOrReplace(attribute);
                    }
                }
            }

            Whitelist cachedWhitelist;

            if (this.TryGetCached(filtered, out cachedWhitelist, false))
            {
                foreach (var key in cachedWhitelist)
                {
                    whitelist.Add(key);
                }
                return(cachedWhitelist.Count > 0);
            }
            bool[] canTraverse;
            if (this.Add(filtered, out cachedWhitelist, out canTraverse, false))
            {
                foreach (var key in cachedWhitelist)
                {
                    whitelist.Add(key);
                }
                return(cachedWhitelist.Count > 0);
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        public override bool AddToWhiteList(IAttributeCollection attributes, Whitelist whitelist)
        {
            if (_attributesTable == null)
            {
                _attributesTable = new Table(this.Script);
                _resultsTable    = new Table(this.Script);
            }

            var traversable = false;

            // build lua table.
            _attributesTable.Clear();
            foreach (var attribute in attributes)
            {
                _attributesTable.Set(attribute.Key, DynValue.NewString(attribute.Value));
            }

            // call each function once and build the list of attributes to keep.
            foreach (var function in this.ProfileFunctions)
            {
                // call factor_and_speed function.
                _resultsTable.Clear();
                this.Script.Call(function, _attributesTable, _resultsTable);

                float val;
                if (_resultsTable.TryGetFloat("speed", out val))
                {
                    if (val != 0)
                    {
                        traversable = true;
                    }
                }

                // get the result.
                var dynAttributesToKeep = _resultsTable.Get("attributes_to_keep");
                if (dynAttributesToKeep == null)
                {
                    continue;
                }
                foreach (var attribute in dynAttributesToKeep.Table.Keys.Select(x => x.String))
                {
                    whitelist.Add(attribute);
                }
            }
            return(traversable);
        }