feat(loot): add item, loot table, and combat reward entities
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>
This commit is contained in:
51
apps/api/src/items/entities/character-item.entity.ts
Normal file
51
apps/api/src/items/entities/character-item.entity.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
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;
|
||||
}
|
||||
74
apps/api/src/items/entities/item-definition.entity.ts
Normal file
74
apps/api/src/items/entities/item-definition.entity.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
Index,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { EquipmentSlot } from '../equipment-slot.enum';
|
||||
import { ItemRarity } from '../item-rarity.enum';
|
||||
import { ItemType } from '../item-type.enum';
|
||||
|
||||
@Entity({ name: 'item_definitions' })
|
||||
@Index('IDX_item_definitions_key', ['key'], { unique: true })
|
||||
export class ItemDefinition {
|
||||
@PrimaryGeneratedColumn('uuid', { name: 'id' })
|
||||
id!: string;
|
||||
|
||||
@Column({ name: 'key', type: 'varchar', length: 100 })
|
||||
key!: string;
|
||||
|
||||
@Column({ name: 'name', type: 'varchar', length: 150 })
|
||||
name!: string;
|
||||
|
||||
@Column({ name: 'description', type: 'text' })
|
||||
description!: string;
|
||||
|
||||
@Column({ name: 'type', type: 'enum', enum: ItemType, enumName: 'item_type_enum' })
|
||||
type!: ItemType;
|
||||
|
||||
@Column({
|
||||
name: 'equipment_slot',
|
||||
type: 'enum',
|
||||
enum: EquipmentSlot,
|
||||
enumName: 'equipment_slot_enum',
|
||||
nullable: true,
|
||||
})
|
||||
equipmentSlot!: EquipmentSlot | null;
|
||||
|
||||
@Column({ name: 'rarity', type: 'enum', enum: ItemRarity, enumName: 'item_rarity_enum' })
|
||||
rarity!: ItemRarity;
|
||||
|
||||
@Column({ name: 'tier', type: 'integer' })
|
||||
tier!: number;
|
||||
|
||||
@Column({ name: 'required_level', type: 'integer' })
|
||||
requiredLevel!: number;
|
||||
|
||||
@Column({ name: 'weapon_damage', type: 'integer' })
|
||||
weaponDamage!: number;
|
||||
|
||||
@Column({ name: 'bonus_hp', type: 'integer' })
|
||||
bonusHp!: number;
|
||||
|
||||
@Column({ name: 'bonus_attack', type: 'integer' })
|
||||
bonusAttack!: number;
|
||||
|
||||
@Column({ name: 'bonus_armor', type: 'integer' })
|
||||
bonusArmor!: number;
|
||||
|
||||
// Always 0 in Slice 0.4: there are no merchants, and the balancing doc's
|
||||
// Grenzmarken table lists purchase prices, not sell prices.
|
||||
@Column({ name: 'sell_price', type: 'integer' })
|
||||
sellPrice!: number;
|
||||
|
||||
@Column({ name: 'icon_path', type: 'varchar', length: 255 })
|
||||
iconPath!: string;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
||||
createdAt!: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
||||
updatedAt!: Date;
|
||||
}
|
||||
Reference in New Issue
Block a user