feat: add cooldown timer

This commit is contained in:
2021-11-09 19:18:24 +01:00
parent f71f69cfc2
commit 9a256a4c66
4 changed files with 39 additions and 28 deletions

View File

@@ -208,51 +208,42 @@ std::string getTowerName(TowerType type) {
void ArcherTower::tick(std::uint64_t delta, World* world) {
if (m_Timer.update(delta)) {
bool wasTowerActive = false;
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->OnArrowShot(mob, this);
wasTowerActive = true;
arrowsShot++;
if (arrowsShot >= arrows)
break;
m_Timer.applyCooldown();
}
}
if (!wasTowerActive)
m_Timer.wait();
}
}
void IceTower::tick(std::uint64_t delta, World* world) {
if (m_Timer.update(delta)) {
float damage = getStats()->getDamage();
bool wasTowerActive = false;
for (MobPtr mob : world->getMobList()) {
if (isMobInRange(mob)) {
mob->addEffect(EffectType::Slowness, 1, this); // slowness for 1s every second
mob->damage(damage, this);
wasTowerActive = true;
m_Timer.applyCooldown();
}
}
if (!wasTowerActive)
m_Timer.wait();
}
}
void MageTower::tick(std::uint64_t delta, World* world) {
if (m_Timer.update(delta)) {
bool wasTowerActive = false;
for (MobPtr mob : world->getMobList()) {
if (isMobInRange(mob)) {
mob->addEffect(EffectType::Fire, getLevel().getLevel() * 3, this);
wasTowerActive = true;
m_Timer.applyCooldown();
}
}
if (!wasTowerActive)
m_Timer.wait();
}
}