#keep garden fight
from eventAPI import *
from APIUtils import *

rtKeep1Garden = 0

def fireEvent(e):
   global rtKeep1Garden
   rtKeep1Garden = getTag(e, "rtKeep1Garden")
   if (rtKeep1Garden == 1):
      return 1
   else:
      returnSeed(e)
   return 0

def returnSeed(e):
   showMessage(e, ["There is a strange garden here, you have no idea of it's intended purpose."], optionInput)
   i, max = 0, getPartyCount(e)
   hasSeed = 0
   while (i < max):
      if (hasItem(e, i, "Magic Seeds")):
         hasSeed = 1
         break
      i += 1
   text = ["The soil here is fine and damp."]
   if (hasSeed):
      optionTexts = ["(Y)es", "(N)o"]
      optionsKeys = [SDLK_y, SDLK_n]
      text.extend(["", "Do you plant the Magic Seeds within the soil?"])
   else:
      optionTexts = ["(L)eave the Scene"]
      optionsKeys = [SDLK_l]
   if (optionInput(e, text, optionTexts, optionsKeys) == SDLK_y):
      removeSeed(e)

def removeSeed(e):
   global rtKeep1Garden
   i, max = 0, getPartyCount(e)
   hasSeed = 0
   while (i < max):
      if (hasItem(e, i, "Magic Seeds")):
         hasSeed = 1
         break
      i += 1
   removeItem(e, i, "Magic Seeds")
   showMessage(e, ["The ground shakes and magical trees spring up from the soil."])
   showMessage(e, ["To your surprise, the trees attack you."])
   rtKeep1Garden = 1
   setTag(e, "rtKeep1Garden", rtKeep1Garden)
   fightThem(e)

def fightThem(e):
   combatRet = combat(e, [("Haunted Ironwood", 3, 0, 10)])
   if (combatRet == 1):
      wonFight(e)
   elif (combatRet == 3):
      lostFight(e)
   else:
      ranAwayFight(e)

def wonFight(e):
   showMessage(e, ["You continue to hack at the fallen trees until only splinters remain."])
   showMessage(e, ["You notice something lying in the debris."])
   giveItems(e, ["Enchanted Ironwood Fists"])

def lostFight(e):
   showMessage(e, ["Food for the trees."])

def ranAwayFight(e):
   showMessage(e, ["You flee the battle and the trees collapse and fade away."])
