:intro
  preload_sprites

  if quick start
    play event intro_skip
    return
  end

  start cutscene
  switch startedTutorial ON
  refresh bgm

  fade out
  # ToDo: Theme song with a short movie

  play event opening_event

:intro_skip
  fade out
  switch hidePlayer OFF
  teleport to home (18, 5, 2)
  wait 1
  
  switch hasIronHoe on
  switch hasRegularWateringCan on
  gain item turnip-seeds x 10
  gain item apple x 1
  meet Julia
  meet Mom
  meet Benjamin

  speed Player restore
  create_dog
  set day 2
  set hour 6
  pause ON

  end cutscene
  wait 120

  fade in
  switch toolHudEnabled on
  switch timeHudEnabled on
  switch finishedIntroEvent on
  refresh bgm
  wait 20
  accept meet-everyone
  wait 10
  accept benjamins-payment
  wait 10
  pause OFF

:opening_event
  set time 19:00
  start cutscene
  teleport to farm (44, 0, down)
  wait 1
  switch hidePlayer OFF
  create villager Shiba 45,0,2
  offset Shiba Y -12
  speed Player 2.2
  speed Shiba 2.3
  move villager Player 44,6,2
  move villager Shiba 45,6,2

  wait 10
  fade in

  wait for Player

  Player "Wow, this place is much bigger than I thought it would be."

  wait for Player
  wait for Shiba
  wait 10
  turn Player right
  wait 10
  turn Shiba left
  Player "What do you think, <var:dogName>? Not too shabby, huh?"
  play sound Dog
  wait 30
  Player "Why don't you go around checking if there's any buried treasure?"
  play sound Dog
  wait 30

  play event intro_dog_run async
  wait 10
  turn Player down

  Player "Now, where do I start?"
  include player_long_stretching
  wait 40
  Julia "<hideName>Excuse me, are you <name>?"
  create villager Julia 44,0,2
  speed Julia 2.2
  move villager Julia 44,4,2
  turn Player up
  Player "<?:async>"
  wait 20
  move villager Player 44,5,8
  
  Player "Yes I am! have you heard about me?"
  Julia "<hideName>I have, yes. My name is Julia, I'm the mayor here in Orange Town."
  meet Julia
  Player "Oh, the mayor? I didn't think I would run into you so soon. Nice to meet you!"
  Julia "It's good to be meeting you too, <name>. To be honest, I thought one of our current residents would be buying this farm."
  Julia "But since you did, I'm happy that you decided to move here! I'm working hard to create new opportunities for young people to move in."
  Player "I can't say I'm not surprised either. This place is huge! I never thought I would be winning the auction with the low bid I did."
  Julia "Can you tell me what motivated you to buy a farm?"
  Player ("What motivated me...", "It's always been my dream", "I want to get rich", "I want to work hard", "I'm running away", "I don't know")

  switch motivationDream OFF
  switch motivationMoney OFF
  switch motivationWork OFF
  switch motivationRunningAway OFF

  if response == "It's always been my dream"
    # Benjamin, Nathalia
    switch motivationDream ON
    Julia "That's so sweet, I wish you the best of luck with the farm then!"
  end

  if response == "I want to get rich"
    # Brittany, Billy
    switch motivationMoney ON
    Julia "Oh, will you try to become the most profitable farm around, then?"
  end

  if response == "I want to work hard"
    # Stella
    switch motivationWork ON
    Julia "Oh, will you try to become the most productive farm in town, then?"
  end

  if response == "I'm running away"
    # Viktor, Raphael
    switch motivationRunningAway ON
    Julia "Oh... I won't ask you for details, don't worry."
  end

  if response == "I don't know"
    # Lucas, Devin
    Julia "It's alright, we can discuss your goals at some other day."
  end

  create villager Benjamin 45,0,2
  speed Benjamin 2.2
  move villager Benjamin 45,4,2

  wait 40

  turn Player up
  turn Julia up

  wait 20
  include player_stretching

  wait for Benjamin
  turn Julia right
  Julia "Ah, you're here now. Thanks for taking the time to stop by, Benji."
  turn Julia down
  Julia "<name>, this is my younger brother Benjamin. He's also a farmer like you."
  meet Benjamin
  turn Player up
  Julia "If you need any help or advice, he'll be glad to help you out."
  Julia "Now, if you'll excuse me I should be going back to work..."

  move villager Julia 44,2,8
  wait for Julia
  turn Player up
  turn Benjamin up

  wait 5
  turn Julia down
  Julia "Don't forget to introduce yourself to everyone in town tomorrow, ok?"
  move villager Julia 44,0,remove

  accept meet-everyone
  wait 20

  Player "Err... She doesn't talk much, does she?"
  Benjamin "She's just too busy these days. She talked a lot more when she wasn't mayor."
  Benjamin "At any rate, you didn't come to hear me ramble about my sister. You came here to farm."

  Benjamin ("I brought you a farming handbook. Do you want me to go over it with you?", "Yes, please!", "No, I'll check the book later.", "No thanks, I'm already a good farmer.")
  switch benjamin_tutorial_picked_item OFF
  
  if response == "Yes, please!"
    play event benjamin_tutorial
    return
  end

  if response == "No, I'll check the book later."
    play event benjamin_no_tutorial
    return
  end

  if response == "No thanks, I'm already a good farmer."
    play event benjamin_no_tutorial
    return
  end

