summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors/BehaviorAttacker.h
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-08-30 09:27:09 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-08-30 09:27:09 +0200
commitf29f9d45cecdd66097fc1ec287df9b6b84f11732 (patch)
tree68806cd7eb0d669d5737daf159f2ae07c9c7ac84 /src/Mobs/Behaviors/BehaviorAttacker.h
parentMuch safer raw pointers to entities (diff)
downloadcuberite-f29f9d45cecdd66097fc1ec287df9b6b84f11732.tar
cuberite-f29f9d45cecdd66097fc1ec287df9b6b84f11732.tar.gz
cuberite-f29f9d45cecdd66097fc1ec287df9b6b84f11732.tar.bz2
cuberite-f29f9d45cecdd66097fc1ec287df9b6b84f11732.tar.lz
cuberite-f29f9d45cecdd66097fc1ec287df9b6b84f11732.tar.xz
cuberite-f29f9d45cecdd66097fc1ec287df9b6b84f11732.tar.zst
cuberite-f29f9d45cecdd66097fc1ec287df9b6b84f11732.zip
Diffstat (limited to 'src/Mobs/Behaviors/BehaviorAttacker.h')
-rw-r--r--src/Mobs/Behaviors/BehaviorAttacker.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAttacker.h b/src/Mobs/Behaviors/BehaviorAttacker.h
new file mode 100644
index 000000000..67592acba
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorAttacker.h
@@ -0,0 +1,64 @@
+#pragma once
+
+class cBehaviorAttacker;
+
+#include "Behavior.h"
+class cBehaviorStriker;
+
+
+/** Grants attack capability to the mob. Note that this is not the same as agression!
+The mob may possess this trait and not attack anyone or only attack when provoked.
+Unlike most traits, this one has several forms, and therefore it is an abstract type
+You should use one of its derived classes, and you cannot use it directly. */
+class cBehaviorAttacker : public cBehavior
+{
+
+public:
+ cBehaviorAttacker();
+ void AttachToMonster(cMonster & a_Parent, cBehaviorStriker & a_ParentStriker);
+
+ // Functions our host Monster should invoke:
+ bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
+ void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
+ void Destroyed() override;
+ void PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
+ void DoTakeDamage(TakeDamageInfo & a_TDI) override;
+
+ // Our host monster will call these once it loads its config file
+ void SetAttackRate(float a_AttackRate);
+ void SetAttackRange(int a_AttackRange);
+ void SetAttackDamage(int a_AttackDamage);
+
+ /** Returns the target pointer, or a nullptr if we're not targeting anyone. */
+ cPawn * GetTarget();
+
+ /** Sets the target. */
+ void SetTarget(cPawn * a_Target);
+protected:
+ void ApproachTarget();
+ // virtual void ApproachTarget() = 0; //mobTodo
+private:
+
+ /** Our parent */
+ cMonster * m_Parent;
+ cBehaviorStriker * m_ParentStriker;
+
+ // The mob we want to attack
+ cPawn * m_Target;
+
+ // Target stuff
+ bool TargetIsInStrikeRange();
+ bool TargetOutOfSight();
+ void StrikeTarget();
+
+ // Cooldown stuff
+ void ResetStrikeCooldown();
+
+ // Our attacking parameters (Set by the setter methods, loaded from a config file in cMonster)
+ float m_AttackRate;
+ int m_AttackDamage;
+ int m_AttackRange;
+ int m_AttackCoolDownTicksLeft;
+
+ int m_TicksSinceLastDamaged; // How many ticks ago were we last damaged by a player?
+};