# ╔══════════════════════════════════════════════════════════════════╗
# ║         SHOWCASE JDR-BOT — YAML Syntax Tutorial v4.7           ║
# ║                                                                  ║
# ║  This scenario covers ALL engine features.                      ║
# ║  Each room is commented to serve as a reference for             ║
# ║  authors getting started with JDR-Bot YAML syntax.             ║
# ║                                                                  ║
# ║  Structure:                                                      ║
# ║    Room 1  — Home & Navigation                                  ║
# ║    Room 2  — Items, Inventory, Reactions                        ║
# ║    Room 3  — Custom Actions & Crafting                          ║
# ║    Room 4  — Automatic Events & Randomness                      ║
# ║    Room 5  — Variables & Advanced Conditions                    ║
# ║    Room 6  — Sounds, Images, Formatting                         ║
# ║    Room 7  — Timers                                             ║
# ║    Room 8  — Online Variables & Leaderboard                     ║
# ║    Room 9  — Endings (victory / defeat)                         ║
# ║    Intermediate result rooms                                    ║
# ╚══════════════════════════════════════════════════════════════════╝


# ─────────────────────────────────────────────────────────────────
# TITLE
# Displayed when the game starts. Can include online variables
# (v_name_o_v) to show live stats.
# ⚠️ The | character is forbidden in the title — use · or —
# ─────────────────────────────────────────────────────────────────
title: "🎓 JDR-Bot Showcase · v4.7 · (v_nbgames_o_v games played)"


# ─────────────────────────────────────────────────────────────────
# MARKDOWN
# Controls text rendering. "fix" = Discord code block (monospace).
# "none" = plain text with no formatting.
# Default value if omitted: "fix"
# ─────────────────────────────────────────────────────────────────
markdown: fix


# ─────────────────────────────────────────────────────────────────
# GLOBAL OPTIONS
# Persistent buttons shown at the top of the game.
#   refresh     → redisplays the current room
#   inventory   → opens the inventory
#   previous    → go back to the previous room
#                 (only shown if the room has goto: precedent in its choices)
#   v_name_v    → displays a variable's value with its emoji
#   room_id     → direct access to a room (hidden if already there)
# ─────────────────────────────────────────────────────────────────
options:
  rafraichir: "🔄"
  inventaire: "🎒"
  precedent: "↩️"
  v_score_v: "⭐"    # displays the value of the "score" variable with the ⭐ emoji
  home: "🏠"         # direct access to the home room from anywhere


# ─────────────────────────────────────────────────────────────────
# NUMERIC GLOBAL VARIABLES
# Initialised when the game starts.
# Two forms: short (value only) or long (with description).
# ⚠️ Never use v_, _v, t_, _t, o_, _o inside a variable name
#    (only _o is allowed as a suffix for online variables)
# ─────────────────────────────────────────────────────────────────
vars:
  # Short form
  score: 0

  # Long form (with description — shown in inventory via v_score_v§⭐)
  hp:
    value: 10
    description: "Hit points"

  hpmax:
    value: 10
    description: "Maximum HP"

  strength:
    value: 3
    description: "Character strength"

  luck:
    value: 5
    description: "Luck rating"

  dieresult:
    value: 0
    description: "Last die roll result"

  # Variable used in advanced conditions
  counter:
    value: 0
    description: "Visit counter"

  # Flag for the global timer "bomb" (0 = inactive, 1 = running)
  bomb_active:
    value: 0


# ─────────────────────────────────────────────────────────────────
# TEXT GLOBAL VARIABLES
# Store text values (player name, narrative state, etc.)
# Referenced in text with t_name_t
# ─────────────────────────────────────────────────────────────────
text_vars:
  playername:
    value: "Adventurer"
    description: "Player name"

  # Combination slot variable for crafting (room 3)
  combination:
    value: "none"
    description: "Ingredient waiting to be combined"


# ─────────────────────────────────────────────────────────────────
# ONLINE VARIABLES
# Persist across all games, on all servers.
# The name MUST end with _o.
# nb_parties_o exists automatically — no need to declare it.
# ─────────────────────────────────────────────────────────────────
online_vars:
  nbgames_o:
    value: 0
    description: "Total games played (all combined)"

  highscore_o:
    value: 0
    description: "All-time high score"


