<commit_before>var mongoose = require( 'mongoose' );
var MonsterModel = require( '../models/monster' );
var Schema = mongoose.Schema;

var MonsterSchema = new Schema({
	name: String,
	description: String,
	created: { type: Date, default: Date.now },
	level: { type: Number, default: 1 }, // CR 0 = level 1, CR 1/8 = level 2, etc.
	size: { type: String, default: 'medium' }, // one of 'tiny', 'small', 'medium', 'large', 'huge', 'gargantuan'
	speed: { type: String, default: '30 ft.' },
	armor: String, // one of 'padded', 'leather', 'studded leather'... 'splint mail', 'plate mail'
	shield: { type: Boolean, default: false },
	naturalArmor: String, // same as (and replaces) armor, but will be reported as 'natural armor'
	senses: String,
	languages: String,
	resistances: [String],
	immunities: [String],
	vulnerabilities: [String],
	traits: [String],
	actions: [String],
	legendaryActions: [String],
	abilityOrder: { type: [String], default: [ 'str', 'dex', 'con', 'wis', 'int', 'cha' ] }, // each string should be one of 'con', 'str', etc.
	abilities: { type: Object, default: {} }
});

MonsterSchema.pre( 'save', function( next ) {
	for ( var i = 0; i < 6; i++ ) {
		this.abilities[ this.abilityOrder[ i ] ] = MonsterModel.getDefaultAbilityAt( i );
	}
	next();
});

MonsterSchema.virtual( 'cr' ).get( function() {
	return MonsterModel.getCR( this.level );
});

MonsterSchema.virtual( 'hitDie' ).get( function() {
	return MonsterModel.getHitDie( this.size );
});

MonsterSchema.virtual( 'hitDice' ).get( function() {
	return MonsterModel.getHitDiceCount( this.level );
});

MonsterSchema.virtual( 'hp' ).get( function() {
	return MonsterModel.getHP( this.hitDie, this.hitDice, this.abilities.con );
});

MonsterSchema.virtual( 'ac' ).get( function() {
	return MonsterModel.getAC( this.armor, this.naturalArmor, this.shield, this.abilities.dex );
});<commit_msg>Allow setting ability scores manually<commit_after>var mongoose = require( 'mongoose' );
var MonsterModel = require( '../models/monster' );
var Schema = mongoose.Schema;

var MonsterSchema = new Schema({
	name: String,
	description: String,
	created: { type: Date, default: Date.now },
	level: { type: Number, default: 1 }, // CR 0 = level 1, CR 1/8 = level 2, etc.
	size: { type: String, default: 'medium' }, // one of 'tiny', 'small', 'medium', 'large', 'huge', 'gargantuan'
	speed: { type: String, default: '30 ft.' },
	armor: String, // one of 'padded', 'leather', 'studded leather'... 'splint mail', 'plate mail'
	shield: { type: Boolean, default: false },
	naturalArmor: String, // same as (and replaces) armor, but will be reported as 'natural armor'
	senses: String,
	languages: String,
	resistances: [String],
	immunities: [String],
	vulnerabilities: [String],
	traits: [String],
	actions: [String],
	legendaryActions: [String],
	abilityOrder: { type: [String], default: [ 'str', 'dex', 'con', 'wis', 'int', 'cha' ] }, // each string should be one of 'con', 'str', etc.
	abilities: { type: Object, default: {} }
});

MonsterSchema.pre( 'save', function( next ) {
	for ( var i = 0; i < 6; i++ ) {
		if ( ! this.abilities[ this.abilityOrder[ i ] ] ) {
			this.abilities[ this.abilityOrder[ i ] ] = MonsterModel.getDefaultAbilityAt( i );
		}
	}
	next();
});

MonsterSchema.virtual( 'cr' ).get( function() {
	return MonsterModel.getCR( this.level );
});

MonsterSchema.virtual( 'hitDie' ).get( function() {
	return MonsterModel.getHitDie( this.size );
});

MonsterSchema.virtual( 'hitDice' ).get( function() {
	return MonsterModel.getHitDiceCount( this.level );
});

MonsterSchema.virtual( 'hp' ).get( function() {
	return MonsterModel.getHP( this.hitDie, this.hitDice, this.abilities.con );
});

MonsterSchema.virtual( 'ac' ).get( function() {
	return MonsterModel.getAC( this.armor, this.naturalArmor, this.shield, this.abilities.dex );
});
{'fraction_non_alphanumeric': 0.18079244292836527, 'fraction_numerical': 0.005247966413014957, 'mean_word_length': 4.548762736535663, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1512205', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1292, 'n_words': 376}