protected override void ApplyToItem(AttributeAffix affix, QualityRoll quality) { Assert.IsTrue(IsApplicableToItem(affix)); MagnitudeRange magnitudeRange = affix.Range.Value; int magnitude = magnitudeRange.Interpolate(quality); tempEnhancement.ApplyWeaponAttribute(affix.Attribute, affix.Priority, magnitude); }
DamageInfo ComputeDamage(MagnitudeRange damageRange, int mitigation, int absorption, int reduction) { int rawDamage = damageRange.Interpolate(QualityRoll.GetRandom()); int afterResistance = ApplyMitigation(rawDamage, mitigation); int absorbed = rawDamage - ApplyMitigation(rawDamage, absorption); DamageInfo damageResult = new DamageInfo(rawDamage, rawDamage - afterResistance, absorbed, reduction); return(damageResult); }
DamageInfo ComputePhysicalDamage(MagnitudeRange damageRange, int armor, int critFactor, int reduction) { int mitigation = ArmorToMitigation(armor); int rawDamage = critFactor * damageRange.Interpolate(QualityRoll.GetRandom()); int afterArmor = ApplyMitigation(rawDamage, mitigation); DamageInfo damageResult = new DamageInfo(rawDamage, rawDamage - afterArmor, 0, reduction); return(damageResult); }
public override void OnEquip(IEquipContext context, QualityRoll quality) { if (rangeVariable == null) { throw new InvalidOperationException("Magnitude range not supplied to AttributeAffix."); } OnEquip(context, quality, rangeVariable.Value); }
Item BuildRare(ItemTemplate template) { template.StartBuilding(); int numPrefixes = UnityEngine.Random.Range(1, maxSuffixesOnRare); int numSuffixes = UnityEngine.Random.Range(1, maxPrefixesOnRare); foreach (var affix in GetAffixesForRareItem(template.Slot, numPrefixes, numSuffixes)) { template.AddAffix(affix, QualityRoll.GetRandom()); } // Will most likely replace with a random name generator, similar in design to how the rare enemy // name generator works. return(template.FinishBuilding($"Rare {template.Name}")); }
Item BuildMagic(ItemTemplate template) { template.StartBuilding(); var affixes = GetAffixesForRareItem(template.Slot, 1, 1); foreach (var affix in GetAffixesForRareItem(template.Slot, 1, 1)) { template.AddAffix(affix, QualityRoll.GetRandom()); } var prefix = affixes.First(aff => aff.IsPrefix); var suffix = affixes.First(aff => aff.IsSuffix); return(template.FinishBuilding($"{prefix.Name} {template.Name} of {suffix.Name}")); }
/// <summary> /// Apply an attribute affix to the item. The item will consume the affix directly if it can (e.g. weapons may /// consume MinDamage directly by adding it to their minimum damage), in which case the affix will not be applied /// to the player. /// </summary> public void AddAffix(AffixDefinition affix, QualityRoll quality) { if (!isBuilding) { throw new InvalidOperationException("Must start building before adding affixes."); } if (affix == null) { throw new ArgumentNullException("affix"); } // Double-dispatch could be used to avoid the type-sniffing, but this is a lot simpler AttributeAffix attributeAffix = affix as AttributeAffix; bool applyToItem = (attributeAffix != null) && IsApplicableToItem(attributeAffix); if (applyToItem) { ApplyToItem(attributeAffix, quality); } tempAffixes.Add(new Affix(affix, quality, applyToItem)); }
protected override void ApplyToItem(AttributeAffix affix, QualityRoll quality) { armorEnhancement.ApplyArmorAttribute(affix.Attribute, affix.Priority, affix.Range.Value.Interpolate(quality)); }
/// <summary> /// Apply the affix, identified by IsApplicableToItem, to the item. /// </summary> protected virtual void ApplyToItem(AttributeAffix affix, QualityRoll quality) { throw new ArgumentException("Affix not applicable to item."); }
/// <param name="appliedToItem">Affix was applied directly to an item, so it will do nothing when equipped.</param> public Affix(AffixDefinition definition, QualityRoll quality, bool appliedToItem = false) { affix = definition; this.quality = quality; this.appliedToItem = appliedToItem; }
public int Interpolate(QualityRoll quality) { return((int)Mathf.Lerp(min, max, quality.Value)); }
public abstract void OnEquip(IEquipContext context, QualityRoll quality);
/// <summary> /// The description of the affix appearing in the item's player-facing list of affixes, e.g. "+3 to strength", /// "+19 to all resistances", "5% chance to cast level 3 Tornado". /// </summary> public abstract string GetAffixDescription(QualityRoll quality);
AttributeEnhancement BuildEnhancement(QualityRoll quality, MagnitudeRange range) { return(new AttributeEnhancement(attribute, priority, range.Interpolate(quality))); }
/* * This overload is provided to allow for a simple run-time change to the value. Originally this * was implemented to allow a compound attribute to substitute a different value for the range without * having to rebuild new attribute affixes for every sub-attribute. e.g. a compound affix that improves * all primary stats would have references to an affix for each primary stat, but we want to provide lesser * values for the range for balance reasons (otherwise, the compound attribute would be 4x as strong as the * individual affixes). */ /// <summary> /// Provide a different value for the magnitude range than the one attached to this affix. /// </summary> public void OnEquip(IEquipContext context, QualityRoll quality, MagnitudeRange rangeOverride) { context.ApplyAttributeBuff(BuildEnhancement(quality, rangeOverride)); }
public override string GetAffixDescription(QualityRoll quality) { return(string.Format(affixFormatDescription, rangeVariable.Value.Interpolate(quality))); }