# ═════════════════════════════════════════════════════════════════
# ROOMS
# ═════════════════════════════════════════════════════════════════
rooms:

  # ───────────────────────────────────────────────────────────────
  # ROOM 1 — HOME & NAVIGATION
  #
  # Shows:
  #   - choice with button (command + button + target)
  #   - choice without button (text navigation only)
  #   - button on the room itself (button:)
  #   - variables in text (v_name_v and t_name_t)
  #   - "home" option in global options (id of this room)
  # ───────────────────────────────────────────────────────────────
  - id: home
    # button: defines the button label for THIS room
    # (used by other rooms that have goto: home)
    button: "🏠 Home"

    text: |
      **🎓 Welcome to the JDR-Bot Showcase!**
      Hello t_playername_t! Current score: v_score_v ⭐

      Choose a demo:

    choices:
      # Choice with Discord button (command + button + target)
      - command: "1"
        button: "📦 Items & Inventory"
        goto: demo_items

      - command: "2"
        button: "⚙️ Custom Actions"
        goto: demo_actions

      - command: "3"
        button: "🎲 Events & Randomness"
        goto: demo_events

      - command: "3g"
        button: "✨ Global Events"
        goto: demo_global_events

      - command: "4"
        button: "🔢 Variables & Conditions"
        goto: demo_variables

      - command: "5"
        button: "🔊 Sound, Images, Formatting"
        goto: demo_media

      # No button: here → the button label comes from the button: of demo_timers itself.
      # This is an alternative: define the button in the room rather than in the choice.
      - command: "6"
        goto: demo_timers

      - command: "7"
        button: "🌐 Online Variables"
        goto: demo_online

      - command: "8"
        button: "🏆 Game Endings"
        goto: demo_endings

      # Choice without command or button: only accessible by id ("go help")
      # or by room number. No text alias, no button displayed.
      - goto: help


  # ───────────────────────────────────────────────────────────────
  # HELP ROOM — no command or button in the home choice
  # Accessible by id ("go help") or number — no button displayed.
  # ───────────────────────────────────────────────────────────────
  - id: help
    text: |
      **💡 How to navigate this showcase?**

      Type a number or click a button to move forward.
      To interact: type the verb directly (e.g. take key)
      On Discord: use dedicated slash commands (/take, /inspect, /throw)
      or /action for custom verbs (/action combine crystal)
      The ↩️ button goes back to the previous room.
      The 🏠 button returns to home from anywhere.

    choices:
      # goto: precedent → go back to where you came from
      # Also enables the permanent "precedent" button in options:
      - command: "back"
        button: "↩️ Back"
        goto: precedent


  # ───────────────────────────────────────────────────────────────
  # ROOM 2 — ITEMS & INVENTORY
  #
  # Shows:
  #   - objects: (declared on room entry)
  #   - visible vs invisible location
  #   - furniture_description vs description (furniture ≠ item)
  #   - furniture_reaction, pickup_reaction, object_reaction
  #   - remove: true to remove an item
  #   - same name multiple times on same furniture → shrinking stock
  #   - conditional exit (if item is present)
  # ───────────────────────────────────────────────────────────────
  - id: demo_items
    text: |
      **📦 Demo — Items & Inventory**

      A table stands in the middle of the room.
      On the floor, a key glints faintly.
      An old chest holds gold coins — examine it and take one coin at a time.
      (The chest empties progressively, but you can only carry one coin.)

      take [item] · inspect [item] · throw [item]
      (Discord: /take · /inspect · /throw)

    # objects: are declared here and applied on room entry.
    # Format: name, location, description, pickup message (+ optional reactions)
    objects:
      # Item on a visible furniture — the player sees "a table" in the room
      - name: grimoire
        location: "table"
        # furniture_description: shown when the player inspects the FURNITURE (e.g. inspect table)
        furniture_description: "An old wooden table. A dusty grimoire rests on top."
        # description: shown when the player inspects the ITEM (e.g. inspect grimoire)
        description: "An old grimoire with yellowed pages, covered in alchemical formulae."
        pickup_text: "You pick up the grimoire from the table."
        # furniture_reaction: button shown to inspect the furniture
        furniture_reaction: "🪑 Inspect the table"
        # pickup_reaction: button shown to pick up the item
        pickup_reaction: "📖 Take the grimoire"
        # object_reaction: button shown to inspect the item itself
        object_reaction: "🔎 Inspect the grimoire"

      # Invisible item — present in the game but not directly visible
      - name: key
        location: "invisible"
        description: "A small silver key."
        pickup_text: "You pick up the key."

      # ── Multiple items on the same furniture ─────────────────────
      # Declare the same name multiple times on the same location:
      # each time one is taken, the next slot becomes active → furniture_description changes.
      # Great for simulating a pile, a depleting stock, etc.
      - name: coin
        location: "chest"
        furniture_description: "An old chest. It holds three gold coins!"
        description: "A shiny gold coin."
        pickup_text: "You take a coin. Two remain."
        furniture_reaction: "💰 Inspect the chest"
        pickup_reaction: "🪙 Take a coin"

      # Same name "coin", same location "chest" → slot 2
      # Different furniture_description: the chest slowly empties
      - name: coin
        location: "chest"
        furniture_description: "An old chest. Two gold coins remain."
        description: "A shiny gold coin."
        pickup_text: "You take a coin. One remains."

      # Slot 3: last coin
      - name: coin
        location: "chest"
        furniture_description: "An old chest. One last coin remains."
        description: "A shiny gold coin."
        pickup_text: "You take the last coin. The chest is empty."

      # Slot 4: hidden item revealed once all coins are taken
      # The player can still inspect the chest — they'll see this message.
      # Different name to distinguish this state in conditions (if emptyChest)
      - name: emptyChest
        location: "chest"
        furniture_description: "The chest is completely empty. But... a false bottom?"
        description: "A secret compartment! You find a rolled-up scroll inside."
        pickup_text: "You discover the secret compartment!"

      # Item removed on entry (equivalent to -name in .txt)
      # Useful for "consuming" an item or resetting a state
      - name: oldpotion
        remove: true
        location: invisible

    # No actions: here — take/inspect/throw are built-in bot commands.
    # They work automatically thanks to the objects: declared above,
    # without needing to redefine them as custom actions.
    # → /take grimoire · /inspect grimoire · /throw grimoire (Discord)
    # → take grimoire · inspect grimoire · throw grimoire (terminal/web/desktop)
    # Inspection text comes from furniture_description: and description: in the items.

    events:
      # Multi-criteria conditional event (AND): key present AND counter > 2
      - if: "key v_counter_v > 2"
        do: "score.+.5"
        text: "🗝️ You have the key AND visited 3 times — bonus +5 score!"

    choices:
      - command: "back"
        goto: home


  # ───────────────────────────────────────────────────────────────
  # ROOM 3 — CUSTOM ACTIONS & CRAFTING
  #
  # Shows:
  #   - action:target simple with condition
  #   - action:all with t_action_cible_ok_t and t_action_cible_t
  #   - same verb/target multiple times (first true condition wins)
  #   - action with attached button (button:)
  #   - crafting: combining 2 ingredients → result
  #   - text variable as a "combination slot" (t_combination_t)
  #   - global_actions (defined below, available everywhere)
  # ───────────────────────────────────────────────────────────────
  - id: demo_actions
    text: |
      **⚙️ Demo — Custom Actions**

      An alembic sits on the workbench.
      Ingredients are available: herb, crystal.

      inspect [item] · take [herb / crystal]
      combine [ingredient] · go [destination]
      (Discord: /inspect · /take · /action combine · /action go)
      "go" is a global action — works in every room!

    # Items available in this room
    objects:
      - name: herb
        location: "workbench"
        description: "A green herb with magical properties."
        pickup_text: "You take the herb."
        pickup_reaction: "🌿 Take the herb"

      - name: crystal
        location: "workbench"
        description: "A translucent blue crystal."
        pickup_text: "You take the crystal."
        pickup_reaction: "💎 Take the crystal"

    actions:
      # ── Take with condition (item not in inventory) ──
      - verb: take
        target: herb
        if: "-herb"
        do:
          - object: herb
            goto: inventaire
        success_text: "You take the herb."
        failure_text: "You already have the herb."

      - verb: take
        target: crystal
        if: "-crystal"
        do:
          - object: crystal
            goto: inventaire
        success_text: "You take the crystal."
        failure_text: "You already have the crystal."

      # ── Inspect: same verb, different targets ──
      - verb: inspect
        target: herb
        if: ~
        success_text: "A soothing herb. Perfect as a first ingredient."

      - verb: inspect
        target: crystal
        if: ~
        success_text: "The crystal hums faintly. It amplifies potions."

      - verb: inspect
        target: alembic
        if: ~
        success_text: "The central alembic. Use 'combine [ingredient]' to brew potions."

      # ── Crafting: same verb/target, multiple conditions (first true wins) ──
      # Step 1: add the herb first
      - verb: combine
        target: herb
        if: "herb t_combination_t.=.none"
        do:
          - "-herb&&inventaire&&null"
          - text_var: combination
            value: "herb"
            description: "Waiting for crystal"
        success_text: "🌿 The herb goes into the alembic. Now add: combine crystal"
        failure_text: "You don't have any herb."

      # Step 2: add the crystal → potion created
      - verb: combine
        target: crystal
        if: "crystal t_combination_t.=.herb"
        do:
          - "-crystal&&inventaire&&null"
          - text_var: combination
            value: "none"
          - "potion&&inventaire&&Glowing green potion (+5 HP)"
          - "score.+.10"
          - text_var: combination
            value: "none"
        success_text: "💚 The alembic lights up! Potion brewed! (+10 score)"
        failure_text: "You don't have any crystal."

      # Fallback: unknown ingredient — t_action_cible_t = what the player typed
      - verb: combine
        target: all
        if: ~
        success_text: "«t_action_cible_t» is not a known ingredient. Try: herb, crystal."

      # ── Action with attached button ──
      # button: shows a clickable Discord reaction for this action
      - verb: use
        target: potion
        button: "💚 Use the potion"
        if: "potion"
        do:
          - "-potion&&inventaire&&null"
          - "hp.+.5"
          - "score.+.5"
        success_text: "You drink the potion. +5 HP, +5 score! (HP: v_hp_v/v_hpmax_v)"
        failure_text: "You don't have a potion."

    choices:
      - command: "back"
        goto: home


  # ───────────────────────────────────────────────────────────────
  # ROOM 4 — AUTOMATIC EVENTS & RANDOMNESS
  #
  # Shows:
  #   - init: with %=X:Y (random on entry)
  #   - init: with variables as bounds (%=v_a_v:v_b_v)
  #   - sequential 997 events (each die roll → different text)
  #   - sequential behaviour: each event sees the values from previous ones
  #   - weighted loot table (redirect)
  #   - weighted value table (variable)
  # ───────────────────────────────────────────────────────────────
  - id: demo_events
    text: |
      **🎲 Demo — Automatic Events & Randomness**

      On entering this room, a die is rolled automatically.
      Last roll result: v_dieresult_v 🎲
      (0 on first visit — the result appears on the next entry)

      Click a button to see more examples.

    # init: runs every time you enter the room (equivalent to L3 in .txt)
    # %=1:6 draws a random integer between 1 and 6
    init:
      - var: dieresult
        value: "%=1:6"
        description: "Last die roll result (1-6)"

      # Random with variables as bounds
      - var: luck
        value: "%=v_strength_v:v_hpmax_v"
        description: "Luck recalculated from strength and max HP"

    # events: run in order after init
    # ⚠️ CRITICAL: sequential behaviour — each event sees the values
    # modified by previous ones. A redirecting event stops the rest.
    events:
      # Each face of the die shows a different text
      - if: "v_dieresult_v = 1"
        do: "score.+.1"
        text: "🎲 Roll 1 — Rotten luck! (+1 score anyway)"

      - if: "v_dieresult_v = 2"
        do: "score.+.2"
        text: "🎲 Roll 2 — Not great... (+2 score)"

      - if: "v_dieresult_v = 3"
        do: "score.+.3"
        text: "🎲 Roll 3 — Decent. (+3 score)"

      - if: "v_dieresult_v = 4"
        do: "score.+.4"
        text: "🎲 Roll 4 — Nice one! (+4 score)"

      - if: "v_dieresult_v = 5"
        do: "score.+.5"
        text: "🎲 Roll 5 — Excellent! (+5 score)"

      - if: "v_dieresult_v = 6"
        do: "score.+.10"
        text: "🎲 Roll 6 — CRITICAL! Double score! (+10 score)"

    choices:
      - command: "reroll"
        button: "🎲 Reroll"
        goto: demo_events  # returning to the same room re-triggers init

      - command: "global"
        button: "✨ Global Events"
        goto: demo_global_events

      - command: "loot"
        button: "🎁 Loot Table"
        goto: demo_loot

      - command: "back"
        goto: home


  # ───────────────────────────────────────────────────────────────
  # ROOM 4b — WEIGHTED LOOT TABLE
  #
  # Shows:
  #   - weighted redirect: %=room1:weight,room2:weight,...
  #   - weighted value:    var.=.%val1:weight,val2:weight,...
  #   - weights via variables
  # ───────────────────────────────────────────────────────────────
  - id: demo_loot
    text: |
      **🎁 Demo — Weighted Loot Tables**

      A mysterious chest creaks open...

    init:
      - var: dieresult
        value: "%=1:6"

    events:
      # Weighted redirect: 60% common, 30% rare, 10% legendary
      # Weights are relative (don't need to add up to 100)
      - if: ~
        do: "%=loot_common:60,loot_rare:30,loot_legendary:10"
        text: "You open the chest..."


  # ── Loot result rooms ──
  - id: loot_common
    text: |
      **🪨 Common Loot**
      You find a handful of copper coins. (+2 score)
    events:
      - if: ~
        do: "score.+.2"
    choices:
      - command: "reroll"
        button: "🔄 Roll again"
        goto: demo_loot
      - command: "back"
        goto: home

  - id: loot_rare
    text: |
      **💎 Rare Loot!**
      A glittering blue gem! (+10 score)
    events:
      - if: ~
        do: "score.+.10"
    choices:
      - command: "reroll"
        button: "🔄 Roll again"
        goto: demo_loot
      - command: "back"
        goto: home

  - id: loot_legendary
    text: |
      **🌟 LEGENDARY LOOT!!**
      An ancient artefact! Unbelievable! (+50 score)
    events:
      - if: ~
        do: "score.+.50"
    choices:
      - command: "reroll"
        button: "🔄 Roll again"
        goto: demo_loot
      - command: "back"
        goto: home


  # ───────────────────────────────────────────────────────────────
  # ROOMS — GLOBAL EVENTS
  #
  # Shows:
  #   - event_global: ON/OFF/SWITCH to enable/disable a global event
  #   - Global events run in every room
  #   - Declared in global_events: at the bottom of this file
  # ───────────────────────────────────────────────────────────────
  - id: demo_global_events
    text: |
      **✨ Demo — Global Events**

      Global events run after every room visit
      (after local events, by default).

      Here you can activate a +1 score bonus for every room visited.
      Once activated, navigate to other rooms to see it apply.

    events:
      # event_global:id:ON activates the global event "visit_bonus"
      # Declared in global_events: at the bottom of this file
      - if: ~
        do: "event_global:visit_bonus:ON"
        text: "✨ Global bonus activated! (+1 score every room visited)"

    choices:
      - command: "deactivate"
        button: "🚫 Deactivate bonus"
        goto: demo_global_events_off
      - command: "back"
        goto: home

  - id: demo_global_events_off
    text: |
      **✨ Global bonus deactivated**

    events:
      # event_global:id:OFF deactivates the global event
      # SWITCH would toggle the state: ON→OFF or OFF→ON
      - if: ~
        do: "event_global:visit_bonus:OFF"
        text: "🚫 Global bonus deactivated."

    choices:
      - command: "reactivate"
        button: "✨ Reactivate"
        goto: demo_global_events
      - command: "back"
        goto: home


  # ───────────────────────────────────────────────────────────────
  # ROOM 5 — VARIABLES & ADVANCED CONDITIONS
  #
  # Shows:
  #   - operators = != > >= < <=
  #   - .in. (inclusive range) and .out. (exclusive range)
  #   - comparing two variables (v_a_v > v_b_v)
  #   - multiple AND conditions (v_a_v = 1 v_b_v = 2)
  #   - item present / absent condition (-item)
  #   - text variable t_name_t in texts and conditions
  #   - chained actions @@ (multiple actions in do:)
  #   - explicit num: (for migration from .txt — rare in native YAML)
  # ───────────────────────────────────────────────────────────────
  - id: demo_variables
    text: |
      **🔢 Demo — Variables & Conditions**

      Score: v_score_v ⭐ | HP: v_hp_v/v_hpmax_v ❤️
      Name: t_playername_t | Counter: v_counter_v

      The events below trigger automatically on entry.

    init:
      # Increment the counter on each visit
      - var: counter
        value: "+1"

    events:
      # ── Comparison operators ──
      - if: "v_score_v = 0"
        text: "📊 Score is zero — just starting out!"

      - if: "v_score_v > 0"
        text: "📊 Positive score: v_score_v points!"

      - if: "v_hp_v < v_hpmax_v"
        text: "❤️ You're not at full health (v_hp_v/v_hpmax_v)"

      - if: "v_hp_v = v_hpmax_v"
        text: "❤️ You're at full health!"

      # ── Inclusive range .in. ──
      - if: "v_score_v in 1-9"
        text: "⭐ Score between 1 and 9 — keep going!"

      # ── Exclusive range .out. ──
      - if: "v_score_v out 1-99"
        text: "🏆 Score outside the 1-99 range (≤0 or ≥100)!"

      # ── Multiple AND conditions ──
      - if: "v_counter_v > 1 v_score_v > 0"
        text: "🔁 You've visited this room more than once AND have points!"

      # ── Item present / absent condition ──
      - if: "grimoire"
        text: "📖 You have the grimoire from the Items room!"

      - if: "-grimoire"
        text: "📖 You don't have the grimoire (visit the Items room to get it)."

      # ── Chained actions @@ (or YAML list) ──
      - if: "v_score_v > 50"
        do:
          - "hp.+.2"
          - "score.+.5"
        text: "🌟 Score > 50! Bonus: +2 HP and +5 score!"

    actions:
      # Change the player's name (text variable)
      - verb: rename
        target: all
        if: ~
        do:
          - text_var: playername
            value: "t_action_cible_t"
            description: "Player name"
        success_text: "Your name is now: t_playername_t"

      - verb: heal
        target: all
        if: ~
        do:
          - "hp.=.v_hpmax_v"
        success_text: "❤️ HP restored to v_hpmax_v!"

    choices:
      - command: "back"
        goto: home


  # ───────────────────────────────────────────────────────────────
  # ROOM 6 — SOUNDS, IMAGES, FORMATTING
  #
  # Shows:
  #   - <<url>> audio sound (replaces current sound)
  #   - <<N:url>> simultaneous sounds on separate channels
  #   - <<stop>> stops all sounds
  #   - <<stop:N>> stops only channel N
  #   - [[url]] image
  #   - [[text]] Discord markdown block
  #   - **bold** in text
  #   - +n+ line break (accepted for .txt migration)
  #   - variables in text (v_name_v and t_name_t)
  # ───────────────────────────────────────────────────────────────
  - id: demo_media
    text: |
      **🔊 Demo — Sounds, Images, Formatting**

      <<https://cyril-fiesta.fr/jdr-bot/scenarios/sounds/sulimo/balade.mp3>>

      A soothing melody plays. (<<url>> starts a sound)
      🎵 *Music from the scenario "Une galerie pour Sulimo" (Virginie Chaillou)*

      [[**📖 Discord markdown block**
      This text is in a [[text]] block — displayed as a code block.
      Useful for tables or structured data.]]

      **Bold text** with native **markdown**.
      Current score: v_score_v ⭐ | Player: t_playername_t

    events:
      - if: ~
        do: "score.+.3"
        text: "+3 score for exploring the media room!"

    actions:
      # Simultaneous sounds on separate channels (v4.6+)
      - verb: test
        target: channels
        button: "🎵 Simultaneous sounds"
        if: ~
        success_text: |
          <<1:https://cyril-fiesta.fr/jdr-bot/scenarios/sounds/sulimo/balade.mp3>>
          <<2:https://cyril-fiesta.fr/jdr-bot/scenarios/sounds/combat/kotor-hit.wav>>
          Two sounds playing simultaneously on channels 1 and 2!

      # Stop all sounds
      - verb: stop
        target: sounds
        button: "🔇 Stop all sounds"
        if: ~
        success_text: "<<stop>>All sounds stopped."

      # Stop a specific channel
      - verb: stop
        target: channel1
        if: ~
        success_text: "<<stop:1>>Channel 1 stopped."

    choices:
      - command: "back"
        goto: home


  # ───────────────────────────────────────────────────────────────
  # ROOM 7 — TIMERS
  #
  # Shows:
  #   - {{timer:N}} visual pause (blocks N seconds with display)
  #   - timer: in an event (local async timer → redirects on expiry)
  #   - timer_global: ON/OFF/SWITCH (global timer, survives room changes)
  #   - timer cancellation
  # ───────────────────────────────────────────────────────────────
  - id: demo_timers
    # button: defined here rather than in the home choice:.
    # Alternative to putting button: in the choice — the result is identical.
    button: "⏱️ Timers"
    text: |
      **⏱️ Demo — Timers**

      Three types of timers exist:

      1. {.{timer:N}.} (without the dots) — visual pause
         Blocks the game for N seconds, then shows choices.

      2. timer: in an event — local timer (tied to the room)
         Starts on room entry. If you leave the room, it cancels.
         Useful for in-situ countdowns.

      3. timer_global: ON/OFF/SWITCH — global timer
         Continues even if you change rooms. Triggers global
         events when it reaches 0.

      Click a button to try one:

    choices:
      - command: "pause"
        button: "⏳ Visual pause (3s)"
        goto: demo_timer_block

      - command: "local"
        button: "⏱️ Local timer (5s)"
        goto: demo_timer_local

      - command: "global"
        button: "🌐 Global timer (10s)"
        goto: demo_timer_global

      - command: "back"
        goto: home


  - id: demo_timer_block
    text: |
      **⏳ Timer block — visual pause**

      The game is paused for 3 seconds...
      {{timer:3}}
      Resume! The visual pause is over.

    events:
      - if: ~
        do: "score.+.2"
        text: "+2 score for your patience!"

    choices:
      - command: "timers"
        button: "↩️ Back to timers"
        goto: demo_timers
      - command: "back"
        goto: home


  - id: demo_timer_local
    text: |
      **⏱️ Local timer — tied to the room**

      A 5-second timer starts on entry to this room.
      Stay here — if you leave, it cancels.

    events:
      # timer: in an event → local timer tied to the room
      # Triggered on entry (implicit init via null 997)
      # If the player leaves the room, the timer is automatically cancelled
      - if: ~
        timer: fuse
        duration: "5"
        goto: timer_local_expired
        text: "⏱️ Timer 'fuse' started — v_fuse_v seconds remaining."

    choices:
      - button: "🌐 Try the global timer"
        goto: demo_timer_global
      - command: "back"
        goto: home


  - id: timer_local_expired
    text: |
      **⏱️ Local timer expired!**

      5 seconds passed without you leaving.
      (+3 score for your patience!)

    events:
      - if: ~
        do: "score.+.3"
        goto: demo_timers


  - id: demo_timer_global
    text: |
      **🌐 Global timer — survives room changes**

      A 10-second global timer is activated.
      Unlike the local timer, it keeps running even if you
      navigate to other rooms!

      When it reaches 0, the global event "alarm" fires
      in whatever room you're in at that moment.

      Navigate freely — the timer runs in the background.

    events:
      # If the timer is already running, display remaining time without restarting it
      - if: "v_bomb_active_v = 1"
        text: "🌐 Timer 'bomb' running — v_bomb_v seconds remaining."

      # timer_global: ON → activates the global timer "bomb"
      # event_global: ON → activates the alarm that fires on expiry
      # bomb_active goes to 1 → prevents this event from re-running on expiry
      # (on expiry, verifier_cases_speciales re-enters this room before globals)
      - if: "v_bomb_active_v = 0"
        do:
          - "bomb_active.=.1"
          - "timer_global:bomb:ON"
          - "event_global:bomb_alarm:ON"
        text: "🌐 Global timer 'bomb' activated — v_bomb_v seconds remaining."

    choices:
      - command: "back"
        goto: home


  # ───────────────────────────────────────────────────────────────
  # ROOM 8 — ONLINE VARIABLES & LEADERBOARD
  #
  # Shows:
  #   - online_vars in the title (v_nbgames_o_v)
  #   - conditional high score update (display source, not destination)
  #   - nb_parties_o automatic (incremented on every game start)
  #   - text online variable
  # ───────────────────────────────────────────────────────────────
  - id: demo_online
    text: |
      **🌐 Demo — Online Variables**

      Online variables persist across ALL games,
      on ALL Discord servers.

      📊 Global stats:
      • Games played: v_nbgames_o_v
      • High score: v_highscore_o_v ⭐

      Your current score: v_score_v ⭐

    events:
      # ⚠️ CLASSIC TRAP: the text of an event is evaluated BEFORE the action.
      # To display the NEW high score, show v_score_v (the source),
      # not v_highscore_o_v (the destination, which hasn't been updated yet).
      - if: "v_score_v > v_highscore_o_v"
        do: "highscore_o.=.v_score_v"
        text: "🏆 New world record: v_score_v ⭐ (previous: v_highscore_o_v)"

      - if: "v_score_v <= v_highscore_o_v"
        text: "📊 Current record: v_highscore_o_v ⭐ — try to beat it!"

    choices:
      - command: "back"
        goto: home


  # ───────────────────────────────────────────────────────────────
  # ROOM 9 — GAME ENDINGS
  #
  # Shows:
  #   - end: victory (→ internal room 999)
  #   - end: defeat  (→ internal room 998)
  #   - direct ending in an event (no intermediate room)
  #   - intermediate room with text before the ending
  #   - score-based condition to pick which ending
  # ───────────────────────────────────────────────────────────────
  - id: demo_endings
    text: |
      **🏆 Demo — Game Endings**

      Final score: v_score_v ⭐

      Choose your ending:

    choices:
      - command: "victory"
        button: "🏆 Victory Ending"
        goto: ending_victory

      - command: "defeat"
        button: "💀 Defeat Ending"
        goto: ending_defeat

      - command: "auto"
        button: "🎲 Auto ending (based on score)"
        goto: ending_auto

      - command: "back"
        goto: home


  - id: ending_victory
    text: |
      <<https://cyril-fiesta.fr/jdr-bot/scenarios/sounds/chateau/congratulations.ogg>>
      **🏆 VICTORY!**

      Congratulations t_playername_t!
      Final score: v_score_v ⭐
      World record: v_highscore_o_v ⭐

    events:
      # end: victory → triggers a victory ending (equivalent to 999 in .txt)
      # end: and do: are mutually exclusive — you can't combine them.
      # To perform an action AND end the game, use an intermediate room.
      - if: ~
        do: "highscore_o.=.v_score_v"
      - if: ~
        end: victory
        text: "🏆 You completed the Showcase with v_score_v points!"


  - id: ending_defeat
    text: |
      **💀 DEFEAT**

      You give up, t_playername_t...
      Score: v_score_v ⭐

    events:
      # end: defeat → equivalent to 998 in .txt
      - if: ~
        end: defeat
        text: "💀 Game over. Start again to improve your score!"


  - id: ending_auto
    text: |
      **🎲 Auto ending based on your score...**
      Score: v_score_v ⭐

    events:
      # Conditional ending: victory if score > 20, defeat otherwise
      # ⚠️ Events stop at the first one that redirects or ends the game.
      # So: put the "victory" case first with its condition,
      # then the "defeat" case with no condition (always true if reached).
      - if: "v_score_v > 20"
        end: victory
        text: "🏆 Score high enough (>20) — Victory!"

      - if: ~
        end: defeat
        text: "💀 Score too low (≤20) — Defeat! Score: v_score_v"


