from eventAPI import *
from APIUtils import *

def fireEvent(e):
    global kp
    kp = getTag(e, "kssPlot")
    if (kp == 3):
        return first(e)
    elif (kp == 4):
        return second(e)
    else:
        return 1
               
def first(e):
    playSpecAudio(e, "arrow")
    showMessage(e, ["Several ranger guards ambush you from a side tunnel; before you even have time to react, they launch a volley of arrows at you."])
    x, c = 0, getPartyCount(e)
    while (x < c):
        modifyHP(e, x, -dice(5, 10, 50))
        x += 1
    combatRet = combat(e, [("Ranger", 5, 0, 50)])
    if (combatRet == 1):
        won(e)
        return 1
    elif (combatRet == 3):
        lost(e)
    else:
        ran(e)
        return 0

def second(e):
    playSpecAudio(e, "arrow")
    showMessage(e, ["The guards were waiting for you (obviously), arrows nocked (well, that was to be expected).","","Here we go again..."])
    x, c = 0, getPartyCount(e)
    while (x < c):
        modifyHP(e, x, -dice(5, 10, 50))
        x += 1
    combatRet = combat(e, [("Ranger", 5, 0, 50)])
    if (combatRet == 1):
        won(e)
        return 1
    elif (combatRet == 3):
        lost(e)
    else:
        ran(e)
        return 0

def won(e):
    stopSpecAudio(e)
    showMessage(e, ["These rangers won't ambush anyone again. Satisfied, you kick their corpses aside and get ready to explore the area."])
    setTag(e, "kssPlot", 5)

def lost(e):
    stopSpecAudio(e)
    showMessage(e, ["Having defeated you, the guards drag your bodies to the kitchen.","","You're starting afterlife on the wrong foot..."])

def ran(e):
    playSpecAudio(e, "arrow")
    showMessage(e, ["As you run for life, they loose some more arrows into you.","","Hey, that stings !"])
    x, c = 0, getPartyCount(e)
    while (x < c):
        modifyHP(e, x, -dice(5, 6, 20))
        x += 1
    setTag(e, "kssPlot", 4)
