1
0
Fork 0
cuberite-2a/src/Mobs/Creeper.cpp

158 lines
3.3 KiB
C++
Raw Permalink Normal View History

#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Creeper.h"
#include "../World.h"
#include "../Entities/ProjectileEntity.h"
#include "../Entities/Player.h"
cCreeper::cCreeper(void) :
2021-04-06 15:09:16 +00:00
Super("Creeper", mtCreeper, "entity.creeper.hurt", "entity.creeper.death", "entity.creeper.ambient", 0.6f, 1.7f),
m_bIsBlowing(false),
m_bIsCharged(false),
m_BurnedWithFlintAndSteel(false),
m_ExplodingTimer(0)
{
}
void cCreeper::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
2020-04-13 16:38:06 +00:00
Super::Tick(a_Dt, a_Chunk);
if (!IsTicking())
{
// The base class tick destroyed us
return;
}
if (((GetTarget() == nullptr) || !TargetIsInRange()) && !m_BurnedWithFlintAndSteel)
{
if (m_bIsBlowing)
{
m_ExplodingTimer = 0;
m_bIsBlowing = false;
m_World->BroadcastEntityMetadata(*this);
}
}
else
{
if (m_bIsBlowing)
{
2014-07-17 20:59:02 +00:00
m_ExplodingTimer += 1;
}
if ((m_ExplodingTimer == 30) && (GetHealth() > 0.0)) // only explode when not already dead
{
m_World->DoExplosionAt((m_bIsCharged ? 5 : 3), GetPosX(), GetPosY(), GetPosZ(), false, esMonster, this);
Destroy(); // Just in case we aren't killed by the explosion
}
}
}
void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer)
{
if (m_ExplodingTimer == 30)
{
// Exploded creepers drop naught but charred flesh, which Minecraft doesn't have
return;
}
unsigned int LootingLevel = 0;
2014-10-20 20:55:07 +00:00
if (a_Killer != nullptr)
{
LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
}
AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER);
2015-03-21 14:52:49 +00:00
// If the creeper was killed by a skeleton, add a random music disc drop:
if (
(a_Killer != nullptr) &&
a_Killer->IsProjectile() &&
((static_cast<cProjectileEntity *>(a_Killer))->GetCreatorUniqueID() != cEntity::INVALID_ID))
{
auto ProjectileCreatorCallback = [](cEntity & a_Entity)
2014-07-05 21:59:22 +00:00
{
return (
a_Entity.IsMob() &&
((static_cast<cMonster &>(a_Entity)).GetMobType() == mtSkeleton)
);
};
if (GetWorld()->DoWithEntityByID(static_cast<cProjectileEntity *>(a_Killer)->GetCreatorUniqueID(), ProjectileCreatorCallback))
{
2015-03-21 14:52:49 +00:00
AddRandomDropItem(a_Drops, 1, 1, static_cast<short>(m_World->GetTickRandomNumber(11) + E_ITEM_FIRST_DISC));
}
}
}
2014-04-25 22:32:30 +00:00
bool cCreeper::DoTakeDamage(TakeDamageInfo & a_TDI)
{
2020-04-13 16:38:06 +00:00
if (!Super::DoTakeDamage(a_TDI))
2014-04-25 22:32:30 +00:00
{
return false;
}
if (a_TDI.DamageType == dtLightning)
{
m_bIsCharged = true;
}
m_World->BroadcastEntityMetadata(*this);
2014-04-25 22:32:30 +00:00
return true;
}
fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack
2015-11-08 12:44:17 +00:00
bool cCreeper::Attack(std::chrono::milliseconds a_Dt)
{
UNUSED(a_Dt);
if (!m_bIsBlowing)
{
m_World->BroadcastSoundEffect("entity.creeper.primed", GetPosition(), 1.f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
m_bIsBlowing = true;
m_World->BroadcastEntityMetadata(*this);
fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack
2015-11-08 12:44:17 +00:00
return true;
}
fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack
2015-11-08 12:44:17 +00:00
return false;
2014-01-25 21:29:27 +00:00
}
void cCreeper::OnRightClicked(cPlayer & a_Player)
{
2020-04-13 16:38:06 +00:00
Super::OnRightClicked(a_Player);
2017-08-21 08:46:41 +00:00
if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_FLINT_AND_STEEL))
{
if (!a_Player.IsGameModeCreative())
{
a_Player.UseEquippedItem();
}
m_World->BroadcastSoundEffect("entity.creeper.primed", GetPosition(), 1.f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
m_bIsBlowing = true;
m_World->BroadcastEntityMetadata(*this);
m_BurnedWithFlintAndSteel = true;
}
}