def librarykey(storage, obj, m):
    storage._go()
    if storage._playerInDistance(m.getPlayer().position, obj.rect):
        tr = GlobalServices.getTextRenderer()
        ad = GlobalServices.getAudioDevice()
        ad.play(SOUND, 'pick_key', VOLUME_SOUND)
        tr.write("Got 'Library Key'", 3, COLOR_GOT_ITEM)
        m.getPlayer().inventory.add(ItemFactory.create(INVENTORY_ITEM_LIBRARY_KEY, 1))
        remove_from_map(get_savegame(), OBJECT, 'mirrorhall', 'librarykey')
        storage._setData('librarykey_obtained', True)
    storage._halt()
def ladder(storage, obj, m):
    storage._go()
    if storage._playerInDistance(m.getPlayer().position, obj.rect):
        tr = GlobalServices.getTextRenderer()
        ad = GlobalServices.getAudioDevice()
        if storage._getData('masterroom_ladder_needed'):
            storage._toggleCutscene(True)
            tr.write("This ladder should get me up through that loft hatch.", 3)
            storage._wait(3000)
            inv = m.getPlayer().inventory
            inv.add(ItemFactory.create(INVENTORY_ITEM_LADDER, 1))
            remove_from_map(get_savegame(), OBJECT, 'rightwing', 'ladder')
            ad.play(SOUND, 'pick_item', VOLUME_SOUND)
            tr.write("Got 'Ladder'", 3, COLOR_GOT_ITEM)
            storage._toggleCutscene(False)
            GlobalServices.getEventManager().post(ObjectHighlightedEvent(None))
        else:
            tr.write("There is a ladder on the ground. I have no purpose for that right now.", 3)
    storage._halt()
def keyshelf(storage, obj, m):
    storage._go()
    
    tr = GlobalServices.getTextRenderer()
    ad = GlobalServices.getAudioDevice()
    
    if storage._playerInDistance(m.getPlayer().position, obj.rect):
        # If the player has got the key
        if storage._getData('atriumkey_obtained'):
            tr.write("Nothing of interest.", 3)
        # If the player has pressed the switch
        elif storage._getData('guestroom_switch_pressed'):
            storage._toggleCutscene(True)
            tr.write("That lever has moved the wooden canvas.", 3)
            storage._wait(3000)
            tr.write("A small compartment containing a pale key was revealed.", 3)
            storage._wait(3000)
            emptyshelf = os.path.join(PATH_GRAPHICS_TILES,'shelf_taken.png')
            obj.changeImage(emptyshelf, True)
            ad.play(SOUND, 'pick_key', VOLUME_SOUND)
            tr.write("Got 'Atrium Key'", 3, COLOR_GOT_ITEM)
            m.getPlayer().inventory.add(ItemFactory.create(\
                                        INVENTORY_ITEM_ATRIUM_KEY, 1))
            storage._setData('atriumkey_obtained', True)
            storage._toggleCutscene(False)
            
        # Otherwise
        else:
            storage._toggleCutscene(True)
            tr.write("This is a weird bookshelf.", 3)
            storage._wait(3000)
            tr.write("The \"books\" are actually painted on top of a wooden canvas.", 3)
            storage._wait(3000)
            tr.write("There are hinges on the sides, but I can't move the front.", 3)
            storage._setData('guestroom_foundshelf', True)
            storage._toggleCutscene(False)
    else:
        tr.write("I can't reach that from here.", 3)        
    
    storage._halt()
def flashlight(storage, obj, m):
    storage._go()
    
    tr = GlobalServices.getTextRenderer()
    ad = GlobalServices.getAudioDevice()
    
    storage._faceObject(m.getPlayer(), obj)
    
    if not storage._playerInDistance(m.getPlayer().position, obj.rect):
        tr.write("I can't reach that from here.", 3)
    else:
        # Bed scare sequence done
        if storage._getData('bedroom_bedscare_done'):
            # Add the flashlight to the inventory
            m.getPlayer().inventory.add(\
                          ItemFactory.create(INVENTORY_ITEM_FLASHLIGHT, 1))
            ad.play(SOUND, 'pick_item', VOLUME_SOUND)
            tr.write("Got 'Flashlight'", 3, COLOR_GOT_ITEM)
            # Delete the note from the map
            m.removeObject(obj)
            remove_from_map(get_savegame(), OBJECT, 'bedroom', 'bedroom_flashlight')
            # Set a flag that this script was executed
            storage._setData('flashlight_obtained', True)        
            # Add the global flashlight overlay, deleting the others
            flashlight = OverlayFactory.create_flashlight()
            set_global_overlays([flashlight])
            # Add the overlay to this map, too
            m.clearOverlays()
            m.addOverlay(flashlight)
            ad.play(SOUND, 'flashlight_toggle', VOLUME_SOUND)
            ad.stop(SOUND, 1500, 'insanity_bug3')
        else:
            storage._toggleCutscene(True)
            tr.write("Sometimes I need my flashlight when the power tends to get all freaky.", 3)
            storage._wait(3000)
            tr.write("I don't know if that's because the mansion is just old or haunted, though.", 3)
            storage._toggleCutscene(False)
    
    storage._halt()
