from eventAPI import *
from APIUtils import *

def fireEvent(e):
    if ((getTag(e, "lFlagS") & 0x100) == 0):
        return 1
    global kp
    kp = getTag(e, "kssPlot")
    if (kp <= 6):
        return first(e)
    elif (kp >= 9):
        showMessage(e, ["Bits of meat and rangers litter the refectory."])
        return 1
    else:
        return second(e)
               
def first(e):
    kp = getTag(e, "kssPlot")
    kp += 2
    setTag(e, "kssPlot", kp)
    showMessage(e, ["As you enter this communal room, you spot a group of druids and rangers eating at a table.","",
                    "They spot you as well and surge to their feet, grabbing their weapons. A  tall ranger dressed all in black addresses you:"])
    showMessage(e, ["\"Visitors? I see you gave our welcoming party the slip.","",
                    "Anyway, you've come to the right place. Allow us to escort you to the kitchen.\""])
    combatRet = combat(e, [("Ranger", 5, 0, 30), ("Druid", 2, 0, 50), ("Black Ranger", 1, 0, 60)])
    if (combatRet == 1):
        won(e)
        return 1
    elif (combatRet == 3):
        lost(e)
    else:  
        ran(e)
        return 0

def second(e):
    showMessage(e, ["The group had resumed eating. Seeing you, they stand up again and retrieve their weapons."])
    combatRet = combat(e, [("Ranger", 5, 0, 30), ("Druid", 2, 0, 50), ("Black Ranger", 1, 0, 60)])
    if (combatRet == 1):
        won(e)
        return 1
    elif (combatRet == 3):
        lost(e)
    else:
        ran(e)
        return 0

def won(e):
    kp = getTag(e, "kssPlot")
    if (kp == 7):
        showMessage(e, ["Your foes lie dead at your feet. As you turn to leave, you spy a glint near the Black Ranger's nearly severed neck.",
                        "","You kneel down to examine the body. The cloak's clasp is a polished piece of stone shaped like an S."])
        showMessage(e, ["It will make a nice reminder of your latest victory, so you pocket it, stand up, and depart."])
    else:
        showMessage(e, ["Your foes lie dead at your feet. As you turn to leave, you spy a glint near the Black Ranger's nearly severed neck.",
                        "","You kneel down to examine the body. The cloak's clasp is a polished piece of stone shaped like an S."])
        showMessage(e, ["It reminds you of something, but you can't recall what.","","Anyway, you pocket it, stand up, and depart."])
    kp += 2
    setTag(e, "kssPlot", kp)

def lost(e):
    showMessage(e, ["As announced, they escort (though \"carry\" would be more appropriate now) you to the kitchen.","",
                    "Thanks to you, there will be a feast tonight."])

def ran(e):
    showMessage(e, ["You flee in terror. These foes too don't even try to give chase (after all, where can you go)."])
