# ---------------------------------------------------------------------------
#			バレンタインイベント　Evolution鯖管理人　[GM] ちびにゃん
#			http://l2je.ath.cx
# ---------------------------------------------------------------------------

import sys
from com.l2jserver.gameserver.model.quest import State
from com.l2jserver.gameserver.model.quest import QuestState
from com.l2jserver.gameserver.model.quest.jython import QuestJython as JQuest

qn = "5801_Valentines"

HEART1	= 4209
HEART2	= 4210
HEART3	= 4211
HEART4	= 4212
HEART5	= 4213
HEART6	= 4214
HEART7	= 4215
HEART8	= 4216
HEART9	= 4217

# 勝ったときの賞品
ITEMS_WIN = [ []
 , [955,851,882]                      # 1回め:  955 D-DAI | D耳|D指
 , [951,854,886]                      # 2回め:  951 C-DAI | 封印の耳|指
 , [947,859,117]                      # 3回め:  947 B-DAI | マナ耳|指
 , [729,6324,6325]                    # 4回め:  729 A-DAI | 封印されたフェニックス耳|指
 , [959,6724,6725]                    # 5回め:  959 S-DAI | 封印されたタテオシアン耳|指
 ]

# 負けたときの賞品
ITEMS_LOS = [ []
 , [4625,4626,4627,4628]	# 1回め: 4625〜4628 サイコロ
 , [956]	# 2回め:  956 D-ZEL
 , [952]	# 3回め:  952 C-ZEL
 , [948]	# 4回め:  948 B-ZEL
 , [730]	# 5回め:  730 A-ZEL
 ]

class Quest (JQuest) :

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

 def onEvent (self,event,st) :
    htmltext = event

    if st.get("cond") == "0":
        if event == "a":  # <main.htm>
            if st.getQuestItemsCount(HEART1) > 0 and \
               st.getQuestItemsCount(HEART2) > 0 and \
               st.getQuestItemsCount(HEART3) > 0 and \
               st.getQuestItemsCount(HEART4) > 0 and \
               st.getQuestItemsCount(HEART5) > 0 and \
               st.getQuestItemsCount(HEART6) > 0 and \
               st.getQuestItemsCount(HEART7) > 0 and \
               st.getQuestItemsCount(HEART8) > 0 and \
               st.getQuestItemsCount(HEART9) > 0 :
                st.takeItems(HEART1,1)
                st.takeItems(HEART2,1)
                st.takeItems(HEART3,1)
                st.takeItems(HEART4,1)
                st.takeItems(HEART5,1)
                st.takeItems(HEART6,1)
                st.takeItems(HEART7,1)
                st.takeItems(HEART8,1)
                st.takeItems(HEART9,1)
                st.set("cond", "1")
                return "1.htm"
            else:
                return "NG-a.htm"
        elif event == "b":  # <main.htm>
            if 29 < st.getQuestItemsCount(HEART1) + \
                    st.getQuestItemsCount(HEART2) + \
                    st.getQuestItemsCount(HEART3) + \
                    st.getQuestItemsCount(HEART4) + \
                    st.getQuestItemsCount(HEART5) + \
                    st.getQuestItemsCount(HEART6) + \
                    st.getQuestItemsCount(HEART7) + \
                    st.getQuestItemsCount(HEART8) + \
                    st.getQuestItemsCount(HEART9):
                st.takeItems(HEART1, st.getQuestItemsCount(HEART1))
                st.takeItems(HEART2, st.getQuestItemsCount(HEART2))
                st.takeItems(HEART3, st.getQuestItemsCount(HEART3))
                st.takeItems(HEART4, st.getQuestItemsCount(HEART4))
                st.takeItems(HEART5, st.getQuestItemsCount(HEART5))
                st.takeItems(HEART6, st.getQuestItemsCount(HEART6))
                st.takeItems(HEART7, st.getQuestItemsCount(HEART7))
                st.takeItems(HEART8, st.getQuestItemsCount(HEART8))
                st.takeItems(HEART9, st.getQuestItemsCount(HEART9))
                st.set("cond", "1")
                return "1.htm"
            else:
                return "NG-b.htm"

    elif event == "u" or event == "v" or event == "w":  # <123.htm> <even.htm>
        cond = st.getInt("cond")
        pon = st.getRandom(3)

        if   pon == 0:
                return "even.htm"
        elif pon == 1:
                cond = cond + 1
                st.set("cond", str(cond))
                return str(cond)+".htm"
        else:
                aa = ITEMS_LOS[cond]
                item = aa[ st.getRandom(len(aa)) ]
                st.giveItems(item,1)
                return "lose.htm"

    elif event == "end.htm":
                cond = st.getInt("cond")
                cond = cond + 1
                aa = ITEMS_WIN[cond]
                item = aa[ st.getRandom(len(aa)) ]
                st.giveItems(item, 1)

    return htmltext

 def onTalk (self,npc,player):
    st = player.getQuestState(qn)
    st.setState(State.STARTED)
    st.set("cond","0")
    return "main.htm"


QUEST       = Quest(5801,qn,"custom")
QUEST.addStartNpc(31854)
QUEST.addTalkId(31854)
