/// <summary>
        ///  Gets all layers existing in the cache for a particular entity.
        /// </summary>
        /// <param name="entityId">The entity to get all layers for.</param>
        /// <returns>All layers existing for a particular entity.</returns>
        public LayerMask[] GetLayersForEntity(string entityId)
        {
            // Get all IDs for this entity's layers.
            var layerIds = this.redisCache.Sets.GetAllMembers(this.EntityLayers(entityId));

            // Build the array to return to the caller.
            LayerMask[] layersList = new LayerMask[layerIds.Length];
            for (var i = 0; i < layerIds.Length; i++)
            {
                // Get all keys for this layer, and build the object to add to the list.
                var layerResult = this.redisCache.Hashing.GetValues(this.LayerId(entityId, layerIds[i]), DamageCapKey, DamageTypeKey, MultiplierKey);
                if (layerResult.Count == 0)
                {
                    // If no results returned, the layer must have expired, or been removed elsewhere from the entity.
                    this.RemoveLayer(entityId, layerIds[i]);
                    continue;
                }

                // Parse the numerical values from the strings grabbed from the cache.
                int damageCap  = 0;
                int multiplier = 0;

                NumericalExtensions.ParseIntFromString(ref damageCap, layerResult[DamageCapKey]);
                NumericalExtensions.ParseIntFromString(ref multiplier, layerResult[MultiplierKey]);

                layersList[i] = new LayerMask(layerResult[DamageTypeKey], (decimal)damageCap, null, (decimal)multiplier);
            }

            return(layersList);
        }
Beispiel #2
0
        public void ParseFromString_ParseFailsOnCharacters()
        {
            int    testInt    = 32;
            string testString = "NotAnInteger";

            Assert.IsFalse(NumericalExtensions.ParseIntFromString(ref testInt, testString));
            Assert.AreEqual(0, testInt);
        }
Beispiel #3
0
        public void ParseFromString_ParsesSuccessfully(string testString)
        {
            int testInt = 0;

            // Ensure it was parsed, and the number changed.
            Assert.IsTrue(NumericalExtensions.ParseIntFromString(ref testInt, testString));
            Assert.IsTrue(testInt > 0);
        }
Beispiel #4
0
 public static MathNet.Numerics.LinearAlgebra.Vector <T> vector <T>(int n)
     where T : struct, System.IEquatable <T>, System.IFormattable
 {
     if (typeof(T) == typeof(double) || NumericalExtensions.IsNumericType(typeof(T)))
     {
         return
             (new MathNet.Numerics.LinearAlgebra.Double.DenseVector(n) as MathNet.Numerics.LinearAlgebra.Vector <T>);
     }
     if (typeof(T) == typeof(System.Numerics.Complex))
     {
         return
             (new MathNet.Numerics.LinearAlgebra.Complex.DenseVector(n) as
              MathNet.Numerics.LinearAlgebra.Vector <T>);
     }
     throw new System.ArgumentException("Wrong type for vector creation, consider using real or complex");
 }
Beispiel #5
0
 public void Extension_NumericalExtension_Rnd_Rounds_To_Expected_Decimal_Places(decimal d, int decimalPlaces, decimal expectedOutcome)
 {
     Assert.That(NumericalExtensions.Round(d, decimalPlaces), Is.EqualTo(expectedOutcome));
 }