/*
 * 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 q3_WilltheSealbeBroken1 extends Quest
{
	private final static int TALLOTH = 30141;
	private final static int[] MONSTERS = {20031, 20041, 20046, 20048, 20052, 20057};

	private final static int ONYX_BEAST_EYE = 1081;
	private final static int TAINT_STONE = 1082;
	private final static int SUCCUBUS_BLOOD = 1083;
	private final static int SCROLL_ENCHANT_ARMOR_D = 956;
	
	private State CREATED;
	private State STARTED;
	private State COMPLETED;

	public q3_WilltheSealbeBroken1(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(TALLOTH);
		addTalkId(TALLOTH);
		for(int monster : MONSTERS)
			addKillId(monster);
		
		STARTED.addQuestDrop(TALLOTH,ONYX_BEAST_EYE,1);
		STARTED.addQuestDrop(TALLOTH,TAINT_STONE,1);
		STARTED.addQuestDrop(TALLOTH,SUCCUBUS_BLOOD,1);
	}

	public String onEvent(String event, QuestState st)
	{
	
		if(event.equalsIgnoreCase("30141-03.htm"))
		{
			st.set("cond", "1");
			st.setState(STARTED);
			st.playSound("ItemSound.quest_accept");
		}
		return event;
	}

	public String onTalk(L2NpcInstance npc, L2PcInstance talker)
	{
		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>";
		QuestState st = talker.getQuestState(getName());
		if(st == null) return htmltext;
		
		if(st.getState() == COMPLETED)
		{
			htmltext = "<html><body>This quest has already been completed.</body></html>";
			return htmltext;
		}
		else if(st.getState() == CREATED)
			if(st.getPlayer().getRace().ordinal() != 2)
			{
				htmltext = "30141-00.htm";
				st.exitQuest(true);
			}
			else if(st.getPlayer().getLevel() >= 16)
			{
				htmltext = "30141-02.htm";
				return htmltext;
			}
			else
			{
				htmltext = "30141-01.htm";
				st.exitQuest(true);
			}
		else if(st.getState() == STARTED)
			if(st.getQuestItemsCount(ONYX_BEAST_EYE) > 0 && st.getQuestItemsCount(TAINT_STONE) > 0 && st.getQuestItemsCount(SUCCUBUS_BLOOD) > 0)
			{
				htmltext = "30141-06.htm";
				st.takeItems(ONYX_BEAST_EYE, 1);
				st.takeItems(TAINT_STONE, 1);
				st.takeItems(SUCCUBUS_BLOOD, 1);
				st.giveItems(SCROLL_ENCHANT_ARMOR_D, 1);
				st.playSound("ItemSound.quest_finish");
				st.unset("cond");
				st.setState(COMPLETED);
				st.exitQuest(false);
			}
			else
				htmltext = "30141-04.htm";
		return htmltext;
	}	
	
	public String onKill(L2NpcInstance npc, L2PcInstance player, boolean isPet)
	{
		QuestState st = player.getQuestState(getName());
		if(st == null) return null;	
		int npcId = npc.getNpcId();
		if(st.getState() == STARTED && (st.getInt("cond") == 1))
		{
			if(npcId == MONSTERS[0] && st.getQuestItemsCount(ONYX_BEAST_EYE) == 0)
			{
				st.giveItems(ONYX_BEAST_EYE, 1);
				st.playSound("Itemsound.quest_itemget");
			}			
			else if((npcId == MONSTERS[1] || npcId == MONSTERS[2]) && st.getQuestItemsCount(TAINT_STONE) == 0)
			{
				st.giveItems(TAINT_STONE, 1);
				st.playSound("Itemsound.quest_itemget");
			}
			else if((npcId == MONSTERS[3] || npcId == MONSTERS[4] || npcId == MONSTERS[5]) && st.getQuestItemsCount(SUCCUBUS_BLOOD) == 0)
			{
				st.giveItems(SUCCUBUS_BLOOD, 1);
				st.playSound("Itemsound.quest_itemget");
			}
			if(st.getQuestItemsCount(ONYX_BEAST_EYE) == 1 && st.getQuestItemsCount(TAINT_STONE) == 1 && st.getQuestItemsCount(SUCCUBUS_BLOOD) == 1)
			{
				st.set("cond", "2");
				st.playSound("ItemSound.quest_middle");
			}			
		}
		return null;
	}
	public static void main(String[] args)
    {
		_log.info("3_ReleaseDarkelfElder1:     load");
    	new q3_WilltheSealbeBroken1(3, "q3_WilltheSealbeBroken1", "Will the Seal be Broken?");    	
	}
}