PercentageBonusFormulaTemplate - jimdroberts/FishMMO GitHub Wiki
Defines a formula template for calculating a percentage-based bonus to a character attribute. Used to apply a scaling bonus in the FishMMO attribute system.
-
public float Percentage
The percentage multiplier to apply to the bonus attribute's value.
-
public override int CalculateBonus(CharacterAttribute self, CharacterAttribute bonusAttribute)
Calculates the percentage-based bonus to apply to the attribute. self (CharacterAttribute): The attribute being modified. bonusAttribute (CharacterAttribute): The attribute providing the bonus. Returns the product of bonusAttribute.FinalValue and Percentage, cast to int (int).
- Create a PercentageBonusFormulaTemplate ScriptableObject via the Unity editor (Assets > Create > FishMMO > Character > Attribute > Formula > Percentage Bonus Formula).
- Set the Percentage field in the Inspector to the desired multiplier (e.g., 0.1 for 10%).
- Assign the formula to a character attribute template as needed.
// Example 1: Using the percentage bonus formula
int bonus = percentageBonusFormula.CalculateBonus(attribute, bonusSource);
// Example 2: Assigning the formula to an attribute template
attributeTemplate.Formula = percentageBonusFormula;
- Use this formula for scaling bonuses that depend on another attribute's value.
- Set the Percentage field carefully to avoid unintended scaling.
- Assign formulas via ScriptableObjects for easy editor integration and reuse.
- Extend CharacterAttributeFormulaTemplate for more advanced bonus calculations.