/*
 * 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.base.Race;
import com.l2jcore.Game.model.quest.Quest;
import com.l2jcore.Game.model.quest.QuestState;
import com.l2jcore.Game.model.quest.State;

public class q6_StepIntoTheFuture extends Quest
{
	//NPC
	private static final int Roxxy = 30006;
	private static final int Baulro = 30033;
	private static final int Windawood = 30311;
	//Quest Item
	private static final int BaulrosLetter = 7571;
	//Items Rewards
	private static final int ScrollOfEscapeGiran = 7126;
	private static final int MarkOfTraveler = 7570;
	
	private State CREATED;
	private State STARTED;
	private State COMPLETED;

	public q6_StepIntoTheFuture(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(Roxxy);
		addTalkId(Roxxy);
		addTalkId(Baulro);
		addTalkId(Windawood);
		
		STARTED.addQuestDrop(Roxxy,BaulrosLetter,1);
	}

	public String onEvent(String event, QuestState st)
	{	
		if(event.equalsIgnoreCase("30006-03.htm"))
		{
			st.set("cond", "1");
			st.setState(STARTED);
			st.playSound("ItemSound.quest_accept");
		}
		else if(event.equalsIgnoreCase("30033-02.htm"))
		{
			st.giveItems(BaulrosLetter, 1);
			st.set("cond", "2");
			st.playSound("ItemSound.quest_middle");
		}
		else if(event.equalsIgnoreCase("30311-03.htm"))
		{
			st.takeItems(BaulrosLetter, 1);
			st.set("cond", "3");
			st.playSound("ItemSound.quest_middle");
		}
		else if(event.equalsIgnoreCase("30006-06.htm"))
		{
			st.giveItems(ScrollOfEscapeGiran, 1);
			st.giveItems(MarkOfTraveler, 1);
			st.unset("cond");
			st.playSound("ItemSound.quest_finish");
			st.exitQuest(false);
		}
		return event;
	}

	@Override
	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 == Roxxy)
		{
			if(cond == 0)
				if(st.getPlayer().getRace() == Race.Human && st.getPlayer().getLevel() >= 3)
					htmltext = "30006-02.htm";
				else
				{
					htmltext = "30006-01.htm";
					st.exitQuest(true);
				}
			else if(cond == 1)
				htmltext = "30006-04.htm";
			else if(cond == 3)
				htmltext = "30006-05.htm";
		}
		else if(npcId == Baulro)
		{
			if(cond == 1)
				htmltext = "30033-01.htm";
			else if(cond == 2 && st.getQuestItemsCount(BaulrosLetter) > 0)
				htmltext = "30033-03.htm";
		}
		else if(npcId == Windawood)
			if(cond == 2 && st.getQuestItemsCount(BaulrosLetter) > 0)
				htmltext = "30311-02.htm";
			else if(cond == 2 && st.getQuestItemsCount(BaulrosLetter) == 0)
				htmltext = "30311-havent.htm";
			else if(cond == 3)
				htmltext = "30311-03r.htm";
		return htmltext;
	}
	
	public static void main(String[] args)
	{
		_log.info("6_StepIntoTheFuture:     load");
		new q6_StepIntoTheFuture(6, "6_StepIntoTheFuture", "Step Into The Future");    	
	}
}