Skip to main content

Add Custom Calculation

In many games you should need some Custom Calculation when you apply some damage, the damage is not directly applied, but we want to reduce it first with let's say armor, etc.

  • If you go to C++ Classes/AgateGAS/Public/Attribute you should find AGASDamageExecCalculation. It is what I've just created to reduce the incoming damage with target armor.
  • Focused on Execute_Implementation function, from there you can see we read Damage and Armor attributes in the calculation.
    float Damage = 0.f;
    // Capture optional damage value set on the damage GE as a CalculationModifier under the ExecutionCalculation
    ExecutionParams.AttemptCalculateCapturedAttributeMagnitude(DamageStatics().DamageDef, EvaluationParameters, Damage);
    Damage = FMath::Max<float>(Damage, 0.f);
    
    float Armor = 0.f;
    ExecutionParams.AttemptCalculateCapturedAttributeMagnitude(DamageStatics().ArmorDef, EvaluationParameters, Armor);
    Armor = FMath::Max<float>(Armor, 0.f);

    And then we just reduced the value (you can tweak this to become something like percentage reduction, etc).

    int32 MitigatedDamage = FMath::Max(UnmitigatedDamage - Armor, 1);
  • Okay, let's try the implementation on character. First you need to add Armor attribute in GE_CharacterAttribute.
  • Let's add 1 Armor to make the calculation simple.

    image.png

  • Then, back to GE_Burn. Remove the modifiers, because we will use Executions instead.

    image.png

    Let's just move what we've created in the Modifiers before. So add calculation class with AGASDamageExecCalculation and then add Calculations Modifiers with Damage, Override the value with 2.
  • Then, add the second Calculation Modifiers with Armor, this will be slightly different, because we want to get the Armor from the Target attribute.

    image.png

    So the different is, we set the Calculation Type as Attribute Based, and adjust the Backing Attribute with AGASAttributeSet.Armor and the Attribute Source is the Target, because we want to get the target Armor, not the Source Armor.
  • Okay let's play and you'll see the damage will only applied 1 instead of 2, because the damage is decreased by Armor.

    image.png