#include <Item/StatefulItem/BasicTool/Pickaxe/Pickaxe.hpp>
#include <Block/Block.hpp>
#include <World/LocalWorld/LocalWorld.hpp>
#include <Utilities/Utilities.hpp>

bool Pickaxe::isEffectiveAgainst(Block &block)
{
    if ((name == "main:steelPickaxe" || name == "main:diamondPickaxe") && block.isSuffixed("OreX"))
    {
        return true;
    }

    return block.isPrefixed("stone") || (!isStone && block.isSuffixed("Ore"))
        || block.isSuffixed("Bricks") || block.name == "main:bricks";
}

Pickaxe::Pickaxe(std::string name, Material &mat, int numUses, float power, std::string displayName, bool isStone) :
    BasicTool(name, mat, numUses),
    m_power(power),
    m_displayName(displayName),
    isStone(isStone)
{}

bool Pickaxe::canDig(ItemStack &stack, Block &block)
{
    return block.canManuallyDig() || (isEffectiveAgainst(block) && uses(stack) != m_maxUses);
}

float Pickaxe::getPowerAgainst(ItemStack &stack, Block &block)
{
    return m_power;
}

std::string Pickaxe::getDisplayName(const ItemStack &stack)
{
    return m_displayName;
}

void Pickaxe::harvest(ItemStack &stack, LocalWorld &world, glm::ivec3 pos)
{
    Block *block = world.getBlockAt(pos);
    if (!block->canManuallyDig())
    {
        uses(stack)++;
    }

    world.breakBlock(pos);
}

void Pickaxe::getExtraToolTipLines(const ItemStack &stack, ToolTip &tip)
{
    BasicTool::getExtraToolTipLines(stack, tip);
    tip.addLine(formatString("Power: $+$+", GraphicsContext::colorstr(Color::toolPower), m_power));
}

Sound& Pickaxe::getDigSoundFor(ItemStack &stack, Block &block)
{
    return Sound::pickaxe;
}