#Dragon cave plot event, fight for the Axe of dwarfhome
from eventAPI import getTag, setTag, giveItems, optionInput, combat
from APIUtils import isclearall, showMessage

DragonFlag1 = 0

def fireEvent(e):
    global DragonFlag1
    DragonFlag1 = getTag(e, "DragonFlag1")
    if (DragonFlag1 == 1):
        return 1
    elif (DragonFlag1 == 2):
        showMessage(e,
            ["Foolish little things, how can you expect to defeat us?"])
    else:
        showMessage(e,
            ["Approaching what you know must be the resting place of the dwarf heirloom, the temperature in the room escalates suddenly",
             "What do you think you're doing puny ones?",
             "With a rustle of wings and a steam of dragon's breath, you are assaulted"],
            optionInput)
    fightThem(e)
    setTag(e, "DragonFlag1", DragonFlag1)
    return 0


def fightThem(e):
    combatRet = combat(e, [("Green Dragon", 10, 0, 20), ("Red Dragon", 5, 0, 50)])
    if (combatRet == 1):
        wonDragonFight(e)
    elif (combatRet == 3):
        lostDragonFight(e)
    else:
        defeatedDragonFight(e)

def wonDragonFight(e):
    global DragonFlag1
    showMessage(e, 
        ["With the dying throes of the last dragon still echoing in your ears you search about for the Axe",
         "Then your eyes come across a chest tucked under the wing of a fallen foe"])
    giveItems(e, ["Star Sword", "Star Plate", "Axe of DwarfHome", Ariel's Rose Harp", "Blade of N'anoc"])
    showMessage(e,
        ["While the axe appears to be useless as a weapon, you know it is much more meaningful to the dwarves",
	 "you should take this back to Almara straightaway"])
    DragonFlag1 = 1
    setTag(e, "DragonFlag1", DragonFlag1)
    setTag(e, "DwarfPlt1", 3)

def lostDragonFight(e):
    showMesasge(e,
        ["With your last gasp of breath, you see your enemies smiling as they know your end is near"])

def defeatedDragonFight(e):
    global DragonFlag1
    showMessage(e,
        ["Your retreating footsteps are followed by laughter"])
    DragonFlag1 = 2
    setTag(e, "DragonFlag1", DragonFlag1)
    
