From 21df3cb0d8a194461bbcec5803c5d6243f254a95 Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Tue, 12 Jan 2016 12:11:10 +0200 Subject: Fix mob attack interval --- src/Mobs/Monster.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 7d8c3de02..a24df6bc2 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -88,7 +88,7 @@ cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const A , m_AttackRate(3) , m_AttackDamage(1) , m_AttackRange(1) - , m_AttackInterval(0) + , m_AttackCoolDownTicksLeft(0) , m_SightDistance(25) , m_DropChanceWeapon(0.085f) , m_DropChanceHelmet(0.085f) @@ -214,6 +214,11 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) super::Tick(a_Dt, a_Chunk); GET_AND_VERIFY_CURRENT_CHUNK(Chunk, POSX_TOINT, POSZ_TOINT); + if (m_AttackCoolDownTicksLeft > 0) + { + m_AttackCoolDownTicksLeft -= 1; + } + if (m_Health <= 0) { // The mob is dead, but we're still animating the "puff" they leave when they die @@ -690,6 +695,15 @@ void cMonster::InStateEscaping(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) +void cMonster::ResetAttackCooldown() +{ + m_AttackCoolDownTicksLeft = static_cast(3 * 20 * m_AttackRate); // A second has 20 ticks, an attack rate of 1 means 1 hit every 3 seconds +} + + + + + void cMonster::SetCustomName(const AString & a_CustomName) { m_CustomName = a_CustomName; -- cgit v1.2.3