#include "td/game/Towers.h"
#include "td/game/World.h"

namespace td {
namespace game {

void ArcherTower::Tick(std::uint64_t delta, World* world) {
	if (m_Timer.Update(delta)) {
		std::uint8_t arrowsShot = 0;
		bool explosiveArrows = GetLevel().GetPath() == TowerPath::Bottom;
		std::uint8_t arrows = explosiveArrows ? 2 : GetLevel().GetLevel();
		for (MobPtr mob : world->GetMobList()) {
			if (IsMobInRange(mob)) {
				world->GetWorldNotifier().NotifyListeners(&WorldListener::OnArcherTowerShot, mob, this);
				m_Timer.ApplyCooldown();
				arrowsShot++;
				if (arrowsShot >= arrows)
					break;
			}
		}
	}
}

} // namespace game
} // namespace td
