Skip to content

06_TeamsFriendlyFire — Teams • Friendly Fire

Goal

Teach how team identity affects damage through TeamRule, including blocked friendly fire, scaled friendly fire, and scaled enemy damage.

What This Scene Demonstrates

Attacker team → victim team → TeamRule scale/block decision → PreviewDamage → ApplyDamage.

This scene compares one attacker hitting an ally victim and an enemy victim. TeamRule reads team information from the damage context and the victim, then decides whether damage should be blocked or scaled.

PreviewDamage is the authoritative preview. ApplyDamage is the authoritative runtime result. TeamRule is only one rule in the pipeline, so other victim rules can still affect the final value.

What To Look For

  • Setup: The panel binds an attacker, ally victim, and enemy victim.
  • Team IDs: The panel shows attacker, ally, and enemy team IDs when ITeamProvider is present.
  • Rule: Friendly-fire permission, friendly-fire scale, and enemy scale are mirrored onto both victims.
  • Preview / Apply: Ally and enemy previews are shown side by side before either target is mutated.
  • Mini-bars: Ally/enemy preview values are shown as a fraction of the raw input amount.
  • Apply result: Attack buttons call HealthSystem.ApplyDamage and report the real result or rejection reason.

Mental model: attacker team + victim team → TeamRule branch → preview result → apply result.

Sample Scope

This scene covers:

  • Attacker, ally victim, and enemy victim bindings
  • ITeamProvider team identity checks
  • Demo fallback when attacker has no ITeamProvider
  • Same-team vs other-team comparison
  • Friendly fire disabled
  • Friendly fire enabled
  • Friendly-fire scaling
  • Enemy damage scaling
  • Side-by-side ally/enemy preview
  • Real ApplyDamage calls against ally and enemy victims
  • Detection of other damage rules that may affect final results

This scene does NOT cover:

  • Full faction systems
  • Relationship matrices
  • Networked team authority
  • Production team assignment UI
  • All possible damage-rule ordering cases
  • Isolated TeamRule-only maths when other victim rules are present

In Play Mode, this panel may add missing TeamRule components so the demo remains runnable. That is demo convenience, not a production integration pattern.

Authority Note

This scene may include a permissive sample authority setup where mutations are allowed locally for demonstration purposes.

Networking Reminder

No networking is included; integration is the developer’s responsibility.

How To Use

  1. Enter Play Mode.
  2. Open the Setup tab.
  3. Confirm the panel has:

  4. Attacker binding

  5. Ally Victim binding
  6. Enemy Victim binding
  7. HealthSystem on both victims
  8. TeamRule on both victims
  9. ITeamProvider on victims for clear team comparison
  10. Check the displayed team IDs:

  11. Attacker Team

  12. Ally Team
  13. Enemy Team
  14. Open the Rule tab.
  15. Toggle Allow Friendly Fire.
  16. Adjust Friendly Scale.
  17. Adjust Enemy Scale.
  18. Confirm the displayed rule settings:

  19. Allow Friendly Fire

  20. Friendly Fire Scale
  21. Enemy Scale
  22. Open the Preview / Apply tab.
  23. Set Amount to the raw incoming damage amount.
  24. Compare:

  25. Preview Ally (same-team)

  26. Preview Enemy (other-team)

  27. Use the mini-bars to compare ally/enemy preview output visually.

  28. Click Attack Ally (same team) to apply damage to the ally victim.
  29. Click Attack Enemy (other team) to apply damage to the enemy victim.
  30. Read the result message to confirm whether the hit was applied, blocked, absorbed, or reduced.

