Skip to content

🔥 Health — Damage Affinities

📦 Folder Overview

This folder contains affinity providers and authoring assets used by the Health system.

Affinities define how effective different damage types are against a target.

They implement IDamageAffinity and are typically consumed by rules such as AffinityRule.


🎯 Purpose

Affinities provide:

  • Per-tag damage multipliers
  • Data-driven resist and weakness systems
  • Composable victim-side behaviour

They answer:

How effective is this damage type against this target?


🧩 What Lives Here

AffinityProfile (ScriptableObject)

Reusable table mapping DamageTag to multipliers.

Behaviour:

  • Supports multi-tag masks
  • Matching entries multiply together
  • Returns null when no match is found

Use cases:

  • Enemy archetypes
  • Elemental systems
  • Equipment sets
  • Faction modifiers

AffinityProfileProvider (MonoBehaviour)

Bridges a profile into runtime.

Behaviour:

  • Implements IDamageAffinity
  • Delegates lookup to assigned profile
  • Returns null when no match or profile is missing

Use cases:

  • Shared tuning data
  • Centralised balancing

SimpleAffinityProvider (MonoBehaviour)

Inline affinity configuration.

Behaviour:

  • Inspector-based entries
  • Same matching and multiplication rules
  • Local to prefab

Use cases:

  • Prototyping
  • One-off overrides

⚠️ Important Notes

Evaluation Model

Affinities are consumed by rules (typically AffinityRule).

The rule is responsible for:

  • Enumerating tags
  • Querying all IDamageAffinity providers
  • Combining results (commonly multiplicative)
  • Handling special values such as 0

Provider Contract

Implementations should:

  • Return null for no opinion
  • Return values ≥ 0
  • Avoid allocations where possible
  • Remain side-effect free

Common conventions:

Value Meaning
0 immune
0.5 resist
1 normal
>1 weak

Boundaries

Do not:

  • Return 1 to indicate no opinion (use null)
  • Mix flat mitigation into affinity logic
  • Depend on execution order
  • Assume healing is affected

Affinities provide inputs only; behaviour is defined by rules.


🧠 Usage Guidance

Typical setup:

  1. Add DamageRuleHub
  2. Add AffinityRule
  3. Add one or more providers:

  4. AffinityProfileProvider

  5. SimpleAffinityProvider
  6. Configure values

  • Damage Rules (AffinityRule)
  • Contracts (DamageTag, DamageContext)
  • Health Abstractions