#Dwarf templet plot event, fight for the Raven Beacon
from eventAPI import getTag, setTag, giveItems, optionInput, combat
from APIUtils import isclearall, showMessage

DwarfTempleFlag1 = 0

def fireEvent(e):
    global DwarfTempleFlag1
    DwarfTempleFlag1 = getTag(e, "DwarfTempleFlag1")
    if (DwarfTempleFlag1 == 1):
        return 1
    elif (DwarfTempleFlag1 == 2):
        showMessage(e,
            ["Holy Father wonders why you came back."])
    else:
        showMessage(e,
            ["Approaching what appears to be a holy shrine, maniacal laughter greets you from behind",
             "Holy Father wants to know what these big ones are doing next to his pretty.",
             "Ok father, we'll take care of them"],
            optionInput)
    fightThem(e)
    setTag(e, "DwarfTempleFlag1", DwarfTempleFlag1)
    return 0


def fightThem(e):
    combatRet = combat(e, [("Stone Cleric", 6, 1, 40), ("Gnomicron", 5, 2, 30), ("Dwarf", 20, 5, 10)])
    if (combatRet == 1):
        wonDragonFight(e)
    elif (combatRet == 3):
        lostDragonFight(e)
    else:
        defeatedDragonFight(e)

def wonDragonFight(e):
    global DwarfTempleFlag1
    showMessage(e, 
        ["You almost pity these poor mad creatures who attack you, but you know what you're doing is for the greater good",
         "Your eyes come across a chest near one of the bodies"])
    giveItems(e, ["Raven Beacon"])
    showMessage(e,
        ["This is the device Almara spoke of, you should take it to her for proof of your deeds,",
	 "and to let her know her people can try to rebuild here now"])
    DwarfTempleFlag1 = 1
    setTag(e, "DwarfTempleFlag1", DwarfTempleFlag1)
    setTag(e, "DwarfPlt1", 5)

def lostDragonFight(e):
    showMesasge(e,
        ["With your last gasp of breath, you see your enemies smiling and dancing around your bodies"])

def defeatedDragonFight(e):
    global DwarfTempleFlag1
    showMessage(e,
        ["As you run away, you here screaming and wails of \"Holy Father will be angry!\""])
    DwarfTempleFlag1 = 2
    setTag(e, "DwarfTempleFlag1", DwarfTempleFlag1)
    