def entrancenote(storage, obj, m):
    storage._go()

    storage._faceObject(m.getPlayer(), obj)
    tr = GlobalServices.getTextRenderer()

    if storage._playerInDistance(m.getPlayer().position, obj.rect):
        # Cutscene toggle: Disable user input
        storage._toggleCutscene(True)
        ad = GlobalServices.getAudioDevice()

        tr.write("There is a note on the ground.", 3)
        storage._wait(3000)
        tr.write("Did someone slide this under the entrance door?", 3)
        storage._wait(4000)
        tr.deleteAll()

        # Overlays
        note = OverlayFactory.create("note_big.png")
        togray = OverlayFactory.create_animated_color((0, 0, 0), 1000, 0, True, 0, 200)
        m.addOverlay(note)
        m.addOverlay(togray)

        # Play sound
        ad.play(SOUND, "journal_page", VOLUME_SOUND)

        # Text of the note
        y = 120
        ofs = 18
        tr.write("Clyde,", 0, COLOR_TEXT, (100, y))
        tr.write("you know we like you. However, you kinda freak us out, dude.", 0, COLOR_TEXT, (100, y + (ofs * 2)))
        tr.write(
            "We have grown sick of your accusations and want to give you some time", 0, COLOR_TEXT, (100, y + (ofs * 3))
        )
        tr.write("for yourself to sort things out and get your mind straight.", 0, COLOR_TEXT, (100, y + (ofs * 4)))
        tr.write(
            "Why would you keep blaming us for shit that's obviously not real?", 0, COLOR_TEXT, (100, y + (ofs * 6))
        )
        tr.write(
            "What good would it do us if we, like you said we do, 'keep changing things in the house'?",
            0,
            COLOR_TEXT,
            (100, y + (ofs * 7)),
        )
        tr.write(
            "Never ever has any of us witnessed anything suspicious when we gave in",
            0,
            COLOR_TEXT,
            (100, y + (ofs * 8)),
        )
        tr.write(
            "to your begging us to stay overnight. What, are you frightened of your",
            0,
            COLOR_TEXT,
            (100, y + (ofs * 9)),
        )
        tr.write("grandpa's house and see spooky things that aren't even there?", 0, COLOR_TEXT, (100, y + (ofs * 10)))
        tr.write(
            "We don't want to say this, but we ain't gonna stay for tonight.", 0, COLOR_TEXT, (100, y + (ofs * 11))
        )
        tr.write("Get it together, man.", 0, COLOR_TEXT, (100, y + (ofs * 13)))

        # Wait for user input
        storage._pauseUntilClick()

        GlobalServices.getEventManager().post(ObjectHighlightedEvent(None))

        # Delete note overlay
        m.removeOverlay(note)
        m.removeOverlay(togray)
        # Play sound
        ad.play(SOUND, "journal_page", VOLUME_SOUND)
        # Delete texts
        tr.deleteAll()
        # Fadeout music
        ad.stop(MUSIC, 12000)
        ad.stop(SOUND, 12000, "vind2")
        # More text
        tr.write("Did they...?", 3)
        storage._wait(4000)
        tr.write("They have forsaken me.", 3)
        storage._wait(4000)
        tr.write("I didn't want to upset them... it's just...", 3)
        storage._wait(4000)
        tr.write("I am NOT making this up. Something is wrong here.", 3)
        storage._wait(4000)
        tr.deleteAll()
        storage._wait(1000)
        m.getPlayer().setDirection([0, -1])
        tr.write("I feel dizzy. I should get back to bed.", 3)
        storage._wait(4000)
        storage._faceObject(m.getPlayer(), obj)
        # Delete texts
        tr.deleteAll()
        # Add the note to the inventory
        m.getPlayer().inventory.add(ItemFactory.create(INVENTORY_ITEM_ENTRANCE_NOTE, 1))
        ad.play(SOUND, "pick_paper", VOLUME_SOUND)
        tr.write("Got 'Note (Forsaken Friends)'", 3, COLOR_GOT_ITEM)
        tr.write("[Press TAB to access your possessions.]", 3, COLOR_OBJECTIVE, (0, POSITION_BOTTOM_SCREEN[1] + 20))

        # Delete the note from the map
        m.removeObject(obj)
        # Set a flag that this script was executed
        storage._setData("entrancenote_obtained", True)
        # End cutscene
        storage._toggleCutscene(False)
        # Play a new BGM
        ad.play(MUSIC, "ambienceloop", VOLUME_MUSIC, -1)
    else:
        tr.write("Is that a note on the ground?", 3)
    storage._halt()