#bwfinal script
from eventAPI import *
from APIUtils import *
from SDLKeys import SDLK_f, SDLK_r
bwfinal = 0
def fireEvent(e):
    global bwfinal
    bwfinal = getTag(e, "bwfinal")
    if (bwfinal == 0):
        begin(e)
    elif (bwfinal == 1):
       	ratfight(e)
    elif (bwfinal == 2):
    	magefight(e)
    elif (bwfinal == 3):
    	vault(e)
    elif (bwfinal == 4):
    	end(e)    	
    elif (bwfinal == 5):
    	altmfight(e)
    else:
        return 1        
       
def begin(e):
    showPicture(e, "bw_cauldron")
    showMessage(e, ["As you walk into this room you see a large cauldron. Something appears to be cooking in the pot, though you can't make out exactly what it is from where you are."])
    showMessage(e, ["You start to walk up to the giant boiling cauldron but then you realize that you are not alone."])
    showMessage(e, ["A beholder enters the room!."])
    showPicture(e, "Abeholder")
    showMessage(e, ["Oh, it seems that I have visitors, it says as it's eye looks you over. Just in time for......dinner.... Why don't you join me."])
    showMessage(e, ["Before you can speak, the apparition appears before you again."])
    showPicture(e, "Ghost")
    showMessage(e, ["Fellow adventurers...This is the cruel beast that killed me and there is no doubt in my mind that this horrid beholder is cooking more people in its cauldron as we speak. You must kill this wretched beast before it kills you, and continues its evil and murderous ways!"])
    showPicture(e, "Abeholder")
    showMessage(e, ["The beholder shouts WAIT!! Lets keep our heads about us!! I invite you to dinner and then you accuse me of murder? It's always the same.....People judge me just because I'm this big horrid looking thing with tentacles for legs and this one big eye. People always run screaming, and those who don't, grab their pitchforks and try to poke me to death. All I did was offer my hospitality."])
    showMessage(e, ["And to think that I, Xoram, would cook you in this big cauldron and then gobble you up like you were tasty morsels, well thats just ludicrous! All I'm cooking is some chicken noodle soup, because I have a bit of a cold. a..a...Acheww!"])
    showPicture(e, "Ghost")
    showMessage(e, ["IT LIES! Don't listen to it! It's just buying time to prepare its spells to unleash against you. You must fight it now, before it's too late!"])
    if (optionInput(e,
        ["","\"Won't you avenge my death?\""],
        ["(f)ight the beholder", "(r)efuse to fight"], [SDLK_f, SDLK_r]) == SDLK_f):
        setTag(e, "bwfinal", bwfinal)
        fightbeholder(e)
    else:
        refusetofight(e)
    return 1
    
 
def fightbeholder(e): 
   combatRet = combat(e, [("Beholder", 1, 0, 10)])
   if (combatRet == 1):
      wonbattle(e)
   elif (combatRet == 3):
      lostFight(e)
   else:  
      ranAwayFight(e)  

									      
def wonbattle(e):
	showMessage(e, ["As the beholder lies dead at your feet, the apparition begins to laugh."])
	showMessage(e, ["The image of the Ghost starts to flicker and fade and you realize that the ghost isn't really a ghost at all, but just the clever trick of an illusionist mage."])
	showPicture(e, "Summoner")
	showMessage(e, ["You have done well, pawns. I could have never killed Xoram myself. Now that the beholder is dead, I have no more use for you. Surely you have heard of the vast treasures the beholder has aquired, and guarded all these years."]) 
	showMessage(e, ["Too bad for you that i'll be out of this basement with the loot while this place is the last place you will ever see."])
	showMessage(e, ["Incidentally, while you were battling Xoram I took the liberty to alerting the remaining Senrats and other guild members of your heinous crime."])
	showMessage(e, ["When they find you've killed Xoram they will have your head on a stick. Oh, rats! Look they're here. Well It was nice knowing you. Bye."])
	showMessage(e, ["The mage darts off through the north door as hoardes of Senrats surround you. One Senrat steps forward sword drawn.."])		
	showPicture(e, "Senrat")
	showMessage(e, ["A look of hatred sweeps over the Senrat's face. YOU KILLED XORAM! You have tresspassed on our guild and murdered our sacred beholder. For this there is only one thing that you can do now."])
	showMessage(e, ["You and your party WILL PAY WITH YOUR LIVES! The guildmembers lunge forward and attack."])
	bwfinal = 1
	setTag(e, "bwfinal", bwfinal)
	ratfight(e)
	
	
		
def ratfight(e): 
   combat2Ret = combat(e, [("Senrat", 40, 0, 10)])
   if (combat2Ret == 1):
      wonbattle2(e)
   elif (combat2Ret == 3):
      lostFight2(e)
   else:
      ranAwayFightrt(e)
      		

def wonbattle2(e):
	clearPicture(e)
	showMessage(e, ["After you defeat the Senrats, your anger enflares and you rush to the north to find the mage."])
	showPicture(e, "bw_endwalk1")	
	showMessage(e, ["Let's Go!"])
	showPicture(e, "bw_endwalk2")
	showMessage(e, ["You kick open the north door."])	
	showPicture(e, "bw_endwalk3")
	showMessage(e, ["Just up ahead you see the mage still stuffing his pockets with some of Xoram's treasure."])		
	showPicture(e, "bw_endwalk4")	
	showMessage(e, ["The mage looks up in suprise. You survived?! Must I do everything myself?! So be it! Prepare to meet your doom!"])
	bwfinal = 2
	setTag(e, "bwfinal", bwfinal)
	magefight(e)
	

	
		
