reznok / GMCAbilitySystem

An Unreal Engine plugin that adds an ability system to the General Movement Component plugin
MIT License
27 stars 12 forks source link

Attribute refactor #51

Closed reznok closed 2 months ago

reznok commented 3 months ago

Core Change:

AttributeModifiers now have a bApplyToBaseValue flag:

    // Only affects Add modifiers
    // Should this value directly modify the Attribute's BaseValue
    // Set True for temporary effects, False for permanent effects

Applying to base value will directly modify the base value (duh :D). Otherwise it will use the Additive Modifier like how the old version does. For temporary effects, the effect will be (likely) be negated when the effect ends, or at some other point. For these kinds of effects, the total modifier is needed, as when the effect negates, it will subtract that value. This mostly matters when clamping (also in this PR).


Some Examples of this in action:

Effect That Negates At End with bApplyToBaseValue=true (Wrong Usage, as effect is temporary and negates at end)

CurrentAttributeValue: 100 (+0 Add modifier) CurrentAttribute Value gets clamped to [0, 300]. Effect applies +500 modifier with bApplyToBaseValue as true

Result: CurrentAttributeValue: 300 (+0 Add modifier)

Effect gets removed/negated. Result: CurrentAttributeValue: 0 (+0 Add modifier)

Effect That Negates At End with bApplyToBaseValue=false (Correct Usage)

CurrentAttributeValue: 100 (+0 Add modifier) CurrentAttribute Value gets clamped to [0, 300]. Effect applies +500 modifier with bApplyToBaseValue as false

Result: CurrentAttributeValue: 300 (+500 Add modifier)

Effect gets removed/negated. Result: CurrentAttributeValue: 100 (+0 Add modifier)

This really matters for "Health" attributes, where most times you want to apply the value to the base and NOT the modifier. ie, if your max health is 100, you're at 75 health, and you get healed for 50 health, you Don't want "Value: 100, AddMod:+25", as subtracting from this value (taking damage) would use that +25 as a buffer. Health change is typically a permanent change, and should apply to BaseValue, so bApplyToBaseValue should be true.


Attribute Clamping

Clamping can now be set in the AttributeData. You can set raw floats for Min/Max, or optionally use existing Attribute tags. If the tag is set, that will take priority. Example:

Health: Min = 0, Max = Attribute.MaxHealth

This change required some changes in how attributes are initialized, mainly making sure they all initialize to their correct base values before trying to apply cross-attribute clamps.

If clamps aren't modified at all, they're not used at all (opt-in).

image

Closes #46

reznok commented 3 months ago

Updates:

Removed bApplyToBaseValue from AttributeModifiers Removed bNegateAtEnd from AbilityEffects as something that is set by the user

This is replaced with the following logic:

Instant Effects and Periodic Effects: Affect Base Value, do not negate at end Duration Effects (Non-Instant, and Period == 0): Affect Modifiers, negate at end

I think this should cover ~99% of use cases

Also, SetAttributeValueByTag on the ASC now directly modifies BaseValue, which is what you probably want to do when using it.