"""
School Life Events
Daily school events, interactions, and situations (ages 6-18)

Events:
- likeSchool: Reaction to starting kindergarten
- dropBooks: Helping someone who dropped their books
- fieldTrip: Field trip destination choice
- vendingMachine: Vending machine mishap
- schoolAssembly: School assembly volunteer
- schoolFight: School fight situation
- schoolLunch: Lunch choice
- forgotCombo: Forgot locker combination
- latetoSchool: Running late for school
- tiredinClass: Tired in class
"""

import random
from events.base import messageFunction, questionFunction, answerOption


def likeSchool(player, type='message', message=False, response=False):
    """Reaction to starting kindergarten"""
    fname = 'likeSchool'
    check = fname not in player.askedQuestions and player.c.occupation == 'student' and player.c.ageYears >= 4 and player.c.ageYears < 8 and 1 >= random.random()*1000
    message = "You have started Kindergarten, do you like it?"
    answerOptions = ['Yes','No']
    if (type != 'answer'):
        return questionFunction(fname,message,player,check,answerOptions)
    elif (type == 'answer'):
        if (response['option'] == "Yes"):
            player.c.happiness += 10
        else:
            player.c.happiness -= 10


def dropBooks(player, type='message', message=False, response=False):
    """Helping someone who dropped their books"""
    fname ='dropBooks'
    check = fname not in player.askedQuestions and 'school' in player.c.location and 1 >=random.random()*1000
    message = "You're walking down a busy hall at school and see someone drop their books."
    answerOptions = [answerOption('Stop and help them pick up their books',energyCost=5),answerOption("Keep walking"),answerOption("Stop and laugh - what a loser!"),answerOption("Grab a few books and offer to walk them to class",diamondCost=5)]
    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        if (response ['option'] == answerOptions[0]):
            player.messageQueue.append("They give you a quick nod of appreciation, say thanks, and hurry off to class. You stop for a second and smile - it feels good to help out!")
            player.c.happiness += 10
        elif (response ['option'] == answerOptions[1]):
            player.messageQueue.append("You made it to class on time and spend the first few minutes of class wondering if that student made it on time as well")
        elif (response ['option'] == answerOptions[2]):
            player.messageQueue.append("Tears form in the student's eyes and they scramble to pick up their books. You smile to yourself, happy you're not a loser like they are.")
            player.social -= 20
            player.c.happiness += 5
        elif (response ['option'] == answerOptions[3]):
            player.messageQueue.append("The student looks visibly surprised and happy to receive your help. They say a quiet 'thank you' once you get to their classroom and you both go on your way. You think you hear the student whispering to their friends about your good deed.")
            player.social += 10
            player.c.happiness += 10


def fieldTrip(player, type='message', message=False, response=False):
    """Field trip destination choice"""
    fname ='fieldTrip'
    check = fname not in player.askedQuestions and player.c.ageYears >= 8 and player.c.ageYears <= 12 and 1 >=random.random() * 100
    message = "Your school has handed you a form for the next field trip - it looks like you're able to vote for where to go! What looks best?"
    answerOptions = [answerOption('Visit the local zoo',moneyCost=20),answerOption('Explore the science museum',moneyCost=15),answerOption('Take a trip to a historical landmark',moneyCost=10)]
    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        if (response['option'] == answerOptions[0]):
            player.messageQueue.append("You had a great time at the zoo and learned a lot about different animals!")
            player.c.happiness += 10
        elif (response['option'] == answerOptions[1]):
            player.messageQueue.append("The science museum was fascinating! You got to perform fun experiments and see interactive exhibits.")
            player.social += 5
            player.c.happiness += 5
        elif (response['option'] == answerOptions[2]):
            player.messageQueue.append("You spent some time at an old war memorial. It was a little sad, but you found it interesting to see the rich history of where you live.")
            player.social += 10