Failure Behaviour

  • Missing Victim Binding

  • Meaning: Ally and/or enemy victim is not assigned.

  • Fix: Assign same-team and other-team targets.

  • Missing HealthSystem

  • Meaning: One or both victims cannot preview or apply damage.

  • Fix: Add HealthSystem to the missing victim(s).

  • Missing Team Provider

  • Meaning: Team comparison may be unclear because team IDs cannot be resolved.

  • Fix: Add ITeamProvider components to victims.

  • Zero TeamId Detected

  • Meaning: One or more victims resolve TeamId = 0.

  • Fix: Assign non-zero team IDs for a clearer ally/enemy demo.

  • Attacker TeamId = 0

  • Meaning: The attacker has ITeamProvider, but its team ID is zero.

  • Fix: Assign a meaningful attacker team or rely on the demo fallback.

  • Victims Share TeamId

  • Meaning: Ally and enemy currently resolve to the same team.

  • Fix: Give the enemy a different TeamId for an other-team comparison.

  • Demo Fallback Active

  • Meaning: Attacker has no ITeamProvider, so the panel uses Ally TeamId as the attacker TeamId.

  • Fix: Add ITeamProvider to the attacker for production-style wiring.

  • Other Damage Rules Detected

  • Meaning: Preview/Apply may include more than TeamRule.

  • Fix: Temporarily remove or disable other rules if you want isolated TeamRule behaviour.

  • Rule Blocked

  • Meaning: Both victims need HealthSystem before TeamRule testing can run.

  • Fix: Return to Setup and fix missing HealthSystem bindings.

  • TeamRule Not Fully Ready

  • Meaning: A TeamRule is missing.

  • Fix: Enter Play Mode to let the demo add it, or add TeamRule manually.

  • Preview / Apply Blocked

  • Meaning: Both victims need HealthSystem before preview/apply can run.

  • Fix: Return to Setup and fix missing victim bindings.

  • Apply Requires Play Mode

  • Meaning: Attack buttons mutate health and are disabled outside Play Mode.

  • Fix: Enter Play Mode.

  • Zero Damage

  • Meaning: Amount is zero, so hits may be rejected or reduced to nothing.

  • Fix: Set Amount above 0.

  • No ally/enemy victim

  • Meaning: The selected attack target is missing.

  • Fix: Assign the missing victim in Setup.

  • AuthorityBlocked

  • Meaning: Damage was blocked by authority policy.

  • Fix: Check health authority settings or run from an allowed authority path.

  • Invincible

  • Meaning: Damage was blocked by invincibility.

  • Fix: Wait for i-frames to expire or disable the invincibility source.

  • DamageLocked

  • Meaning: Damage is currently locked.

  • Fix: Unlock damage or inspect the component/rule that enabled the lock.

  • TargetIsDead

  • Meaning: The selected victim is dead.

  • Fix: Revive or reset the victim before attacking again.

  • AbsorbedByShield

  • Meaning: Damage was fully absorbed by a shield.

  • Fix: Deplete/bypass shield or increase Amount if you want HP damage.

  • ZeroOrNegativeAmount

  • Meaning: Damage was reduced to zero by TeamRule, another rule, or damage math.

  • Fix: Enable friendly fire, raise scale, increase Amount, or inspect other rules.

Behind The Scenes

  • HealthSystem — previews and applies damage for each victim
  • DamageContext — carries attacker, victim, amount, tags, and attacker team ID
  • DamageTag — passed into the damage context
  • ITeamProvider — supplies team identity for attacker and victims
  • TeamRule — compares attacker team and victim team, then blocks or scales damage
  • TeamRule.SetAllowFriendlyFire(...) — updates friendly-fire permission
  • TeamRule.SetFriendlyFireScale(...) — updates same-team damage scale
  • TeamRule.SetEnemyScale(...) — updates other-team damage scale
  • IDamageRule — used to detect other victim rules that may affect results
  • HealthSystem.PreviewDamage(in ctx, includeShields:true) — authoritative preview
  • HealthSystem.ApplyDamage(in ctx) — authoritative runtime mutation result
  • DamageResult — reports applied state, final amount, shield bypass state, and rejection reason

The panel uses public HealthSystem, TeamRule, damage-rule, and team-provider seams only. It does not access internals, use reflection, or fake damage results.

Key Takeaway

TeamRule uses team IDs to decide whether a hit is same-team or other-team damage.

It can block friendly fire, scale friendly fire, or scale enemy damage, while HealthSystem remains the source of truth for preview and apply results.

That keeps team logic out of weapons and callers, and lets the damage pipeline handle it consistently.