diff options
Diffstat (limited to 'src/Mobs/Ghast.cpp')
-rw-r--r-- | src/Mobs/Ghast.cpp | 80 |
1 files changed, 70 insertions, 10 deletions
diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index 2f1f2cf8b..40a7bdf0f 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -9,8 +9,13 @@ cGhast::cGhast(void) : - super("Ghast", mtGhast, "entity.ghast.hurt", "entity.ghast.death", "entity.ghast.ambient", 4, 4) + super("Ghast", mtGhast, "entity.ghast.hurt", "entity.ghast.death", "entity.ghast.ambient", 4, 4), + m_IsCharging(false), + m_FlightCooldown(5), + m_TicksUntilShot(10) { + SetGravity(0); + SetAirDrag(0); } @@ -34,24 +39,79 @@ void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) bool cGhast::Attack(std::chrono::milliseconds a_Dt) { - if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0)) + if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0) && (!m_IsCharging)) { - // Setting this higher gives us more wiggle room for attackrate + auto & Random = GetRandomProvider(); + auto SoundPitchMultiplier = 1.0f + (Random.RandReal(1.0f) - Random.RandReal(1.0f)) * 0.2f; + + m_World->BroadcastSoundEffect("entity.ghast.warn", GetPosition(), 4.0f, SoundPitchMultiplier * 0.9f); + m_IsCharging = true; + m_World->BroadcastEntityMetadata(*this); + return true; + } + return false; +} + + + + + +bool cGhast::DoTakeDamage(TakeDamageInfo & a_TDI) +{ + // No fall damage + if (a_TDI.DamageType == dtFalling) + { + return false; + } + + return super::DoTakeDamage(a_TDI); +} + + + + + +void cGhast::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } + + if ((m_IsCharging) && (m_TicksUntilShot-- == 0)) + { + m_TicksUntilShot = 10; + m_IsCharging = false; + m_World->BroadcastEntityMetadata(*this); + Vector3d Speed = GetLookVector() * 20; Speed.y = Speed.y + 1; - auto GhastBall = cpp14::make_unique<cGhastFireballEntity>(this, GetPosition().addedY(1), Speed); + auto GhastBall = cpp14::make_unique<cGhastFireballEntity>(this, GetPosition(), Speed); auto GhastBallPtr = GhastBall.get(); - if (!GhastBallPtr->Initialize(std::move(GhastBall), *m_World)) + GhastBallPtr->Initialize(std::move(GhastBall), *m_World); + + m_World->BroadcastSoundEffect("entity.ghast.shoot", GetPosition(), 4.0f, 1.0f); + + ResetAttackCooldown(); + } + + // TODO: Better flying + if (m_FlightCooldown-- == 0) + { + m_FlightCooldown = 5; + auto & Random = GetRandomProvider(); + auto SpeedVector = Vector3d(Random.RandReal(-0.3, 0.3), Random.RandReal(-0.4, 0.4), Random.RandReal(-0.3, 0.3)); + + if (GetPosY() > 120) { - return false; + SpeedVector = Vector3d(Random.RandReal(-0.4, 0.4), Random.RandReal(-0.45, 0.4), Random.RandReal(-0.4, 0.4)); } - ResetAttackCooldown(); - return true; + AddSpeed(SpeedVector); } - return false; } - |