public void EqualsTest(string type, double value) { WeaponAttributeFactor weaponAttributeFactor = new WeaponAttributeFactor() { Type = type, Value = value, }; Assert.AreEqual(weaponAttributeFactor, weaponAttributeFactor); }
public void NotSameObjectTest() { WeaponAttributeFactor weaponAttributeFactor = new WeaponAttributeFactor() { Type = "type1333", Value = 12.0, }; Assert.AreNotEqual(new List <string>() { "asdf" }, weaponAttributeFactor); }
public void EqualsMethodTests() { WeaponAttributeFactor weaponAttributeFactor = new WeaponAttributeFactor() { Type = "type1", Value = 12.0, }; Assert.IsFalse(weaponAttributeFactor.Equals((int?)null)); Assert.IsFalse(weaponAttributeFactor.Equals(5)); Assert.IsTrue(weaponAttributeFactor.Equals(obj: weaponAttributeFactor)); }
public void NotEqualsTest(string type, double value) { WeaponAttributeFactor weaponAttributeFactor = new WeaponAttributeFactor() { Type = "type1333", Value = 12.0, }; Assert.AreNotEqual(weaponAttributeFactor, new WeaponAttributeFactor() { Type = type, Value = value, }); }
/// <summary> /// Sets the <see cref="Unit"/>'s weapon data. /// </summary> /// <param name="element">The <see cref="JsonElement"/> to read from.</param> /// <param name="unit">The data to be set from <paramref name="element"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="unit"/> is <see langword="null"/>.</exception> protected virtual void SetUnitWeapons(JsonElement element, Unit unit) { if (unit is null) { throw new ArgumentNullException(nameof(unit)); } if (element.TryGetProperty("weapons", out JsonElement weapons)) { foreach (JsonElement weaponArrayElement in weapons.EnumerateArray()) { string?weaponIdValue = weaponArrayElement.GetProperty("nameId").GetString(); if (weaponIdValue is null) { continue; } UnitWeapon unitWeapon = new UnitWeapon { WeaponNameId = weaponIdValue, Range = weaponArrayElement.GetProperty("range").GetDouble(), Period = weaponArrayElement.GetProperty("period").GetDouble(), Damage = weaponArrayElement.GetProperty("damage").GetDouble(), DamageScaling = weaponArrayElement.GetProperty("damageScale").GetDouble(), }; if (weaponArrayElement.TryGetProperty("name", out JsonElement nameElement)) { unitWeapon.Name = nameElement.ToString(); } // attribute factors if (weaponArrayElement.TryGetProperty("damageFactor", out JsonElement damageFactor)) { foreach (JsonProperty attributeFactorProperty in damageFactor.EnumerateObject()) { WeaponAttributeFactor weaponAttributeFactor = new WeaponAttributeFactor { Type = attributeFactorProperty.Name, Value = attributeFactorProperty.Value.GetDouble(), }; unitWeapon.AttributeFactors.Add(weaponAttributeFactor); } } unit.Weapons.Add(unitWeapon); } } }
private void WeaponAddEffectDamage(XElement effectDamageElement, UnitWeapon weapon) { // parent lookup string?parentValue = effectDamageElement.Attribute("parent")?.Value; if (!string.IsNullOrEmpty(parentValue)) { XElement?parentElement = GameData.MergeXmlElements(_gameData.Elements("CEffectDamage").Where(x => x.Attribute("id")?.Value == parentValue)); if (parentElement != null) { WeaponAddEffectDamage(parentElement, weapon); } } foreach (XElement element in effectDamageElement.Elements()) { string elementName = element.Name.LocalName.ToUpperInvariant(); if (elementName == "AMOUNT") { weapon.Damage = XmlParse.GetDoubleValue(weapon.WeaponNameId, element, _gameData); } else if (elementName == "ATTRIBUTEFACTOR") { string?index = element.Attribute("index")?.Value; string?value = element.Attribute("value")?.Value; WeaponAttributeFactor attributeFactor = new WeaponAttributeFactor(); if (!string.IsNullOrEmpty(index) && !string.IsNullOrEmpty(value)) { attributeFactor.Type = index; attributeFactor.Value = XmlParse.GetDoubleValue(weapon.WeaponNameId, element, _gameData); weapon.AttributeFactors.Add(attributeFactor); } } } double?scaleValue = _gameData.GetScaleValue(("Effect", effectDamageElement.Attribute("id")?.Value ?? string.Empty, "Amount")); if (scaleValue.HasValue) { weapon.DamageScaling = scaleValue.Value; } }
public void OperatorEqualTest(string type, double value, string type2, double value2) { WeaponAttributeFactor weaponAttributeFactor = new WeaponAttributeFactor() { Type = type, Value = value, }; WeaponAttributeFactor weaponAttributeFactor2 = new WeaponAttributeFactor() { Type = type2, Value = value2, }; #pragma warning disable SA1131 // Use readable conditions Assert.IsFalse(null ! == weaponAttributeFactor2); #pragma warning restore SA1131 // Use readable conditions Assert.IsFalse(weaponAttributeFactor2 == null !); Assert.IsTrue(null ! == (Announcer)null !); Assert.IsTrue(weaponAttributeFactor == weaponAttributeFactor2); Assert.AreEqual(weaponAttributeFactor.GetHashCode(), weaponAttributeFactor2 !.GetHashCode()); }
public void AddWeaponAttributeFactorTests() { UnitWeapon unitWeapon = new UnitWeapon(); WeaponAttributeFactor weaponAttributeFactor = new WeaponAttributeFactor() { Type = "type1", Value = 5, }; unitWeapon.AttributeFactors.Add(weaponAttributeFactor); Assert.IsTrue(unitWeapon.AttributeFactors.Contains(weaponAttributeFactor)); WeaponAttributeFactor weaponAttributeFactor2 = new WeaponAttributeFactor() { Type = "type1", Value = 7, }; unitWeapon.AttributeFactors.Add(weaponAttributeFactor2); Assert.AreEqual(1, unitWeapon.AttributeFactors.Count); Assert.IsTrue(unitWeapon.AttributeFactors.Contains(weaponAttributeFactor2)); }
protected override void SetTestData() { WeaponAttributeFactor weaponAttributeFactor1 = new WeaponAttributeFactor() { Type = "Minion", Value = 5, }; WeaponAttributeFactor weaponAttributeFactor2 = new WeaponAttributeFactor() { Type = "Structure", Value = 0.75, }; UnitWeapon unitWeapon = new UnitWeapon() { Damage = 56, Name = "Minion Archer Weapon", Period = 4, Range = 6, WeaponNameId = "MinionArcherWeapon", }; unitWeapon.AttributeFactors.Add(weaponAttributeFactor1); unitWeapon.AttributeFactors.Add(weaponAttributeFactor2); Unit unit = new Unit() { Name = "Minion Archer", Id = "MinionArcher", Description = new TooltipDescription(string.Empty), HyperlinkId = "MinionArcher", CUnitId = "MinionArcher", DamageType = "Minion", InnerRadius = 1.125, Radius = 1.111, Sight = 6, Speed = 4, ScalingBehaviorLink = "MinionScaling", KillXP = 210, UnitPortrait = new UnitPortrait() { TargetInfoPanelFileName = "targetInfo.png", }, }; unit.Life.LifeMax = 500; unit.Weapons.Add(unitWeapon); unit.Attributes.Add("att1"); unit.Attributes.Add("att2"); TestData.Add(unit); Unit unit2 = new Unit() { Name = "Minion Footman", Id = "MinionFootman", Description = new TooltipDescription(string.Empty), HyperlinkId = "MinionFootman", CUnitId = "MinionFootman", DamageType = "Minion", InnerRadius = 1.125, Radius = 1.111, Sight = 6, Speed = 4, }; unit2.Life.LifeMax = 900; unit2.Weapons.Add(new UnitWeapon() { Damage = 75, Name = "Minion Footman Weapon", Period = 6, Range = 7, WeaponNameId = "MinionFootmanWeapon", }); unit2.Weapons.Add(new UnitWeapon() { Damage = 56, Name = "Minion Archer Weapon", Period = 4, Range = 6, WeaponNameId = "MinionArcherWeapon", }); TestData.Add(unit2); }