:player_tired
  label beginning
  if !Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_poses').isReady()
    wait 12
    go to label beginning
  end
  switch hidePlayer ON
  js var characterName = Managers.Player.generatePlayerSpriteName() + '_poses';
  + window.tiredAnimationEvent = $gameMap.createPlayerImpersonatorEvent(characterName, 7, Direction.DOWN, false, false, 0, true);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.LEFT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.RIGHT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  switch hidePlayer OFF
  js window.tiredAnimationEvent.erase(); delete window.tiredAnimationEvent;

:player_very_tired
  label beginning
  if !Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_poses').isReady()
    wait 12
    go to label beginning
  end
  switch hidePlayer ON
  js var characterName = Managers.Player.generatePlayerSpriteName() + '_poses';
  + window.tiredAnimationEvent = $gameMap.createPlayerImpersonatorEvent(characterName, 1, Direction.DOWN, false, false, 0, true);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.LEFT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.RIGHT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.UP);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent._characterIndex = 2;
  + window.tiredAnimationEvent.setDirection(Direction.UP);
  + window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent._characterIndex = 1;
  + window.tiredAnimationEvent.setDirection(Direction.DOWN);
  + window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(0);
  wait 12
  switch hidePlayer OFF
  js window.tiredAnimationEvent.erase(); delete window.tiredAnimationEvent;

:player_pass_out
  label beginning
  if !Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_poses').isReady()
    wait 12
    go to label beginning
  end
  switch hidePlayer ON
  js var characterName = Managers.Player.generatePlayerSpriteName() + '_poses';
  + window.tiredAnimationEvent = $gameMap.createPlayerImpersonatorEvent(characterName, 1, Direction.DOWN, false, false, 0, true);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.LEFT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.RIGHT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.UP);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent._characterIndex = 2;
  + window.tiredAnimationEvent.setDirection(Direction.DOWN);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.LEFT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 60

  fade out
  wait 20
  switch hidePlayer OFF
  js window.tiredAnimationEvent.erase();
  + delete window.tiredAnimationEvent;
  
  js Managers.Health.doPassOutEffect();

:player_waking_up_from_passing_out
  label beginning
  if !Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_poses').isReady()
    wait 12
    go to label beginning
  end
  switch hidePlayer ON
  if !window.tiredAnimationEvent
    js var characterName = Managers.Player.generatePlayerSpriteName() + '_poses';
    + window.tiredAnimationEvent = $gameMap.createPlayerImpersonatorEvent(characterName, 5, Direction.DOWN, false, false, 0, true);
    + window.tiredAnimationEvent.setDirection(Direction.DOWN);
    + window.tiredAnimationEvent.setPattern(0);
    wait 60
  end
  include player_continue_waking_up
  js Engine.Data.autoSave();

:player_continue_waking_up
  if window.tiredAnimationEvent
    js window.tiredAnimationEvent._characterIndex = 6;
    + window.tiredAnimationEvent.setDirection(Direction.DOWN);
    + window.tiredAnimationEvent.setPattern(0);
    wait 12
    js window.tiredAnimationEvent.setPattern(1);
    wait 12
    js window.tiredAnimationEvent.setPattern(2);
    wait 24
    js window.tiredAnimationEvent.setDirection(Direction.LEFT);
    + window.tiredAnimationEvent.setPattern(0);
    wait 12
    js window.tiredAnimationEvent.setPattern(1);
    wait 12
    js window.tiredAnimationEvent.setPattern(2);
    wait 12
    js window.tiredAnimationEvent.setDirection(Direction.RIGHT);
    + window.tiredAnimationEvent.setPattern(0);
    wait 12
    js window.tiredAnimationEvent.setPattern(1);
    wait 24
    js window.tiredAnimationEvent.setPattern(2);
    wait 12
    js window.tiredAnimationEvent.setDirection(Direction.UP);
    + window.tiredAnimationEvent.setPattern(0);
    wait 12
    js window.tiredAnimationEvent.setPattern(1);
    wait 12
    switch hidePlayer OFF
    js window.tiredAnimationEvent.erase();
    + delete window.tiredAnimationEvent;
  else
    switch hidePlayer OFF
  end

:player_hungry
  label beginning
  if !Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_poses').isReady()
    wait 12
    go to label beginning
  end
  switch hidePlayer ON
  js var characterName = Managers.Player.generatePlayerSpriteName() + '_poses';
  + window.tiredAnimationEvent = $gameMap.createPlayerImpersonatorEvent(characterName, 0, Direction.DOWN, false, false, 0, true);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.LEFT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.RIGHT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.UP);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  switch hidePlayer OFF
  js window.tiredAnimationEvent.erase(); delete window.tiredAnimationEvent;

