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); }
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"); }
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"); }
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; } } }
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")); }