def vendingMachine(player, type='message', message=False, response=False):
    """Vending machine mishap"""
    fname ='vendingMachine'
    check = fname not in player.askedQuestions and 'school' in player.c.location and 1 >=random.random()*1000
    message = "You walk past someone standing next to a vending machine at school. As you pass, they yell 'Hey - this machine isn't accepting my dollar, can you help out?'"
    answerOptions = [answerOption('Point to your headphones and shake your head'),answerOption('Give them one of your dollar bills to try',moneyCost=1),answerOption('You only have a 5 dollar bill, but hand it over anyways',moneyCost=5),answerOption('Walk over and hit the vending machine',diamondCost=10)]
    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        if (response ['option'] == answerOptions[0]):
            player.messageQueue.append("You weren't listening to anything, but you got the point across")
            player.social -= 5
        elif (response ['option'] == answerOptions[1]):
            player.messageQueue.append("The dollar bill works perfectly.The appreciative student gives you their dollar with a smile, grabs their snack, and heads to class")
            player.social += 5
        elif (response ['option'] == answerOptions[2]):
            player.messageQueue.append("To both of your surprise, the machine takes the 5 dollar bill... but it doesn't give any change.")
            player.social += 10
        elif (response ['option'] == answerOptions[2]):
            player.messageQueue.append("You've seen this machine act up before - nothing a quick kick can't fix! Your foot connects with the glass and two bags of chips fall down. Nice.")
            #add item to inventory? Chips for energy recharge or something
            player.social += 5


def schoolAssembly(player, type='message', message=False, response=False):
    """School assembly volunteer"""
    fname ='schoolAssembly'
    check = fname not in player.askedQuestions and 'school' in player.c.location and 1 >=random.random()*1000
    message = "All students are called for an impromptu assembly. Once you take your seat, the speaker asks for a volunteer."
    answerOptions = [answerOption("Raise your hand"),answerOption("Shrink smaller into your seat, hoping he doesn't see you")]
    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        if (response ['option'] == answerOptions[0]):
            player.messageQueue.append("You smile as the speaker points directly at you. As you stand up, you feel all eyes on you... and its a great feeling.")
            player.social += 10
        if (response ['option'] == answerOptions[1]):
            player.messageQueue.append("You let out a giant sigh of relief as the speaker picks an enthusiasic student across the room.")
            player.social -= 10


def schoolFight(player, type='message', message=False, response=False):
    """School fight situation"""
    fname = 'schoolFight'
    check = fname not in player.askedQuestions and 'school' in player.c.location and player.c.ageYears >= 14 and player.c.ageYears <= 18 and 1 >=random.random() * 100
    message = "Tensions are high, and a fight is about to break out at school. What will you do?"
    answerOptions = [
        answerOption('Intervene and try to break up the fight', energyCost=15),
        answerOption('Stay out of it and find a teacher to handle the situation', energyCost=5),
        answerOption('Join in and fight alongside your friends', diamondCost=10)
    ]
    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        if (response['option'] == answerOptions[0]):
            player.messageQueue.append("You courageously step in to break up the fight and promptly get punched in the face...")
            player.c.happiness -= 5
        elif (response['option'] == answerOptions[1]):
            player.messageQueue.append("You run the other way in search of a teacher. Some things just aren't worth the risk")
        elif (response['option'] == answerOptions[2]):
            player.messageQueue.append("Fists are flying, but you've got your friends' back. Once the dust settles you see a crowd of teachers around - you know you're in trouble, but it was totally worth it.")
            player.social += 10


def schoolLunch(player, type='message', message=False, response=False):
    """Lunch choice"""
    fname = 'schoolLunch'
    check = fname not in player.askedQuestions and player.hourOfDay == 12 and 'school' in player.c.location and 1 >=random.random() * 100
    message = "Your stomach growls - when's lunch? Thankfully, the bell rings and you make your way to the cafeteria. What are you eating today?"
    answerOptions = [
        answerOption('Grab a slice of pizza and a soda', moneyCost=10),
        answerOption('Choose a healthy salad and a bottle of water', diamondCost=10),
        answerOption('Go to your locker and grab your packed lunch from home',energyCost=5),
        answerOption("Grab someone else's lunch")
    ]
    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        if (response['option'] == answerOptions[0]):
            player.messageQueue.append("The pizza was amazing, but you spend the next few hours regretting leaving all the grease on the slice.")
        elif (response['option'] == answerOptions[1]):
            player.messageQueue.append("It might be more expensive, but its worth the cost!")
        elif (response['option'] == answerOptions[2]):
            player.messageQueue.append("As you finish your sandwich, you reach into the bag and find a cookie - score!")
        elif (response['option'] == answerOptions[3]):
            player.messageQueue.append("You eye the cafeteria looking for a student sitting alone. You spot a lanky kid at the end of a long table, walk over, and grab the lunch. Everything is better when its free!")


