// Returns damage nature of gem. public DamageNature NatureOf(Item gem) { // Implicit nature from keywords. DamageNature nature = new DamageNature(gem.Keywords); if (nature.Is(DamageSource.Attack)) { // Attacks with melee form implicitly gets melee weapon type. if ((nature.Form & DamageForm.Melee) != 0) { nature.WeaponType |= WeaponType.Melee; } // Attacks with ranged weapons implicitly gets projectile form. if (nature.Is(WeaponType.Ranged)) { nature.Form |= DamageForm.Projectile; } } else if (nature.Is(DamageSource.Cast)) // All Cast skill gems have damage on use form. { nature.Form |= DamageForm.OnUse; } if (GemIndex.ContainsKey(gem.Name)) { Gem entry = GemIndex[gem.Name]; // Override weapon type requirement if defined. if (entry.RequiredWeapon != WeaponType.Any) { nature.WeaponType = entry.RequiredWeapon; } // Ignore form. if (entry.ExcludeForm != DamageForm.Any) { nature.Form ^= entry.ExcludeForm; } // Ignore source. if (entry.ExcludeSource != DamageSource.Any) { nature.Source ^= entry.ExcludeSource; } // Include form. if (entry.IncludeForm != DamageForm.Any) { nature.Form |= entry.IncludeForm; } // Unarmed. if (entry.Unarmed) { nature.WeaponType |= WeaponType.Unarmed; } } return(nature); }
// Creates attack from gem. AttackSkill(Item gem) { Gem = gem; Name = gem.Name; Nature = ItemDB.NatureOf(gem); HitsPerAttack = ItemDB.HitsPerAttackOf(gem); IsStrikingWithBothWeaponsAtOnce = ItemDB.IsStrikingWithBothWeaponsAtOnce(gem); Effectiveness = gem.Properties.First("Damage Effectiveness: #%", 0, 100); }
// Creates attack from gem. AttackSkill(Item gem) { Gem = gem; Name = gem.Name; Nature = ItemDB.NatureOf(gem); HitsPerAttack = ItemDB.HitsPerAttackOf(gem); IsStrikingWithBothWeaponsAtOnce = ItemDB.IsStrikingWithBothWeaponsAtOnce(gem); Effectiveness = gem.Attributes.ContainsKey("Damage Effectiveness: #%") ? gem.Attributes["Damage Effectiveness: #%"][0] : 100; }
// Copy constructor. Weapon(Weapon weapon) { Item = weapon.Item; Nature = new DamageNature(weapon.Nature); Attributes = new AttributeSet(weapon.Attributes); foreach (Damage damage in weapon.Deals) { Deals.Add(new Damage(damage)); } Added = weapon.Added; }
public DamageStruct(string reason, Player from, Player to, int damage = 1, DamageNature nature = DamageNature.Normal) { From = from; To = to; Card = null; Damage = damage; this.Nature = nature; Chain = false;; Transfer = false; ByUser = true; this.reason = reason; TransferReason = string.Empty; Prevented = false; Steped = DamageStep.None; }
public void Base_Copy_Test() { var orig = new DamageNature { Form = DamageForm.DoT, Source = DamageSource.Spell, Type = DamageType.Cold, WeaponHand = WeaponHand.Main, WeaponType = WeaponType.Melee }; var result = new DamageNature(orig); Assert.AreEqual(orig.Form, result.Form); Assert.AreEqual(orig.Source, result.Source); Assert.AreEqual(orig.Type, result.Type); Assert.AreEqual(orig.WeaponHand, result.WeaponHand); Assert.AreEqual(orig.WeaponType, result.WeaponType); Assert.IsTrue(orig.Matches(result)); result.Type = DamageType.Chaos; Assert.IsTrue(orig.MatchesExceptType(result)); }
// Damage originated from specified damage but with different type. // Used in Damage.PercentOf. Damage(Damage damage, DamageType type, float min, float max) : base(damage) { Origin = new DamageNature(damage); Type = type; Min = min; Max = max; }
public AttackSource(string name, AttackSkill skill, Weapon weapon) { Name = name; if (weapon == null) // Spells get damage from gem local attributes. { Nature = new DamageNature(skill.Nature); foreach (var attr in skill.Local) { Damage damage = Damage.Create(skill.Nature, attr); if (damage != null) Deals.Add(damage); } if (skill.Gem.Attributes.ContainsKey("Cast Time: # sec")) { CastTime = skill.Gem.Attributes["Cast Time: # sec"][0]; APS = 1 / CastTime; } else APS = CastTime = 1; // Spell without Cast Time has cast time of 1 second. if (skill.Gem.Attributes.ContainsKey("Critical Strike Chance: #%")) CriticalChance = skill.Gem.Attributes["Critical Strike Chance: #%"][0]; else CriticalChance = 0; // Spell without Critical Strike Chance has none. Local = new AttributeSet(); // No local weapon attributes. } else { if ((skill.Nature.WeaponType & weapon.Nature.WeaponType) == 0) // Skill can't be used. // Override weapon type and form of skill with actual weapon (client shows damage of unuseable skills as well). Nature = new DamageNature(skill.Nature) { Form = weapon.Nature.Form, WeaponHand = weapon.Hand, WeaponType = weapon.Nature.WeaponType }; else // Narrow down weapon type and form of skill gem to actual weapon (e.g. Frenzy). Nature = new DamageNature(skill.Nature) { Form = skill.Nature.ChooseWeaponForm(weapon.Nature), // XXX: Choose between melee or projectile form according to weapon. WeaponHand = weapon.Hand, WeaponType = skill.Nature.WeaponType & weapon.Nature.WeaponType }; // XXX: If source has no form, but skill has form defined, then force form of skill. // This happens in form transition from melee to projectile with skills like Spectral Throw. if (Nature.Form == DamageForm.Any && skill.Nature.Form != DamageForm.Any) Nature.Form = skill.Nature.Form; foreach (Damage damage in weapon.Deals) Deals.Add(new Damage(damage) { Form = Nature.Form, Source = Nature.Source, WeaponHand = Nature.WeaponHand, WeaponType = Nature.WeaponType }); foreach (Damage.Added added in weapon.Added) if (weapon.Is(added.Hand)) // Added damage may require specific hand. added.Apply(this, 100); APS = weapon.Attributes["Attacks per Second: #"][0]; if (weapon.Attributes.ContainsKey("Critical Strike Chance: #%")) CriticalChance = weapon.Attributes["Critical Strike Chance: #%"][0]; else CriticalChance = 0; // Weapon without Critical Strike Chance has none. Local = weapon.Attributes; } }
public Weapon(WeaponHand hand, Item item) { Hand = hand; if (item != null) { Item = item; // Get weapon type (damage nature). if (item.Keywords == null) // Quiver or shield. { if (item.BaseType.Contains("Quiver")) Nature = new DamageNature() { WeaponType = WeaponType.Quiver }; else if (item.BaseType.Contains("Shield") || item.BaseType.Contains("Buckler") || item.BaseType == "Spiked Bundle") Nature = new DamageNature() { WeaponType = WeaponType.Shield }; else throw new Exception("Unknown weapon type: " + item.BaseType); } else // Regular weapon. foreach (string keyword in item.Keywords) if (Types.ContainsKey(keyword)) { Nature = new DamageNature() { WeaponType = Types[keyword] }; break; } // 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 attr in item.Attributes) { Attributes.Add(attr); Damage damage = Damage.Create(Nature, attr); 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); } }
// Copy constructor. Weapon(Weapon weapon) { Item = weapon.Item; Nature = new DamageNature(weapon.Nature); Attributes = new AttributeSet(weapon.Attributes); foreach (Damage damage in weapon.Deals) Deals.Add(new Damage(damage)); Added = weapon.Added; }
// Returns true if damage or its origin matches nature, false otherwise. new public bool Matches (DamageNature nature) { return nature.Matches(this) || nature.Matches(Origin); }
// Creates damage from attribute. public static Damage Create(DamageNature nature, KeyValuePair<string, List<float>> attr) { Match m = ReDamageAttribute.Match(attr.Key); if (m.Success) return new Damage(nature, m.Groups[1].Value, attr.Value[0], attr.Value[1]); else { m = ReDamageMod.Match(attr.Key); if (m.Success) return new Damage(nature, m.Groups[1].Value, attr.Value[0], attr.Value[1]); } return null; }
// Creates unarmed damage. public static Damage Create(DamageNature nature) { return new Damage(nature, UnarmedDamageRangeMin, UnarmedDamageRangeMax) { Type = DamageType.Physical }; }
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); } }
// Returns damage form narrowed down according to weapon. public DamageForm ChooseWeaponForm(DamageNature weapon) { return (Form & ~DamageForm.WeaponMask) | (Form & weapon.Form); }
public DamageNature(DamageNature nature) { Form = nature.Form; Source = nature.Source; Type = nature.Type; WeaponHand = nature.WeaponHand; WeaponType = nature.WeaponType; }
// Copy constructor. public Damage(Damage damage) : base(damage) { Origin = new DamageNature(damage.Origin); Min = damage.Min; Max = damage.Max; }
public DamageStruct(WrappedCard card, Player from, Player to, int damage = 1, DamageNature nature = DamageNature.Normal) { From = from; To = to; Card = card; Damage = damage; this.Nature = nature; Chain = false;; Transfer = false; ByUser = true; reason = string.Empty; TransferReason = string.Empty; Prevented = false; Steped = DamageStep.None; Drank = false; Marks = new List <string>(); ChainStarter = false; }
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); } }
// Creates damage from attribute. public static Damage Create(DamageNature nature, string attrName, IReadOnlyList<float> attrValues) { Match m = ReDamageAttribute.Match(attrName); if (m.Success) return new Damage(nature, m.Groups[1].Value, attrValues[0], attrValues[1]); else { m = ReDamageMod.Match(attrName); if (m.Success) return new Damage(nature, m.Groups[1].Value, attrValues[0], attrValues[1]); } return null; }
public DamageNature(DamageNature nature, string str) { Form = nature.Form; Source = nature.Source; Type = nature.Type; WeaponHand = nature.WeaponHand; WeaponType = nature.WeaponType; string[] words = str.Split(' '); foreach (string word in words) { if (Forms.ContainsKey(word)) Form |= Forms[word]; if (Types.ContainsKey(word)) Type = Types[word]; if (Weapon.Types.ContainsKey(word)) WeaponType = Weapon.Types[word]; if (Sources.ContainsKey(word)) Source = Sources[word]; } }
// Damage with specified nature but with different type. Damage(DamageNature nature, string type, float min, float max) : base(nature, type) { Origin = new DamageNature(this); Min = min; Max = max; }
public bool MatchesExceptType(DamageNature nature) { return (Form == DamageForm.Any || (nature.Form & Form) != 0) && (WeaponHand == WeaponHand.Any || (nature.WeaponHand & WeaponHand) != 0) && (WeaponType == WeaponType.Any || (nature.WeaponType & WeaponType) != 0) && (Source == DamageSource.Any || nature.Source == Source); }
// Damage from specified source with specified type. public Damage(DamageSource source, DamageType type, float min, float max) : base(source, type) { Origin = new DamageNature(Source, Type); Min = min; Max = max; }