package com.rs.game.player.dialogues.impl;

import com.rs.Settings;
import com.rs.game.WorldObject;
import com.rs.game.player.Skills;
import com.rs.game.player.actions.Smelting;
import com.rs.game.player.actions.Smelting.SmeltingBar;
import com.rs.game.player.actions.Smithing;
import com.rs.game.player.content.SkillsDialogue;
import com.rs.game.player.content.SkillsDialogue.SkillDialogueResult;
import com.rs.game.player.dialogues.Dialogue;
import com.rs.utils.Logger;

public class SmithingD extends Dialogue {

	private WorldObject object;
	int barIndex;
	boolean dungeoneering;
	
	@Override
	public void start() {
		object = (WorldObject) parameters[0];
		barIndex = (Integer) parameters[1];
		dungeoneering = (boolean) parameters[2];
		
		int baseLevel = Smithing.BASE_LEVEL[dungeoneering ? 1 : 0][barIndex];
		int currentLevel = player.getSkills().getLevel(Skills.SMITHING);
		if (currentLevel < baseLevel) {
			player.getDialogueManager().startDialogue("SimpleMessage", "You need a Smithing level of " + baseLevel + " to forge this bar.");
			return;
		} else if (!player.getInventory().containsItemToolBelt(dungeoneering ? Smithing.DUNG_HAMMER : Smithing.HAMMER)) {
			player.getDialogueManager().startDialogue("SimpleMessage", "You need a hammer to work the metal with.");
			return;
		}
		
		SkillsDialogue.sendSkillDialogueByProduce(player, Smithing.BUILDS[barIndex+(dungeoneering ? 6 : 0)][0]);
	}

	@Override
	public void run(int interfaceId, int componentId) {
		SkillDialogueResult result = SkillsDialogue.getResult(player);
		if(Settings.DEBUG) Logger.log(this,"produce = "+result.getProduce() +", bar = " + barIndex +", quantity = "+result.getQuantity());
		end();
		player.getActionManager().setAction(new Smithing(result.getProduce(),barIndex, result.getQuantity(), dungeoneering,object));
	}

	@Override
	public void finish() {
	}

}
