
### Quests ###

# Add any event triggers to this list.
# Only one event can play for each day/night (this might change.)
# Add date specific events at the start of the list (create the date if it's not there.)

label quests:

    $ renpy.choice_for_skipping()

    if current_room == "main_room":
        #
        # DAY-BASED EVENTS
        #

        if game.day >= 1:
            if game.daytime:
                if not genie_intro.E2_complete and bird_examined and desk_examined and cupboard_examined and door_examined and fireplace_examined:
                    jump genie_intro_E2
            else:
                if not snape_intro.E1_complete:
                    jump snape_intro_E1

        if game.day >= 2:
            if game.daytime:
                if not genie_intro.E3_complete:
                    jump genie_intro_E3
            else:
                if ss_event_pause == 0 and not snape_intro.E2_complete:
                    # Snape's second visit.
                    jump snape_intro_E2

        if game.day >= 3:
            if game.daytime:
                if not genie_intro.E4_complete:
                    jump genie_intro_E4
            else:
                if ss_event_pause == 0 and not snape_intro.E3_complete:
                    # Day of the duel.
                    jump snape_intro_E3


        if game.day >= 4:
            if game.daytime:
                pass
            else:
                if ss_event_pause == 0 and not snape_intro.E5_complete:
                    # You bother decide to just "roll with it"... Snape summon unlocked.
                    jump snape_intro_E5

        if game.day >= 5:
            if game.daytime:
                if hg_event_pause == 0 and not hermione_intro.E1_complete:
                    # Hermione shows up for the first time.
                    jump hermione_intro_E1

        if game.day >= 6:
            if game.daytime:
                if hg_event_pause == 0 and ss_he.hermione_E1 and not hermione_intro.E2_complete:
                    # Second visit from Hermione. Says she sent a letter to the Ministry.
                    jump hermione_intro_E2
            else:
                pass

        if game.day >= 7:
            if game.daytime:
                pass
            else:
                if hg_event_pause == 0 and ss_he.hermione_E2 and not hermione_intro.E3_complete:
                    # Takes place after first special event with Snape, where he just complains about Hermione.
                    # Hermione might have failed a test...
                    jump hermione_intro_E3

        if game.day >= 8:
            if game.daytime:
                pass
            else:
                if hg_event_pause == 0 and hermione_intro.E3_complete and not hermione_intro.E4_complete:
                    # She failed a test and cries.
                    jump hermione_intro_E4

        if game.day >= 9:
            if game.daytime:
                if hg_event_pause == 0 and hermione_intro.E4_complete and not hermione_intro.E5_complete:
                    # Hermione asks to be tutored. Summon unlocked!
                    jump hermione_intro_E5

        if game.day >= 10:
            if game.daytime:
                if nt_event_pause == 0 and hermione_intro.E5_complete and not tonks_intro.E1_complete:
                    # Tonks visits for the first time.
                    jump tonks_intro_E1
            else:
                if tonks_intro.E1_complete and not tonks_intro.E2_complete:
                    # Tonks has found no evidence so far.
                    jump tonks_intro_E2

        if game.day >= 11:
            if game.daytime:
                pass
            else:
                if nt_event_pause == 0 and ss_he.tonks_E1 and not tonks_intro.E3_complete:
                    # Tonks becomes a teacher. Summon unlocked!
                    jump tonks_intro_E3

        if game.day >= 13:
            if game.daytime:
                if hg_event_pause == 0 and hermione_intro.E5_complete and ss_he.tonks_E1 and nt_he.hermione_E1 and not hermione_intro.E6_complete:
                    # Hermione wants to buy favours. Favours unlocked!
                    jump hermione_intro_E6

        if is_puzzle_box_in_fireplace():
            $ fire_in_fireplace = False
            $ fireplace_OBJ.foreground = "glow_effect_fireplace"
        elif fireplace_OBJ.foreground == "glow_effect_fireplace":
            $ fireplace_OBJ.foreground = None

        #
        # CARDGAME - EVENTS
        #

        if game.day >= twins_cards_delay:
            if deck_unlocked and twins_first_win and not twins_cards_stocked:
                if not game.daytime:
                    $ letter_cards_store.send()

        if geniecard_level < 2 and snape_third_win and her_third_win and twins_second_win:
            if not game.daytime:
                $ letter_cards_tier2.send()

        #
        # CHO CHANG - EVENTS
        #

        if cc_event_pause == 0:
            if game.daytime:

                if not cho_intro.E1_complete and her_tier >= 2:
                    # Cho intro
                    jump cho_intro_E1

                if hufflepuff_match == "start":
                    $ game.weather = "clear"
                    stop weather
                    $ hufflepuff_match = "return"
                    jump hufflepuff_match
                elif slytherin_match == "start":
                    $ game.weather = "clear"
                    stop weather
                    $ slytherin_match = "return"
                    jump slytherin_match
                elif gryffindor_match == "start":
                    $ game.weather = "clear"
                    stop weather
                    $ gryffindor_match = "return"
                    jump gryffindor_match

                if cho_tier == 1:
                    # Lee Jordan gets knocked out cold
                    if cho_quid.hufflepuff_training and not cho_quid.E3_complete:
                        jump cho_quid_E3

                elif cho_tier == 2:
                    # Hermione refuses to commentate for Slytherin match.
                    if cho_quid.slytherin_failed and not cho_quid.E6_complete:
                        jump cho_quid_E6

                elif cho_tier == 3:
                    # Genie decides to get the broom.
                    if cho_quid.gryffindor_training and not cho_quid.E12_complete:
                        jump cho_quid_E12

                    # Informs the player that all preparations are complete
                    if cho_quid.E11_complete and cho_quid.E12_complete and not cho_quid.E13_complete:
                        jump cho_quid_E13

            else:
                # Introduction
                if cho_intro.E1_complete and not cho_intro.E2_complete:
                    jump cho_intro_E2

                # Quidditch training matches
                if cho_quid.in_progress:
                    $ cho_quid.in_progress = False

                    if cho_tier == 1:
                        # Hufflepuff
                        jump cc_ht_return
                    elif cho_tier == 2:
                        # Slytherin
                        jump cc_st_return
                    elif cho_tier == 3:
                        # Gryffindor
                        jump cc_gt_return

                    # Note: The return events now get jumped to right after the main match events.

                python:
                    for i in cc_requests_list:
                        if i.inProgress:
                            i.inProgress = False
                            i.start()

            $ play_potion_return("cho")

        #
        # SUSAN BONES - EVENTS
        #

        if sb_event_pause == 0:
            if game.daytime:
                # Introduction
                if nt_he.susan_E1 and not susan_intro.E1_complete:
                    jump susan_intro_E1

            $ play_potion_return("susan")

        #
        # ASTORIA GREENGRASS - EVENTS
        #

        # Astoria events not triggered by a date.
        if ag_event_pause == 0:
            if game.daytime:
                # Introduction
                if astoria_intro.E2_hermione and astoria_intro.E2_snape and not astoria_intro.E3_complete:
                    jump astoria_intro_E3
                if nt_he.astoria_E1 and not astoria_intro.E4_complete:
                    jump astoria_intro_E4
            else:
                # Introduction
                if susan_intro.E1_complete and not astoria_intro.E1_complete:
                    jump astoria_intro_E1

                python:
                    for i in ag_spell_list: # Spell Training
                        if i.inProgress:
                            i.inProgress = False
                            i.start()

            $ play_potion_return("astoria")

        #
        # SEVERUS SNAPE - EVENTS
        #

        if ss_event_pause == 0:
            if game.daytime:
                # Ending events
                if her_whoring >= 15 and ball_quest.E1_complete and not ball_quest.E2_complete:
                    # Snape complains that appointing Hermione in the Autumn Ball committee was a mistake.
                    jump ball_quest_E2

            else:
                # Ending events
                if ball_quest.started and not ball_quest.completed:
                    jump ball_ending_E1

        #
        # NYMPHADORA TONKS - EVENTS
        #

        # Tonks events not triggered by a date.
        if nt_event_pause == 0:
            if game.daytime:
                python:
                    for i in tonks_mail_list:
                        if i == "poster_1_gift":
                            letter_nt_1.send()
                        tonks_mail_list.remove(i)
            else:
                python:
                    for i in nt_requests_list:
                        if i.inProgress:
                            i.inProgress = False
                            i.start()

            $ play_potion_return("tonks")

        #
        # HERMIONE GRANGER - EVENTS
        #

        if hg_event_pause == 0:
            if game.daytime:
                # Ending events
                if her_whoring >= 15 and not ball_quest.E1_complete:
                    # Hermione wants to be in the Autumn Ball committee.
                    jump ball_quest_E1

                if her_whoring >= 18 and ball_quest.E2_complete and not ball_quest.E3_complete:
                    # Hermione cries about having no proper dress for the Ball.
                    jump ball_quest_E3

                if her_whoring >= 18 and ball_quest.E3_complete and not ball_quest.E4_complete:
                    # Hermione apologizes for the day (event) before.
                    jump ball_quest_E4

                if hg_pr_sex.is_event_complete(6, 1) and not hg_pr_sex.is_event_complete(6, 2):
                    # Hermione missed the debriefing
                    $ hg_pr_sex.start()
            else:
                if current_job == "maid":
                    jump maid_responses
                elif current_job == "barmaid":
                    jump barmaid_responses
                elif current_job == "gryffindor_cheerleader":
                    jump gryffindor_cheer_responses
                elif current_job == "slytherin_cheerleader":
                    jump slytherin_cheer_responses
                elif current_job == "promoter":
                    jump hermione_helping_selling_cards

                python:
                    for i in hg_requests_list:
                        if i.inProgress:
                            i.start()

                    for i in hg_ps_list: #Call any public shaming event if it's in progress
                        if i.inProgress:
                            renpy.jump(i.complete_label)

            $ play_potion_return("hermione")

        #
        # LUNA LOVEGOOD - EVENTS
        #

        if ll_event_pause == 0:
            if not luna_intro_E1 and her_tier >= 3:
                if not game.daytime:
                    # Luna barges into your office sleepwalking.
                    jump luna_intro_E1

            if luna_intro_E1 and not luna_intro_E2:
                if game.daytime:
                    jump luna_intro_E2

            if spectrespecs_E1 and not quibbler_stocked:
                if game.daytime:
                    jump spectrespecs_E2_reminder

            $ play_potion_return("luna")
    elif current_room == "snape_office":

        if game.daytime:
            if not snape_office_intro_E1:
                # Genie searches the office
                jump potions_intro_E1

            if not snape_office_intro_E2 and snape_office_intro_E1:
                # Genie gets caught by the painting.
                jump potions_intro_E2
        else:
            if not snape_office_intro_E2:
                # (Optional) Genie gets caught by Snape. (E0 can play either before or after E1)
                jump potions_intro_E0

    $ eventqueue.start()

    # All quest events should somehow end with a jump to the main room day/night cycle
    # If no quest event is triggered, resume normally from the main room
    call music_block
    call screen room_menu


