package common.init;

import java.util.Set;

import common.collect.Sets;
import common.item.Item;

public class ToolMaterial
{
    private static final int[] MAX_DAMAGE = new int[] {11, 16, 15, 13};
    private static final float[] RAD_REDUCE = new float[] {1.0f, 1.7f, 1.6f, 1.4f};
    private static final float[] MAG_REDUCE = new float[] {1.0f, 1.2f, 1.1f, 1.0f};
    
    private final int harvestLevel;
    private final int maxUses;
    private final float efficiencyOnProperMaterial;
    private final int damageVsEntity;
    private final float radiationResistance;
    private final float magicResistance;
    private final int enchantability;
    private final int maxDamageFactor;
    private final int[] damageReductionAmountArray;
    private final int armorEnchantability;
    private final boolean tools;
    private final boolean weapons;
	private final boolean extras;
	private boolean magnetic;
	private int defColor = 0xffffffff;
	private Set<Item> repair = Sets.newHashSet();

	private ToolMaterial(float rad, float mag, int level, int uses, float efficiency, int damage, int ench, boolean tools, 
    		boolean weapons, boolean extras, int auses, int aench, int r1, int r2, int r3, int r4) {
        this.harvestLevel = level;
        this.maxUses = uses;
        this.efficiencyOnProperMaterial = efficiency;
        this.damageVsEntity = damage;
        this.enchantability = ench;
        this.maxDamageFactor = auses;
        this.damageReductionAmountArray = new int[] {r1, r2, r3, r4};
        this.armorEnchantability = aench;
        this.radiationResistance = rad;
        this.magicResistance = mag;
        this.tools = tools;
        this.weapons = weapons;
        this.extras = extras;
    }
    
    protected ToolMaterial(int level) {
    	this(0.0f, 0.0f, level, 0, 0.0f, 0, 0, false, false, false, 0, 0, 0, 0, 0, 0);
    }
    
    protected ToolMaterial(int level, int uses, float efficiency, int damage, int ench, boolean weapons) {
    	this(0.0f, 0.0f, level, uses, efficiency, damage, ench, true, weapons, false, 0, ench, 0, 0, 0, 0);
    }
    
    protected ToolMaterial(int level, float rad, float mag, int uses, int damage, int ench, int auses, int aench, int r1, int r2, int r3, int r4) {
    	this(rad, mag, level, uses, 0.0F, damage, ench, false, true, false, auses, aench, r1, r2, r3, r4);
    }
    
    protected ToolMaterial(int level, float rad, float mag, int auses, int aench, int r1, int r2, int r3, int r4) {
    	this(rad, mag, 0, 0, 0.0F, 0, 0, false, false, false, auses, aench, r1, r2, r3, r4);
    }
    
    protected ToolMaterial(int level, float rad, float mag, int uses, float efficiency, int damage, int ench, boolean extras, 
    		int auses, int aench, int r1, int r2, int r3, int r4) {
    	this(rad, mag, level, uses, efficiency, damage, ench, true, true, extras, auses, aench, r1, r2, r3, r4);
    }
    
    protected ToolMaterial setDyeable(int defColor) {
    	this.defColor = defColor;
    	return this;
    }
    
    protected ToolMaterial setMagnetic() {
    	this.magnetic = true;
    	return this;
    }
    
    protected void addRepairItem(Item item) {
    	this.repair.add(item);
    }
    
    public boolean hasArmor() {
    	return this.maxDamageFactor > 0;
    }
    
    public boolean hasTools() {
    	return this.tools;
    }
    
    public boolean hasWeapons() {
    	return this.weapons;
    }
    
    public boolean hasExtras() {
    	return this.extras;
    }

    public int getMaxUses()
    {
        return this.maxUses;
    }

    public float getEfficiencyOnProperMaterial()
    {
        return this.efficiencyOnProperMaterial;
    }

    public int getDamageVsEntity()
    {
        return this.damageVsEntity;
    }

    public int getHarvestLevel()
    {
        return this.harvestLevel;
    }

    public int getEnchantability()
    {
        return this.enchantability;
    }

    public boolean isRepairItem(Item item) {
    	return this.repair.contains(item);
    }

    public int getDurability(int armorType)
    {
        return MAX_DAMAGE[armorType] * this.maxDamageFactor;
    }

    public float getRadiationReduction(int armorType)
    {
        return RAD_REDUCE[armorType] * this.radiationResistance;
    }

    public float getMagicReduction(int armorType)
    {
        return MAG_REDUCE[armorType] * this.magicResistance;
    }

    public int getDamageReductionAmount(int armorType)
    {
        return this.damageReductionAmountArray[armorType];
    }

    public int getArmorEnchantability()
    {
        return this.armorEnchantability;
    }
    
    public boolean canBeDyed() {
    	return this.defColor != 0xffffffff;
    }
    
    public int getDefaultColor() {
    	return this.defColor;
    }
    
    public boolean isMagnetic() {
    	return this.magnetic;
    }
}