import sys
from com.l2dot.gameserver.model.actor.instance import L2PcInstance
from java.util import Iterator
from com.l2dot.gameserver.datatables import SkillTable
from com.l2dot			       import L2DatabaseFactory
from com.l2dot.gameserver.model.actor.appearance import PcAppearance
from com.l2dot.gameserver.model.quest import State
from com.l2dot.gameserver.model.actor.appearance import PcAppearance
from com.l2dot.gameserver.model.quest import QuestState
from com.l2dot.gameserver.model.quest.jython import QuestJython as JQuest

qn = "20104_NpcNoblesse"

NPC=[20104]
GOLDBAR= 3470
NOBLESS_TIARA = 7694
QuestId     = 20104
QuestName   = "NpcNoblesse"
QuestDesc   = "custom"
InitialHtml = "1.htm"

print "Importing Custom: Noblesse Manager"

class Quest (JQuest) :

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


	def onEvent(self,event,st):
		htmltext = event
		count=st.getQuestItemsCount(GOLDBAR)
		if count < 25  and st.getPlayer().getLevel() < 78 :
			htmltext = "Error2.htm"

		elif st.getPlayer().isNoble() == 1 :
			htmltext = "Error1.htm"
		
		elif st.getQuestItemsCount(GOLDBAR) < 25 :	
                        htmltext = "Error2.htm"

		elif st.getPlayer().getLevel() < 80 :
			htmltext = "Error2.htm"

		else:
			st.getPlayer().setTarget(st.getPlayer())
			
			if event == "2":
				st.takeItems(GOLDBAR,25)
                                st.getPlayer().setNoble(True)
                                st.giveItems(NOBLESS_TIARA,1)
                                st.playSound("ItemSound.quest_finish")
				st.setState(COMPLETED)
				return "End.htm"
                                st.exitQuest(1)	
	
				
			if htmltext != event:
				st.setState(COMPLETED)
				st.exitQuest(1)
		return htmltext


	def onTalk (self,npc,player):
	   st = player.getQuestState(qn)
	   htmltext = "<html><head><body>I have nothing to say to you</body></html>"
	   st.setState(STARTED)
	   return InitialHtml

QUEST       = Quest(QuestId,str(QuestId) + "_" + QuestName,QuestDesc)
CREATED = State('Start',QUEST)
STARTED = State('Started',QUEST)
COMPLETED = State('Completed',QUEST)

QUEST.setInitialState(CREATED)

for npcId in NPC:
 QUEST.addStartNpc(npcId)
 QUEST.addTalkId(npcId)
