# L2J_JP CREATE SANDMAN
import sys
from net.sf.l2j import Config
from net.sf.l2j.gameserver.model.quest import State
from net.sf.l2j.gameserver.model.quest import QuestState
from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest
from net.sf.l2j.gameserver.instancemanager.lastimperialtomb import LastImperialTombManager
from net.sf.l2j.gameserver.instancemanager.lastimperialtomb import FrintezzaManager

# Main Quest Code
class lastimperialtomb(JQuest):

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

  def onTalk (self,npc,player):
    st = player.getQuestState("lastimperialtomb")
    if not st : return "<html><head><body>I have no tasks for you</body></html>"
    npcId = npc.getNpcId()
    if npcId == 32011 :    # Freintezza Teleporter
      if player.isFlying() :
        return "<html><body>フリンテッサ テレポーター :<br>ワイバーン搭乗中は中に入ることはできません。</body></html>"
        #return "<html><body>Imperial Tomb Guide :<br>To go in, get off the wyvern.</body></html>"
      if Config.LIT_REGISTRATION_MODE == 0 :
        if LastImperialTombManager.getInstance().tryRegistrationCc(player) :
          LastImperialTombManager.getInstance().registration(player,npc)
        else :
          return "<html><body>フリンテッサ テレポーター :<br>パーティーを率いる指揮官チャンネルのリーダーが「フリンテッサの結界解除スクロール」を持っていれば、フリンテッサ様の結界内部に入れます。</body></html>"
          #return "<html><body>Imperial Tomb Guide :<br>It is possible to apply only to the commander for the entry. And,""Frintezza's Magic Force Field Removal Scroll"" is necessary to enter.</body></html>"
      elif Config.LIT_REGISTRATION_MODE == 1 :
        if LastImperialTombManager.getInstance().tryRegistrationPt(player) :
          LastImperialTombManager.getInstance().registration(player,npc)
        else :
          return "<html><body>フリンテッサ テレポーター :<br>パーティーを率いるリーダーが「フリンテッサの結界解除スクロール」を持っていれば、フリンテッサ様の結界内部に入れます。</body></html>"
          #return "<html><body>Imperial Tomb Guide :<br>It is only the leader of the party that can apply for the entry. And,""Frintezza's Magic Force Field Removal Scroll"" is necessary to enter.</body></html>"
      elif Config.LIT_REGISTRATION_MODE == 2 :
        if LastImperialTombManager.getInstance().tryRegistrationPc(player) :
          LastImperialTombManager.getInstance().registration(player,npc)
        else :
          return "<html><body>フリンテッサ テレポーター :<br>「フリンテッサの結界解除スクロール」を持っていれば、フリンテッサ様の結界内部に入れます。</body></html>"
          #return "<html><body>Imperial Tomb Guide :<br>""Frintezza's Magic Force Field Removal Scroll"" is necessary to enter.</body></html>"
    return

  def onKill (self,npc,player,isPet):
    st = player.getQuestState("lastimperialtomb")
    if not st: return
    npcId = npc.getNpcId()
    if npcId == 18328 :
      LastImperialTombManager.getInstance().onKillHallAlarmDevice()
    elif npcId == 18339 :
      LastImperialTombManager.getInstance().onKillDarkChoirPlayer()
    elif npcId == 18334 :
      LastImperialTombManager.getInstance().onKillDarkChoirCaptain()
    elif npcId == 29047 :
      FrintezzaManager.getInstance().doSvhDead(1)

  def onAttack(self,npc,player,damage,isPet):
    st = player.getQuestState("lastimperialtomb")
    if not st: return
    FrintezzaManager.getInstance().svhMorphCheck()

# Quest class and state definition
QUEST = lastimperialtomb(-1,"lastimperialtomb","ai")
# Quest NPC starter initialization
QUEST.addStartNpc(32011)
QUEST.addTalkId(32011)
QUEST.addKillId(18328)
QUEST.addKillId(18339)
QUEST.addKillId(18334)
QUEST.addKillId(29047)
QUEST.addAttackId(29046)