### Quests flags ###

# Genie
default genie_intro = quest_class(
    E1_complete = False,
    E2_complete = False,
    E3_complete = False,
    E4_complete = False,
)

# Snape
default snape_intro = quest_class(
    E1_complete   = False, # 1st visit
    E2_complete   = False, # 2nd visit
    E3_complete   = False, # 3rd visit, before the duel.
    duel_complete = False, # Duel
    E4_complete   = False, # After the duel.
    E5_complete   = False, # 4th visit, summon unlocked.
)

# Hermione
default hermione_intro = quest_class(
    E1_complete = False, # 1st visit
    E2_complete = False, # 2nd visit, MRM + informed the Ministry.
    E3_complete = False, # 3rd visit, did she fail a test?
    E4_complete = False, # 4th visit, she's crying. Failed a test.
    E5_complete = False, # 5th visit, asks to be tutored, summon unlocked.
    E6_complete = False, # 6th visit, asks to buy favours, favours unlocked.
)

# Tonks
default tonks_intro = quest_class(
    E1_complete = False, # 1st visit
    E2_complete = False, # 2nd visit
    E3_complete = False, # 3rd visit, summon unlocked.
)

# Cho
default cho_intro = quest_class(
    E1_complete = False, # 1st visit
    E2_complete = False, # 2nd visit
    E3_intro    = False, # You talked to Hermione once, but event failed.
    E3_complete = False, # 3rd visit, summon unlocked.
)

