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
targetfield. - 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_cooldowncounter. - Mechanics:
- Every tick,
cooldownis decremented. - If
cooldown <= 0and target is valid/in-range:- Perform Attack Roll (Accuracy vs Defence).
- Roll Damage (0 to Max Hit).
- Apply Hit.
- Reset
cooldown = weapon_speed. - Grant XP.
- Every tick,
3. Implementation Status
- Pending Implementation:
combat_system.rs. - Planned Fields:
Player.combat_state: Holds target, cooldown.GameState: Callscombat_system::process_tick()every game tick.
Special Attacks
- Separate bar (0-100%).
- Consumes % to perform enhanced attack.
- Instant, often ignores cooldown or adds delay.