/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */

package quests.java;

import com.l2jcore.Game.model.actor.instance.L2NpcInstance;
import com.l2jcore.Game.model.actor.instance.L2PcInstance;
import com.l2jcore.Game.model.quest.Quest;
import com.l2jcore.Game.model.quest.QuestState;
import com.l2jcore.Game.model.quest.State;

public class q33_MakeAPairOfDressShoes extends Quest
{
	private final static int LEATHER = 1882;
	private final static int THREAD = 1868;
	private final static int DRESS_SHOES_BOX = 7113;
	
	private State CREATED;
	private State STARTED;
	
	public q33_MakeAPairOfDressShoes(int questId, String name, String descr)
	{
		super(questId, name, descr);
		CREATED = new State("Start", this);
		STARTED = new State("Started", this);
		this.setInitialState(CREATED);

		addStartNpc(30838);
		addTalkId(30838);
		addTalkId(30164);
		addTalkId(31520);
	}

	public String onEvent(String event, QuestState st)
	{
		String htmltext = event;
		if(event.equalsIgnoreCase("30838-1.htm"))
		{
			st.set("cond", "1");
			st.setState(STARTED);
			st.playSound("ItemSound.quest_accept");
		}
		else if(event.equalsIgnoreCase("31520-1.htm"))
			st.set("cond","2");
		else if(event.equalsIgnoreCase("30838-3.htm"))
			st.set("cond","3");
		else if(event.equalsIgnoreCase("30838-5.htm"))
		{
			if(st.getQuestItemsCount(LEATHER) >= 200 && st.getQuestItemsCount(THREAD) >= 600 && st.getQuestItemsCount(57) >= 200000)
			{
				st.takeItems(LEATHER,200);
				st.takeItems(THREAD,600);
				st.takeItems(57,200000);
				st.set("cond","4");
			}
			else
				htmltext = "You don't have enough materials";
		}
		else if(event.equalsIgnoreCase("30164-1.htm"))
		{
			if(st.getQuestItemsCount(57) >= 300000)
			{
				st.takeItems(57,300000);
				st.set("cond","5");
			}
			else
				htmltext="Youn don't have enough materials";
		}
		else if(event.equalsIgnoreCase("30838-7.htm"))
		{
			st.giveItems(DRESS_SHOES_BOX,1);
			st.playSound("ItemSound.quest_finish");
			st.exitQuest(true);
		}
		return htmltext;
	}

	public String onTalk(L2NpcInstance npc, L2PcInstance talker)
	{
		QuestState st = talker.getQuestState(getName());
		String htmltext = "<html><body>You are either not carrying out your quest or don't meet the criteria.</body></html>";
		int npcId = npc.getNpcId();
		int cond = st.getInt("cond");
		if(st == null) return htmltext;
		State id = st.getState();
		if(id == CREATED)
			st.set("cond","0");
		if(npcId == 30838 && cond == 0 && st.getQuestItemsCount(DRESS_SHOES_BOX) == 0)
		{
			QuestState fwear = talker.getQuestState("37_PleaseMakeMeFormalWear");
			if(fwear != null)
				if(fwear.getInt("cond") == 7)
					htmltext = "30838-0.htm";
				else
					st.exitQuest(true);
			else
				st.exitQuest(true);
		}
		else if(id == STARTED)
		{
			if(npcId == 31520 && cond == 1)
				htmltext = "31520-0.htm";
			else if(npcId == 30838 && cond == 2)
				htmltext = "30838-2.htm";
			else if(npcId == 30838 && cond == 3)
				htmltext = "30838-4.htm";
			else if(npcId == 30164 && cond == 4)
				htmltext = "30164-0.htm";
			else if(npcId == 30838 && cond == 5)
				htmltext = "30838-6.htm";
		}
		return htmltext;
	}

	public static void main(String[] args)
	{
		_log.info("33_MakeAPairOfDressShoes:     load");
		new q33_MakeAPairOfDressShoes(33, "33_MakeAPairOfDressShoes", "Make A Pair Of Dress Shoes");    	
	}
}