:intro_dog_run
  change villager Shiba sprite index 1
  speed Shiba 3

  move villager Shiba 52,6,6
  wait for Shiba
  change villager Shiba sprite index 0
  speed Shiba 2.2
  move villager Shiba 53,6,6
  wait for Shiba

  change villager Shiba sprite index 4
  wait 60
  change villager Shiba sprite index 1
  move villager Shiba 58,6,2
  wait for Shiba
  move villager Shiba 58,41,2


:benjamin_tutorial
  Benjamin "Ok, then I'll explain everything to you and if you have any questions, you can do them at the end."
  Benjamin "First things first: do you know how to walk around?"
  Player "...<wait>I came all the way here, didn't I?"
  Benjamin "You did, but it's different now."
  Player "How come?"
  Benjamin "From now on, whenever you want to walk, you'll have to press the <color:important><keys:up,left,down,right></color>, but you can change those in the game options if you feel the need."
  
  if Engine.Input.gamepadActivated
    Benjamin "Oh, that gamepad should work too."
  end

  Benjamin "When you want to talk to someone, open a door, pick an item or anything like that, you have to press the <color:important><key:ok><color:default>."
  if Engine.Input.gamepadActivated
    Benjamin "On the gamepad, use <color:important><gamepadIcon:ok></color> for that."
  else
    if Managers.Config.enableMouse
      Benjamin "You can even <color:important>click on things with the mouse</color>. Most of the time, it works everytime."
    end
  end

  Player "Oh, the same key I'm using to skip this conversation?"
  Benjamin "Yes!<wait><wait> Wait, what?"
  Player "After I'm finished listening to you, of course!"

  Benjamin "Ah, ok.<wait> Although you can use it to make people speak and act faster when you're on a hurry."
  Player "That will be useful!"

  Benjamin "I'll show you something nice now, hang on."
  wait 20
  switch toolHudEnabled ON
  switch timeHudEnabled ON
  switch forceToolHud ON
  switch forceTimeHud ON
  wait 20
  Benjamin "Can you see it? All the information visible on screen. It's so useful."

  include player_stretching

  wait 10
  include benjamin_add_tutorial_options
  Benjamin ("Are you tired? Let's make things quicker then. Just tell me what do you want to know about.", "I'm good")

  label check_responses
  if response == "Health"
    Benjamin "Regarding your health, there are two things that you need to keep track of: <color:important>stamina and fatigue</color>."
    Benjamin "Your stamina depletes as you work. Everytime you use tools it will go down a little bit, but it's not really a problem if you eat and rest well."
    Benjamin "If you run out of stamina, you may collapse, so make sure you always carry something with you to eat if you're feeling weak."
    Benjamin "There are many orange trees around town. You can pick as many as you need. They are not really worth selling, but eating one may save you from passing out."
    Benjamin "Fatigue is a different story. It doesn't build up unless you work too much, but you need to sleep to recover from it."
    Benjamin "Your stamina will go down much faster when you're suffering from fatigue, so you have to be extra careful."
    Benjamin "So, in short: make sure to sleep well and eat a lot. I'll give you an apple in case you're hungry right now."
    wait 10
    js Managers.Items.pickItemId('apple')
    wait 30
  end

  if response == "Tools"
    Benjamin "Tools. That is a very important subject. Do you have a good watering can?"
    Player "Uhh. I don't know, I haven't checked inside the house yet."
    Benjamin "So you didn't bring any with you?"
    Player "Should I? I always thought the rain would take care of watering the crops."
    Benjamin "Hah, not in this world. I'll give you an old watering can that I don't use anymore, but make sure you get a better one eventually."
    switch hasRegularWateringCan ON
    refresh hud
    Notice "<mid>Received a <color:important>Cheap Watering Can</color>."
    Benjamin "I'm gonna assume that you also forgot to get yourself a <color:important>hoe</color> and give you an old one too."
    switch hasIronHoe ON
    refresh hud
    Notice "<mid>Received a <color:important>Cheap Hoe</color>."
    Benjamin "Those are all the tools you're getting from me. You're probably gonna need a lot more of them to properly take care of this farm, so make sure you find some more."

    Benjamin "To use a tool, you need to equip it first. It's pretty simple, you just have to press the <color:important><key:pageup></color>."
    if Engine.Input.gamepadActivated
      Benjamin "On that gamepad of yours, use <gamepadIcon:left_backbutton><gamepadIcon:right_backbutton>"
    else
      if Managers.Config.enableMouse
        Benjamin "Or just click on a tool from the toolbar."
      end
    end

    Benjamin "Once a tool is equipped, press the <color:important><key:use></color> to use it."
    if Engine.Input.gamepadActivated
      Benjamin "And on the gamepad, use <gamepadIcon:use>"
    else
      if Managers.Config.enableMouse
        Benjamin "You can also <color:important>click on objects</color> to automatically use the equipped tool on them, or <color:important>right click the tool on the toolbar</color> to use them anywhere."
      end
    end
  end

  if response == "Items"
    Benjamin "Items are very easy to use. Let me give you some so you will understand it better."
    wait 10
    js Managers.Items.pickItemId('turnip-seeds', 10);
    wait 30
    Benjamin "Did you see how the seeds showed up on the item bar? You can select them with the <color:important><key:pagedown></color>."
    if Engine.Input.gamepadActivated
      Benjamin "On the gamepad, you can use <gamepadIcon:left_trigger><gamepadIcon:right_trigger>"
    else
      if Managers.Config.enableMouse
        Benjamin "Or click on the item with the mouse."
      end
    end

    wait 10
    js Managers.Items._itemIndex = 0;
    wait 20
    Benjamin "Once you've selected an item, you'll see it on your hands. You can now do with it whatever you want: use it, give it to someone, place it in a box. Anything."
    Benjamin "When using an item, it works just like an equipped tool."
    if !Engine.Input.gamepadActivated && Managers.Config.enableMouse
      Benjamin "The only exception is when you're playing with the mouse. To eat food or use medicine, you need to right click the item <color:important>on the item bar</color> itself."
    end

    Benjamin "To deselect an item, hold the <color:important><key:control></color> and then press <color:important><key:pagedown></color>."
    if Engine.Input.gamepadActivated
      Benjamin "On the gamepad, press at the same time both buttons: <gamepadIcon:left_trigger><gamepadIcon:right_trigger>"
    end

    js Managers.Items._itemIndex = -1;
  end
  
  if response == "I'm good"
    play benjamin_no_tutorial
    return
  end

  wait 10
  include benjamin_add_tutorial_options
  if this._reservedChoices.length > 0
    Benjamin ("What do you want to know about?", "I'm good")
    go to label check_responses
  end

  Benjamin "Did you get all of that? If you have any question left, check the book on your bookcase later. I'll be leaving now."
  play benjamin_tutorial_leave_farm

