Example #1
0
        private bool _addNewSpellToSlot(int slot, ESFRecord data, short level)
        {
            var emptySpellInDestinationSlot = _childItems.Single(x => x.Slot == slot);

            if (slot < 0 || !(emptySpellInDestinationSlot is EmptySpellIcon))
            {
                return(false);
            }

            _setSpellSlotInRegistry(slot, data.ID);
            _childItems.Remove(emptySpellInDestinationSlot);
            ((XNAControl)emptySpellInDestinationSlot).SetParent(null);
            ((XNAControl)emptySpellInDestinationSlot).Close();

            var newSpell = new SpellIcon(this, data, slot)
            {
                Level = level
            };

            var displaySlot = GetDisplaySlotFromSlot(slot);

            newSpell.SetDisplaySlot(displaySlot);

            var scrollOffset = _scroll == null ? 0 : _scroll.ScrollOffset;

            newSpell.Visible = displaySlot >= scrollOffset * SPELL_ROW_LENGTH &&
                               displaySlot < scrollOffset * SPELL_ROW_LENGTH + 2 * SPELL_ROW_LENGTH;

            _childItems.Add(newSpell);

            return(true);
        }
Example #2
0
        public void ESFRecord_InvalidPropertyReturnType_ThrowsInvalidCastException()
        {
            var rec = new ESFRecord {
                Name = ""
            };

            Assert.Throws <InvalidCastException>(() => rec.Get <int>(PubRecordProperty.GlobalName));
        }
Example #3
0
        public void ESFRecord_GetClassProperty_ThrowsArgumentOutOfRangeException()
        {
            const PubRecordProperty invalidProperty = PubRecordProperty.ClassAgi;

            var record = new ESFRecord();

            Assert.Throws <ArgumentOutOfRangeException>(() => record.Get <object>(invalidProperty));
        }
Example #4
0
        public void ESFRecord_GetGlobalPropertyName_GetsRecordName()
        {
            const string expected = "some name";
            var          rec      = new ESFRecord {
                Name = expected
            };

            var actual = rec.Get <string>(PubRecordProperty.GlobalName);

            Assert.AreEqual(expected, actual);
        }
Example #5
0
        public void ESFRecord_GetGlobalPropertyID_GetsRecordID()
        {
            const int expected = 44;
            var       rec      = new ESFRecord {
                ID = expected
            };

            var actual = rec.Get <int>(PubRecordProperty.GlobalID);

            Assert.AreEqual(expected, actual);
        }
Example #6
0
        private static byte[] GetExpectedBytes(ESFRecord rec, INumberEncoderService nes)
        {
            var ret = new List <byte>();

            ret.AddRange(nes.EncodeNumber(rec.Name.Length, 1));
            ret.AddRange(nes.EncodeNumber(rec.Shout.Length, 1));
            ret.AddRange(Encoding.ASCII.GetBytes(rec.Name));
            ret.AddRange(Encoding.ASCII.GetBytes(rec.Shout));
            ret.AddRange(GetExpectedBytesWithoutNames(rec, nes));

            return(ret.ToArray());
        }
Example #7
0
        public SpellIcon(OldActiveSpells parent, ESFRecord data, int slot)
            : base(parent, slot)
        {
            _spellData              = data;
            _spellGraphic           = ((EOGame)Game).GFXManager.TextureFromResource(GFXTypes.SpellIcons, _spellData.Icon);
            _spellGraphicSourceRect = new Rectangle(0, 0, _spellGraphic.Width / 2, _spellGraphic.Height);

            _spellLevelColor = new Texture2D(Game.GraphicsDevice, 1, 1);
            _spellLevelColor.SetData(new[] { Color.FromNonPremultiplied(0xc9, 0xb8, 0x9b, 0xff) });
            OnLevelChanged();

            _clickTime = DateTime.Now;
        }
Example #8
0
        public void ESFRecord_GetSpellPropertiesComprehensive_NoException()
        {
            var spellProperties = Enum.GetNames(typeof(PubRecordProperty))
                                  .Where(x => x.StartsWith("Spell"))
                                  .Select(x => (PubRecordProperty)Enum.Parse(typeof(PubRecordProperty), x))
                                  .ToArray();

            Assert.AreNotEqual(0, spellProperties.Length);

            var record = new ESFRecord {
                Shout = ""
            };

            foreach (var property in spellProperties)
            {
                var dummy = record.Get <object>(property);
                Assert.IsNotNull(dummy);
            }
        }
Example #9
0
        private static byte[] GetExpectedBytesWithoutNames(ESFRecord rec, INumberEncoderService nes)
        {
            var ret = new List <byte>();

            ret.AddRange(nes.EncodeNumber(rec.Icon, 2));
            ret.AddRange(nes.EncodeNumber(rec.Graphic, 2));
            ret.AddRange(nes.EncodeNumber(rec.TP, 2));
            ret.AddRange(nes.EncodeNumber(rec.SP, 2));
            ret.AddRange(nes.EncodeNumber(rec.CastTime, 1));
            ret.AddRange(Enumerable.Repeat((byte)254, 2));
            ret.AddRange(nes.EncodeNumber((byte)rec.Type, 1));
            ret.AddRange(Enumerable.Repeat((byte)254, 5));
            ret.AddRange(nes.EncodeNumber((byte)rec.TargetRestrict, 1));
            ret.AddRange(nes.EncodeNumber((byte)rec.Target, 1));
            ret.AddRange(Enumerable.Repeat((byte)254, 4));
            ret.AddRange(nes.EncodeNumber(rec.MinDam, 2));
            ret.AddRange(nes.EncodeNumber(rec.MaxDam, 2));
            ret.AddRange(nes.EncodeNumber(rec.Accuracy, 2));
            ret.AddRange(Enumerable.Repeat((byte)254, 5));
            ret.AddRange(nes.EncodeNumber(rec.HP, 2));
            ret.AddRange(Enumerable.Repeat((byte)254, 15));

            return(ret.ToArray());
        }
Example #10
0
        public void ESFRecord_DeserializeFromByteArray_HasCorrectData()
        {
            var numberEncoderService = new NumberEncoderService();
            var sourceRecord         = CreateRecordWithSomeGoodTestData();
            var sourceRecordBytes    = GetExpectedBytesWithoutNames(sourceRecord, numberEncoderService);

            var record = new ESFRecord {
                ID = sourceRecord.ID, Name = sourceRecord.Name, Shout = sourceRecord.Shout
            };

            record.DeserializeFromByteArray(sourceRecordBytes, numberEncoderService);

            var properties = record.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            Assert.IsTrue(properties.Length > 0);

            foreach (var property in properties)
            {
                var expectedValue = property.GetValue(sourceRecord);
                var actualValue   = property.GetValue(record);

                Assert.AreEqual(expectedValue, actualValue, "Property: {0}", property.Name);
            }
        }
Example #11
0
        public void ESFRecord_DeserializeFromByteArray_InvalidArrayLength_ThrowsException()
        {
            var record = new ESFRecord();

            Assert.Throws <ArgumentOutOfRangeException>(() => record.DeserializeFromByteArray(new byte[] { 1, 2, 3 }, new NumberEncoderService()));
        }