/*
 * 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 custom.MissQueen;

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 MissQueen extends Quest
{
	private static final int[] COUPON = {7832,7833};
	private static final int[] NPCs = {31760,31761,31762,31763,31764,31765,31766};
	
	private State CREATED;

	public MissQueen(int questid, String name, String descr)
	{
		super(questid, name, descr);
		CREATED = new State("Start", this);
		this.setInitialState(CREATED);
		for(int NPC_ID : NPCs)
		{
			addStartNpc(NPC_ID);
			addFirstTalkId(NPC_ID);
			addTalkId(NPC_ID);
		}
	}

	public String onAdvEvent (String event, L2NpcInstance npc, L2PcInstance player)
	{
		QuestState st = player.getQuestState(getName());
		String htmltext = "";
		boolean newbie = player.isNewbie();
		int level = player.getLevel();
		int occupation_level = player.getClassId().level();
		int pkkills = player.getPkKills();
		int has_newbie_coupon = st.getQuestItemsCount(COUPON[0]);
		int has_travel_coupon = st.getQuestItemsCount(COUPON[1]);
		if(event.equalsIgnoreCase("newbie_give_coupon"))
		{
			if(level <= 25 && level >= 6 && pkkills == 0 && occupation_level == 0)
			{
				if(newbie == true && has_newbie_coupon == 0)
				{
					st.giveItems(COUPON[0],1);
					htmltext = "31760-2.htm";
					st.exitQuest(true);
				}
				else
				{
					htmltext = "31760-1.htm";
					st.exitQuest(true);
				}
			}
			else
			{
				htmltext = "31760-3.htm";
				st.exitQuest(true);
			}
		}
		else if(event.equalsIgnoreCase("traveller_give_coupon"))
		{
			if(level <= 25 && level >= 6 && pkkills == 0 && occupation_level == 1)
			{
				if(newbie == true && has_travel_coupon == 0)
				{
					st.giveItems(COUPON[1],1);
					htmltext = "31760-5.htm";
					st.exitQuest(true);
				}
				else
				{
					htmltext = "31760-4.htm";
					st.exitQuest(true);
				}
			}
			else
			{
				htmltext = "31760-6.htm";
				st.exitQuest(true);
			}
		}
		return htmltext;
	}

	public String onFirstTalk(L2NpcInstance npc, L2PcInstance player)
	{
		return "31760.htm";
	}

	public static void main(String[] args)
	{
		new MissQueen(5000, "MissQueen", "custom");
	}
}