From 60e24ca8b41bcfa92ab579b178d2c7adf51c3bcf Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Wed, 30 Aug 2017 15:08:57 +0300 Subject: BehaviorAttacker --- src/Mobs/Behaviors/BehaviorAttacker.h | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/Mobs/Behaviors/BehaviorAttacker.h') diff --git a/src/Mobs/Behaviors/BehaviorAttacker.h b/src/Mobs/Behaviors/BehaviorAttacker.h index 4573f9a4a..099cb1987 100644 --- a/src/Mobs/Behaviors/BehaviorAttacker.h +++ b/src/Mobs/Behaviors/BehaviorAttacker.h @@ -24,25 +24,38 @@ public: void SetAttackDamage(int a_AttackDamage); // Behavior functions - virtual bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; void Destroyed() override; - virtual void PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + void PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; void DoTakeDamage(TakeDamageInfo & a_TDI) override; /** Returns the target pointer, or a nullptr if we're not targeting anyone. */ cPawn * GetTarget(); - /** Sets a new target. Forgets the older target if present. */ + /** Sets a new target. Forgets the older target if present. Set this to nullptr to unset target. */ void SetTarget(cPawn * a_Target); + + /** Makes the mob strike a target the next tick. Ignores the strike cooldown. + * Ignored if already striking or if no target is set. */ + void StrikeTarget(); + + /** Makes the mob strike a target the next tick only if the strike cooldown permits it. + * Ignored if already striking or if no target is set. */ + void StrikeTargetIfReady(); protected: - virtual void StrikeTarget() = 0; + + /** Called when the actual attack should be made. Will be called again and again every tick until + it returns false. a_StrikeTickCnt tracks how many times it was called. It is 1 the first call. + It increments by 1 each call. This mechanism allows multi-tick attacks, like blazes shooting multiple + fireballs, but most attacks are single tick and return true the first call. */ + virtual bool StrikeTarget(std::chrono::milliseconds a_Dt, cChunk & a_Chunk, int a_StrikeTickCnt) = 0; // Target related methods bool TargetIsInStrikeRadius(); bool TargetIsInStrikeRadiusAndLineOfSight(); bool TargetOutOfSight(); - void StrikeTargetIfReady(); + void StrikeTargetIfReady(std::chrono::milliseconds a_Dt, cChunk & a_Chunk); // Cooldown stuff void ResetStrikeCooldown(); @@ -64,4 +77,6 @@ private: // The mob we want to attack cPawn * m_Target; + int m_StrikeTickCnt; + }; -- cgit v1.2.3