diff options
author | Mat <mail@mathias.is> | 2020-03-26 18:54:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-26 18:54:40 +0100 |
commit | 84f86a467e7c289936571c738f9422868ecaaee6 (patch) | |
tree | 3145442b002ae6eb18589a3d9e6ebd0de27e4197 /src/Mobs/Ghast.cpp | |
parent | Update Core (diff) | |
download | cuberite-84f86a467e7c289936571c738f9422868ecaaee6.tar cuberite-84f86a467e7c289936571c738f9422868ecaaee6.tar.gz cuberite-84f86a467e7c289936571c738f9422868ecaaee6.tar.bz2 cuberite-84f86a467e7c289936571c738f9422868ecaaee6.tar.lz cuberite-84f86a467e7c289936571c738f9422868ecaaee6.tar.xz cuberite-84f86a467e7c289936571c738f9422868ecaaee6.tar.zst cuberite-84f86a467e7c289936571c738f9422868ecaaee6.zip |
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; } - |