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

public class q505_BloodOffering extends Quest
{
	private final static int[] TOWN_DAWN = {31078,31079,31080,31081,31083,31084,31082,31692,31694,31997,31168};
	private final static int[] TOWN_DUSK = {31085,31086,31087,31088,31090,31091,31089,31693,31695,31998,31169};
	private final static int[] DIM_GK =
	{
		31494,31495,31496,31497,31498,31499,31500,
		31501,31502,31503,31504,31505,31506,31507
	};
	private final static int[] GK_ZIGGURAT =
	{
		31095,31096,31097,31098,31099,31100,31101,
		31102,31103,31104,31105,31106,31107,31108,
		31109,31110,31114,31115,31116,31117,31118,
		31119,31120,31121,31122,31123,31124,31125
	};
	private final static int[] FESTIVALGUIDE = {31127,31128,31129,31130,31131,31137,31138,31139,31140,31141};
	private final static int[] FESTIVALWITCH = {31132,31133,31134,31135,31136,31142,31143,31144,31145,31146};
	private final static int[] RIFTPOST = {31488,31489,31490,31491,31492,31493};
	
	private State CREATED;
	private State STARTED;
	
	public q505_BloodOffering(int questId, String name, String descr)
	{
		super(questId, name, descr);
		CREATED = new State("Start", this);
		STARTED = new State("Started", this);
		this.setInitialState(CREATED);

		for(int NPC_ID : TOWN_DAWN)
		{
			addStartNpc(NPC_ID);
			addTalkId(NPC_ID);
		}
		for(int NPC_ID1 : TOWN_DUSK)
		{
			addStartNpc(NPC_ID1);
			addTalkId(NPC_ID1);
		}
		for(int NPC_ID2 : DIM_GK)
		{
			addStartNpc(NPC_ID2);
			addTalkId(NPC_ID2);
		}
		for(int NPC_ID3 : GK_ZIGGURAT)
		{
			addStartNpc(NPC_ID3);
			addTalkId(NPC_ID3);
		}
		for(int NPC_ID4 : FESTIVALGUIDE)
		{
			addStartNpc(NPC_ID4);
			addTalkId(NPC_ID4);
		}
		for(int NPC_ID5 : FESTIVALWITCH)
		{
			addStartNpc(NPC_ID5);
			addTalkId(NPC_ID5);
		}
		for(int NPC_ID6 : RIFTPOST)
		{
			addStartNpc(NPC_ID6);
			addTalkId(NPC_ID6);
		}
	}

	public String onTalk(L2NpcInstance npc, L2PcInstance talker)
	{
		QuestState st = talker.getQuestState(getName());
		QuestState st2 = talker.getQuestState("635_InTheDimensionalRift");
		int npcId = npc.getNpcId();
		if(st != null)
		{
			for(int NPC_ID : FESTIVALGUIDE)
			{
				if(npcId == NPC_ID)
				{
					talker.teleToLocation(-114796,-179334,-6752);
					if(st2 != null)
					{
						st2.setState(STARTED);
						st2.set("cond","1");
					}
					st.playSound("ItemSound.quest_accept");
					st.exitQuest(true);
					return "guide.htm";
				}
			}
			if(npcId == FESTIVALWITCH[0])
			{
				talker.teleToLocation(-80204,87056,-5154);
				return "witch.htm";
			}
			else if(npcId == FESTIVALWITCH[1])
			{
				talker.teleToLocation(-77198,87678,-5182);
				return "witch.htm";
			}
			else if(npcId == FESTIVALWITCH[2])
			{
				talker.teleToLocation(-76183,87135,-5179);
				return "witch.htm";
			}
			else if(npcId == FESTIVALWITCH[3])
			{
				talker.teleToLocation(-76945,86602,5153);
				return "witch.htm";
			}
			else if(npcId == FESTIVALWITCH[4])
			{
				talker.teleToLocation(-79970,85997,-5154);
				return "witch.htm";
			}
			else if(npcId == FESTIVALWITCH[5])
			{
				talker.teleToLocation(-79182,111893,-4898);
				return "witch.htm";
			}
			else if(npcId == FESTIVALWITCH[6])
			{
				talker.teleToLocation(-76176,112505,-4899);
				return "witch.htm";
			}
			else if(npcId == FESTIVALWITCH[7])
			{
				talker.teleToLocation(-75198,111969,-4898);
				return "witch.htm";
			}
			else if(npcId == FESTIVALWITCH[8])
			{
				talker.teleToLocation(-75920,111435,-4900);
				return "witch.htm";
			}
			else if(npcId == FESTIVALWITCH[9])
			{
			   talker.teleToLocation(-78928,110825,-4926);
			   return "witch.htm";
			}
			for(int NPC_ID1 : RIFTPOST)
			{
				if(npcId == NPC_ID1)
				{
					boolean SEALVALIDATIONPERIOD = SevenSigns.getInstance().isSealValidationPeriod();
					String CABAL = SevenSigns.getInstance().getPlayerData(talker).getString("cabal");
					if(SEALVALIDATIONPERIOD == false)
					{
						if(CABAL == "dawn")
						{
							st.setState(STARTED);
							st.set("cond","1");
							talker.teleToLocation(-80157,111344,-4901);
							if(st2 != null)
								st2.unset("cond");
							return "riftpost-1.htm";
						}
						else
						{
							if(CABAL == "dusk")
							{
								st.setState(STARTED);
								st.set("cond","1");
								if(st2 != null)
									st2.unset("cond");
								talker.teleToLocation(-81261,86531,-5157);
								return "riftpost-1.htm";
							}
							else
								return "riftpost-2.htm";
						}
					}
					else
						return "riftpost-2.htm";
				}
			}
		}
		return null;
	}

	public static void main(String[] args)
	{
		_log.info("505_BloodOffering:     load");
		new q505_BloodOffering(505, "505_BloodOffering", "Blood Offering");    	
	}
}