Exemple #1
0
        private void PrimaryAttributeTest(PrimaryAttribute attr)
        {
            GameTime.time = 0;
            // Set some values
            attr.Value = attr.MinValue;
            Assert.AreEqual(attr.Value, attr.MinValue);
            attr.Value = float.MaxValue;
            Assert.AreEqual(attr.Value, attr.MaxValue);
            attr.Value = float.MinValue;
            Assert.AreEqual(attr.Value, attr.MinValue);

            // Add a modifier
            attr.AddModifier(new TimeBasedModifier("StrengthBuff", 10, 10));
            Assert.AreEqual(attr.MinValue + 10, attr.Value);

            attr.BaseValue += 1;
            Assert.AreEqual(attr.MinValue + 11, attr.Value);
            attr.BaseValue -= 1;

            // Advance in time
            for (int i = 0; i < 10; i++)
            {
                GameTime.time = i;
                Assert.AreEqual(attr.MinValue + 10, attr.Value);
            }
            // Until the modifier's life cycle is over
            GameTime.time += 1;
            Assert.AreEqual(attr.MinValue, attr.Value);

            // Add some more modifiers and advance time
            GameTime.time = 0;
            attr.AddModifier(new TimeBasedModifier("StrengthBuff", 10, 10));
            attr.AddModifier(new TimeBasedModifier("AnotherStrengthBuff", 20, 5));
            Assert.AreEqual(attr.MinValue + 30, attr.Value);

            GameTime.time = 5;
            Assert.AreEqual(attr.MinValue + 10, attr.Value);
            Assert.AreEqual(1, attr.Modifiers.Count);
            Assert.IsTrue(attr.IsModified);

            GameTime.time = 10;
            Assert.AreEqual(attr.MinValue, attr.Value);
            Assert.AreEqual(0, attr.Modifiers.Count);
            Assert.IsFalse(attr.IsModified);

            attr.Value = attr.MaxValue;
            attr.Reset();
            Assert.AreEqual(attr.MinValue, attr.Value);
        }
Exemple #2
0
        private void SecondaryAttributeTest(SecondaryAttribute attr)
        {
            // Check the default values
            Assert.AreEqual(0, attr.MinValue);
            Assert.AreEqual(99, attr.MaxValue);
            Assert.AreEqual(0, attr.Value);

            // Try directly setting it
            attr.Value = float.MaxValue;
            Assert.AreEqual(0, attr.Value);
            attr.Value = float.MinValue;
            Assert.AreEqual(0, attr.Value);

            // Change the contributing attributes
            for (int i = 0; i < 100; i++)
            {
                float xp = i * i * 100;
                Experience.Value = xp;
                Assert.AreEqual(i, attr.Value);
            }
            Experience.Reset();
            Assert.AreEqual(0, Experience.Value);
            Assert.AreEqual(0, attr.Value);
        }