Senior Graduation Project · SENG/CMPE 491/492

A cozy village where NPCs speak through AI

LLM Valley is a narrative-driven life simulation built in Unity. Players explore a cozy pixel-art village, farm, fish, trade, and converse with fully AI-powered NPCs — each with unique personalities driven by real-time Large Language Model responses.

🎮
Unity 6.3 LTS
Game Engine
🤖
OpenRouter API
AI Integration
💬
Dynamic NPCs
Free-text Dialogue
Main Menu
NPC Dialogue
Fishing Minigame
Main Menu
First impression of LLM Valley
ACTIVE NPCs
4
AI-Powered
Project Overview

Games deserve better conversations

Traditional games rely on static dialogue trees — branching menus scripted by developers. LLM Valley replaces them with free-text input and real-time AI responses, making every NPC feel like a genuine inhabitant of the world.

💬

Natural NPC Conversation

Players type freely — no dialogue trees, no fixed choices. Each NPC responds with context-aware, in-character dialogue powered by a real LLM.

🌾

Cozy Life-Sim Gameplay

Farm crops, fish at the lake, trade with merchants, and sleep to advance days. A complete simulation loop grounded in a charming pixel-art world.

🔗

Modular AI Integration

The LLM integration is cleanly separated from gameplay logic. Persona prompts, conversation history, and relationship evaluation run independently.

The Problem

Traditional dialogue trees are expensive to write, can't scale to natural conversation, and break player immersion the moment a response doesn't fit the expected branch. Every variation must be handcrafted by a developer.

Our Solution

LLM Valley integrates the OpenRouter API inside a playable Unity demo. Players type anything — the NPC reads a rich persona prompt plus conversation history and responds contextually in real-time. Relationship stats evolve automatically.

Gameplay

A full life-sim loop

Every day in LLM Valley is a repeating cycle of farming, social interaction, and economic progress. Traverse between Farm and Town using WASD, interact with objects and NPCs via E.

🌱

Farm

Till soil, plant seeds, water crops daily, harvest when grown. 12 crop types across 3 tiers, up to 4 farmable fields.

🐟

Fish

Head to the farm lake with a fishing rod. Engage a timing-based minigame to catch from 6 fish types by rarity.

💬

Talk

Approach any NPC with E to open free-text dialogue. Each NPC has a unique AI persona and remembers your history.

🏪

Trade

Sell to Donald the Merchant, buy seeds from Helen, upgrade tools at Rudy's, unlock new farm areas with Ezekiel.

🏠

Sleep

Return home and sleep to end the day. Stamina resets, crops grow, NPC schedules refresh for a new cycle.

📈

Progress

Build Trust, Friendship, and Love with NPCs to unlock higher shop tiers, new crops, and deeper conversation.

Two interconnected scenes

Farm Scene

Player's home, 4 farmable fields (1 unlocked initially), fishing lake, and the path to Town.

🏠 Player House🌾 Farm Fields ×4🐟 Fishing Lake🛤️ Town Path

Town Scene

Town Square with the statue, all four NPC shops, and the path back to the farm.

🗿 Town Square🌻 Seed Shop (Helen)🔨 Tool Shop (Rudy)🏗️ Builder (Ezekiel)💰 Merchant (Donald)
Guide & Tutorial

LLM Valley - User Manual

Everything you need to know to play LLM Valley. From controls and gameplay mechanics to NPC interaction and progression systems.

▶️

Starting the Game

1. Launch the game 2. Click API Key on the Main Menu 3. Enter your OpenRouter API Key 4. Save the key 5. Click Play

⌨️

Controls

W/A/S/D or Arrow Keys: Move E: Interact Left Mouse: Use Tool/Item I: Open Inventory 1-0: Select Hotbar Slot Hold Z: Drop Item Stack

💬

Talking to NPCs

1. Approach an NPC 2. Press E to open dialogue 3. Type your message 4. Submit and wait for response NPCs respond based on: Personality, Previous conversations, Relationship status, Context

🌾

Farming

1. Equip a farming tool 2. Prepare the soil 3. Plant seeds 4. Water crops regularly 5. Wait for crops to grow 6. Harvest mature crops

🐟

Fishing

1. Equip the fishing rod 2. Move near a fishing area 3. Start fishing 4. Receive randomized catches and rewards based on your skill

🎒

Inventory

Store collected items, equip tools, manage resources, and organize farming materials. Use number keys (1-0) to quickly switch between hotbar slots.

💾

Saving Progress

Game progress is automatically stored locally. Data includes: Inventory, Currency, Relationships, Calendar progress, and Conversation history.

🔧

Troubleshooting

NPC no response: Check API key and internet connection Game cannot save: Verify file write permissions LLM Valley is a prototype. Some features may be incomplete.

