/*
 * 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 q7_ATripBegins extends Quest
{
	private final static int MIRABEL = 30146;
	private final static int ARIEL = 30148;
	private final static int ASTERIOS = 30154;

	private final static int ARIELS_RECOMMENDATION = 7572;

	private final static int SCROLL_OF_ESCAPE_GIRAN = 7126;
	private final static int MARK_OF_TRAVELER = 7570;

	private State CREATED;
	private State STARTED;
	private State COMPLETED;
	
	public q7_ATripBegins(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(MIRABEL);
		addTalkId(MIRABEL);
		addTalkId(ARIEL);
		addTalkId(ASTERIOS);
		STARTED.addQuestDrop(MIRABEL,ARIELS_RECOMMENDATION,1);
	}

	public String onEvent(String event, QuestState st)
	{
		if(event.equalsIgnoreCase("30146-03.htm"))
		{
			st.set("cond", "1");
			st.setState(STARTED);
			st.playSound("ItemSound.quest_accept");
		}
		else if(event.equalsIgnoreCase("30148-02.htm"))
		{
			st.giveItems(ARIELS_RECOMMENDATION, 1);
			st.set("cond", "2");
			st.playSound("ItemSound.quest_middle");
		}
		else if(event.equalsIgnoreCase("30154-02.htm"))
		{
			st.takeItems(ARIELS_RECOMMENDATION, 1);
			st.set("cond", "3");
			st.playSound("ItemSound.quest_middle");
		}
		else if(event.equalsIgnoreCase("30146-06.htm"))
		{
			st.giveItems(SCROLL_OF_ESCAPE_GIRAN, 1);
			st.giveItems(MARK_OF_TRAVELER, 1);
			st.set("cond", "0");
			st.playSound("ItemSound.quest_finish");
			st.exitQuest(false);
		}
		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 == MIRABEL)
		{
			if(cond == 0)
				if(st.getPlayer().getRace().ordinal() == 1)
					if (st.getPlayer().getLevel() >= 3)
						htmltext = "30146-02.htm";
					else
					{
						htmltext = "<html><body>Quest for characters level 3 above.</body></html>";
						st.exitQuest(true);
					}
				else
				{
					htmltext = "30146-01.htm";
					st.exitQuest(true);
				}
			else if(cond == 1)
				htmltext = "30146-04.htm";
			else if(cond == 3)
				htmltext = "30146-05.htm";
		}
		else if(npcId == ARIEL)
		{
			if(cond == 1 && st.getQuestItemsCount(ARIELS_RECOMMENDATION) == 0)
				htmltext = "30148-01.htm";
			else if(cond == 2)
				htmltext = "30148-03.htm";
		}
		else if(npcId == ASTERIOS)
			if(cond == 2 && st.getQuestItemsCount(ARIELS_RECOMMENDATION) > 0)
				htmltext = "30154-01.htm";
			else if(cond == 3)
				htmltext = "30146-05.htm";
		return htmltext;
	}
	
	public static void main(String[] args)
	{
		_log.info("7_ATripBegins:     load");
		new q7_ATripBegins(7, "7_ATripBegins", "A Trip Begins");    	
	}
}