feat(api): seed the starting sword as a real, equipped CharacterItem
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
import { DEMO_CHARACTER_ID } from '../../demo/demo-character.constants';
|
||||
import {
|
||||
DEMO_CHARACTER_ID,
|
||||
DEMO_CHARACTER_STARTING_WEAPON_EQUIPMENT_ID,
|
||||
DEMO_CHARACTER_STARTING_WEAPON_ITEM_ID,
|
||||
} from '../../demo/demo-character.constants';
|
||||
import { Character } from '../../characters/entities/character.entity';
|
||||
import { CharacterEquipment } from '../../equipment/entities/character-equipment.entity';
|
||||
import { CharacterItem } from '../../items/entities/character-item.entity';
|
||||
import { EquipmentSlot } from '../../items/equipment-slot.enum';
|
||||
import { ItemDefinition } from '../../items/entities/item-definition.entity';
|
||||
import { LootTableEntry } from '../../loot/entities/loot-table-entry.entity';
|
||||
import { LootTable } from '../../loot/entities/loot-table.entity';
|
||||
@@ -11,6 +18,7 @@ import { LocationConnection } from '../../world/entities/location-connection.ent
|
||||
import { LocationDefinition } from '../../world/entities/location-definition.entity';
|
||||
import {
|
||||
ASH_RAT_LOOT_TABLE_ID,
|
||||
ITEM_IDS,
|
||||
ROAD_BANDIT_LOOT_TABLE_ID,
|
||||
} from './item.constants';
|
||||
import { ITEM_DEFINITIONS, LOOT_TABLES, LOOT_TABLE_ENTRIES } from './item-content';
|
||||
@@ -205,4 +213,32 @@ export async function seedVisibleVerticalSlice(
|
||||
currentLocationId: southGateId,
|
||||
});
|
||||
}
|
||||
|
||||
const characterItemRepository = dataSource.getRepository(CharacterItem);
|
||||
const characterEquipmentRepository = dataSource.getRepository(CharacterEquipment);
|
||||
|
||||
const existingStartingSword = await characterItemRepository.findOneBy({
|
||||
id: DEMO_CHARACTER_STARTING_WEAPON_ITEM_ID,
|
||||
});
|
||||
if (!existingStartingSword) {
|
||||
await characterItemRepository.insert({
|
||||
id: DEMO_CHARACTER_STARTING_WEAPON_ITEM_ID,
|
||||
characterId: DEMO_CHARACTER_ID,
|
||||
itemDefinitionId: ITEM_IDS['worn-short-sword'],
|
||||
quantity: 1,
|
||||
});
|
||||
}
|
||||
|
||||
const existingWeaponEquipment = await characterEquipmentRepository.findOneBy({
|
||||
characterId: DEMO_CHARACTER_ID,
|
||||
slot: EquipmentSlot.WEAPON,
|
||||
});
|
||||
if (!existingWeaponEquipment) {
|
||||
await characterEquipmentRepository.insert({
|
||||
id: DEMO_CHARACTER_STARTING_WEAPON_EQUIPMENT_ID,
|
||||
characterId: DEMO_CHARACTER_ID,
|
||||
slot: EquipmentSlot.WEAPON,
|
||||
characterItemId: DEMO_CHARACTER_STARTING_WEAPON_ITEM_ID,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user