AI Dialogue System

How the conversation pipeline works

Every NPC interaction is a live API call. There are no scripted branches — each response is generated fresh, shaped by a rich persona prompt and the player's full conversation history.

🚶
STEP 01

Player Approaches NPC

Player walks near an NPC in the village. An interaction prompt appears: "Press E to interact."

⌨️
STEP 02

Free-Text Input

The dialogue UI opens. Player types any message freely — no fixed choices or branching menus.

📝
STEP 03

Prompt Construction

NPCChatAgent builds the system prompt: NPC persona + roleplay rules + current Love/Friendship/Trust scores + conversation history.

🌐
STEP 04

OpenRouter API Request

NPCOpenRouterClient sends a POST request via UnityWebRequest to openrouter.ai/api/v1/chat/completions with JSON payload.

🤖
STEP 05

LLM Response

The selected free LLM returns a contextual, in-character response. Out-of-character AI disclosures are stripped by a regex filter before display.

💬
STEP 06

Response Appears in UI

The NPC's reply is appended to the NPCChatUIManager dialogue view. The conversation is saved to NPCConversationStore (JSON files).

❤️
STEP 07

Relationship Evaluation

Every 5 player messages, a second LLM call evaluates the conversation window and returns Love/Friendship/Trust deltas (−2 to +2 each). Stats update and persist.

⚡

Asynchronous by design

All API calls use Unity Coroutines via UnityWebRequest. The game never blocks — UI shows "NPC is thinking…" while waiting for a response.

🛡️

Fallback on failure

If the API key is missing, the model ID is invalid, or the network fails, the error is shown directly in the dialogue UI. No silent crashes.

🎭

Identity filtering

A regex pass removes out-of-character AI disclosures ("I am an AI", "dil modeli" etc.) before any text is displayed, preserving immersion.

Simulation Systems

Relationships that actually evolve

Every NPC tracks three independent relationship metrics. They update automatically after every fifth conversation exchange through a hidden LLM evaluation pass — not through button presses or arbitrary triggers.

❤️
Love
0100
Starting value (grows with interaction)

Rises through romantic affection, sincere compliments, and emotional closeness. Influences tone and romantic tension in responses.

Unlocks
Romantic dialogue paths
Deeper emotional responses
Unique interaction events
🤝
Friendship
0100
Starting value (grows with interaction)

Grows with warmth, humor, kindness, and shared moments. Makes NPCs more relaxed and willing to share information.

Unlocks
Relaxed NPC tone
Item unlocks
Extended shop availability
🌿
Trust
0100
Starting value (grows with interaction)

Built through honesty, consistency, and respecting NPC boundaries. Unlocks higher shop tiers, new farm areas, and deeper dialogue.

Unlocks
New shop tiers (seeds/tools)
Farm area unlocks
Advanced daily sell limit

Meet the four NPCs

💰
Donald J. SimonMerchant

"Ah… the new farmer. Let's see if you've brought anything worth my time today."

🔓 Trust = more daily sell limit
🌻
HelenSeed Shop

"Oh! You must be the one who inherited your grandfather's farm. Welcome to LLM Valley!"

🔓 Trust = more seed tiers
🔨
RudyTool Shop

"…Oh. You're the new farmer, right? Need a hoe or something sturdier?"

🔓 Trust = Iron-tier tools
🏗️
EzekielBuilder

"Hey there! You must be the one fixin' up that old farm. Name's Ezekiel."

🔓 Trust = new farm fields
⚖️
Automatic relationship evaluation

Every 5 player messages, a separate LLM call evaluates the conversation window and returns structured JSON deltas (−2 to +2) for each stat. The system accounts for flirting, vulnerability sharing, rudeness, manipulation, and more — following a detailed evaluation rulebook baked into the prompt.

System Architecture

Three clean layers

The AI module is intentionally decoupled from gameplay logic. Game systems talk to the AI module; the AI module never directly touches farming or inventory. This separation makes the system testable and extensible.

01
🎮

Game Client

The Unity 6.3 runtime: player movement, farming mechanics, scene transitions, HUD, and all simulation state.

Player.csPlayerInventory.csPlayerWallet.csCalendarSystem.csSceneTransitionManager.csFarmableArea.csPlantable.csGateStateStore.cs
UnityWebRequest · HTTPS · JSON payload
02
🤖

AI Integration Module

The bridge between Unity and the LLM. Builds prompts, sends API requests, parses responses, filters identity breaks, and triggers relationship evaluation.

NPCOpenRouterClient.csNPCChatAgent.csNPCPersona.cs (ScriptableObject)NPCConversationStore.csNPCChatUIManager.csOpenRouterApiKeyStore.cs
Love / Friendship / Trust deltas (JSON)
03
⚙️

