Ejemplo n.º 1
0
        public void Dict_Set()
        {
            var dict = new EventedDictionary <int, string, string>("CONTEXT", false);

            var first = true;

            dict.GetReadOnlyEvent = (_) => false;

            dict.Add(1, "a");
            dict.Add(2, "b");
            dict.Add(3, "c");

            Aver.AreEqual(3, dict.Count);

            dict.ChangeEvent = (d, ct, p, k, v) =>
            {
                Aver.AreObjectsEqual(EventedDictionary <int, string, string> .ChangeType.Set, ct);
                Aver.IsTrue((first ? EventPhase.Before : EventPhase.After) == p);
                Aver.AreEqual(1, k);
                Aver.AreEqual("z", v);
                first = false;
            };

            dict[1] = "z";
            Aver.AreEqual("z", dict[1]);
        }
Ejemplo n.º 2
0
        public void Dict_Remove()
        {
            var dict = new EventedDictionary <int, string, string>("CONTEXT", false);

            var first = true;

            dict.GetReadOnlyEvent = (_) => false;

            dict.Add(1, "a");
            dict.Add(2, "b");
            dict.Add(3, "c");

            Assert.AreEqual(3, dict.Count);

            dict.ChangeEvent = (d, ct, p, k, v) =>
            {
                Assert.AreEqual(EventedDictionary <int, string, string> .ChangeType.Remove, ct);
                Assert.AreEqual(first ? EventPhase.Before : EventPhase.After, p);
                Assert.AreEqual(2, k);
                first = false;
            };

            dict.Remove(2);
            Assert.AreEqual(2, dict.Count);
        }
Ejemplo n.º 3
0
        public void Dict_Clear()
        {
            var dict = new EventedDictionary<int, string, string>("CONTEXT", false);

              var first = true;
              dict.GetReadOnlyEvent = (_) => false;

              dict.Add(1, "a");
              dict.Add(2, "b");
              dict.Add(3, "c");

              Assert.AreEqual(3, dict.Count);

              dict.ChangeEvent = (d, ct, p, k, v) =>
                            {
                              Assert.AreEqual( EventedDictionary<int, string, string>.ChangeType.Clear, ct);
                              Assert.AreEqual( first ? EventPhase.Before : EventPhase.After, p);
                              Assert.AreEqual( 0, k);
                              Assert.AreEqual( null, v);
                              first = false;
                            };

              dict.Clear();
              Assert.AreEqual( 0, dict.Count);
        }
Ejemplo n.º 4
0
        public void Dict_Readonly()
        {
            var dict = new EventedDictionary <int, string, string>("CONTEXT", false);

            var ro = false;

            dict.GetReadOnlyEvent = (l) => ro;

            dict.Add(1, "a");
            dict.Add(2, "b");
            dict.Add(3, "c");

            Aver.AreEqual(3, dict.Count);
            ro = true;

            Aver.Throws <AzosException>(() => dict.Add(4, "d"));
        }
Ejemplo n.º 5
0
        public void Dict_Add()
        {
            var dict = new EventedDictionary<int, string, string>("CONTEXT", false);

              var first = true;
              dict.GetReadOnlyEvent = (_) => false;

              dict.ChangeEvent = (d, ct, p, k, v) =>
                            {
                              Assert.AreEqual( EventedDictionary<int, string, string>.ChangeType.Add, ct);
                              Assert.AreEqual( first ? EventPhase.Before : EventPhase.After, p);
                              Assert.AreEqual( 1, k);
                              Assert.AreEqual( "a", v);
                              first = false;
                            };

              dict.Add(1, "a");
        }
Ejemplo n.º 6
0
        private static void DeductArmor(ModLoader.OnHitData box, EventedDictionary <ArmorSlot, ItemState> entityArmor)
        {
            if (box.ResultDamage > 0)
            {
                float armor  = 0;
                bool  missed = false;
                var   weap   = Weapons.WeaponFactory.GetWeapon(box);

                foreach (ArmorSlot armorSlot in ArmorSlotEnum)
                {
                    if (!entityArmor.ContainsKey(armorSlot))
                    {
                        entityArmor.Add(armorSlot, new ItemState());
                    }

                    if (!entityArmor[armorSlot].IsEmpty())
                    {
                        var item = ArmorLookup[entityArmor[armorSlot].Id];
                        armor += item.ArmorRating;

                        if (item.MissChance != 0 && item.MissChance > Pipliz.Random.NextFloat())
                        {
                            missed = true;
                            break;
                        }
                    }
                }

                if (!missed && armor != 0)
                {
                    box.ResultDamage = box.ResultDamage - box.ResultDamage * armor;

                    var hitLocation = _rand.Next(1, 100);

                    var dic = _hitChance;

                    if (!entityArmor[ArmorSlot.Shield].IsEmpty())
                    {
                        dic = _hitChanceShield;
                    }

                    foreach (var loc in dic)
                    {
                        if (!entityArmor[loc.Key].IsEmpty() && loc.Value >= hitLocation)
                        {
                            entityArmor[loc.Key].Durability--;

                            if (entityArmor[loc.Key].Durability <= 0)
                            {
                                entityArmor[loc.Key].Durability = 0;
                                entityArmor[loc.Key].Id         = default(ushort);
                            }

                            break;
                        }
                    }
                }

                if (missed)
                {
                    box.ResultDamage = 0;
                }
            }
        }
Ejemplo n.º 7
0
        public void Dict_Readonly()
        {
            var dict = new EventedDictionary<int, string, string>("CONTEXT", false);

              var ro = false;

              dict.GetReadOnlyEvent = (l) => ro;

              dict.Add(1,"a");
              dict.Add(2,"b");
              dict.Add(3,"c");

              Assert.AreEqual(3, dict.Count);
              ro = true;

              Assert.Throws<NFXException>(() =>  dict.Add(4, "d"));
        }