2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "JukeboxEntity.h"
|
|
|
|
#include "../World.h"
|
2015-11-23 18:39:19 -05:00
|
|
|
#include "../EffectID.h"
|
2014-09-26 13:13:19 -04:00
|
|
|
#include "json/value.h"
|
|
|
|
#include "Entities/Player.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-15 09:32:33 -04:00
|
|
|
cJukeboxEntity::cJukeboxEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World):
|
|
|
|
Super(a_BlockType, a_BlockMeta, a_BlockX, a_BlockY, a_BlockZ, a_World),
|
2013-11-14 09:37:09 -05:00
|
|
|
m_Record(0)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-06-15 09:32:33 -04:00
|
|
|
ASSERT(a_BlockType == E_BLOCK_JUKEBOX);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cJukeboxEntity::~cJukeboxEntity()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-15 09:32:33 -04:00
|
|
|
void cJukeboxEntity::CopyFrom(const cBlockEntity & a_Src)
|
|
|
|
{
|
|
|
|
Super::CopyFrom(a_Src);
|
2018-05-02 03:50:36 -04:00
|
|
|
auto & src = static_cast<const cJukeboxEntity &>(a_Src);
|
2017-06-15 09:32:33 -04:00
|
|
|
m_Record = src.m_Record;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-01 17:12:44 -05:00
|
|
|
bool cJukeboxEntity::UsedBy(cPlayer * a_Player)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-02-21 16:26:04 -05:00
|
|
|
if (IsPlayingRecord())
|
|
|
|
{
|
|
|
|
EjectRecord();
|
2015-12-01 17:12:44 -05:00
|
|
|
return true;
|
2014-02-21 16:26:04 -05:00
|
|
|
}
|
|
|
|
else
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
const cItem & HeldItem = a_Player->GetEquippedItem();
|
2014-02-21 16:26:04 -05:00
|
|
|
if (PlayRecord(HeldItem.m_ItemType))
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
2015-12-01 17:12:44 -05:00
|
|
|
return true;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
}
|
2015-12-01 17:12:44 -05:00
|
|
|
return false;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-21 16:26:04 -05:00
|
|
|
bool cJukeboxEntity::PlayRecord(int a_Record)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-02-21 16:26:04 -05:00
|
|
|
if (!IsRecordItem(a_Record))
|
|
|
|
{
|
|
|
|
// This isn't a Record Item
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (IsPlayingRecord())
|
|
|
|
{
|
|
|
|
// A Record is already in the Jukebox.
|
|
|
|
EjectRecord();
|
|
|
|
}
|
|
|
|
m_Record = a_Record;
|
2018-07-26 19:12:41 -04:00
|
|
|
m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), m_Record);
|
2014-02-21 16:26:04 -05:00
|
|
|
m_World->SetBlockMeta(m_PosX, m_PosY, m_PosZ, E_META_JUKEBOX_ON);
|
|
|
|
return true;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-21 16:26:04 -05:00
|
|
|
bool cJukeboxEntity::EjectRecord(void)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-02-21 16:26:04 -05:00
|
|
|
if (!IsPlayingRecord())
|
2013-11-14 10:05:55 -05:00
|
|
|
{
|
|
|
|
// There's no record here
|
2014-02-21 16:26:04 -05:00
|
|
|
return false;
|
2013-11-14 10:05:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
cItems Drops;
|
2014-10-11 22:39:55 -04:00
|
|
|
Drops.push_back(cItem(static_cast<short>(m_Record), 1, 0));
|
2014-02-21 16:26:04 -05:00
|
|
|
m_Record = 0;
|
2013-11-10 17:20:25 -05:00
|
|
|
m_World->SpawnItemPickups(Drops, m_PosX + 0.5, m_PosY + 1, m_PosZ + 0.5, 8);
|
2018-07-26 19:12:41 -04:00
|
|
|
m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), 0);
|
2014-02-21 16:26:04 -05:00
|
|
|
m_World->SetBlockMeta(m_PosX, m_PosY, m_PosZ, E_META_JUKEBOX_OFF);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cJukeboxEntity::IsPlayingRecord(void)
|
|
|
|
{
|
|
|
|
return (m_Record != 0);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-14 10:05:55 -05:00
|
|
|
int cJukeboxEntity::GetRecord(void)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return m_Record;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-14 10:05:55 -05:00
|
|
|
void cJukeboxEntity::SetRecord(int a_Record)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
m_Record = a_Record;
|
|
|
|
}
|