Simulation Logic

Stateful simulation systems that react to AI-driven relationship changes. Manages shop tiers, area unlocks, and persistent save state.

NPCRelationshipStats.csSaveManager.csNPCShopManager.csMainMenuController.cs
💾

Save System

SaveManager.cs serializes player data — coins, inventory (10 slots), calendar state, scene position, gate states — to Unity's PlayerPrefs as JSON strings.

💬

Conversation Persistence

NPCConversationStore.cs writes full message history per NPC to JSON files. On next interaction, history is loaded and prepended to the system prompt — giving NPCs persistent memory across sessions.

Technology Stack

Built on proven, open tools

Every technology in LLM Valley was chosen for reliability, Unity ecosystem compatibility, and the ability to ship a working demo within an academic semester.

🎮
Game Engine
Unity 6.3 LTS

Latest long-term support release. Universal Render Pipeline, 2D Tilemap system, UI Toolkit, and the full C# scripting environment.

⚙️
Language
C# / .NET

All gameplay logic, AI integration, save system, UI management, and NPC behavior are written in C# using Unity's MonoBehaviour component model.

🌐
AI Backend
OpenRouter API

Unified API gateway providing access to multiple LLM providers with a single key. Used for both dialogue generation and relationship evaluation calls.

🤖
Language Model
Claude Haiku / Free LLMs

The system is model-agnostic — any OpenRouter-compatible model works. Claude Haiku was the primary target; the client auto-filters for free available models.

🔗
Networking
UnityWebRequest

Unity's built-in HTTP client, used for all API calls. Runs in Coroutines so the game never blocks while waiting for a response. Full async/await pattern.

📦
Serialization
Newtonsoft.Json

JSON parsing and serialization for API payloads, conversation history files, and the save system. Industry-standard library via Unity Package Manager.

✍️
UI / Text
TextMeshPro

Crisp, high-resolution text rendering for all dialogue, HUD elements, and NPC names. Supports rich text markup for name coloring in chat.

💾
Save System
PlayerPrefs + JSON

Player state (coins, inventory, calendar, position, gates) serialized to JSON and stored in Unity's cross-platform PlayerPrefs key-value store.

🐙
Version Control
GitHub

Full source version control for the Unity project, with .gitignore for Library/Temp folders. Collaborative development by the 4-person team.

Testing & Validation

16 of 16 test cases passed

All functional, interface, and validation tests passed at final submission. Tests covered the full game loop — from NPC dialogue to farming, trading, save/load, and UI consistency.

16
Total Test Cases
16
Passed
0
Failed
100%
Pass Rate
⚙️
Functional Testing
7/7 passed
✓NPC dialogue starts and receives LLM response
✓Relationship metrics update after 5 messages
✓Farming cycle: hoe → plant → water → harvest
✓Fish minigame completes and adds item to inventory
✓Trading: sell item to merchant, balance updates
✓Sleep: day advances, crops progress, stamina resets
✓Scene transition Farm ↔ Town without data loss
🖥️
Interface Testing
5/5 passed
✓Chat UI renders NPC response with name label
✓Relationship bars update visually in UI
✓Inventory HUD reflects item changes in real time
✓Player wallet balance updates after trade
✓Day counter and time display advance correctly
✅
Validation Testing
4/4 passed
✓Empty player input rejected — no API call made
✓API error surfaced in UI (not silently swallowed)
✓Identity-break phrases stripped from LLM output
✓Save/load cycle preserves all player state correctly
The Team

Built by four students

LLM Valley was created as the SENG/CMPE 491/492 Senior Graduation Project at TED University, Spring 2026. A 4-person team, one semester, one playable demo.

🎨
Yusuf Sadi Pesen
Game Designer & Developer

Designed the core gameplay loop, world structure, NPC systems, and economic balancing, while defining the overall game design direction and progression mechanics.

🖌️
Reyhan Sena Çimen
Game Developer & 2D Artist

Implemented the movement, farming, item, and tool systems using scalable object-oriented architecture and design patterns, while integrating the projects visual assets and UI elements.

💻
Egemen Asım Ersoy
Game Developer

Developed the LLM-powered NPC interaction system, including OpenRouter API integration, relationship evaluation mechanics, dialogue persistence, and AI-driven economy interactions.

⚙️
Deniz Şeker
Game Developer

Implemented the inventory, calendar, sleep, save/load, and scene transition systems while coordinating development tasks, milestone planning, and subsystem integration.

🎓
Project Supervisor
Dr. Eren Ulu
Computer Engineering, TED University
🎓 TED University · SENG/CMPE 491 / SENG/CMPE 492 · Spring 2026