#Mage Tower riddles
from eventAPI import *
from APIUtils import *

SolvedRiddleNum = 0

def askRiddle(e, num):
    showPicture(e, "Laneraven")
    if( num == 1 ):
        result = riddle1(e)
    elif(num == 2):
        result = riddle2(e)
    elif(num == 3):
        result = riddle3(e)
    elif(num == 4):
        result = riddle4(e)
    elif(num == 5):
        result = riddle5(e)
    elif(num == 6):
        result = riddle6(e)
    elif(num == 7):
        result = riddle7(e)
    elif(num == 8):
        result = riddle8(e)
   
    #mark num as solved if result is 1
    if(result):
        setTag(e, "SolvedRiddleNum", num)

    return result


def checkCorrectRiddle(e, num):
    #we assume that num passed in here is the num of the correct next riddle
    #since this is called from the portal script, we know which portal we're at
    #they can only go to the next riddle, any other one will return 0
    solved = getTag(e, "SolvedRiddleNum")

    if( (solved + 1) == num):
        return 1
    else:
        return 0

def alreadySolved(e, num):
    #returns 1 if this riddle has already been solved
    solved = getTag(e, "SolvedRiddleNum")
    if(num <= solved):
        return 1
    else:
        return 0

def getSolvedNum(e):
    return getTag(e, "SolvedRiddleNum")

def riddle1(e):
    answer = stringInput(e, 
        ["Someone slew his father and took the family heirloom. Then, he turned into a dragon to protect the treasure.",
         "Name the one who slew that dragon."])

    if(answer.lower() == "sigurd"):
        return 1
    else:
        return 0

def riddle2(e):
    answer = stringInput(e,
        ["Name the Great Snake whose belly encompassed the oceans."])

    if(answer.lower() == "midgard serpent" or answer.lower() == "jormungard"):
        return 1
    else:
        return 0

def riddle3(e):
    answer = stringInput(e,
        ["Who guides the soul of a dead warrior to the Hall of Valhalla?"])

    if(answer.lower() == "valkyrie"):
        return 1
    else:
        return 0

def riddle4(e):
    answer = stringInput(e,
        ["Who slew his father, became a dragon, and was then slain by Sigurd?"])

    if(answer.lower() == "fafnir"):
        return 1
    else:
        return 0

def riddle5(e):
    answer = stringInput(e,
        ["What is the end of it all and a new beginning?"])

    if(answer.lower() == "ragnarok" or answer.lower() == "gotterdammerung"):
        return 1
    else:
        return 0

def riddle6(e):
    answer = stringInput(e,
        ["Name Thor's weapon"])

    if(answer.lower() == "mjollnir"):
        return 1
    else:
        return 0

def riddle7(e):
    answer = stringInput(e,
        ["Which weapon did Odin weild?"])
    
    if(answer.lower() == "spear"):
        return 1
    else:
        return 0

def riddle8(e):
    answer = stringInput(e,
        ["Who, at Ragnarok, slew Jormungard and died due to it's poisonous bite shortly after?"])

    if(answer.lower() == "thor"):
        return 1
    else:
        return 0
