Esempio n. 1
0
        public void SerializationTest()
        {
            Assert.IsTrue(typeof(PrimaryAttribute).IsSerializable);
            Assert.IsTrue(typeof(SecondaryAttribute).IsSerializable);
            Assert.IsTrue(typeof(VolumeAttribute).IsSerializable);

            var random = new Random();

            // Serialize a PrimaryAttribute
            Body.Value    = random.Next(10, 500);
            Body.MinValue = random.Next(0, 9);
            Body.MaxValue = random.Next(501, 999);
            Body.AddModifier(new TimeBasedModifier("Test", 10, 10));
            BinarySerialize(Body);

            // Binary deserialization of PrimaryAttribute
            PrimaryAttribute binarySerializedBody = (PrimaryAttribute)BinaryDeserialize(Body);

            Assert.AreEqual(Body.Value, binarySerializedBody.Value);
            Assert.AreEqual(Body.MinValue, binarySerializedBody.MinValue);
            Assert.AreEqual(Body.MaxValue, binarySerializedBody.MaxValue);
            PrimaryAttributeTest(binarySerializedBody);

            // Serialize a SecondaryAttribute
            Experience.Value = 100;
            BinarySerialize(Level);

            // Binary deserialization of SecondaryAttribute
            SecondaryAttribute binarySerializedLevel = (SecondaryAttribute)BinaryDeserialize(Level);

            Assert.AreEqual(Level.Value, binarySerializedLevel.Value);
            Assert.AreEqual(1, binarySerializedLevel.Attributes.Length);
            Experience.Value = 0;
            binarySerializedLevel.Attributes = new BaseAttribute[] { Experience };
            binarySerializedLevel.Value      = binarySerializedLevel.MaxValue;
            SecondaryAttributeTest(binarySerializedLevel);

            // Serialize a VolumeAttribute
            Body.MinValue = 0;
            Body.MaxValue = 999;
            Body.Value    = 0;
            Life.Value    = random.Next(0, 23);
            BinarySerialize(Life);

            // Binary deserialization of VolumeAttribute
            VolumeAttribute binarySerializedLife = (VolumeAttribute)BinaryDeserialize(Life);

            Assert.AreEqual(Life.Value, binarySerializedLife.Value);
            Assert.AreEqual(2, binarySerializedLife.Attributes.Length);
            Body.Value = 0;
            binarySerializedLife.Attributes = new BaseAttribute[] { Level, Body };
            binarySerializedLife.Value      = binarySerializedLife.MaxValue;
            VolumeTest(binarySerializedLife);
        }
Esempio n. 2
0
 public void SetUp()
 {
     GameTime.Reset();
     Body                  = new PrimaryAttribute("Body", 0, 999, 10);
     Experience            = new PrimaryAttribute("Experience", 0);
     MagicRegenerationRate = new PrimaryAttribute("MagicRegenerationRate", 0, 99, 1);
     Level                 = new SecondaryAttribute("Level",
                                                    x => (int)(Math.Sqrt(x[0].Value / 100)) * 1f,
                                                    new BaseAttribute[] { Experience }, 0, 99);
     Life = new VolumeAttribute("Life",
                                x => (int)(20 + 5 * x[0].Value + x[1].Value / 3) * 1f,
                                new BaseAttribute[] { Level, Body }, 0, 999);
     Magic = new VolumeAttribute("Magic",
                                 x => (int)(20 + 5 * x[0].Value + x[1].Value / 3) * 1f,
                                 new BaseAttribute[] { Level, Body }, 0, 999);
     Energy = new SimpleVolumeAttribute("Energy", 0, 999, 0);
 }
Esempio n. 3
0
        private void VolumeTest(VolumeAttribute volumeAttr)
        {
            GameTime.time = 0;
            // Check the default values
            Body.Value = 0;
            Assert.AreEqual(0, volumeAttr.MinValue);
            Assert.AreEqual(20, volumeAttr.MaxValue);
            Assert.AreEqual(20, volumeAttr.Value);
            Body.Value = 10;
            Assert.AreEqual(23, volumeAttr.MaxValue);
            Assert.AreEqual(20, volumeAttr.Value);
            volumeAttr.Value = 23;
            Body.Value       = 0;
            Assert.AreEqual(0, volumeAttr.MinValue);
            Assert.AreEqual(20, volumeAttr.MaxValue);
            Assert.AreEqual(20, volumeAttr.Value);
            Body.Value = 10;
            // Set the value
            volumeAttr.Value = 10;
            Assert.AreEqual(10, volumeAttr.Value);
            volumeAttr.Value -= 10;
            Assert.AreEqual(0, volumeAttr.Value);

            // Dropping below the minimum
            volumeAttr.Value = float.MinValue;
            Assert.AreEqual(0, volumeAttr.Value);

            // Exceeding the maximum
            volumeAttr.Value = float.MaxValue;
            Assert.AreEqual(23, volumeAttr.Value);

            // Change corresponding attributes
            Experience.Value = 100;
            Assert.AreEqual(28, volumeAttr.MaxValue);

            // Apply modifier and advance in time
            Body.AddModifier(new TimeBasedModifier("StrengthBuff", 11, 10));
            Assert.AreEqual(32, volumeAttr.MaxValue);
            GameTime.time = 11f;
            Assert.AreEqual(28, volumeAttr.MaxValue);

            // Reset
            volumeAttr.Value = 0;
            volumeAttr.Reset();
            Assert.AreEqual(28, volumeAttr.Value);
        }
Esempio n. 4
0
        public PlayerStats()
        {
            // Primary Attributes
            Body             = new PrimaryAttribute("Body", 0, 999, 0);
            Mind             = new PrimaryAttribute("Mind", 0, 999, 0);
            Soul             = new PrimaryAttribute("Soul", 0, 999, 0);
            Experience       = new PrimaryAttribute("Experience", 0, 980100, 0);
            AlertnessRange   = new PrimaryAttribute("AlertnessRange", 2, 999, 2);
            AttackRange      = new PrimaryAttribute("AttackRange", 1, 999, 1);
            Damage           = new PrimaryAttribute("Damage", 0, 999, 0);
            MovementSpeed    = new PrimaryAttribute("MovementSpeed", 1, 10, 1);
            Alertness        = new PrimaryAttribute("Alertness", 0, 10, 0);
            ChasePersistency = new PrimaryAttribute("ChasePersistency", 0, 100, 0);

            // Secondary Attributes
            Level = new SecondaryAttribute("Level",
                                           x => (int)(Math.Sqrt(x[0].Value / 100)) * 1f,
                                           new BaseAttribute[] { Experience }, 0, 99);
            MagicRegenerationRate = new SecondaryAttribute(
                "MagicRegenerationRate",
                x => 1 + (x[0].Value / 1000),
                new BaseAttribute[] { Mind }, 0, 99);
            LifeRegenerationRate = new SecondaryAttribute(
                "LifeRegenerationRate",
                x => 1 + (x[0].Value / 1000),
                new BaseAttribute[] { Body }, 0, 99);

            // Volume Attributes
            Life = new VolumeAttribute("Life",
                                       x => (int)(20 + 5 * x[0].Value + x[1].Value / 3) * 1f,
                                       new BaseAttribute[] { Level, Body }, 0, 999);
            Magic = new VolumeAttribute("Magic",
                                        x => (int)(20 + 5 * x[0].Value + x[1].Value / 3) * 1f,
                                        new BaseAttribute[] { Level, Soul }, 0, 999);

            AssignAttributesToDict();
        }