package cz.jzitnik.game.threads.list;

import cz.jzitnik.game.annotations.ThreadRegistry;
import cz.jzitnik.game.entities.Player;
import lombok.AllArgsConstructor;

/**
 * A thread responsible for periodically regenerating the player's health.
 * Executes every 4 seconds and stops if the thread is interrupted.
 */
@AllArgsConstructor
@ThreadRegistry
public class HealthRegenerationThread extends Thread {
    private final Player player;

    /**
     * Runs the health regeneration loop, healing the player every 4 seconds.
     * The loop continues until the thread is interrupted.
     */
    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(4000); // Heal every 4 seconds
                player.heal();
            } catch (InterruptedException e) {
                break;
            }
        }
    }
}
