예제 #1
0
        /// <summary>
        /// Counts the at the given location.
        /// </summary>
        /// <param name="location">The location at which to count.</param>
        /// <param name="comparer">The comparison to make.</param>
        /// <param name="value">The value to compare against.</param>
        /// <returns>True if the count passes the comparison and value provided, false otherwise.</returns>
        public bool CountObjectsOnMap(Location location, string comparer, ushort value)
        {
            FunctionComparisonType comparison = FunctionComparisonType.Undefined;

            switch (comparer.Trim())
            {
            case "=":
            case "==":
                comparison = FunctionComparisonType.Equal;
                break;

            case ">=":
                comparison = FunctionComparisonType.GreaterThanOrEqual;
                break;

            case "<=":
                comparison = FunctionComparisonType.LessThanOrEqual;
                break;

            case ">":
                comparison = FunctionComparisonType.GreaterThan;
                break;

            case "<":
                comparison = FunctionComparisonType.LessThan;
                break;
            }

            if (comparison == FunctionComparisonType.Undefined)
            {
                throw new ArgumentException($"{nameof(this.CountObjects)}: Invalid {nameof(comparer)} value '{comparer}'.", nameof(comparer));
            }

            return(this.ScriptApi.CompareCountItemsAt(location, comparison, value));
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoveUseComparisonFunction"/> class.
 /// </summary>
 /// <param name="name">The name of the comparison.</param>
 /// <param name="type">The type of the comparison to make.</param>
 /// <param name="compareIdentifier">The comparison identifier.</param>
 /// <param name="parameters">The parameters to compare.</param>
 public MoveUseComparisonFunction(string name, FunctionComparisonType type, string compareIdentifier, object[] parameters)
 {
     this.FunctionName        = name;
     this.Type                = type;
     this.CompareToIdentifier = compareIdentifier;
     this.Parameters          = parameters;
 }
 public ItemEventFunctionComparison(string name, FunctionComparisonType type, string compareIdentifier, object[] parameters)
 {
     FunctionName        = name;
     Type                = type;
     CompareToIdentifier = compareIdentifier;
     Parameters          = parameters;
 }
예제 #4
0
        public bool CompareCountItemsAt(Location location, FunctionComparisonType comparisonType, ushort value)
        {
            if (!this.TileAccessor.GetTileAt(location, out ITile tile))
            {
                return(false);
            }

            var count = tile.Ground != null ? 1 : 0;

            count += tile.Items.Count();

            return(comparisonType switch
            {
                FunctionComparisonType.Equal => count == value,
                FunctionComparisonType.GreaterThanOrEqual => count >= value,
                FunctionComparisonType.LessThanOrEqual => count <= value,
                FunctionComparisonType.GreaterThan => count > value,
                FunctionComparisonType.LessThan => count < value,

                _ => false,
            });
예제 #5
0
        /// <summary>
        /// Checks of the thing is an item, if it has the given attribute, and if that attribute has a value matching the comparison.
        /// </summary>
        /// <param name="thing">The thing to check.</param>
        /// <param name="attributeStr">The attribute to check.</param>
        /// <param name="comparer">The type of comparison to make.</param>
        /// <param name="value">The value to comapre for.</param>
        /// <returns>True if the thing is an item, has the attribute, and the value of the attribute satisfies the comparison. False otherwise.</returns>
        public bool HasInstanceAttribute(IThing thing, string attributeStr, string comparer, ushort value)
        {
            if (!Enum.TryParse(attributeStr, out ItemAttribute actualAttribute))
            {
                return(false);
            }

            FunctionComparisonType comparison = FunctionComparisonType.Undefined;

            switch (comparer.Trim())
            {
            case "=":
            case "==":
                comparison = FunctionComparisonType.Equal;
                break;

            case ">=":
                comparison = FunctionComparisonType.GreaterThanOrEqual;
                break;

            case "<=":
                comparison = FunctionComparisonType.LessThanOrEqual;
                break;

            case ">":
                comparison = FunctionComparisonType.GreaterThan;
                break;

            case "<":
                comparison = FunctionComparisonType.LessThan;
                break;
            }

            if (comparison == FunctionComparisonType.Undefined)
            {
                throw new ArgumentException($"{nameof(this.HasInstanceAttribute)}: Invalid {nameof(comparer)} value '{comparer}'.", nameof(comparer));
            }

            return(this.ScriptApi.HasInstanceAttribute(thing, actualAttribute, comparison, value));
        }