summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mobs/Behaviors/BehaviorAttackerRanged.cpp')
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerRanged.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp b/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp
new file mode 100644
index 000000000..389c6b9f7
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp
@@ -0,0 +1,24 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "BehaviorAttackerRanged.h"
+#include "../Monster.h"
+#include "../../Entities/Pawn.h"
+#include "../../BlockID.h"
+#include "../../Entities/ArrowEntity.h"
+
+bool cBehaviorAttackerRanged::StrikeTarget(int a_StrikeTickCnt)
+{
+ UNUSED(a_StrikeTickCnt);
+ auto & Random = GetRandomProvider();
+ if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0))
+ {
+ Vector3d Inaccuracy = Vector3d(Random.RandReal<double>(-0.25, 0.25), Random.RandReal<double>(-0.25, 0.25), Random.RandReal<double>(-0.25, 0.25));
+ Vector3d Speed = (GetTarget()->GetPosition() + Inaccuracy - m_Parent->GetPosition()) * 5;
+ Speed.y += Random.RandInt(-1, 1);
+
+ auto Arrow = cpp14::make_unique<cArrowEntity>(m_Parent, m_Parent->GetPosX(), m_Parent->GetPosY() + 1, m_Parent->GetPosZ(), Speed);
+ auto ArrowPtr = Arrow.get();
+ ArrowPtr->Initialize(std::move(Arrow), *m_Parent->GetWorld());
+ }
+ return true; // Finish the strike. It only takes 1 tick.
+}