from eventAPI import *
from APIUtils import *

def fireEvent(e):
   if ((getTag(e, "lFlagS") & 0x100) == 0):
        return 1
   k = getTag(e, "kssBF")
   if (k == 0):
      k += 1
      setTag(e, "kssBF", k)
      showMessage(e, ["Judging on the many bits of organic matter stored here, the ants obviously use the place to stockpile food.","",
                      "It doubles as an aphid farm too, making you wonder where the ants found aphids this size (for that matter, whence do these ants come from?)."])
      showMessage(e, ["Anyway, several of them rush to protect their investment."])
   elif (k == 1):
      showMessage(e, ["No sooner do you try to enter the food store than several ants jump to bar your way."])
   elif (k == 2):
      showMessage(e, ["More ants try to prevent you from stealing their food."])
   elif (k == 3):
      showMessage(e, ["Ants come to protect their herd from aphid rustlers."])
   elif (k == 4):
      showMessage(e, ["Another ant squad stands in your way."])
   elif (k == 5):
      showMessage(e, ["Ants, ants, ants. Don't they know when to call it a day?"])
   elif (k < 11):
      if (poseYesNo(e, ["There is some honeydew left: do you want to drink some?"])):
         k += 1
         setTag(e, "kssBF", k)
         x, c = 0, getPartyCount(e)
         while (x < c):
            modifyHP(e, x, 500)
            modifySP(e, x, 100)
            x += 1
         if (k < 11):
            showMessage(e, ["The honeydew restores you. Use it sparingly though, for it will not last forever."])
         else:
            showMessage(e, ["You consume the last of the honeydew, and feel restored."])
         fireEvent(e)
      return 1
   else:
      return 1
   cr = combat(e, [("Warrior Ant", 2, 6, 10), ("Fire Ant", 0, 3, 30)])
   if (cr == 1):
      k += 1
      setTag(e, "kssBF", k)
      if (k == 6):
         showMessage(e, ["After defeating those ants, no more try to stop you. You have the run of the food store and the farm.","",
                         "Out of curiosity, you taste the much contested for aphid's honeydew, and find it has surprisingly restorative properties."])
         x, c = 0, getPartyCount(e)
         while (x < c):
            modifyHP(e, x, 100)
            modifySP(e, x, 20)
            x += 1
      else:
         showMessage(e, ["These ants won't bother you anymore.","","","","However..."])
      return fireEvent(e)
   elif (cr == 3):
      showMessage(e, ["You've lost, but you still get to visit the food store (albeit in little pieces)."])
   else:  
      showMessage(e, ["Let them keep their aphids, you have better things to do."])
      return 0

