import time
from threading import Thread
from core.Logger import Logger
from core.Player import CLASSES, SPE

class FightingAgent:
  def __init__(self, monitor, player) -> None:
    self.isCombatModeEnabled = False
    self.monitor = monitor
    self.player = player
    self.classRoutine = None
    self.logger = Logger("Combat Agent", player.debug)
    self.hasTarget = False
    self.combatClass = self.loadCombatClass()
    self.getRoutine()

  def loadCombatClass(self):
    return 42

  def getRoutine(self):
    if (self.player.playerClass == CLASSES.HUNTER and self.player.player.playerSpe == SPE.MARKSMANSHIP):
      from bots.fighting.hunter.marksmanship.Routine import Routine
    else:
      self.logger.log("Cannot find a Routine for your class and spe")
    self.classRoutine = Routine(self.monitor, self.player)

  def startFighting(self):
    self.player.checkConnection()
    self.classRoutine.start()
    self.isCombatModeEnabled = True
    while self.isCombatModeEnabled is True:
      time.sleep(0.1)
    self.logger.log("Combat mode is now disabled...")

  def stopFighting(self):
    self.isCombatModeEnabled = False

  def run(self):
    self.logger.log("Combat mode is now enabled...")
    
    fightingThread = Thread(
        target=self.startFighting, 
        args=(),
        name="fighting thread",
        daemon=True)
    fightingThread.start()