Character creation

docs/character-creation.md

Character Creation System

Database Schema

The characters table has the following structure:

| Column | Type | Description | |--------|------|-------------| | id | UUID | Primary key | | user_id | UUID | References auth.users(id) | | name | TEXT | Character name | | gender | TEXT | Character gender (male/female) | | age | INTEGER | Character age (default 16) | | home_region_id | UUID | References regions(id) - The starting region | | background | JSONB | Character background information | | title | TEXT | Character title | | location_id | UUID | Current location | | current_location_id | UUID | Duplicate of location_id (will be consolidated) | | current_region_id | UUID | Current region | | gold | INTEGER | Currency amount | | reputation | INTEGER | Reputation score | | health | INTEGER | Health points | | energy | INTEGER | Energy points | | stamina | INTEGER | Stamina points | | is_traveling | BOOLEAN | Whether character is traveling | | traveling | BOOLEAN | Duplicate of is_traveling (will be consolidated) | | travel_destination_id | UUID | Destination when traveling | | travel_arrival_time | TIMESTAMPTZ | Expected arrival time |

Row Level Security Policies

The following RLS policies are applied to the characters table:

  • Allow authenticated users to create their own characters - Users can only create characters linked to their own user_id
  • Allow users to read their own characters - Users can only read characters linked to their own user_id
  • Allow users to update their own characters - Users can only update characters linked to their own user_id

API Endpoints

Create Character

Endpoint: /api/character/create Method: POST Body:

{
  "name": "Character Name",
  "gender": "male|female",
  "regionId": "UUID of starting region",
  "age": 16,
  "background": {
    "origin": "noble|commoner|merchant",
    "motivation": "wealth|power|knowledge|adventure",
    "skill": "combat|diplomacy|trade|crafting"
  }
}

Frontend Implementation

The character creation process is implemented in /src/app/game/create-character/page.tsx which handles:

  • Character name selection
  • Gender selection
  • Starting region selection
  • Background choices
  • Age selection (default 16)

Upon submission, the data is sent to the API endpoint which creates a new character record.

Troubleshooting

If character creation fails:

  • Check that all required fields are provided
  • Verify the user is authenticated
  • Check the server logs for specific error messages
  • Ensure the RLS policies are set up correctly

Character Creation

This document outlines the character creation process for FeudalSim.

Character Creation Process

  • Users register an account through Supabase Authentication
  • Upon first login, new users are directed to the character creation flow
  • Players select their starting region, name, gender, and other attributes
  • On completion, a character is created with starting resources

Starting Resources

New characters begin with:

  • 10 silver coins (changed from 100)
  • 2 loaves of bread
  • Basic health and energy values (100%)
  • No titles or land ownership
  • Basic reputation (50)

Character Attributes

| Attribute | Default Value | Description | |-------------|---------------|-----------------------------------------------------| | Health | 100 | Character's physical well-being | | Energy | 100 | Character's stamina for performing actions | | Gold | 10 | Currency used for trade and services | | Reputation | 50 | How the character is perceived in society | | Title | None | Optional nobility title if granted | | Inventory | 2 bread | Items the character possesses |

Important Technical Notes

  • Each user can have only one character
  • Characters are tied to a user account via the user_id field
  • Characters must be associated with a valid location
  • The character creation endpoint is in src/app/api/character/route.ts
  • Initial inventory items are created after character creation
  • Bread is a consumable food item that helps manage hunger

Currency System

In FeudalSim, currency is used in the form of silver coins rather than "gold". Players start with 10 silver coins. In the future, elected governments will be able to mint their own coins, making currency and economic management a key part of the gameplay.

Food System

Food items like bread are essential resources that:

  • Restore energy when consumed
  • Prevent hunger penalties
  • Can be traded or sold
  • Are perishable over time

Loaves of bread are a basic food item that fills hunger when consumed.

All articles