const mongoose = require('mongoose'); const Schema = mongoose.Schema; const ActorSchema = new Schema({ name: { type: String, required: true, trim: true }, type: { type: String, enum: ['character', 'npc', 'creature'], default: 'character' }, species: { type: String, default: '' }, className: { type: String, default: '' }, subclass: { type: String, default: '' }, level: { type: Number, min: 1, max: 20, default: 1 }, background: { type: String, default: '' }, challengeRating: { type: String, default: '' }, description: { type: String, default: '' }, image: { type: String, default: '' }, abilityScores: { str: { type: Number, min: 1, max: 30, default: 10 }, dex: { type: Number, min: 1, max: 30, default: 10 }, con: { type: Number, min: 1, max: 30, default: 10 }, int: { type: Number, min: 1, max: 30, default: 10 }, wis: { type: Number, min: 1, max: 30, default: 10 }, cha: { type: Number, min: 1, max: 30, default: 10 } }, armorClass: { type: Number, min: 0, default: 10 }, speed: { type: Number, min: 0, default: 30 }, // The two pools the sheet draws as bars under the portrait (Syndria98/dragonroll#64): the bar // fills `current` of `max`, so both travel together. `current` is kept below `max` by whoever // writes them (routes/actor.js), the same way the sheet clamps the bar. hitPoints: { current: { type: Number, min: 0, default: 10 }, max: { type: Number, min: 0, default: 10 } }, hitDice: { current: { type: Number, min: 0, default: 1 }, max: { type: Number, min: 0, default: 1 } }, proficiencies: { type: String, default: '' }, // The skills the character is proficient with (Syndria98/dragonroll#83). Dragonroll holds // whole names; services/actor-foundry.js translates the short keys a Foundry world uses. skills: { acrobatics: { type: Boolean, default: false }, animalHandling: { type: Boolean, default: false }, arcana: { type: Boolean, default: false }, athletics: { type: Boolean, default: false }, deception: { type: Boolean, default: false }, history: { type: Boolean, default: false }, insight: { type: Boolean, default: false }, intimidation: { type: Boolean, default: false }, investigation: { type: Boolean, default: false }, medicine: { type: Boolean, default: false }, nature: { type: Boolean, default: false }, perception: { type: Boolean, default: false }, performance: { type: Boolean, default: false }, persuasion: { type: Boolean, default: false }, religion: { type: Boolean, default: false }, sleightOfHand: { type: Boolean, default: false }, stealth: { type: Boolean, default: false }, survival: { type: Boolean, default: false } }, // Which of the six saving throws the character adds its proficiency bonus to. savingThrows: { str: { type: Boolean, default: false }, dex: { type: Boolean, default: false }, con: { type: Boolean, default: false }, int: { type: Boolean, default: false }, wis: { type: Boolean, default: false }, cha: { type: Boolean, default: false } }, // Tool and language proficiencies: plain names, one per entry. The free-form // `proficiencies` text keeps whatever else the character is proficient with // (armour and weapons, say), which has no list of its own. tools: [{ type: String, trim: true }], languages: [{ type: String, trim: true }], // The coins the character holds, in the five D&D denominations. currency: { pp: { type: Number, min: 0, default: 0 }, gp: { type: Number, min: 0, default: 0 }, ep: { type: Number, min: 0, default: 0 }, sp: { type: Number, min: 0, default: 0 }, cp: { type: Number, min: 0, default: 0 } }, inventory: [{ name: { type: String, trim: true, default: '' }, quantity: { type: Number, min: 1, default: 1 }, weight: { type: Number, min: 0, default: 0 }, // The gear's own picture: what a Foundry world sends with the item it stands // for, shown on the left of the inventory row. icon: { type: String, default: '' } }], traits: { type: String, default: '' }, spells: { type: String, default: '' }, campaign: { type: Schema.Types.ObjectId, ref: 'Campaign', required: true }, // The folder this actor stands in: a Folder of the same campaign whose target is // 'actor' (null = the root of the actor list). folder: { type: Schema.Types.ObjectId, ref: 'Folder', default: null }, foundryActorId: { type: String }, // The Discord player this character belongs to (Syndria98/dragonroll#72): each player // of the server a campaign is linked to holds one character of it. Only // routes/discord.js writes it, so the campaign keeps owning it whichever guild claimed it. discordUserId: { type: String, default: null }, date: { type: Date, default: Date.now } }); ActorSchema.index( { campaign: 1, foundryActorId: 1 }, { unique: true, partialFilterExpression: { foundryActorId: { $type: 'string' } } } ); // A player holds at most one character of a campaign: the id is unique within it. ActorSchema.index( { campaign: 1, discordUserId: 1 }, { unique: true, partialFilterExpression: { discordUserId: { $type: 'string' } } } ); module.exports = mongoose.model('Actor', ActorSchema);