#include "DefaultBlockItemDrop.h"

#include "Block.h"

DefaultBlockItemDrop::DefaultBlockItemDrop()
    : DropConfig()
{}

void DefaultBlockItemDrop::doDrop(Entity* zActor,
    Item* zItem,
    ItemSkill* zUsedSkill,
    Framework::Either<Block*, Entity*> zDestroyedObject) const
{
    if (zDestroyedObject.isA())
    {
        Item* blockItem
            = zDestroyedObject.getA()->zBlockType()->getItemFromBlock(
                zDestroyedObject.getA());
        if (blockItem)
        {
            Game::INSTANCE->spawnItem(
                zDestroyedObject.getA()->getLocation()
                    + Framework::Vec3<float>(0.5f, 0.5f, 0.5f),
                zDestroyedObject.getA()->getDimensionId(),
                blockItem);
        }
    }
}

DefaultBlockItemDropFactory::DefaultBlockItemDropFactory()
    : DropConfigFactory()
{}

JSONObjectValidationBuilder* DefaultBlockItemDropFactory::addToValidator(
    JSONObjectValidationBuilder* builder) const
{
    return DropConfigFactory::addToValidator(builder);
}

const char* DefaultBlockItemDropFactory::getTypeToken() const
{
    return "blockItem";
}

DefaultBlockItemDrop* DefaultBlockItemDropFactory::createInstance(
    Framework::JSON::JSONObject* zJson) const
{
    return new DefaultBlockItemDrop();
}

void DefaultBlockItemDropFactory::addToJson(
    Framework::JSON::JSONObject* zJson, DefaultBlockItemDrop* zObject) const
{}