def magefight(e): 
   combat3Ret = combat(e, [("Summoner", 1, 0, 30)])
   if (combat3Ret == 1):
      wonbattle3(e)
   elif (combat3Ret == 3):
      lostFight3(e)
   else:
      ranAwayFightmg(e)
 

def wonbattle3(e):
	showMessage(e, ["After you defeat the mage you look around in amazement of all of the treasure that Xoram the beholder has collected throughout the years. You think to yourself, well with the mage, the senrats and Xoram all dead, might as well take some of this loot for ourselves."])
   	bwfinal = 3
   	setTag(e, "bwfinal", bwfinal)
   	vault(e)
   	
def vault(e):
	showMessage(e, ["You enter the treasure vault."])
	giveItems(e, ["Perfect Long Sword", "Rune Gauntlets", "Rune Helm", "Rune Shield", "Rune Mail"])
   	bwfinal = 4
   	setTag(e, "bwfinal", bwfinal)
	end(e)
	
      
def end(e):
	setExit(e, "maps/bwquadrant4.cfg", 26, 15, 0)
	bwfinal = 9
	setTag(e, "bwfinal", bwfinal)
	
def refusetofight(e):
	showMessage(e, ["You cowards! You would let this beholder run free to murder at will?! May God curse your wretched souls to hell!."])      
	showMessage(e, ["As the apparition is wringing your ears, you look back and notice Xoram the beholder casting a spell......."])
	showPicture(e, "Abeholder")
	showMessage(e, ["Xoram's spell sends an orange beam of light onto the ghost. You notice that the orange light seems to shine through the ghosts image revealing that it is not really a ghost at all, but an illusionist mage."])	
	showMessage(e, ["You are no ghost at all. I sense evil is afoot here. Who are you?"])
	showPicture(e, "Summoner")
	showMessage(e, ["Curse you Xoram! I was this close to having these wretched adventurers cut you to pieces. Then the treasure that you have been guarding all these years would be mine! MINE! The image of the ghost may not have been real, but I'll show you something that IS real. Lets see how well you deal with my golems!"])
	showPicture(e, "Stone_Golem")
	showMessage(e, ["20 stone golems appear from out of nowhere."])
	showPicture(e, "Iron_Golem")
	showMessage(e, ["20 iron golems appear too!"])	
	showPicture(e, "Abeholder")
	showMessage(e, ["Adventurer's...we must fight together, if we wish to survive. I'll handle the iron golems. You take the stone golems."])	
	bwbasementend = 4
	setTag(e, "bwfinal", bwfinal)
	sgfight(e)

		
def sgfight(e): 
   combat2Ret = combat(e, [("Stone Golem", 40, 0, 10)])
   if (combat2Ret == 1):
      wonbattle4(e)
   elif (combat2Ret == 3):
      lostFight2(e)
   else:
      ranAwayFightsg(e)
	
def wonbattle4(e):
	showMessage(e, ["You defeat the stone golems. You look over and see that the Xoram the beholder has defeated the iron golems also."])		
	showPicture(e, "Summoner")	
	showMessage(e, ["You have defeated my golems, but I'm not through with you yet!"])	
	bwfinal = 5
	setTag(e, "bwfinal", bwfinal)
	altmfight(e)

		
def altmfight(e): 
   combat2Ret = combat(e, [("Summoner", 1, 0, 30)])
   if (combat2Ret == 1):
      wonbattle5(e)
   elif (combat2Ret == 3):
      lostFight2(e)
   else:
      ranAwayFightam(e)
 
      
def wonbattle5(e):
	showPicture(e, "Abeholder")	
	showMessage(e, ["My greatest thanks to you brave adventurers. Many have tried to defeat me to take the wealth that I have accumulated throughout the years, but you have come to my aid in my time of need. Thank you. As a token of my goodwill, please take a walk through my vault and take anything that suits your needs. Just go through the door to the north."])		
	showMessage(e, ["You thank Xoram and start towards the vault."])
	showPicture(e, "bw_endwalk1")
	showMessage(e, ["walking...."])
	showPicture(e, "bw_endwalk2")
	showMessage(e, ["you push open the door"])
	showPicture(e, "bw_endwalk3")
	showMessage(e, ["walking....."])		
	showPicture(e, "bw_endwalk4")
	showMessage(e, ["walking....."])		
   	bwbasementend = 3
   	setTag(e, "bwfinal", bwfinal)
	vault(e)
	
	
def ranAwayFightam(e):
    showMessage(e, ["You can't escape."])
    altmfight(e)
    
def ranAwayFightsg(e):
    showMessage(e, ["You can't escape."])
    sgfight(e) 
    
def ranAwayFightmg(e):
    showMessage(e, ["You can't escape."])
    magefight(e)
    
def ranAwayFightrt(e):
    showMessage(e, ["You can't escape."])
    ratfight(e)    
    
def ranAwayFight(e):
    showMessage(e, ["You can't escape."])
    fightbeholder(e)     
 