/*
 * 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;
import com.l2jcore.Game.network.serverpackets.ExShowSlideshowKamael;

public class q127_KamaelAWindowToTheFuture extends Quest
{	
	private final static int AKLAN = 31288;
	private final static int ALDER = 32092;
	private final static int DOMINIC = 31350;
	private final static int JURIS = 30113;
	private final static int KLAUS = 30187;
	private final static int OLTLIN = 30862;
	private final static int RODEMAI = 30756;

	private final static int MARK_DOMINIC = 8939;
	private final static int MARK_HUMAN = 8940;
	private final static int MARK_DWARF = 8941;
	private final static int MARK_ELF = 8942;
	private final static int MARK_DELF = 8943;
	private final static int MARK_ORC = 8944;
	
	private State CREATED;
	private State STARTED;
	private State COMPLETED;
	
	public q127_KamaelAWindowToTheFuture(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(DOMINIC);
		addTalkId(DOMINIC);
		addTalkId(KLAUS);
		addTalkId(ALDER);
		addTalkId(AKLAN);
		addTalkId(OLTLIN);
		addTalkId(JURIS);
		addTalkId(RODEMAI);

		STARTED.addQuestDrop(KLAUS,MARK_HUMAN,1);
		STARTED.addQuestDrop(ALDER,MARK_DWARF,1);
		STARTED.addQuestDrop(AKLAN,MARK_ORC,1);
		STARTED.addQuestDrop(OLTLIN,MARK_DELF,1);
		STARTED.addQuestDrop(JURIS,MARK_ELF,1);
		STARTED.addQuestDrop(DOMINIC,MARK_DOMINIC,1);
	}

	public String onEvent(String event, QuestState qs)
	{
		if(event.equalsIgnoreCase("30048-06.htm"))
		{
			qs.set("cond", "1");
			qs.setState(STARTED);
			qs.giveItems(DARINGS_LETTER, 1);
			qs.playSound("ItemSound.quest_accept");
		}
		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");
		switch(npcId)
		{
			case DARIN:
				if(cond == 0)
				{
					if(st.getPlayer().getLevel() >= 2)
						htmltext = "30048-02.htm";
					else
					{
						htmltext = "30048-00.htm";
						st.exitQuest(true);
					}
				}
				else if(cond == 1)
					htmltext = "30048-07.htm";
				else if(cond == 2 && st.getQuestItemsCount(RAPUNZELS_KERCHIEF) == 1)
				{
					htmltext = "30048-08.htm";
					st.takeItems(RAPUNZELS_KERCHIEF, 1);
					st.giveItems(DARINGS_RECEIPT, 1);
					st.set("cond", "3");
					st.playSound("ItemSound.quest_middle");
				}
				else if(cond == 3)
					htmltext = "30048-09.htm";
				else if(cond == 4 && st.getQuestItemsCount(BAULROS_POTION) == 1)
				{
					htmltext = "30048-10.htm";
					st.takeItems(BAULROS_POTION, 1);
					st.giveItems(NECKLACE, 1);
					st.giveItems(57, 2466); // T2
					st.addExpAndSp(5672, 446);
					st.playSound("ItemSound.quest_finish");
					st.unset("cond");
					st.setState(COMPLETED);
					st.exitQuest(false);
				}
				break;
			case ROXXY:
				if(cond == 1 && st.getQuestItemsCount(RAPUNZELS_KERCHIEF) == 0 && st.getQuestItemsCount(DARINGS_LETTER) > 0)
				{
					htmltext = "30006-01.htm";
					st.takeItems(DARINGS_LETTER, 1);
					st.giveItems(RAPUNZELS_KERCHIEF, 1);
					st.set("cond", "2");
					st.playSound("ItemSound.quest_middle");
				}
				else if(cond == 2 && st.getQuestItemsCount(RAPUNZELS_KERCHIEF) > 0)
					htmltext = "30006-02.htm";
					else if(cond > 2 && (st.getQuestItemsCount(BAULROS_POTION) > 0 || st.getQuestItemsCount(DARINGS_RECEIPT) > 0))
					htmltext = "30006-03.htm";
				break;
			case BAULRO:
				if(cond == 3 && st.getQuestItemsCount(DARINGS_RECEIPT) == 1)
				{
					htmltext = "30033-01.htm";
					st.takeItems(DARINGS_RECEIPT, 1);
					st.giveItems(BAULROS_POTION, 1);
					st.set("cond", "4");
					st.playSound("ItemSound.quest_middle");
				}
				else if(cond == 4)
					htmltext = "30033-02.htm";
				break;
		}
		return htmltext;
	}
	
    public static void main(String[] args)
    {
    	new q127_KamaelAWindowToTheFuture(1, "127_KamaelAWindowToTheFuture", "Kamael A Window To The Future");    	
    }
}