# In the Dimensional Rift v0.1 by DrLecter
import sys
from com.festina.gameserver.model.quest import State
from com.festina.gameserver.model.quest import QuestState
from com.festina.gameserver.model.quest.jython import QuestJython as JQuest

DIMENSION_FRAGMENT = 7079

# Unconfirmed info:
# how many quest slots you need to have in order to enter be able to take another quests within the Rift
MAX_QUEST = 23
# Rift Posts should take you back to the place you came from
COORD={
1: [-41572,209731,-5087], #Necropolis of Sacrifice 
2: [ 42950,143934,-5381], #Catacomb of the Heretic
3: [ 45256,123906,-5411], #Pilgrim's Necropolis
4: [ 46192,170290,-4981], #Catacomb of the Branded
5: [111273,174015,-5437], #Necropolis of Worship
6: [ 77637, 78399,-5125], #Catacomb of Apostate
7: [-21726, 77385,-5171], #Patriot's Necropolis
8: [140405, 79679,-5427], #Catacomb of the Witch
9: [-52366, 79097,-4741], #Necropolis of Devotion (ex Ascetics)
10:[118311,132797,-4829], #Necropolis of Martyrdom
11:[172185,-17602,-4901], #Disciple's Necropolis
12:[ 83000,209213,-5439], #Saint's Necropolis
13:[-19500, 13508,-4901], #Catacomb of Dark Omens
14:[113865, 84543,-6541]  #Catacomb of the Forbidden Path
}

class Quest (JQuest) :

 def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr)

 def onEvent (self,event,st) :
    htmltext = event
    id=st.getInt("id")
    count=st.getInt("count")
    if event == "7.htm" :
      if id :
         if count:
            htmltext="7a.htm"
         st.set("count",str(count+1))
         st.setState(STARTED)
         st.set("cond","1")
         st.getPlayer().teleToLocation(-114790,-180576,-6781)
      else :
         htmltext="What are you trying to do?"
         st.exitQuest(1)
    elif event == "6.htm" :
      st.exitQuest(1)
    return htmltext

 def onTalk (Self,npc,st):
   npcId = npc.getNpcId()
   cond=st.getInt("cond")
   id=st.getInt("id")
   if npcId in range(8494,8508) :
      if st.getPlayer().getLevel() < 20 :
         st.exitQuest(1)
         htmltext="1.htm"
      elif not st.getQuestItemsCount(DIMENSION_FRAGMENT) :
         htmltext="3.htm"
      else :
#         id=str(npcId-8493)
#         st.set("id",id)
         st.getPlayer().teleToLocation(-114790,-180576,-6781)
         htmltext="4.htm"
   else :
      if id :
         x,y,z=COORD[id]
         st.getPlayer().teleToLocation(x,y,z)
         st.unset("cond")
         st.setState(COMPLETED)
         htmltext="7.htm"
      else :
         htmltext="Where?"
         st.exitQuest(1)
   return htmltext

QUEST       = Quest(635, "635_InTheDimensionalRift", "In The Dimensional Rift")
CREATED     = State('Start', QUEST)
STARTED     = State('Started', QUEST)
COMPLETED   = State('Completed', QUEST)

QUEST.setInitialState(CREATED)

for npcId in range(8494,8508):
    CREATED.addTalkId(npcId)
    STARTED.addTalkId(npcId)
    COMPLETED.addTalkId(npcId)
    QUEST.addStartNpc(npcId)

for npcId in range(8488,8494) :
    STARTED.addTalkId(npcId)

print "importing quests: 635 In The Dimensional Rift"
