Seven steps in one commit, 1.15.0 to 1.21.0. They change the same files and were not saved apart, so they go in together. - The battle at a glance (1.15). A strip across the top of an encounter lists everyone in turn order and stays in view; a click goes to that card. On a wide screen the stat block of whoever is on turn stays beside the cards, and Pin keeps anyone else's there. Saving throws, every skill and passive Perception, Investigation and Insight are on encounter cards and in the character panel, which "Sheet" on a card and a button on the party overview open. For the DM, N is Next Turn and S opens the sheet of whoever is on turn. The party overview shows passive scores and spell save DC. - Subclasses (1.16). Three per class, picked in the level-up checklist at level 2 (cleric, druid, wizard) or 3, shown beside the class everywhere, and changed by the DM from the sheet: the old one's lines come out of Special Abilities and the new one's go in. Characters already at that level keep the path they were on. - Character state (1.17). Inspiration, exhaustion and conditions on the sheet and in the panel, and counters for what a class does a set number of times (Rage, Ki, Channel Divinity...), which the player spends and a rest gives back. A long rest takes a level of exhaustion off. A character's conditions are their own now: they stay from one encounter to the next. - Faster battles (1.18). Up to 20 of a monster added at once, numbered. One button rolls initiative for the monsters and NPCs. A condition can be given a number of rounds and then comes off by itself. Hovering over a condition shows its rule, and damaging someone who is Concentrating shows the save to call for. - Rolls from the sheet (1.19). A number with a dotted underline rolls when clicked, with its bonus: skills, saves, ability checks, attacks, damage, spell dice, and a monster's attack, damage and abilities. The dice roller has advantage and disadvantage. "Call for a roll" rolls one check or save for the whole party. Rolls stay in the browser. - XP and difficulty (1.20). An encounter shows the DM how hard it is, Trivial to Deadly, from the monsters' challenge ratings against the characters in it, and what it is worth in XP; one button shares that out, once. The sheet and the party overview show XP and when a level is due. Levelling up stays the DM's decision. - Subclasses are optional per campaign (1.21). With "Characters choose a subclass" unticked in the campaign's Settings nobody is asked, each class follows its first subclass, and none is named. - Conditions, exhaustion, counters and subclass features are reminders for the table: none of them changes a number on the sheet. - The docs cover all of it, with generated tables of what each subclass adds. - New migrations: a character's subclass; inspiration, exhaustion, conditions and spent counters on a character; the rounds left on a combatant's conditions; the XP awarded for an encounter; the campaign's subclass setting. - All packages at version 1.21.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
742 lines
25 KiB
Plaintext
742 lines
25 KiB
Plaintext
// D&D Campaign Manager — Prisma schema
|
||
// Postgres. The connection (DATABASE_URL) is set in prisma.config.js, not here.
|
||
// Run `npx prisma migrate dev` then `npx prisma generate`; `npx prisma db seed`
|
||
// adds the admin account (prisma/seed.js). Worlds are created in the app from
|
||
// the seeds in /backend/seeds.
|
||
|
||
generator client {
|
||
provider = "prisma-client-js"
|
||
}
|
||
|
||
datasource db {
|
||
provider = "postgresql"
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Enums
|
||
// ---------------------------------------------------------------------------
|
||
|
||
enum CampaignRole {
|
||
DM
|
||
PLAYER
|
||
}
|
||
|
||
enum Species {
|
||
HUMAN
|
||
HALF_ELF
|
||
ELF
|
||
GNOME
|
||
DWARF
|
||
HALFLING
|
||
DRAGONBORN
|
||
TIEFLING
|
||
HALF_ORC
|
||
ORC
|
||
}
|
||
|
||
enum CharacterClass {
|
||
FIGHTER
|
||
BARBARIAN
|
||
ROGUE
|
||
RANGER
|
||
WIZARD
|
||
SORCERER
|
||
CLERIC
|
||
PALADIN
|
||
BARD
|
||
WARLOCK
|
||
DRUID
|
||
MONK
|
||
}
|
||
|
||
enum Ability {
|
||
STR
|
||
DEX
|
||
CON
|
||
INT
|
||
WIS
|
||
CHA
|
||
}
|
||
|
||
enum Skill {
|
||
ACROBATICS
|
||
ANIMAL_HANDLING
|
||
ARCANA
|
||
ATHLETICS
|
||
DECEPTION
|
||
HISTORY
|
||
INSIGHT
|
||
INTIMIDATION
|
||
INVESTIGATION
|
||
MEDICINE
|
||
NATURE
|
||
PERCEPTION
|
||
PERFORMANCE
|
||
PERSUASION
|
||
RELIGION
|
||
SLEIGHT_OF_HAND
|
||
STEALTH
|
||
SURVIVAL
|
||
}
|
||
|
||
enum BuildStage {
|
||
NOT_STARTED
|
||
ROLLING_SPECIES
|
||
ROLLING_CLASS
|
||
ROLLING_MOTIVATION
|
||
ASSIGNING_SCORES
|
||
ASSIGNING_PROFICIENCIES
|
||
CHOOSING_ABILITIES
|
||
CHOOSING_BACKGROUND
|
||
CHOOSING_APPEARANCE
|
||
CHOOSING_EQUIPMENT
|
||
COMPLETE
|
||
}
|
||
|
||
enum EncounterStatus {
|
||
PLANNING
|
||
ACTIVE
|
||
COMPLETE
|
||
}
|
||
|
||
// What kind of scene an encounter is: a fight run in initiative order, or a
|
||
// quest scene built around NPCs and an objective.
|
||
enum EncounterMode {
|
||
BATTLE
|
||
QUEST
|
||
}
|
||
|
||
enum NpcDisposition {
|
||
FRIENDLY
|
||
NEUTRAL
|
||
HOSTILE
|
||
}
|
||
|
||
enum RewardType {
|
||
GOLD
|
||
WEAPON
|
||
ITEM
|
||
}
|
||
|
||
// The money a character carries. The coins' worth is fixed in utils/grants.js:
|
||
// 1 gold = 10 silver = 100 copper. Cash ($) is modern money for crossover
|
||
// worlds; it has no worth in coins and is never exchanged for them.
|
||
enum Currency {
|
||
GOLD
|
||
SILVER
|
||
COPPER
|
||
CASH
|
||
}
|
||
|
||
enum NoteVisibility {
|
||
DM_ONLY
|
||
SHARED
|
||
}
|
||
|
||
enum DiceMode {
|
||
DIGITAL
|
||
PHYSICAL
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Identity & campaigns
|
||
// ---------------------------------------------------------------------------
|
||
|
||
model User {
|
||
id String @id @default(cuid())
|
||
email String @unique
|
||
passwordHash String
|
||
displayName String
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
memberships CampaignMember[]
|
||
charactersOwned Character[] @relation("PlayerCharacters")
|
||
charactersCreated Character[] @relation("CreatedBy")
|
||
notesAuthored Note[]
|
||
goldTransactions GoldTransaction[]
|
||
|
||
@@map("users")
|
||
}
|
||
|
||
model Campaign {
|
||
id String @id @default(cuid())
|
||
name String
|
||
description String?
|
||
inviteCode String @unique
|
||
startingGold Int @default(0)
|
||
startingItemCount Int @default(0)
|
||
startingSpellCount Int @default(0)
|
||
skipMotivationRoll Boolean @default(false)
|
||
// Off: players see only a health bar for monsters and NPCs, not the numbers.
|
||
showMonsterHp Boolean @default(true)
|
||
// An attack on several targets is harder to land: each target's AC counts
|
||
// as this much higher for every target beyond the first. 0 turns it off.
|
||
areaAttackAcPenalty Int @default(2)
|
||
// How much a character can have equipped at once: weapons and items
|
||
// together, and weapons alone. Only equipped gear can be used in an
|
||
// encounter or gives its effects, so this is what a character can bring to
|
||
// bear at one time. A pair of daggers is one weapon, made as such.
|
||
maxEquipped Int @default(2)
|
||
maxEquippedWeapons Int @default(1)
|
||
// Off: nobody chooses a subclass. Each class follows its first one without
|
||
// being asked, and subclasses are not named anywhere.
|
||
subclassesEnabled Boolean @default(true)
|
||
ownerId String
|
||
// Set while the campaign is archived: kept in full, but moved off the main
|
||
// list and closed to new members until the DM restores it.
|
||
archivedAt DateTime?
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
members CampaignMember[]
|
||
characters Character[]
|
||
weapons Weapon[]
|
||
spells Spell[]
|
||
items Item[]
|
||
monsters Monster[]
|
||
npcs Npc[]
|
||
encounters Encounter[]
|
||
saleOffers SaleOffer[]
|
||
notes Note[]
|
||
locations Location[]
|
||
|
||
@@map("campaigns")
|
||
}
|
||
|
||
model Location {
|
||
id String @id @default(cuid())
|
||
campaignId String
|
||
name String
|
||
description String?
|
||
createdAt DateTime @default(now())
|
||
|
||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||
characters Character[]
|
||
encounters Encounter[]
|
||
visits CharacterLocationVisit[]
|
||
|
||
@@index([campaignId])
|
||
@@map("locations")
|
||
}
|
||
|
||
// A location a character has been to. Written whenever a character is put
|
||
// somewhere (by the DM, or by an encounter held there), and never removed by
|
||
// moving on: it is what decides which locations a player may see.
|
||
model CharacterLocationVisit {
|
||
id String @id @default(cuid())
|
||
characterId String
|
||
locationId String
|
||
firstVisitedAt DateTime @default(now())
|
||
|
||
character Character @relation(fields: [characterId], references: [id], onDelete: Cascade)
|
||
location Location @relation(fields: [locationId], references: [id], onDelete: Cascade)
|
||
|
||
@@unique([characterId, locationId])
|
||
@@map("character_location_visits")
|
||
}
|
||
|
||
model CampaignMember {
|
||
id String @id @default(cuid())
|
||
campaignId String
|
||
userId String
|
||
role CampaignRole @default(PLAYER)
|
||
joinedAt DateTime @default(now())
|
||
|
||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||
|
||
@@unique([campaignId, userId])
|
||
@@index([userId])
|
||
@@map("campaign_members")
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Characters
|
||
// ---------------------------------------------------------------------------
|
||
|
||
model Character {
|
||
id String @id @default(cuid())
|
||
campaignId String
|
||
userId String? // owning player; null for a DM-controlled NPC/ally
|
||
createdById String
|
||
name String
|
||
species Species?
|
||
characterClass CharacterClass?
|
||
// The path taken within the class: a key from game/data/subclasses.js. Null
|
||
// until the class reaches the level it chooses at.
|
||
subclass String?
|
||
level Int @default(1)
|
||
xp Int @default(0)
|
||
motivation String?
|
||
|
||
// Rolled ability scores (before species bonus)
|
||
strScore Int @default(10)
|
||
dexScore Int @default(10)
|
||
conScore Int @default(10)
|
||
intScore Int @default(10)
|
||
wisScore Int @default(10)
|
||
chaScore Int @default(10)
|
||
|
||
// Half-Elf's flexible +1/+1 choice; null unless species = HALF_ELF
|
||
halfElfBonusAbility1 Ability?
|
||
halfElfBonusAbility2 Ability?
|
||
|
||
currentHp Int @default(0)
|
||
tempHp Int @default(0)
|
||
// Death saves, counted while the character is at 0 HP (utils/hp.js). Three
|
||
// failures is dead; three successes sets `stable` and clears the tallies.
|
||
deathSaveSuccesses Int @default(0)
|
||
deathSaveFailures Int @default(0)
|
||
stable Boolean @default(false) // at 0 HP but no longer rolling
|
||
// What has been spent since the last rest. Spell slots by slot level (the
|
||
// first entry is 1st-level slots); how many there are comes from class and
|
||
// level (game/calculations.js, spellSlotsFor). A character has one Hit Die
|
||
// per level, spent on short rests.
|
||
spellSlotsUsed Int[] @default([])
|
||
hitDiceUsed Int @default(0)
|
||
// Class counters spent since the rest that gives them back, as
|
||
// { key: used } (game/classResources.js says which a character has).
|
||
resourcesUsed Json @default("{}")
|
||
// How the character is doing beyond HP. Reminders for the table: none of
|
||
// them changes a number on the sheet. Conditions are the character's own,
|
||
// so they outlast the encounter they were given in.
|
||
inspiration Boolean @default(false)
|
||
exhaustion Int @default(0) // 0 to 6
|
||
conditions String[] @default([])
|
||
armorBonus Int @default(0) // a flat AC adjustment the DM sets by hand, on top of what equipped gear gives
|
||
speedOverride Int?
|
||
|
||
// The next three are composed by the builder from the player's picks
|
||
// (game/data/characterOptions.js). After that only the DM can edit them.
|
||
specialAbilities String? // shown in the quick-stats panel
|
||
// The purse: each coin (and cash) is counted on its own and only changes through the
|
||
// money ledger (GoldTransaction).
|
||
gold Int @default(0)
|
||
silver Int @default(0)
|
||
copper Int @default(0)
|
||
cash Int @default(0) // whole dollars
|
||
|
||
background String?
|
||
appearance String?
|
||
privateNotes String? // visible to the owning player only — not even the DM
|
||
|
||
diceMode DiceMode @default(DIGITAL) // chosen once, before the first build roll
|
||
|
||
currentLocationId String?
|
||
|
||
buildStage BuildStage @default(NOT_STARTED)
|
||
buildState Json? // in-progress dice rolls / pending choices while building
|
||
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||
user User? @relation("PlayerCharacters", fields: [userId], references: [id])
|
||
createdBy User @relation("CreatedBy", fields: [createdById], references: [id])
|
||
currentLocation Location? @relation(fields: [currentLocationId], references: [id], onDelete: SetNull)
|
||
|
||
skillProficiencies CharacterSkillProficiency[]
|
||
saveProficiencies CharacterSaveProficiency[]
|
||
inventoryItems InventoryItem[]
|
||
goldTransactions GoldTransaction[]
|
||
weapons CharacterWeapon[]
|
||
spells CharacterSpell[]
|
||
notes Note[]
|
||
encounterEntries EncounterParticipant[]
|
||
locationVisits CharacterLocationVisit[]
|
||
|
||
@@index([campaignId])
|
||
@@index([userId])
|
||
@@map("characters")
|
||
}
|
||
|
||
model CharacterSkillProficiency {
|
||
id String @id @default(cuid())
|
||
characterId String
|
||
skill Skill
|
||
proficient Boolean @default(true)
|
||
expertise Boolean @default(false) // double proficiency bonus, e.g. Rogue
|
||
|
||
character Character @relation(fields: [characterId], references: [id], onDelete: Cascade)
|
||
|
||
@@unique([characterId, skill])
|
||
@@map("character_skill_proficiencies")
|
||
}
|
||
|
||
model CharacterSaveProficiency {
|
||
id String @id @default(cuid())
|
||
characterId String
|
||
ability Ability
|
||
proficient Boolean @default(true)
|
||
|
||
character Character @relation(fields: [characterId], references: [id], onDelete: Cascade)
|
||
|
||
@@unique([characterId, ability])
|
||
@@map("character_save_proficiencies")
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Weapons & inventory
|
||
// ---------------------------------------------------------------------------
|
||
|
||
model Weapon {
|
||
id String @id @default(cuid())
|
||
campaignId String
|
||
name String
|
||
damageDice String // e.g. "1d8"
|
||
damageType String // e.g. "slashing"
|
||
attackAbility String // "STR" | "DEX" | "FINESSE" (finesse = better of STR/DEX)
|
||
properties String[] // e.g. ["finesse", "light", "thrown"]
|
||
rangeNormal Int?
|
||
rangeLong Int?
|
||
// damageDice is the level-1 damage; a held copy's dice climb the damage
|
||
// ladder (game/calculations.js) by this many rungs per level above 1.
|
||
damageScaling Int @default(1)
|
||
// The level this weapon starts at: a held copy is never below it, and
|
||
// damageDice is the damage at this level.
|
||
minLevel Int @default(1)
|
||
// Offered in the character builder's starting-equipment step. Off by default:
|
||
// the DM opts entries in, so the pool can hold gear that must be earned.
|
||
isStartingOption Boolean @default(false)
|
||
// What it does to the sheet of whoever has it equipped: a list of
|
||
// { stat, amount } (game/calculations.js, GEAR_STATS), and a note for
|
||
// anything that is not a number.
|
||
effects Json @default("[]")
|
||
effectNote String?
|
||
createdAt DateTime @default(now())
|
||
|
||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||
assigned CharacterWeapon[]
|
||
rewards EncounterReward[]
|
||
offers SaleOffer[]
|
||
|
||
@@index([campaignId])
|
||
@@map("weapons")
|
||
}
|
||
|
||
model CharacterWeapon {
|
||
id String @id @default(cuid())
|
||
characterId String
|
||
weaponId String
|
||
quantity Int @default(1)
|
||
equipped Boolean @default(false)
|
||
level Int @default(1) // this copy's level; the character must be at least this level to use it
|
||
|
||
character Character @relation(fields: [characterId], references: [id], onDelete: Cascade)
|
||
weapon Weapon @relation(fields: [weaponId], references: [id], onDelete: Cascade)
|
||
|
||
@@unique([characterId, weaponId])
|
||
@@map("character_weapons")
|
||
}
|
||
|
||
// Campaign-level item pool, DM-managed like weapons and spells.
|
||
model Item {
|
||
id String @id @default(cuid())
|
||
campaignId String
|
||
name String
|
||
description String?
|
||
damageDice String? // optional dice (damage, healing...) at its starting level; scales like a weapon's
|
||
damageScaling Int @default(1)
|
||
minLevel Int @default(1)
|
||
isStartingOption Boolean @default(false)
|
||
// As on a weapon: what it does to whoever has it equipped. Armor is an
|
||
// item with an AC effect.
|
||
effects Json @default("[]")
|
||
effectNote String?
|
||
createdAt DateTime @default(now())
|
||
|
||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||
held InventoryItem[]
|
||
rewards EncounterReward[]
|
||
offers SaleOffer[]
|
||
|
||
@@index([campaignId])
|
||
@@map("items")
|
||
}
|
||
|
||
// An Item from the campaign pool held by a character.
|
||
model InventoryItem {
|
||
id String @id @default(cuid())
|
||
characterId String
|
||
itemId String
|
||
quantity Int @default(1)
|
||
equipped Boolean @default(false)
|
||
level Int @default(1)
|
||
|
||
character Character @relation(fields: [characterId], references: [id], onDelete: Cascade)
|
||
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
|
||
|
||
@@unique([characterId, itemId])
|
||
@@map("inventory_items")
|
||
}
|
||
|
||
// Ledger behind a character's purse: every change to a coin balance is one
|
||
// row here. (The name predates silver and copper.)
|
||
model GoldTransaction {
|
||
id String @id @default(cuid())
|
||
characterId String
|
||
currency Currency @default(GOLD) // which coin this entry is in
|
||
amount Int // signed: positive = gained, negative = spent
|
||
balanceAfter Int // that coin's balance afterwards
|
||
reason String?
|
||
createdById String?
|
||
createdAt DateTime @default(now())
|
||
|
||
character Character @relation(fields: [characterId], references: [id], onDelete: Cascade)
|
||
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
||
|
||
@@index([characterId, createdAt])
|
||
@@map("gold_transactions")
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Spells
|
||
// ---------------------------------------------------------------------------
|
||
|
||
model Spell {
|
||
id String @id @default(cuid())
|
||
campaignId String
|
||
name String
|
||
level Int // 0 = cantrip. Also the character level needed to use the spell.
|
||
damageDice String? // fixed; spells don't level up
|
||
school String?
|
||
castingTime String?
|
||
range String?
|
||
duration String?
|
||
description String?
|
||
isStartingOption Boolean @default(false)
|
||
// Brings back the dead: a character who can cast it may revive a dead ally
|
||
// on their turn in a battle (encounters.routes.js).
|
||
revives Boolean @default(false)
|
||
|
||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||
known CharacterSpell[]
|
||
|
||
@@index([campaignId])
|
||
@@map("spells")
|
||
}
|
||
|
||
model CharacterSpell {
|
||
id String @id @default(cuid())
|
||
characterId String
|
||
spellId String
|
||
prepared Boolean @default(false)
|
||
|
||
character Character @relation(fields: [characterId], references: [id], onDelete: Cascade)
|
||
spell Spell @relation(fields: [spellId], references: [id], onDelete: Cascade)
|
||
|
||
@@unique([characterId, spellId])
|
||
@@map("character_spells")
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Monsters & encounters
|
||
// ---------------------------------------------------------------------------
|
||
|
||
model Monster {
|
||
id String @id @default(cuid())
|
||
campaignId String
|
||
name String
|
||
ac Int
|
||
maxHp Int
|
||
speed Int @default(30)
|
||
strScore Int @default(10)
|
||
dexScore Int @default(10)
|
||
conScore Int @default(10)
|
||
intScore Int @default(10)
|
||
wisScore Int @default(10)
|
||
chaScore Int @default(10)
|
||
attackBonus Int @default(0)
|
||
damageDice String?
|
||
challengeRating String?
|
||
specialTrait String?
|
||
notes String?
|
||
|
||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||
encounterAppearances EncounterParticipant[]
|
||
|
||
@@index([campaignId])
|
||
@@map("monsters")
|
||
}
|
||
|
||
// A non-player character the DM runs: a quest-giver, shopkeeper, rival...
|
||
// Combat stats are optional — most NPCs are there to be talked to.
|
||
model Npc {
|
||
id String @id @default(cuid())
|
||
campaignId String
|
||
name String
|
||
role String? // e.g. "Innkeeper", "Captain of the Watch"
|
||
disposition NpcDisposition @default(NEUTRAL)
|
||
description String? // what the party can see and knows
|
||
dmNotes String? // secrets, motives — never sent to players
|
||
ac Int?
|
||
maxHp Int?
|
||
attackBonus Int?
|
||
damageDice String?
|
||
// A money changer swaps gold and cash at their own rate: exchangeGold gold
|
||
// for exchangeCash cash, either way. Both null: this NPC does not exchange.
|
||
exchangeGold Int?
|
||
exchangeCash Int?
|
||
createdAt DateTime @default(now())
|
||
|
||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||
encounterAppearances EncounterParticipant[]
|
||
wares SaleOffer[]
|
||
|
||
@@index([campaignId])
|
||
@@map("npcs")
|
||
}
|
||
|
||
model Encounter {
|
||
id String @id @default(cuid())
|
||
campaignId String
|
||
name String
|
||
mode EncounterMode @default(BATTLE)
|
||
status EncounterStatus @default(PLANNING)
|
||
currentRound Int @default(1)
|
||
// Whose turn it is in a battle; null until the fight starts.
|
||
activeParticipantId String?
|
||
// Who is being attacked (or healed) right now, shown to everyone, in the
|
||
// order they were picked. More than one makes it an area attack. Picked by
|
||
// the DM or by the player on turn, and cleared when the turn passes.
|
||
targetParticipantIds String[] @default([])
|
||
description String? // the scene / objective, shown to everyone
|
||
dmNotes String? // never sent to players
|
||
// Where the scene takes place. While the encounter is in progress, the
|
||
// characters in it are there too.
|
||
locationId String?
|
||
// Set while archived: kept in full, but off the campaign's list — players
|
||
// no longer see it there at all.
|
||
archivedAt DateTime?
|
||
// Place in the campaign's own order, lowest first. The DM rearranges it.
|
||
sortOrder Int @default(0)
|
||
// The experience points handed out for this encounter, in all; null until
|
||
// the DM awards them. They are awarded once.
|
||
xpAwarded Int?
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||
location Location? @relation(fields: [locationId], references: [id], onDelete: SetNull)
|
||
participants EncounterParticipant[]
|
||
rewards EncounterReward[]
|
||
wares SaleOffer[]
|
||
|
||
@@index([campaignId])
|
||
@@map("encounters")
|
||
}
|
||
|
||
// Loot the DM lines up for an encounter and later hands to a character. Until
|
||
// it is awarded it is the DM's secret; awarding it is what actually changes
|
||
// the character (gold ledger entry, or the weapon/item added to what they hold).
|
||
model EncounterReward {
|
||
id String @id @default(cuid())
|
||
encounterId String
|
||
type RewardType
|
||
gold Int? // GOLD: how many coins
|
||
currency Currency @default(GOLD) // GOLD: which coin they are
|
||
weaponId String? // WEAPON
|
||
itemId String? // ITEM
|
||
quantity Int @default(1)
|
||
level Int @default(1) // gear level the weapon/item is handed over at
|
||
note String?
|
||
awardedTo String? // who received it, as display text ("Aria", "Aria, Bo")
|
||
awardedAt DateTime?
|
||
createdAt DateTime @default(now())
|
||
|
||
encounter Encounter @relation(fields: [encounterId], references: [id], onDelete: Cascade)
|
||
weapon Weapon? @relation(fields: [weaponId], references: [id], onDelete: Cascade)
|
||
item Item? @relation(fields: [itemId], references: [id], onDelete: Cascade)
|
||
|
||
@@index([encounterId])
|
||
@@map("encounter_rewards")
|
||
}
|
||
|
||
// Something for sale: a weapon or item from the campaign pools, at a price.
|
||
// It belongs to an NPC (and is on offer wherever that NPC is met) or to an
|
||
// encounter itself (a stall, a vending machine). Only the DM sets these up;
|
||
// players see them, and buy, in a quest encounter in progress
|
||
// (encounters.routes.js).
|
||
model SaleOffer {
|
||
id String @id @default(cuid())
|
||
campaignId String
|
||
npcId String? // exactly one of npcId / encounterId is set
|
||
encounterId String?
|
||
weaponId String? // exactly one of weaponId / itemId is set
|
||
itemId String?
|
||
price Int // for one, in `currency`
|
||
currency Currency @default(GOLD)
|
||
level Int @default(1) // gear level it is handed over at
|
||
stock Int? // how many are left; null = no limit
|
||
createdAt DateTime @default(now())
|
||
|
||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||
npc Npc? @relation(fields: [npcId], references: [id], onDelete: Cascade)
|
||
encounter Encounter? @relation(fields: [encounterId], references: [id], onDelete: Cascade)
|
||
weapon Weapon? @relation(fields: [weaponId], references: [id], onDelete: Cascade)
|
||
item Item? @relation(fields: [itemId], references: [id], onDelete: Cascade)
|
||
|
||
@@index([campaignId])
|
||
@@index([npcId])
|
||
@@index([encounterId])
|
||
@@map("sale_offers")
|
||
}
|
||
|
||
// A row per combatant in an encounter — a character, a monster or an NPC.
|
||
// A monster's currentHp/maxHp live here, per instance. A character's HP has
|
||
// one source of truth, the Character row: encounters read and write that, and
|
||
// the columns here only hold the last values seen (used if the character is
|
||
// later deleted and the row loses its link).
|
||
model EncounterParticipant {
|
||
id String @id @default(cuid())
|
||
encounterId String
|
||
characterId String?
|
||
monsterId String?
|
||
npcId String?
|
||
displayName String // denormalized so a monster can be renamed per-instance, e.g. "Goblin #2"
|
||
// The d20 rolled for initiative (1–20); null until it is rolled.
|
||
initiativeRoll Int?
|
||
// The roll plus the combatant's initiative bonus, worked out when the roll
|
||
// is entered. This is what the turn order sorts on.
|
||
initiative Int @default(0)
|
||
currentHp Int
|
||
maxHp Int
|
||
conditions String[] @default([]) // e.g. ["poisoned", "prone"]; a character's own are on the Character row
|
||
// Conditions that wear off by themselves, as { condition: rounds left }.
|
||
// Counted down each time the round goes up; at 0 the condition is removed.
|
||
conditionRounds Json @default("{}")
|
||
isMonster Boolean
|
||
|
||
encounter Encounter @relation(fields: [encounterId], references: [id], onDelete: Cascade)
|
||
character Character? @relation(fields: [characterId], references: [id], onDelete: SetNull)
|
||
monster Monster? @relation(fields: [monsterId], references: [id], onDelete: SetNull)
|
||
npc Npc? @relation(fields: [npcId], references: [id], onDelete: SetNull)
|
||
|
||
@@index([encounterId])
|
||
@@index([characterId])
|
||
@@map("encounter_participants")
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Notes
|
||
// ---------------------------------------------------------------------------
|
||
|
||
model Note {
|
||
id String @id @default(cuid())
|
||
campaignId String?
|
||
characterId String?
|
||
authorId String
|
||
body String
|
||
visibility NoteVisibility @default(SHARED)
|
||
createdAt DateTime @default(now())
|
||
|
||
campaign Campaign? @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||
character Character? @relation(fields: [characterId], references: [id], onDelete: Cascade)
|
||
author User @relation(fields: [authorId], references: [id])
|
||
|
||
@@index([campaignId])
|
||
@@index([characterId])
|
||
@@map("notes")
|
||
}
|