/*
 * 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 q10_IntoTheWorld extends Quest
{
	private final static int VERY_EXPENSIVE_NECKLACE = 7574;
	private final static int SCROLL_OF_ESCAPE_GIRAN = 7126;
	private final static int MARK_OF_TRAVELER = 7570;

	private final static int BALANKI = 30533;
	private final static int REED = 30520;
	private final static int GERALD = 30650;
	
	private State CREATED;
	private State STARTED;
	private State COMPLETED;
	
	public q10_IntoTheWorld(int questId, String name, String descr)
	{
		super(questId, name, descr);
		CREATED = new State("Start", this);
		STARTED = new State("Started", this);
		COMPLETED = new State("Completed", this);
		this.setInitialState(CREATED);

		addStartNpc(BALANKI);
		addTalkId(BALANKI);
		addTalkId(REED);
		addTalkId(GERALD);
		
		STARTED.addQuestDrop(30520,VERY_EXPENSIVE_NECKLACE,1);

	}

	public String onEvent(String event, QuestState st)
	{
		if(event.equalsIgnoreCase("30533-03.htm"))
		{
			st.set("cond", "1");
			st.setState(STARTED);
			st.playSound("ItemSound.quest_accept");
		}
		else if(event.equalsIgnoreCase("30520-02.htm"))
		{
			st.giveItems(VERY_EXPENSIVE_NECKLACE, 1);
			st.set("cond", "2");
			st.playSound("ItemSound.quest_middle");
		}
		else if(event.equalsIgnoreCase("30650-02.htm"))
		{
			st.takeItems(VERY_EXPENSIVE_NECKLACE, 1);
			st.set("cond", "3");
			st.playSound("ItemSound.quest_middle");
		}
		else if(event.equalsIgnoreCase("30520-05.htm"))
		{
			st.set("cond", "4");
			st.playSound("ItemSound.quest_middle");
		}
		else if(event.equalsIgnoreCase("30533-06.htm"))
		{
			st.giveItems(SCROLL_OF_ESCAPE_GIRAN, 1);
			st.giveItems(MARK_OF_TRAVELER, 1);
			st.exitQuest(false);
			st.playSound("ItemSound.quest_finish");
		}
		return event;
	}

	public String onTalk(L2NpcInstance npc, L2PcInstance talker)
	{
		QuestState st = talker.getQuestState(getName());
		String htmltext = "<html><body>You are either not on a quest that involves this NPC, or you don't meet this NPC's minimum quest requirements.</body></html>";
		
		if(st.getState() == COMPLETED)
		{
			htmltext = "<html><body>This quest has already been completed.</body></html>";
			return htmltext;
		}
		
		if(st == null) return htmltext;	
		int npcId = npc.getNpcId();
		int cond = st.getInt("cond");
		if(npcId == BALANKI)
		{
			if(cond == 0)
			{
				if(st.getPlayer().getRace().ordinal() == 4 && st.getPlayer().getLevel() >= 3)
					htmltext = "30533-02.htm";
				else
				{
					htmltext = "30533-01.htm";
					st.exitQuest(true);
				}
			}
			else if(cond == 1)
				htmltext = "30533-04.htm";
			else if(cond == 4)
				htmltext = "30533-05.htm";
		}
		else if(npcId == REED)
		{
			if(cond == 1)
				htmltext = "30520-01.htm";
			else if(cond == 2)
				htmltext = "30520-03.htm";
			else if(cond == 3)
				htmltext = "30520-04.htm";
			else if(cond == 4)
				htmltext = "30520-06.htm";
		}
		else if(npcId == GERALD)
			if(cond == 2 && st.getQuestItemsCount(VERY_EXPENSIVE_NECKLACE) > 0)
				htmltext = "30650-01.htm";
			else if(cond == 3)
				htmltext = "30650-03.htm";
			else
				htmltext = "30650-04.htm";
		return htmltext;
	}
	
	public static void main(String[] args)
	{
		_log.info("10_IntoTheWorld:     load");
		new q10_IntoTheWorld(10, "10_IntoTheWorld", "Into The World");    	
	}
}