:player_stretching
  label beginning
  if !Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_poses').isReady()
    wait 12
    go to label beginning
  end
  switch hidePlayer ON
  js var characterName = Managers.Player.generatePlayerSpriteName() + '_poses';
  + window.tiredAnimationEvent = $gameMap.createPlayerImpersonatorEvent(characterName, 4, Direction.DOWN, false, false, 0, true);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.LEFT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.RIGHT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  switch hidePlayer OFF
  js window.tiredAnimationEvent.erase(); delete window.tiredAnimationEvent;

:player_long_stretching
  label beginning
  if !Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_poses').isReady()
    wait 12
    go to label beginning
  end
  switch hidePlayer ON
  js var characterName = Managers.Player.generatePlayerSpriteName() + '_poses';
  + window.tiredAnimationEvent = $gameMap.createPlayerImpersonatorEvent(characterName, 4, Direction.DOWN, false, false, 0, true);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.LEFT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 70
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.RIGHT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  # This is showing an empty sprite
  # js window.tiredAnimationEvent.setPattern(2);
  # wait 12
  
  js window.tiredAnimationEvent.erase();
  + delete window.tiredAnimationEvent;
  switch hidePlayer OFF

:player_start_sleeping
  label beginning
  if !Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_poses').isReady()
    wait 12
    go to label beginning
  end
  switch hidePlayer ON
  js var characterName = Managers.Player.generatePlayerSpriteName() + '_poses';
  + window.tiredAnimationEvent = $gameMap.createPlayerImpersonatorEvent(characterName, 4, Direction.DOWN, false, false, 0, true);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.LEFT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(0);
  wait 12

  js window.tiredAnimationEvent._characterIndex = 3;
  + window.tiredAnimationEvent.setDirection(Direction.DOWN);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12

  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12
  js window.tiredAnimationEvent.setDirection(Direction.LEFT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 12
  js window.tiredAnimationEvent.setPattern(1);
  wait 12
  js window.tiredAnimationEvent.setPattern(2);
  wait 12

:player_continue_sleep
  js window.tiredAnimationEvent.setDirection(Direction.RIGHT);
  + window.tiredAnimationEvent.setPattern(0);
  wait 24
  js window.tiredAnimationEvent.setPattern(1);
  wait 24
  js window.tiredAnimationEvent.setPattern(2);
  wait 24
  js window.tiredAnimationEvent.setDirection(Direction.UP);
  + window.tiredAnimationEvent.setPattern(0);
  wait 24
  js window.tiredAnimationEvent.setPattern(1);
  wait 24
  js window.tiredAnimationEvent.setPattern(2);
  wait 24

:player_stop_sleeping
  wait 12
  if window.tiredAnimationEvent
    js window.tiredAnimationEvent._characterIndex = 5;
    + window.tiredAnimationEvent.setDirection(Direction.LEFT);
    + window.tiredAnimationEvent.setPattern(0);
    wait 12
    js window.tiredAnimationEvent.setPattern(1);
    wait 12
  end
  include player_continue_waking_up

:player_start_pushing
  js $gamePlayer.forceForwardMovement(0.25);
  + Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_pushing');

  wait 10

  label beginning
  if !Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_pushing').isReady()
    wait 12
    go to label beginning
  end

  switch hidePlayer ON
  js var characterName = Managers.Player.generatePlayerSpriteName() + '_pushing';
  + window.pushingAnimationEvent = $gameMap.createPlayerImpersonatorEvent(characterName, 0, $gamePlayer._direction, false, false, 0, true);
  
  js window.pushingAnimationEvent._playerImpersonator = false;
  + window.pushingAnimationEvent._x = $gamePlayer._x;
  + window.pushingAnimationEvent._y = $gamePlayer._y - 0.25;
  + window.pushingAnimationEvent._moveSpeed = 2;
  + window.pushingAnimationEvent.forceForwardMovement(0.125);
  + window.pushingAnimationEvent._realX = window.pushingAnimationEvent._x;
  + window.pushingAnimationEvent._realY = window.pushingAnimationEvent._y;
  
  js window.pushingAnimationEvent._characterIndex = 0;
  + window.pushingAnimationEvent.setPattern(0);
  wait 12
  js window.pushingAnimationEvent.setPattern(1);
  wait 12
  js window.pushingAnimationEvent.setPattern(2);
  wait 12
  js window.pushingAnimationEvent._characterIndex = 1;
  + window.pushingAnimationEvent.setPattern(0);
  wait 12
  js window.pushingAnimationEvent.setPattern(1);
  wait 12
  js window.pushingAnimationEvent.setPattern(2);
  wait 12

  if window.objectBeingPushed
    js window.objectBeingPushed.continuePushing();
  else
    play player_stop_pushing
  end

:player_stop_pushing
  js window.pushingAnimationEvent.forceForwardMovement(-0.125);
  + $gamePlayer.setPosition(window.pushingAnimationEvent._x, window.pushingAnimationEvent._y + 0.25);
  + $gamePlayer.forceForwardMovement(-0.25);

  switch hidePlayer OFF
  js window.pushingAnimationEvent.erase();
  + delete window.pushingAnimationEvent;
  + $gamePlayer.restoreSpeed();

  wait for Player
  

:player_move_while_pushing
  js window.pushingAnimationEvent.forceForwardMovement(1);
  + $gamePlayer._moveSpeed = 2;
  + $gamePlayer.forceForwardMovement(1);
  
  js window.pushingAnimationEvent._characterIndex = 0;
  + window.pushingAnimationEvent.setPattern(0);
  wait 12
  js window.pushingAnimationEvent.setPattern(1);
  wait 12
  js window.pushingAnimationEvent.setPattern(2);
  wait 12
  js window.pushingAnimationEvent._characterIndex = 1;
  + window.pushingAnimationEvent.setPattern(0);
  wait 12
  js window.pushingAnimationEvent.setPattern(1);
  wait 12
  js window.pushingAnimationEvent.setPattern(2);
  wait 12

  if window.objectBeingPushed
    js window.objectBeingPushed.continuePushingIfNeeded();
  else
    play player_stop_pushing
  end

:player_knocking
  label beginning
  if !Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_animations').isReady()
    wait 12
    go to label beginning
  end

  switch hidePlayer ON
  js var characterName = Managers.Player.generatePlayerSpriteName() + '_animations';
  + window.knockingAnimationEvent = $gameMap.createPlayerImpersonatorEvent(characterName, 4, Direction.DOWN, false, false, 0, true);
  wait 12

  js window.knockingAnimationEvent._characterIndex = 4; window.knockingAnimationEvent._pattern = 1;
  wait 12

  js window.knockingAnimationEvent._characterIndex = 4; window.knockingAnimationEvent._pattern = 2;
  + Managers.Sound.playSingleKnock();
  wait 12

  js window.knockingAnimationEvent._characterIndex = 5; window.knockingAnimationEvent._pattern = 0;
  wait 12

  js window.knockingAnimationEvent._characterIndex = 4; window.knockingAnimationEvent._pattern = 2;
  + Managers.Sound.playSingleKnock();
  wait 12

  js window.knockingAnimationEvent._characterIndex = 5; window.knockingAnimationEvent._pattern = 0;
  wait 12

  js window.knockingAnimationEvent._characterIndex = 4; window.knockingAnimationEvent._pattern = 2;
  + Managers.Sound.playSingleKnock();
  wait 12

  js window.knockingAnimationEvent._characterIndex = 5; window.knockingAnimationEvent._pattern = 0;
  wait 12

  js window.knockingAnimationEvent._characterIndex = 5; window.knockingAnimationEvent._pattern = 1;
  wait 12

  switch hidePlayer OFF
  js window.knockingAnimationEvent.erase(); delete window.knockingAnimationEvent;

:player_no_answer
  label beginning
  if !Managers.Images.loadCharacter(Managers.Player.generatePlayerSpriteName() + '_animations').isReady()
    wait 12
    go to label beginning
  end

  switch hidePlayer ON
  js var characterName = Managers.Player.generatePlayerSpriteName() + '_animations';
  + window.knockingAnimationEvent = $gameMap.createPlayerImpersonatorEvent(characterName, 4, Direction.LEFT, false, false, 0, true);
  wait 10

  js window.knockingAnimationEvent._characterIndex = 4; window.knockingAnimationEvent._pattern = 1;
  wait 10
  js window.knockingAnimationEvent._characterIndex = 4; window.knockingAnimationEvent._pattern = 2;
  wait 10
  js window.knockingAnimationEvent._characterIndex = 5; window.knockingAnimationEvent._pattern = 0;
  wait 10
  js window.knockingAnimationEvent._characterIndex = 4; window.knockingAnimationEvent._pattern = 2;
  wait 10

  js window.knockingAnimationEvent._characterIndex = 4; window.knockingAnimationEvent._pattern = 1;
  wait 10
  js window.knockingAnimationEvent._characterIndex = 4; window.knockingAnimationEvent._pattern = 2;
  wait 10

  switch hidePlayer OFF
  js window.knockingAnimationEvent.erase(); delete window.knockingAnimationEvent;

:remove_annie_event
  remove villager Annie

:make_raphael_use_hammer
  if $gameSystem.isPlayerSleepingStanding
    return
  end

  js Managers.Villagers.makeVillagerUseTool('Raphael', 'golden-hammer', 6, 140, 'Axe');

:clear_raphael_tool
  js Managers.Villagers.makeVillagerUseTool('Raphael', undefined);

:door_unanswered
  start cutscene
  include player_knocking
  wait 20
  include player_no_answer
  wait 10
  end cutscene

:player_drop_item
  displayItemId none
  play sound DropItem
  wait 30
  displayItemId undefined