PercentageBonusFormulaTemplate - jimdroberts/FishMMO GitHub Wiki

Description

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.


API Access

Fields

  • public float Percentage

    The percentage multiplier to apply to the bonus attribute's value.

Methods

  • 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).


Basic Usage

Setup

  1. Create a PercentageBonusFormulaTemplate ScriptableObject via the Unity editor (Assets > Create > FishMMO > Character > Attribute > Formula > Percentage Bonus Formula).
  2. Set the Percentage field in the Inspector to the desired multiplier (e.g., 0.1 for 10%).
  3. Assign the formula to a character attribute template as needed.

Example

// 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;

Best Practices

  • 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.
⚠️ **GitHub.com Fallback** ⚠️