feat(combat): add combat domain enums, entities, and encounter consumption field
This commit is contained in:
6
apps/api/src/combat/combat-action.enum.ts
Normal file
6
apps/api/src/combat/combat-action.enum.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
// Only ATTACK is implemented in Slice 0.3. Future slices add HEAVY_STRIKE,
|
||||
// SHIELD_BASH, DEFEND, POTION, FLEE as real members with their own
|
||||
// CombatEngineService cases — do not add them here until their behavior ships.
|
||||
export enum CombatAction {
|
||||
ATTACK = 'ATTACK',
|
||||
}
|
||||
5
apps/api/src/combat/combat-event-type.enum.ts
Normal file
5
apps/api/src/combat/combat-event-type.enum.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export enum CombatEventType {
|
||||
DAMAGE = 'DAMAGE',
|
||||
COMBAT_WON = 'COMBAT_WON',
|
||||
COMBAT_LOST = 'COMBAT_LOST',
|
||||
}
|
||||
5
apps/api/src/combat/combat-status.enum.ts
Normal file
5
apps/api/src/combat/combat-status.enum.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export enum CombatStatus {
|
||||
ACTIVE = 'ACTIVE',
|
||||
WON = 'WON',
|
||||
LOST = 'LOST',
|
||||
}
|
||||
4
apps/api/src/combat/combatant.enum.ts
Normal file
4
apps/api/src/combat/combatant.enum.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export enum Combatant {
|
||||
PLAYER = 'PLAYER',
|
||||
MONSTER = 'MONSTER',
|
||||
}
|
||||
62
apps/api/src/combat/entities/combat-event.entity.ts
Normal file
62
apps/api/src/combat/entities/combat-event.entity.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
Index,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { Combatant } from '../combatant.enum';
|
||||
import { CombatEventType } from '../combat-event-type.enum';
|
||||
import { Combat } from './combat.entity';
|
||||
|
||||
@Entity({ name: 'combat_events' })
|
||||
@Index('IDX_combat_events_combat_sequence', ['combatId', 'sequence'], { unique: true })
|
||||
export class CombatEvent {
|
||||
@PrimaryGeneratedColumn('uuid', { name: 'id' })
|
||||
id!: string;
|
||||
|
||||
@Column({ name: 'combat_id', type: 'uuid' })
|
||||
combatId!: string;
|
||||
|
||||
@Column({ name: 'round', type: 'integer' })
|
||||
round!: number;
|
||||
|
||||
@Column({ name: 'sequence', type: 'integer' })
|
||||
sequence!: number;
|
||||
|
||||
@Column({
|
||||
name: 'type',
|
||||
type: 'enum',
|
||||
enum: CombatEventType,
|
||||
enumName: 'combat_event_type_enum',
|
||||
})
|
||||
type!: CombatEventType;
|
||||
|
||||
@Column({
|
||||
name: 'source',
|
||||
type: 'enum',
|
||||
enum: Combatant,
|
||||
enumName: 'combatant_enum',
|
||||
})
|
||||
source!: Combatant;
|
||||
|
||||
@Column({
|
||||
name: 'target',
|
||||
type: 'enum',
|
||||
enum: Combatant,
|
||||
enumName: 'combatant_enum',
|
||||
})
|
||||
target!: Combatant;
|
||||
|
||||
@Column({ name: 'amount', type: 'integer', nullable: true })
|
||||
amount!: number | null;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
||||
createdAt!: Date;
|
||||
|
||||
@ManyToOne(() => Combat, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'combat_id' })
|
||||
combat!: Combat;
|
||||
}
|
||||
89
apps/api/src/combat/entities/combat.entity.ts
Normal file
89
apps/api/src/combat/entities/combat.entity.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
Index,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { Character } from '../../characters/entities/character.entity';
|
||||
import { HuntEncounter } from '../../hunting/entities/hunt-encounter.entity';
|
||||
import { MonsterDefinition } from '../../monsters/entities/monster-definition.entity';
|
||||
import { CombatStatus } from '../combat-status.enum';
|
||||
|
||||
export interface CombatCombatantState {
|
||||
attack: number;
|
||||
armor: number;
|
||||
}
|
||||
|
||||
export interface CombatPlayerState extends CombatCombatantState {
|
||||
weaponDamage: number;
|
||||
}
|
||||
|
||||
@Entity({ name: 'combats' })
|
||||
@Index('IDX_combats_hunt_encounter', ['huntEncounterId'], { unique: true })
|
||||
export class Combat {
|
||||
@PrimaryGeneratedColumn('uuid', { name: 'id' })
|
||||
id!: string;
|
||||
|
||||
@Column({ name: 'character_id', type: 'uuid' })
|
||||
characterId!: string;
|
||||
|
||||
@Column({ name: 'hunt_encounter_id', type: 'uuid' })
|
||||
huntEncounterId!: string;
|
||||
|
||||
@Column({ name: 'monster_definition_id', type: 'uuid' })
|
||||
monsterDefinitionId!: string;
|
||||
|
||||
@Column({
|
||||
name: 'status',
|
||||
type: 'enum',
|
||||
enum: CombatStatus,
|
||||
enumName: 'combat_status_enum',
|
||||
})
|
||||
status!: CombatStatus;
|
||||
|
||||
@Column({ name: 'round', type: 'integer' })
|
||||
round!: number;
|
||||
|
||||
@Column({ name: 'player_max_hp', type: 'integer' })
|
||||
playerMaxHp!: number;
|
||||
|
||||
@Column({ name: 'player_current_hp', type: 'integer' })
|
||||
playerCurrentHp!: number;
|
||||
|
||||
@Column({ name: 'monster_max_hp', type: 'integer' })
|
||||
monsterMaxHp!: number;
|
||||
|
||||
@Column({ name: 'monster_current_hp', type: 'integer' })
|
||||
monsterCurrentHp!: number;
|
||||
|
||||
@Column({ name: 'player_state', type: 'jsonb' })
|
||||
playerState!: CombatPlayerState;
|
||||
|
||||
@Column({ name: 'monster_state', type: 'jsonb' })
|
||||
monsterState!: CombatCombatantState;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
||||
createdAt!: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
||||
updatedAt!: Date;
|
||||
|
||||
@Column({ name: 'completed_at', type: 'timestamptz', nullable: true })
|
||||
completedAt!: Date | null;
|
||||
|
||||
@ManyToOne(() => Character, { onDelete: 'RESTRICT' })
|
||||
@JoinColumn({ name: 'character_id' })
|
||||
character!: Character;
|
||||
|
||||
@ManyToOne(() => HuntEncounter, { onDelete: 'RESTRICT' })
|
||||
@JoinColumn({ name: 'hunt_encounter_id' })
|
||||
huntEncounter!: HuntEncounter;
|
||||
|
||||
@ManyToOne(() => MonsterDefinition, { onDelete: 'RESTRICT' })
|
||||
@JoinColumn({ name: 'monster_definition_id' })
|
||||
monster!: MonsterDefinition;
|
||||
}
|
||||
Reference in New Issue
Block a user