// • ▌ ▄ ·.  ▄▄▄·  ▄▄ • ▪   ▄▄· ▄▄▄▄·  ▄▄▄·  ▐▄▄▄  ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
//      Magicbane Emulator Project © 2013 - 2022
//                www.magicbane.com


package engine.mobileAI.Threads;

import engine.objects.Mob;
import org.pmw.tinylog.Logger;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.DelayQueue;

public enum ReSpawner implements Runnable {

    // MB Dev Notes:
    //
    // Thread acts as a throttle for messages to the client.  Mobiles are
    // respawned over a short time so as not to flood client when
    // entire camp respawns at once.  Client has a tendency to drop
    // messages when given too much to digest.

    RESPAWNER;

    public static final BlockingQueue<Mob> respawnQueue = new DelayQueue<>();

    @Override
    public void run() {

        while (true) {

            try {
                Mob mobile = respawnQueue.take();
                mobile.respawn();
            } catch (InterruptedException e) {
                Logger.error(e.toString());
            }

        }
    }

    public static void start() {
        Thread respawnThread;
        respawnThread = new Thread(RESPAWNER);
        respawnThread.setName("respawnThread");
        respawnThread.start();
    }
}
