// Merges specified attribute set with this one returning new attribute set. // Existing attributes have value increased by value of attribute being merged. public AttributeSet Merge(AttributeSet merge) { AttributeSet merged = Copy(); merged.Add(merge); return(merged); }
// Returns new copy of this attribute set. public AttributeSet Copy() { AttributeSet copy = new AttributeSet(); // Values must be instantiated with new. foreach (var attr in this) { copy.Add(attr.Key, new List <float>(attr.Value)); } return(copy); }
// Returns attribute set of attributes whose key matches regular expression. public AttributeSet Matches(Regex re) { AttributeSet matches = new AttributeSet(); foreach (var attr in this) { if (re.IsMatch(attr.Key)) { matches.Add(attr); } } return(matches); }
public Weapon(WeaponHand hand, Item item) { Hand = hand; if (item != null) { Item = item; // Get weapon type (damage nature). if (item.ItemGroup != ItemGroup.OneHandedWeapon && item.ItemGroup != ItemGroup.TwoHandedWeapon) // Quiver or shield. { if (item.BaseType.Name.Contains("Quiver")) { Nature = new DamageNature() { WeaponType = WeaponType.Quiver } } ; else if (item.BaseType.Name.Contains("Shield") || item.BaseType.Name.Contains("Buckler") || item.BaseType.Name == "Spiked Bundle") { Nature = new DamageNature() { WeaponType = WeaponType.Shield } } ; else { throw new Exception("Unknown weapon type: " + item.BaseType); } } else // Regular weapon. { WeaponType weaponType; if (!Enum.TryParse(item.ItemType.ToString(), out weaponType)) { if (item.ItemType == ItemType.ThrustingOneHandedSword) { weaponType = WeaponType.OneHandedSword; } else if (item.ItemType == ItemType.Sceptre) { weaponType = WeaponType.OneHandedMace; } else { throw new Exception("Unknown weapon type: " + item.BaseType); } } Nature = new DamageNature { WeaponType = weaponType }; } // If weapon is melee, it defaults to melee form. If it's ranged then projectile. if (Nature.Is(WeaponType.Melee)) { Nature.Form = DamageForm.Melee; } else if (Nature.Is(WeaponType.Ranged)) { Nature.Form = DamageForm.Projectile; } // Copy attributes and create damage dealt. foreach (var prop in item.Properties) { Attributes.Add(prop); Damage damage = Damage.Create(Nature, prop.Attribute, prop.Value); if (damage != null && damage.Type == DamageType.Physical) // Create only physical damage from item properties. { Deals.Add(damage); } } // Copy local and non-local mods and collect added non-physical damage. foreach (var mod in item.Mods) { if (mod.IsLocal) { Damage.Added added = Damage.Added.Create(Nature.Source, mod); if (added != null && added.Type != DamageType.Physical) { Added.Add(added); } } Attributes.Add(mod); } } else // No item. if (hand == WeaponHand.Main) // Only Main Hand can be Unarmed. { Nature = new DamageNature() { WeaponType = WeaponType.Unarmed }; // Implicit Unarmed attributes. Attributes.Add("Attacks per Second: #", new List <float>() { UnarmedAttacksPerSecond }); // Unarmed damage. Damage damage = Damage.Create(Nature); Deals.Add(damage); } }