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

namespace td {
namespace game {

void PoisonTower::Tick(std::uint64_t delta, World* world) {
	if (m_Timer.Update(delta)) {
		for (MobPtr mob : world->GetMobList()) {
			if (IsMobInRange(mob)) {
				if (GetLevel().GetPath() == TowerPath::Bottom) {
					world->GetMobNotifier().NotifyListeners(&MobListener::OnMobDamage, mob.get(), GetStats()->GetDamage(), this);
				} else {
					float durationSec;
					switch (GetLevel().GetLevel()) {
					case 1:
						durationSec = 5;
						break;

					case 2:
						durationSec = 15;
						break;

					case 3:
						durationSec = 30;
						break;

					case 4:
						durationSec = 1e10; // about 3 million hours. It should be enough
						break;

					default:
						durationSec = 0; // how did we get there ?
						break;
					}
					mob->AddEffect(EffectType::Poison, durationSec, this);
				}
				m_Timer.ApplyCooldown();
			}
		}
	}
}

} // namespace game
} // namespace td