# ═════════════════════════════════════════════════════════════════
# GLOBAL ALIASES
# Declared once here — reusable in any room via command: name.
# The label is automatically shown as a button without repeating button: everywhere.
# ═════════════════════════════════════════════════════════════════
global_aliases:
  back: "🏠 Home"
  home: "🏠 Home"


# ═════════════════════════════════════════════════════════════════
# GLOBAL ACTIONS
# Available in ALL rooms, not just one specific room.
# Perfect for universal commands (go, inspect, help...).
# ═════════════════════════════════════════════════════════════════
global_actions:
  # Free navigation: go [destination] (Discord: /action go [destination])
  # t_action_cible_ok_t = last valid target typed (= recognised room name)
  # t_action_cible_t    = last target typed (valid or not)
  - verb: go
    target: all
    if: ~
    do: "t_action_cible_ok_t"
    failure_text: "Unknown destination «t_action_cible_t»."

  # Score: display your score from anywhere
  - verb: score
    target: all
    if: ~
    success_text: "⭐ Current score: v_score_v | High score: v_highscore_o_v"


# ═════════════════════════════════════════════════════════════════
# GLOBAL EVENTS
# Run in ALL rooms (after local events by default).
# OFF state by default — activatable via event_global:id:ON from any room.
# Option 997_globaux: avant → runs them BEFORE local events.
# ═════════════════════════════════════════════════════════════════
# 997_globaux: apres   # "avant" or "apres" (default: apres)

