#arena event - good place to pick a fight ;)
from eventAPI import *
from APIUtils import *
from SDLKeys import SDLK_l, SDLK_m, SDLK_b, SDLK_h, SDLK_d, SDLK_e, SDLK_r
import random

def fireEvent(e):
    showPicture(e, "Catacombs")
    showMessage(e, ["This place reeks of blood and sweat, it seems run down and dirty. You notice a sign on the wall. \"Welcome to the arena! Where bloodsport is the only sport!\""])
    keepGoing = 1
    global deady
    deady = 0
    while(keepGoing and not deady):
        keypress = optionInput(e, ["What would you like to do?"], ["Fight (M)ages", "Fight (B)easts", "Fight (H)umanoids", "Fight (D)emons", "(L)eave the Arena"],  [SDLK_m, SDLK_b, SDLK_h, SDLK_d, SDLK_l])
        if(keypress != SDLK_l):
            diffKey = optionInput(e, ["How challenging of a fight are you looking for?"], ["(E)asy", "(R)espectable", "(D)ifficult"], [SDLK_e, SDLK_r, SDLK_d])
            diffLev = 1
            if(diffKey == SDLK_r):
                diffLev = 2
            elif(diffKey == SDLK_d):
                diffLev = 3

        if(keypress == SDLK_l):
            keepGoing = 0
        elif(keypress == SDLK_m):
            fightMages(e, diffLev)
        elif(keypress == SDLK_b):
            fightBeasts(e, diffLev)
        elif(keypress == SDLK_h):
            fightHumanoids(e, diffLev)
        elif(keypress == SDLK_d):
            fightDemons(e, diffLev)

    return 0

#-------MAGES--------------------------------------------------------------------------------------------

def fightMages(e, diffLev):
    if (diffLev == 1):
        combatRet =  combat(e, [("Enchantress", 3, 1, 60)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)
    elif (diffLev == 2):
        combatRet =  combat(e, [("Lightning Mage", 3, 1, 60), ("Enchantress", 2, 1, 40)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)
    else: #diffLev == 3
        combatRet =  combat(e, [("Stone Cleric", 2, 1, 60)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)

#---------BEASTS------------------------------------------------------------------------------------------
def fightBeasts(e, diffLev):
    if (diffLev == 1):
        combatRet =  combat(e, [("Warrior Wolf", 3, 1, 10)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)
    elif (diffLev == 2):
        combatRet =  combat(e, [("Orc", 3, 1, 10), ("Brideck Magi", 2, 1, 30)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)
    else: #diffLev == 3
        combatRet =  combat(e, [("Green Dragon", 5, 1, 60)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)

#----------HUMANS-----------------------------------------------------------------------------------------
def fightHumanoids(e, diffLev):
    if (diffLev == 1):
        combatRet =  combat(e, [("Crueman", 9, 3, 10)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)
    elif (diffLev == 2):
        combatRet =  combat(e, [("War Monger", 3, 1, 10), ("Dark Rogue", 2, 1, 40)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)
    else: #diffLev == 3
        combatRet =  combat(e, [("Dark Sidhe Lord", 1, 0, 40)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)

#-----------DEMONS----------------------------------------------------------------------------------------
def fightDemons(e, diffLev):
    if (diffLev == 1):
        combatRet =  combat(e, [("Crippler", 3, 1, 20)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)
    elif (diffLev == 2):
        combatRet =  combat(e, [("Demon Lord", 2, 1, 30)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)
    else: #diffLev == 3
        combatRet =  combat(e, [("Naga Chief", 1, 1, 10)]) 
        if( combatRet == 2):
            cowards(e)
        elif( combatRet == 3):
            dead(e)
        else:
            congrats(e)

#--------------------------------------------------------------------
def cowards(e):
    showMessage(e, ["Do you think you can just walk out on a fight like that? We'll need recompense for your cowardice!"])

    #take out 10000 gold, if they don't have enough, take what they got
    res = modifyGold(e, 0, -10000, 1)
    if(res):
        showMessage(e, ["A party member has lost a large chunk of gold"])
    else:
        showMessage(e, ["A party member has lost all their gold"])
    showMessage(e, ["Let that be a lesson to you, now leave!"])

#------------------------------------------------------------------
def congrats(e):
    response = random.randint(0, 2)
    if(response == 0):
       showMessage(e, ["Congratulations on your victory! Have you ever considered a career as a prize fighting team?"])
    elif(response == 1):
        showMessage(e, ["Not bad, there may be hope for you yet"])
    else:
        showMessage(e, ["I've seen better in my time, but hey - you survived. Good for you"])

def dead(e):
    showMessage(e, ["They drag your cold lifeless bodies outside the arena, hopefully somone will take you back into town"])
    global deady
    deady= 1
