From 5d00247cce71aae67660623799b66f51bce2b88a Mon Sep 17 00:00:00 2001 From: DarkoGNU <42816979+DarkoGNU@users.noreply.github.com> Date: Sat, 7 May 2022 01:24:50 +0200 Subject: Implement ranged attack for snow golems. Fix failed assertion (#5417) * Implement ranged attack for snow golemas. Fix failed assertion when stopping the server * Decrease snowball speed * Adjust accuracy for snow golems * Use a getter instead of m_World --- src/Mobs/SnowGolem.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/Mobs/SnowGolem.cpp') diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index 3b66311a1..fabcfb070 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -5,6 +5,7 @@ #include "SnowGolem.h" #include "../BlockInfo.h" #include "../World.h" +#include "../Entities/ThrownSnowballEntity.h" @@ -56,3 +57,39 @@ void cSnowGolem::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } } } + + + + + +bool cSnowGolem::Attack(std::chrono::milliseconds a_Dt) +{ + UNUSED(a_Dt); + + // Comment inherited from skeletons + StopMovingToPosition(); // Todo handle this in a better way, the snowman does some uneeded recalcs due to inStateChasing + + if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0)) + { + auto & Random = GetRandomProvider(); + Vector3d Inaccuracy = Vector3d(Random.RandReal(-0.75, 0.75), Random.RandReal(-0.75, 0.75), Random.RandReal(-0.75, 0.75)); + + // The projectile is launched from the head + const auto HeadPos = GetPosition().addedY(1.5); + // It aims around the head / chest + const auto TargetPos = GetTarget()->GetPosition().addedY(GetTarget()->GetHeight() * 0.75); + // With this data, we can calculate the speed + const auto Speed = (TargetPos + Inaccuracy - HeadPos) * 5; + + auto Snowball = std::make_unique(this, HeadPos, Speed); + auto SnowballPtr = Snowball.get(); + if (!SnowballPtr->Initialize(std::move(Snowball), *GetWorld())) + { + return false; + } + + ResetAttackCooldown(); + return true; + } + return false; +} -- cgit v1.2.3