Formula Definition - Grim-/Talented GitHub Wiki

Experience and Talent Point Formulas

This documentation covers how to configure and customize experience and talent point calculations in the Talented mod system.

Experience Formulas

Experience formulas determine how much experience is required for each level. The system uses ExperienceFormulaDef to define these calculations.

ExperienceFormulaDef Configuration

Basic XML structure:

<Talented.ExperienceFormulaDef>
    <defName>Basic_LinearXP</defName>
    <experienceWorkerClass>Talented.LinearExperienceFormula</experienceWorkerClass>
    <baseExperience>100</baseExperience>
</Talented.ExperienceFormulaDef>

Key properties:

  • defName: Unique identifier for your formula definition
  • experienceWorkerClass: The C# class that implements the experience calculation logic
  • baseExperience: Base value used in experience calculations (default: 100)

Creating Custom Experience Formulas

To create a custom experience formula:

  1. Create a C# class that inherits from ExperienceFormulaWorker
  2. Implement your custom calculation logic
  3. Create an XML def referencing your new class
  4. Reference your formula def in your UpgradeTreeDef

Talent Point Formulas

Talent point formulas control how many talent points are awarded at different levels. The system provides two built-in workers:

Standard Talent Points (1:1)

The StandardTalentPointWorker awards one talent point per level gained.

<Talented.TalentPointFormulaDef>
    <defName>PerLevel</defName>
    <talentPointWorkerClass>Talented.StandardTalentPointWorker</talentPointWorkerClass>
</Talented.TalentPointFormulaDef>

Periodic Talent Points

The PeriodicTalentPointWorker awards points based on configurable periods.

<Talented.TalentPointFormulaDef>
    <defName>Periodic</defName>
    <talentPointWorkerClass>Talented.PeriodicTalentPointWorker</talentPointWorkerClass>
    <pointsPerPeriod>2</pointsPerPeriod>
    <levelPeriod>5</levelPeriod>
</Talented.TalentPointFormulaDef>

Configuration options:

  • pointsPerPeriod: Number of points awarded each period (default: 2)
  • levelPeriod: Number of levels between point awards (default: 5)

Example: With default settings, characters receive 2 talent points every 5 levels.

Creating Custom Talent Point Formulas

To create a custom talent point formula:

  1. Create a C# class that inherits from TalentPointFormulaWorker
  2. Override the GetTalentPointsForLevel(int levels) method
  3. Create an XML def referencing your new class
  4. Configure any custom properties your worker needs

Implementation Examples

Example 1: Accelerating Experience Requirements

<Talented.ExperienceFormulaDef>
    <defName>Accelerated_XP</defName>
    <experienceWorkerClass>MyMod.AcceleratingExperienceFormula</experienceWorkerClass>
    <baseExperience>50</baseExperience>
</Talented.ExperienceFormulaDef>

Example 2: Bonus Points at Milestones

<Talented.TalentPointFormulaDef>
    <defName>Milestone_Rewards</defName>
    <talentPointWorkerClass>MyMod.MilestoneTalentPointWorker</talentPointWorkerClass>
    <pointsPerPeriod>5</pointsPerPeriod>
    <levelPeriod>10</levelPeriod>
</Talented.TalentPointFormulaDef>

Best Practices

  1. Always provide clear defName values that indicate the formula's purpose
  2. Test your formulas with various level ranges to ensure balanced progression
  3. Consider providing documentation for custom formulas
  4. Balance point acquisition rates with your mod's progression system

Technical Notes

  • All formula workers are instantiated using Activator.CreateInstance and as such any custom classes MUST contain a parameterless constructor.
  • Custom properties must be properly initialized in your worker classes
  • Consider performance implications for complex calculations
  • Ensure your formulas handle edge cases (negative levels, zero values, etc.)
⚠️ **GitHub.com Fallback** ⚠️