#include "Chest.h" #include #include "Chunk.h" #include "Dimension.h" #include "Entity.h" #include "Game.h" #include "ItemSlot.h" #include "UIController.h" #include "UIDialog.h" Chest::Chest(int typeId, Framework::Vec3 pos, int dimensionId) : BasicBlock(typeId, pos, dimensionId, 1), open(0), userEntityId(0) {} void Chest::onDialogClosed(Framework::Text dialogId) { open = 0; userEntityId = 0; NetworkMessage* msg = new NetworkMessage(); msg->animateBlockBone(getDimensionId(), Game::getChunkCenter(getPos().x, getPos().y), Chunk::index(Dimension::chunkCoordinates(getPos())), 1, 1.0, Framework::Vec3(0.5f, 0.f, 0.45f), Framework::Vec3( 0.0f, 0.f, 0.f)); // close the chest over one second broadcastMessage(msg); } bool Chest::onTick(TickQueue* zQueue, int numTicks, bool& blocked) { if (open) { if (!Game::INSTANCE->zEntity(userEntityId)) { onDialogClosed(""); } } return open; } bool Chest::interact(Item* zItem, Entity* zActor, bool& itemChanged) { lock(); bool result = 0; if (open) { if (!Game::INSTANCE->zEntity(userEntityId)) open = 0; } if (!open) { result = Block::interact(zItem, zActor, itemChanged); if (result) { userEntityId = zActor->getId(); open = 1; NetworkMessage* msg = new NetworkMessage(); msg->animateBlockBone(getDimensionId(), Game::getChunkCenter(getPos().x, getPos().y), Chunk::index(Dimension::chunkCoordinates(getPos())), 1, 1.0, Framework::Vec3(0.5f, 0.f, 0.45f), Framework::Vec3(0.0f, (float)(PI / 2.0), 0.f)); // open the chest over 1 second broadcastMessage(msg); } } unlock(); return result; } void Chest::sendModelInfo(NetworkMessage* zMessage) { if (open) { zMessage->animateBlockBone(getDimensionId(), Game::getChunkCenter(getPos().x, getPos().y), Chunk::index(Dimension::chunkCoordinates(getPos())), 1, 0.0, Framework::Vec3(0.5f, 0.f, 0.45f), Framework::Vec3( 0.0f, (float)(PI / 2.0), 0.f)); // open the chest instantly } } ChestBlockType::ChestBlockType() : BasicBlockType() {} Block* ChestBlockType::createBlock( Framework::Vec3 position, int dimensionId) const { return new Chest(getItemTypeId(), position, dimensionId); } ChestBlockTypeFactory::ChestBlockTypeFactory() : BasicBlockTypeFactory() {} ChestBlockType* ChestBlockTypeFactory::createValue( Framework::JSON::JSONObject* zJson) const { return new ChestBlockType(); } ChestBlockType* ChestBlockTypeFactory::fromJson( Framework::JSON::JSONObject* zJson) const { return BasicBlockTypeFactory::fromJson(zJson); } Framework::JSON::JSONObject* ChestBlockTypeFactory::toJsonObject( ChestBlockType* zObject) const { return BasicBlockTypeFactory::toJsonObject(zObject); } JSONObjectValidationBuilder* ChestBlockTypeFactory::addToValidator( JSONObjectValidationBuilder* builder) const { return BasicBlockTypeFactory::addToValidator(builder); } const char* ChestBlockTypeFactory::getTypeToken() const { return "chest"; } const char* ChestBlockTypeFactory::getTypeName() const { return typeid(ChestBlockType).name(); }