Declares every new TypeORM entity Slice 0.4 needs (ItemDefinition, CharacterItem, LootTable, LootTableEntry, CombatReward, CombatRewardItem) plus the ItemType/EquipmentSlot/ItemRarity enums, and adds the two columns existing entities gain: Character.silver and MonsterDefinition.lootTableId. No migration SQL or service logic yet - just schema declarations backed by a metadata-driven schema spec. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
Index,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
PrimaryGeneratedColumn,
|
|
UpdateDateColumn,
|
|
} from 'typeorm';
|
|
import { Character } from '../../characters/entities/character.entity';
|
|
import { ItemDefinition } from './item-definition.entity';
|
|
|
|
/**
|
|
* One stack of one item definition owned by one character.
|
|
*
|
|
* Duplicate drops increment `quantity` (spec §28 allows duplicates and forbids
|
|
* duplicate protection). Slice 0.5 equips a `CharacterItem.id`, never an
|
|
* `ItemDefinition.id`.
|
|
*/
|
|
@Entity({ name: 'character_items' })
|
|
@Index('IDX_character_items_character_item', ['characterId', 'itemDefinitionId'], {
|
|
unique: true,
|
|
})
|
|
export class CharacterItem {
|
|
@PrimaryGeneratedColumn('uuid', { name: 'id' })
|
|
id!: string;
|
|
|
|
@Column({ name: 'character_id', type: 'uuid' })
|
|
characterId!: string;
|
|
|
|
@Column({ name: 'item_definition_id', type: 'uuid' })
|
|
itemDefinitionId!: string;
|
|
|
|
@Column({ name: 'quantity', type: 'integer' })
|
|
quantity!: number;
|
|
|
|
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
|
createdAt!: Date;
|
|
|
|
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
|
updatedAt!: Date;
|
|
|
|
@ManyToOne(() => Character, { onDelete: 'CASCADE' })
|
|
@JoinColumn({ name: 'character_id' })
|
|
character!: Character;
|
|
|
|
@ManyToOne(() => ItemDefinition, { onDelete: 'RESTRICT' })
|
|
@JoinColumn({ name: 'item_definition_id' })
|
|
itemDefinition!: ItemDefinition;
|
|
}
|