def forgotCombo(player, type='message', message=False, response=False):
    """Forgot locker combination"""
    fname = 'forgotCombo'
    check = fname not in player.askedQuestions and 'school' in player.c.location and player.c.ageYears >= 11 and player.c.ageYears <= 15 and 1 >=random.random() * 100
    message = "You walk over to your locker and enter your combo. 25-44-... what was the last number? You start to panic, did you forget your combination?"
    answerOptions = [
        answerOption('Ask a friend if they remember your combination', energyCost=5),
        answerOption('Head to the school office to get some help', energyCost=10),
        answerOption('Brute force your combination', diamondCost=10),
        answerOption('Start kicking your locker', energyCost=5)
    ]
    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        if (response['option'] == answerOptions[0]):
            player.messageQueue.append("Luckily, your friend remembers your locker combination. ...wait, how did they know that?")
        elif (response['option'] == answerOptions[1]):
            player.messageQueue.append("It took a while, but the school office was able to track down a maintenance person to get you into your locker")
        elif (response['option'] == answerOptions[2]):
            player.messageQueue.append("After about 30 tries you made it into your locker. Good thing you remembered the first two numbers!")
        elif (response['option'] == answerOptions[3]):
            player.messageQueue.append("You loudly kick the locker for a few minutes, doing nothing more than adding a few dents. Eventually a teacher angrily storms into the hall and brings you to the school office.")


def latetoSchool(player, type='message', message=False, response=False):
    """Running late for school"""
    fname = 'latetoSchool'
    check = fname not in player.askedQuestions and 'home' in player.c.location and 1 >=random.random() * 1000 #and morning #bike condition #car condition
    message = "You woke up late and now you're running behind for school. What will you do?"
    answerOptions = [
        answerOption('Arrive late and get a tardy'),
        answerOption('Hurry to school as fast as you can', energyCost=20),
        answerOption('Skip school for the day', diamondCost=10)
    ]
    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif type == 'answer':
        if (response['option'] == answerOptions[0]):
            player.messageQueue.append("You hop out of bed and rush to get to school - you were a little late and forgot your lunch, but you made it!")
        elif (response['option'] == answerOptions[1]):
            player.messageQueue.append("You hop out of bed and rush to get to school... but stop halfway and realize that you're probably this tired for a reason. Some rest would be good!")


def tiredinClass(player, type='message', message=False, response=False):
    """Tired in class"""
    fname = 'tiredinClass'
    check = fname not in player.askedQuestions and 'school' in player.c.location and 1>=random.random() * 1000
    message = "You had a late night last night and now you're struggling to stay awake in class. What will you do?"
    answerOptions = [
        answerOption('Try as hard as you can to stay awake and pay attention', energyCost=10),
        answerOption('Ask the teacher if you can head to the bathroom', diamondCost=5),
        answerOption("Take a quick nap and hope the teacher doesn't notice", energyCost=5)
    ]
    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif type == 'answer':
        if (response['option'] == answerOptions[0]):
            player.messageQueue.append("Through the power of sheer determination you manage to stay awake for the rest of class. Honestly, you're pretty impresssed with yourself!")
        elif (response['option'] == answerOptions[1]):
            player.messageQueue.append("You asked the teacher if you can head to the bathroom. After getting permission, you head out into the hallway and grab a soda from the vending machine. This should work!")
            #add item for energy boost
        elif (response['option'] == answerOptions[2]):
            player.messageQueue.append("The teacher immediately notices you sleeping. At least now you'll be able to sleep in detention...")


__all__ = [
    'likeSchool',
    'dropBooks',
    'fieldTrip',
    'vendingMachine',
    'schoolAssembly',
    'schoolFight',
    'schoolLunch',
    'forgotCombo',
    'latetoSchool',
    'tiredinClass',
]