default cho_quid = quest_class(
    E1_complete = False, # Hufflepuff - Intro 1
    E2_complete = False, # Hufflepuff - Intro 2
    E3_complete = False, # Lee Jordan gets hit by a bludger
    E4_complete = False, # Genie asks Hermione to commentate
    E5_complete = False, # Slytherin - Intro 1
    E6_complete = False, # Hermione refuses to commentate.
    E7_complete = False, # Blackmail Hermione.
    E8_complete = False, # Ask Tonks for help (Hangout)
    E9_complete = False, # Ask Snape for help (Hangout)(Optional)
    E10_complete = False, # Gryffindor - Intro 1
    E11_complete = False, # Ask Luna for help (Talk)
    E12_complete = False, # Acquire new broom
    E13_complete = False, # Notify the player that all preparations are complete

    hufflepuff_prepared = False, # Ready for practice match? (Requirements: tactic)
    hufflepuff_training = False, # Finished Hufflepuff practice match?
    hufflepuff_complete = False, # Finished Hufflepuff event chain?

    slytherin_failed = False, # Has failed first training match?
    slytherin_prepared = False, # Ready for practice match? (Requirements: tactic, blackmail Hermione, Tonks' help)
    slytherin_training = False, # Finished Slytherin practice match?
    slytherin_complete = False, # Finished Slytherin event chain?

    gryffindor_failed = False, # Found a cheerleader? (Requirements: Ask Luna)
    gryffindor_prepared = False, # Ready for practice match? (Requirements: tactic)
    gryffindor_training = False, # Finished Gryffindor practice match?
    gryffindor_complete = False, # Finished Gryffindor event chain?

    position = "", # Valid choices: "front", "above", "close"

    lock_training = False,
    lock_practice = True,
    lock_tactic = False,
    in_progress = False,
)

