diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-30 14:08:57 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-30 14:08:57 +0200 |
commit | 60e24ca8b41bcfa92ab579b178d2c7adf51c3bcf (patch) | |
tree | c79d479defdcaee61cf9bc59bbc98047eb3f9b5c /src/Mobs/Behaviors/BehaviorAttacker.h | |
parent | Attacker updates (diff) | |
download | cuberite-60e24ca8b41bcfa92ab579b178d2c7adf51c3bcf.tar cuberite-60e24ca8b41bcfa92ab579b178d2c7adf51c3bcf.tar.gz cuberite-60e24ca8b41bcfa92ab579b178d2c7adf51c3bcf.tar.bz2 cuberite-60e24ca8b41bcfa92ab579b178d2c7adf51c3bcf.tar.lz cuberite-60e24ca8b41bcfa92ab579b178d2c7adf51c3bcf.tar.xz cuberite-60e24ca8b41bcfa92ab579b178d2c7adf51c3bcf.tar.zst cuberite-60e24ca8b41bcfa92ab579b178d2c7adf51c3bcf.zip |
Diffstat (limited to 'src/Mobs/Behaviors/BehaviorAttacker.h')
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttacker.h | 25 |
1 files changed, 20 insertions, 5 deletions
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; + }; |