/// <summary> /// Underlying convert method /// </summary> private TNumber DoConvert <TNumber>(TNumber value, Unit unit, Prefix prefix, bool toBase) where TNumber : INumber <TNumber> { // Ignore offset allows us to avoid adding/subtracting scalars where it is not reasonable to do so. // For example, conversion of vectors. If offset is required, this will still throw an error. bool ignoreOffset = (!value.OperationsAllowed(v => v.Add(1), v => v.Subtract(1)) && Math.Abs(unit.Offset) < EPSILON); TNumber calculatedValue = value; for (int pow = 0; pow < Math.Abs(Power); pow++) { if (prefix != null) { calculatedValue = toBase ? prefix.Remove(calculatedValue) : Prefix.Apply(calculatedValue); } if (toBase ? (Power > 0) : (Power < 0)) { calculatedValue = calculatedValue.Multiply(unit.Multiplier); if (!ignoreOffset) { calculatedValue = calculatedValue.Add(unit.Offset); // TODO dimensionality with offsets may not work with compound dimensions. } } else { if (!ignoreOffset) { calculatedValue = calculatedValue.Subtract(unit.Offset); } calculatedValue = calculatedValue.Divide(unit.Multiplier); // TODO dimensionality with offsets may not work with compound dimensions. } } return(calculatedValue); }
public PrefixDef(int prefixID, Prefix prefix) { this.prefixID = prefixID; this.prefix = prefix; Item item = new Item(); item.SetDefaults("Unloaded Item"); item.value = 100000; prefix.Apply(item); categories["Positive"] = item.value >= 100000; categories["Negative"] = item.value < 100000; showcaseItem = GetShowcaseItem(prefix); }
/// <summary> /// Finds and applies a prefix to the dimension /// </summary> /// <param name="value">The value that the addition of the prefix should be applied to</param> /// <returns>A copy of the dimension with the found prefix applied, if a useful prefix could be found</returns> public Dimension ApplyPrefix <TNumber>(ref TNumber value) where TNumber : INumber <TNumber> { Dimension d = Clone(); if (d.Prefix != null) { d = RemovePrefix(ref value); } Prefix p = d.FindPrefix(value); if (p != null) { d.Prefix = p; value = p.Apply(value); } return(d); }
public void InitAffixes() { combined = new Prefix("Combined"); float avgRand = 0f; float totalRand = 0f; foreach (GPrefix prefix in prefixes) { combined.pAdd.defense += prefix.pAdd.defense; combined.pAdd.crit += prefix.pAdd.crit; combined.pAdd.mana += prefix.pAdd.mana; combined.pAdd.damage += prefix.pAdd.damage; combined.pAdd.moveSpeed += prefix.pAdd.moveSpeed; combined.pAdd.meleeSpeed += prefix.pAdd.meleeSpeed; combined.pAdd.meleeDamage += prefix.pAdd.meleeDamage; combined.pAdd.rangedDamage += prefix.pAdd.rangedDamage; combined.pAdd.magicDamage += prefix.pAdd.magicDamage; combined.pAdd.meleeCrit += prefix.pAdd.meleeCrit; combined.pAdd.rangedCrit += prefix.pAdd.rangedCrit; combined.pAdd.magicCrit += prefix.pAdd.magicCrit; combined.playerMods.AddRange(prefix.playerMods); combined.itemMods.AddRange(prefix.itemMods); combined.customRequirements.AddRange(prefix.customRequirements); combined.toolTips.AddRange(prefix.toolTips); combined.dynamicTips.AddRange(prefix.dynamicTips); //'register' delegates foreach (string name in prefix.delegates.Keys) { Delegate curDel = null; item.delegates.TryGetValue(name, out curDel); if (curDel != null) { Delegate newDel = Delegate.Combine(curDel, prefix.delegates[name]); item.delegates[name] = newDel; } else item.delegates[name] = prefix.delegates[name]; } avgRand += prefix.rarity; totalRand += 1f; } if (totalRand > 0f) { combined.AddTip("Rarity: " + avgRand); avgRand = avgRand / totalRand; int rare = Rand.SkewedRand(0, 6, avgRand); item.rare += rare; } item.prefix = 0; combined.Apply(item); if (item.rare < -1) { item.rare = -1; } if (item.rare > 6) { item.rare = 6; } }