/*
 * 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 q20_BringUpWithLove extends Quest
{
	private final static int TUNATUN = 31537;
	private final static int JEWEL_INNOCENCE = 7185;

	private State CREATED;
	private State STARTED;
	private State COMPLETED;

	public q20_BringUpWithLove(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(TUNATUN);
		addTalkId(TUNATUN);
	}

	public String onEvent(String event, QuestState st)
	{
		if(st.getState() == CREATED)
		{
			st.set("cond", "0");
			if(event.equals("31537-1.htm") || event.equals("31537-2.htm") || event.equals("31537-3.htm") || event.equals("31537-4.htm") || event.equals("31537-5.htm"))
				return event;
			if(event.equals("31537-6.htm"))
			{
				st.set("cond", "1");
				st.setState(STARTED);
				st.playSound("ItemSound.quest_accept");
				return event;
			}
		}
		else if(event.equals("31537-8.htm"))
		{
			st.takeItems(JEWEL_INNOCENCE, -1);
			st.giveItems(57, 68500);
			st.unset("cond");
			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 cond = st.getInt("cond");
		if(cond == 0)
		{
			if(st.getState() == CREATED)
				if(st.getPlayer().getLevel() <= 64)
				{
					st.exitQuest(true);
					htmltext = "31537-00.htm";
				}
				else
					htmltext = "31537-0.htm";
		}
		else if(cond == 1 && st.getQuestItemsCount(JEWEL_INNOCENCE) == 0)
			htmltext = "31537-6a.htm";
		else if(cond == 2 && st.getQuestItemsCount(JEWEL_INNOCENCE) >= 1)
			htmltext = "31537-7.htm";
		return htmltext;
	}
	
	public static void main(String[] args)
	{
		_log.info("20_BringUpWithLove:     load");
		new q20_BringUpWithLove(20, "20_BringUpWithLove", "Bring Up With Love");    	
	}
}