global_events:
  # Visit bonus: +1 score every room visited
  # Activated/deactivated from demo_global_events
  - id: visit_bonus
    state: OFF          # OFF by default — activated via event_global:visit_bonus:ON
    if: ~
    do: "score.+.1"
    text: "✨ Visit bonus: +1 score! (Total: v_score_v)"

  # Example with condition: only applies when HP < 5
  - id: emergency_heal
    state: OFF
    if: "v_hp_v < 5"
    do: "hp.+.2"
    text: "🚑 Emergency heal! +2 HP (HP: v_hp_v/v_hpmax_v)"

  # Alarm linked to the global timer "bomb"
  # Automatically activated with the timer from demo_timer_global
  # Fires when bomb reaches 0 (verifier_cases_speciales called by the renderer)
  - id: bomb_alarm
    state: OFF
    if: "v_bomb_active_v = 1 v_bomb_v = 0"
    do:
      - "event_global:bomb_alarm:OFF"
      - "score.+.10"
      - "bomb_active.=.0"
    goto: demo_timers
    text: "💥 BOOM! The 'bomb' timer expired — wherever you are! (+10 score)"


# ═════════════════════════════════════════════════════════════════
# GLOBAL TIMERS
# Continue even after a room change.
# Activated via timer_global:id:ON — deactivated via timer_global:id:OFF.
# On expiry (deadline reached), triggers verifier_cases_speciales
# (local + global events) in the player's current room.
# ═════════════════════════════════════════════════════════════════
global_timers:
  # Timer "bomb": used in demo_timer_global
  # Activated via timer_global:bomb:ON from demo_timer_global
  - id: bomb
    duration: 10          # duration in seconds
    state: OFF          # OFF by default