:benjamin_add_tutorial_options
  js this.clearReservedChoices();
  if Managers.Items.numItemsById('apple') == 0
    js this.addChoice("Health");
  end
  if !Switches.hasRegularWateringCan
    js this.addChoice("Tools")
  end
  if Managers.Items.numItemsById('turnip-seeds') == 0
    js this.addChoice("Items");
  end

:benjamin_no_tutorial
  Benjamin "Well, if you're confident already, I'll be leaving now."

  if !Switches.hasIronHoe
    Benjamin "But before I go, let me give you some basic tools."
    switch hasIronHoe ON
    Notice "<mid>Received a <color:important>Cheap Hoe</color>."
    switch hasRegularWateringCan ON
    Notice "<mid>Received a <color:important>Cheap Watering Can</color>."
  end

  if Managers.Items.numItemsById('turnip-seeds') == 0
    Benjamin "I'll also give you some basic seeds so you can get started on your farm."
    wait 10
    js Managers.Items.pickItemId('turnip-seeds', 10)
    wait 30
  end
  
  play benjamin_tutorial_leave_farm

:benjamin_tutorial_leave_farm
  Benjamin "In exchange for the tools and seeds I gave you, I want you to bring me 5 turnips, grown by you, anytime you can."
  wait 10
  accept benjamins-payment

  wait 10
  Benjamin "Sorry if I talked too much, I'll let you rest now."

  move villager Benjamin 44,0,8

  wait 20
  turn Player up

  wait for Benjamin
  remove villager Benjamin
  Player "I guess I can finally check that house and get some sleep."
  move villager Player 34,9,8
  wait 60

  fade out
  speed Player restore
  switch timeHudEnabled ON
  switch toolHudEnabled ON
  switch forceToolHud OFF
  switch forceTimeHud OFF
  switch finishedTutorial ON

  js Managers.Time.hour = 20;
  
  switch finishedIntroEvent on
  refresh bgm
  js Managers.Creatures.createDog();
  teleport to home (15, 10, 8)
  wait 1
  end cutscene
  fade in

:day_1_cant_leave_yet
  Player "I'm too tired to go back outside."
  move villager Player 15,10,8
  wait for Player
  js $gameTemp.clearCommonEvent();
