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