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"
|
2013-11-27 03:17:25 -05:00
|
|
|
#include "json/json.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-14 09:37:09 -05:00
|
|
|
cJukeboxEntity::cJukeboxEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
|
|
|
|
super(E_BLOCK_JUKEBOX, a_BlockX, a_BlockY, a_BlockZ, a_World),
|
|
|
|
m_Record(0)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cJukeboxEntity::~cJukeboxEntity()
|
|
|
|
{
|
2013-11-14 10:05:55 -05:00
|
|
|
EjectRecord();
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cJukeboxEntity::UsedBy(cPlayer * a_Player)
|
|
|
|
{
|
2014-02-21 16:26:04 -05:00
|
|
|
if (IsPlayingRecord())
|
|
|
|
{
|
|
|
|
EjectRecord();
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2013-11-10 17:20:25 -05:00
|
|
|
m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, 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;
|
|
|
|
Drops.push_back(cItem(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);
|
|
|
|
m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-14 10:05:55 -05:00
|
|
|
bool cJukeboxEntity::LoadFromJson(const Json::Value & a_Value)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
m_PosX = a_Value.get("x", 0).asInt();
|
|
|
|
m_PosY = a_Value.get("y", 0).asInt();
|
|
|
|
m_PosZ = a_Value.get("z", 0).asInt();
|
|
|
|
|
|
|
|
m_Record = a_Value.get("Record", 0).asInt();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-14 10:05:55 -05:00
|
|
|
void cJukeboxEntity::SaveToJson(Json::Value & a_Value)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
a_Value["x"] = m_PosX;
|
|
|
|
a_Value["y"] = m_PosY;
|
|
|
|
a_Value["z"] = m_PosZ;
|
|
|
|
|
|
|
|
a_Value["Record"] = m_Record;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|