Documentation / Tile Tick Core RPG / Programmer

Combat Internals

The code boundaries behind combat resolution, attack timing, styles, magic, ranged, projectiles, AI, death, and PvP.

Combat is split between shared RPG state/rules and network authority. Keep formulas and reusable rules transport-agnostic, and let the server-side network path decide when an attack may resolve.

Important boundaries

TypeRole
UnitCombatRuntime combat state and attack lifecycle. Exposes events for command submission, attack launch, resolved hits, blocks, statuses, and projectiles.
CombatFormulaServiceShared formula service. Provides hit chance, max hit and hit resolution helpers.
CombatStyleSetDefinitionData describing available player attack styles.
NpcCombatDefinitionDesigner combat data used by NPC combat behavior.
SpellDefinition / SpellEffectData-driven magic definition and reusable effect seams.
NetworkPlayerDeathSole current server-authoritative player death/respawn path.

Useful combat events

unitCombat.OnAttackCommandSubmitted += target => { /* presentation or diagnostics */ };
unitCombat.OnAttackLaunched += launch => { /* projectile/animation presentation */ };
unitCombat.OnAttackResolved += hit => { /* result presentation */ };
unitCombat.OnAttackBlocked += reason => { /* owner feedback */ };
unitCombat.OnProjectileLaunched += info => { /* client presentation */ };

Use events to react to combat. Do not turn presentation listeners into a second damage authority.

Formula entry points

float chance = CombatFormulaService.ComputeHitChance01(
    offensiveBaseLevel, totalAccuracyBonus,
    defensiveBaseLevel, totalDefenseBonus);

int maxHit = CombatFormulaService.ComputeMaxHit(
    damageBaseLevel, totalStrengthBonus);

Authoritative attack flow

Owner selects attack target/style
Server resolves target + readiness
Combat authority validates distance/state
Movement authority chases if needed
Gameplay tick reaches attack timing
Shared combat formulas resolve outcome
Server mutates health/resources/ammo/runes
Replicated events/state drive hit splats, projectiles, animation and UI

Extending combat safely

  • Put reusable math/status logic in shared rule/services or definitions.
  • Use stable definitions for weapons, attack styles, spells and effects.
  • Consume ammo/runes and apply damage on the server.
  • Let clients spawn projectile visuals or hit presentation from replicated launch/result data.
  • Use NetworkPlayerDeath; PlayerDeathController is obsolete.
Combat Sandbox: useful for formula balancing, but it intentionally simplifies live runtime behavior and is not proof of movement, networking, statuses, or full scene combat behavior.