default cho_quiz = quest_class(
    E1_complete = False,
    E2_complete = False,

    correct_answers = 0,
    checkpoint = False,
    lost = False,
    complete = False,

    hint = "" # Set after reading Quidditch Book
)

# Susan
default susan_intro = quest_class(
    E1_complete = False, # Susan visits.
)

# Astoria
default astoria_intro = quest_class(
    E1_complete = False, # Tonks visits.
    E2_hermione = False, # Tell Hermione to look for her.
    E2_snape    = False, # Tell Snape to look for her.
    E3_complete = False, # Hermione finds her.
    E4_complete = False, # Unlock Astoria.
)

# Ball Quest
default ball_quest = quest_class(
    E1_complete = False,
    E2_complete = False,
    E3_complete = False,
    E4_complete = False,
    gave_dress  = False,
    started     = False,
    completed   = False,
)


### Hangout Events ###

# Snape
default ss_he = quest_class(
    hermione_E1 = False, # I hate her!
    hermione_E2 = False, # Let's ruin her!
    tonks_E1    = False, # Discuss Tonks with Snape.
    tonks_E2    = False, # Inform him that Tonks has joined you both.
    tonks_E3    = False, # Tonks is teaching DAtDA. Snape might use Veritaserum on her...
    cho_E1      = False, # You tell Snape that you have met Cho.
    cho_E2      = False, # Get some help with Quidditch.

    hermione_strip = False, # You invite Snape to watch Hermione strip.
)

# Tonks
default nt_he = quest_class(
    hermione_E1 = False, # Help with/unlock Hermione's favours.
    susan_E1    = False, # Tonks is worried about Susan.
    astoria_E1  = False, # Tonks suggests to teach Astoria the Imperius curse.

    favors_E1   = False, # Unlock Public Requests.
    favors_E2   = False, # Advance to Tier 2.
)
