combat loop

Guide for combat loop

Combat Loop

Overview

The combat loop is the heart of the PvX system, processing attacks, applying damage, and handling triggers (like XP drops and death) every game tick (600ms).

Core Mechanics

1. Targeting

  • Players and NPCs have a target field.
  • If a target is set, the entity attempts to attack.

2. Attack Speed & Cooldowns

  • Each weapon has an attack_speed (in ticks).
  • Entities have an attack_cooldown counter.
  • Mechanics:
    • Every tick, cooldown is decremented.
    • If cooldown <= 0 and target is valid/in-range:
      1. Perform Attack Roll (Accuracy vs Defence).
      2. Roll Damage (0 to Max Hit).
      3. Apply Hit.
      4. Reset cooldown = weapon_speed.
      5. Grant XP.

3. Implementation Status

  • Pending Implementation: combat_system.rs.
  • Planned Fields:
    • Player.combat_state: Holds target, cooldown.
    • GameState: Calls combat_system::process_tick() every game tick.

Special Attacks

  • Separate bar (0-100%).
  • Consumes % to perform enhanced attack.
  • Instant, often ignores cooldown or adds delay.