Make use of DatabaseService
inside ProfileFixerService
and CustomItemService
This commit is contained in:
parent
4c08d64ca5
commit
9f1e0693f5
@ -1,7 +1,9 @@
|
||||
import { error } from "console";
|
||||
import { inject, injectable } from "tsyringe";
|
||||
import { IGlobals } from "@spt/models/eft/common/IGlobals";
|
||||
import { IAchievement } from "@spt/models/eft/common/tables/IAchievement";
|
||||
import { IMatch } from "@spt/models/eft/common/tables/IMatch";
|
||||
import { IQuest } from "@spt/models/eft/common/tables/IQuest";
|
||||
import { ITemplateItem } from "@spt/models/eft/common/tables/ITemplateItem";
|
||||
import { ITrader } from "@spt/models/eft/common/tables/ITrader";
|
||||
import { IBots } from "@spt/models/spt/bots/IBots";
|
||||
@ -155,6 +157,19 @@ export class DatabaseService
|
||||
return this.databaseServer.getTables().templates!;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns assets/database/templates/achievements.json
|
||||
*/
|
||||
public getAchievements(): IAchievement[]
|
||||
{
|
||||
if (!this.databaseServer.getTables().templates!.achievements)
|
||||
{
|
||||
throw new error(this.localisationService.getText("database-data_at_path_missing", "assets/database/templates/achievements.json"));
|
||||
}
|
||||
|
||||
return this.databaseServer.getTables().templates!.achievements!;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns assets/database/templates/items.json
|
||||
*/
|
||||
@ -168,6 +183,19 @@ export class DatabaseService
|
||||
return this.databaseServer.getTables().templates!.items!;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns assets/database/templates/items.json
|
||||
*/
|
||||
public getQuests(): Record<string, IQuest>
|
||||
{
|
||||
if (!this.databaseServer.getTables().templates!.quests)
|
||||
{
|
||||
throw new error(this.localisationService.getText("database-data_at_path_missing", "assets/database/templates/quests.json"));
|
||||
}
|
||||
|
||||
return this.databaseServer.getTables().templates!.quests!;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns assets/database/traders/
|
||||
*/
|
||||
|
@ -19,7 +19,7 @@ import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
|
||||
import { IRagfairConfig } from "@spt/models/spt/config/IRagfairConfig";
|
||||
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
||||
import { ConfigServer } from "@spt/servers/ConfigServer";
|
||||
import { DatabaseServer } from "@spt/servers/DatabaseServer";
|
||||
import { DatabaseService } from "@spt/services/DatabaseService";
|
||||
import { LocalisationService } from "@spt/services/LocalisationService";
|
||||
import { ICloner } from "@spt/utils/cloners/ICloner";
|
||||
import { HashUtil } from "@spt/utils/HashUtil";
|
||||
@ -36,6 +36,7 @@ export class ProfileFixerService
|
||||
constructor(
|
||||
@inject("WinstonLogger") protected logger: ILogger,
|
||||
@inject("Watermark") protected watermark: Watermark,
|
||||
@inject("DatabaseService") protected databaseService: DatabaseService,
|
||||
@inject("HideoutHelper") protected hideoutHelper: HideoutHelper,
|
||||
@inject("InventoryHelper") protected inventoryHelper: InventoryHelper,
|
||||
@inject("TraderHelper") protected traderHelper: TraderHelper,
|
||||
@ -45,7 +46,6 @@ export class ProfileFixerService
|
||||
@inject("TimeUtil") protected timeUtil: TimeUtil,
|
||||
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
||||
@inject("HashUtil") protected hashUtil: HashUtil,
|
||||
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
||||
@inject("ConfigServer") protected configServer: ConfigServer,
|
||||
@inject("RecursiveCloner") protected cloner: ICloner,
|
||||
)
|
||||
@ -74,6 +74,8 @@ export class ProfileFixerService
|
||||
|
||||
if (pmcProfile.Hideout)
|
||||
{
|
||||
const globals = this.databaseService.getGlobals();
|
||||
|
||||
this.migrateImprovements(pmcProfile);
|
||||
this.addMissingBonusesProperty(pmcProfile);
|
||||
this.addMissingWallImprovements(pmcProfile);
|
||||
@ -88,7 +90,7 @@ export class ProfileFixerService
|
||||
|
||||
if (pmcProfile.Hideout.Areas.find((x) => x.type === HideoutAreas.GENERATOR)!.slots.length
|
||||
< 6
|
||||
+ this.databaseServer.getTables().globals!.config.SkillsSettings.HideoutManagement.EliteSlots.Generator
|
||||
+ globals.config.SkillsSettings.HideoutManagement.EliteSlots.Generator
|
||||
.Slots
|
||||
)
|
||||
{
|
||||
@ -96,7 +98,7 @@ export class ProfileFixerService
|
||||
this.addEmptyObjectsToHideoutAreaSlots(
|
||||
HideoutAreas.GENERATOR,
|
||||
6
|
||||
+ this.databaseServer.getTables().globals!.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
+ globals.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
.Generator.Slots,
|
||||
pmcProfile,
|
||||
);
|
||||
@ -105,7 +107,7 @@ export class ProfileFixerService
|
||||
if (
|
||||
pmcProfile.Hideout.Areas.find((x) => x.type === HideoutAreas.WATER_COLLECTOR)!.slots.length
|
||||
< 1
|
||||
+ this.databaseServer.getTables().globals!.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
+ globals.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
.WaterCollector.Slots
|
||||
)
|
||||
{
|
||||
@ -113,7 +115,7 @@ export class ProfileFixerService
|
||||
this.addEmptyObjectsToHideoutAreaSlots(
|
||||
HideoutAreas.WATER_COLLECTOR,
|
||||
1
|
||||
+ this.databaseServer.getTables().globals!.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
+ globals.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
.WaterCollector.Slots,
|
||||
pmcProfile,
|
||||
);
|
||||
@ -122,7 +124,7 @@ export class ProfileFixerService
|
||||
if (
|
||||
pmcProfile.Hideout.Areas.find((x) => x.type === HideoutAreas.AIR_FILTERING)!.slots.length
|
||||
< 3
|
||||
+ this.databaseServer.getTables().globals!.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
+ globals.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
.AirFilteringUnit.Slots
|
||||
)
|
||||
{
|
||||
@ -130,7 +132,7 @@ export class ProfileFixerService
|
||||
this.addEmptyObjectsToHideoutAreaSlots(
|
||||
HideoutAreas.AIR_FILTERING,
|
||||
3
|
||||
+ this.databaseServer.getTables().globals!.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
+ globals.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
.AirFilteringUnit.Slots,
|
||||
pmcProfile,
|
||||
);
|
||||
@ -140,7 +142,7 @@ export class ProfileFixerService
|
||||
if (
|
||||
pmcProfile.Hideout.Areas.find((x) => x.type === HideoutAreas.BITCOIN_FARM)!.slots.length
|
||||
< 50
|
||||
+ this.databaseServer.getTables().globals!.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
+ globals.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
.BitcoinFarm.Slots
|
||||
)
|
||||
{
|
||||
@ -148,7 +150,7 @@ export class ProfileFixerService
|
||||
this.addEmptyObjectsToHideoutAreaSlots(
|
||||
HideoutAreas.BITCOIN_FARM,
|
||||
50
|
||||
+ this.databaseServer.getTables().globals!.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
+ globals.config.SkillsSettings.HideoutManagement.EliteSlots
|
||||
.BitcoinFarm.Slots,
|
||||
pmcProfile,
|
||||
);
|
||||
@ -178,9 +180,9 @@ export class ProfileFixerService
|
||||
return;
|
||||
}
|
||||
|
||||
const db = this.databaseServer.getTables();
|
||||
const hideoutStandAreaDb = db.hideout!.areas.find((x) => x.type === HideoutAreas.WEAPON_STAND)!;
|
||||
const hideoutStandSecondaryAreaDb = db.hideout!.areas.find((x) => x.parentArea === hideoutStandAreaDb._id)!;
|
||||
const hideout = this.databaseService.getHideout();
|
||||
const hideoutStandAreaDb = hideout.areas.find((area) => area.type === HideoutAreas.WEAPON_STAND)!;
|
||||
const hideoutStandSecondaryAreaDb = hideout.areas.find((x) => x.parentArea === hideoutStandAreaDb._id)!;
|
||||
const stageCurrentAt = hideoutStandAreaDb.stages[weaponStandArea.level];
|
||||
const hideoutStandStashId = pmcProfile.Inventory.hideoutAreaStashes[HideoutAreas.WEAPON_STAND];
|
||||
const hideoutSecondaryStashId = pmcProfile.Inventory.hideoutAreaStashes[HideoutAreas.WEAPON_STAND_SECONDARY];
|
||||
@ -281,8 +283,8 @@ export class ProfileFixerService
|
||||
return;
|
||||
}
|
||||
|
||||
const db = this.databaseServer.getTables();
|
||||
const placeOfFameAreaDb = db.hideout!.areas.find((area) => area.type === HideoutAreas.PLACE_OF_FAME);
|
||||
const placeOfFameAreaDb = this.databaseService.getHideout().areas
|
||||
.find((area) => area.type === HideoutAreas.PLACE_OF_FAME);
|
||||
if (!placeOfFameAreaDb)
|
||||
{
|
||||
return;
|
||||
@ -464,7 +466,7 @@ export class ProfileFixerService
|
||||
{
|
||||
const taskConditionKeysToRemove: string[] = [];
|
||||
const activeRepeatableQuests = this.getActiveRepeatableQuests(pmcProfile.RepeatableQuests);
|
||||
const achievements = this.databaseServer.getTables().templates!.achievements;
|
||||
const achievements = this.databaseService.getAchievements();
|
||||
|
||||
// Loop over TaskConditionCounters objects and add once we want to remove to counterKeysToRemove
|
||||
for (const [key, taskConditionCounter] of Object.entries(pmcProfile.TaskConditionCounters))
|
||||
@ -648,9 +650,8 @@ export class ProfileFixerService
|
||||
protected addMissingWallImprovements(pmcProfile: IPmcData): void
|
||||
{
|
||||
const profileWallArea = pmcProfile.Hideout.Areas.find((x) => x.type === HideoutAreas.EMERGENCY_WALL)!;
|
||||
const wallDb = this.databaseServer
|
||||
.getTables()
|
||||
.hideout!.areas.find((x) => x.type === HideoutAreas.EMERGENCY_WALL);
|
||||
const wallDb = this.databaseService.getHideout().areas
|
||||
.find((x) => x.type === HideoutAreas.EMERGENCY_WALL);
|
||||
|
||||
if (profileWallArea.level > 0)
|
||||
{
|
||||
@ -779,7 +780,7 @@ export class ProfileFixerService
|
||||
{
|
||||
const profileHideoutAreas = pmcProfile.Hideout.Areas;
|
||||
const profileBonuses = pmcProfile.Bonuses;
|
||||
const dbHideoutAreas = this.databaseServer.getTables().hideout!.areas;
|
||||
const dbHideoutAreas = this.databaseService.getHideout().areas;
|
||||
|
||||
for (const area of profileHideoutAreas)
|
||||
{
|
||||
@ -870,7 +871,7 @@ export class ProfileFixerService
|
||||
*/
|
||||
public checkForOrphanedModdedItems(sessionId: string, fullProfile: ISptProfile): void
|
||||
{
|
||||
const itemsDb = this.databaseServer.getTables().templates!.items;
|
||||
const itemsDb = this.databaseService.getItems();
|
||||
const pmcProfile = fullProfile.characters.pmc;
|
||||
|
||||
// Get items placed in root of stash
|
||||
@ -972,7 +973,7 @@ export class ProfileFixerService
|
||||
}
|
||||
}
|
||||
|
||||
const clothing = this.databaseServer.getTables().templates!.customization;
|
||||
const clothing = this.databaseService.getTemplates().customization;
|
||||
for (const [_, suitId] of Object.entries(fullProfile.suits))
|
||||
{
|
||||
if (!clothing[suitId])
|
||||
@ -1196,8 +1197,8 @@ export class ProfileFixerService
|
||||
}
|
||||
|
||||
// Iterate over clothing
|
||||
const customizationDb = this.databaseServer.getTables().templates!.customization;
|
||||
const customizationDbArray = Object.values(this.databaseServer.getTables().templates!.customization);
|
||||
const customizationDb = this.databaseService.getTemplates().customization;
|
||||
const customizationDbArray = Object.values(customizationDb);
|
||||
const playerIsUsec = pmcProfile.Info.Side.toLowerCase() === "usec";
|
||||
|
||||
// Check Head
|
||||
@ -1265,7 +1266,7 @@ export class ProfileFixerService
|
||||
return;
|
||||
}
|
||||
|
||||
const profileTemplates = this.databaseServer.getTables().templates?.profiles[fullProfile.info.edition];
|
||||
const profileTemplates = this.databaseService.getTemplates().profiles[fullProfile.info.edition];
|
||||
if (!profileTemplates)
|
||||
{
|
||||
return;
|
||||
@ -1363,7 +1364,7 @@ export class ProfileFixerService
|
||||
}
|
||||
|
||||
// Bonus lacks id, find matching hideout area / stage / bonus
|
||||
for (const area of this.databaseServer.getTables().hideout!.areas)
|
||||
for (const area of this.databaseService.getHideout().areas)
|
||||
{
|
||||
// TODO: skip if no stages
|
||||
for (const stageIndex in area.stages)
|
||||
@ -1428,7 +1429,7 @@ export class ProfileFixerService
|
||||
*/
|
||||
protected removeOrphanedQuests(pmcProfile: IPmcData): void
|
||||
{
|
||||
const quests = this.databaseServer.getTables().templates!.quests;
|
||||
const quests = this.databaseService.getQuests();
|
||||
const profileQuests = pmcProfile.Quests;
|
||||
|
||||
const repeatableQuests: IRepeatableQuest[] = [];
|
||||
|
@ -8,9 +8,8 @@ import {
|
||||
NewItemDetails,
|
||||
NewItemFromCloneDetails,
|
||||
} from "@spt/models/spt/mod/NewItemDetails";
|
||||
import { IDatabaseTables } from "@spt/models/spt/server/IDatabaseTables";
|
||||
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
||||
import { DatabaseServer } from "@spt/servers/DatabaseServer";
|
||||
import { DatabaseService } from "@spt/services/DatabaseService";
|
||||
import { ItemBaseClassService } from "@spt/services/ItemBaseClassService";
|
||||
import { ICloner } from "@spt/utils/cloners/ICloner";
|
||||
import { HashUtil } from "@spt/utils/HashUtil";
|
||||
@ -18,18 +17,15 @@ import { HashUtil } from "@spt/utils/HashUtil";
|
||||
@injectable()
|
||||
export class CustomItemService
|
||||
{
|
||||
protected tables: IDatabaseTables;
|
||||
|
||||
constructor(
|
||||
@inject("WinstonLogger") protected logger: ILogger,
|
||||
@inject("HashUtil") protected hashUtil: HashUtil,
|
||||
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
||||
@inject("DatabaseService") protected databaseServer: DatabaseService,
|
||||
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
||||
@inject("ItemBaseClassService") protected itemBaseClassService: ItemBaseClassService,
|
||||
@inject("RecursiveCloner") protected cloner: ICloner,
|
||||
)
|
||||
{
|
||||
this.tables = this.databaseServer.getTables();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,7 +161,7 @@ export class CustomItemService
|
||||
*/
|
||||
protected addToItemsDb(newItemId: string, itemToAdd: ITemplateItem): void
|
||||
{
|
||||
this.tables.templates.items[newItemId] = itemToAdd;
|
||||
this.databaseServer.getItems()[newItemId] = itemToAdd;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,7 +172,7 @@ export class CustomItemService
|
||||
*/
|
||||
protected addToHandbookDb(newItemId: string, parentId: string, priceRoubles: number): void
|
||||
{
|
||||
this.tables.templates.handbook.Items.push({ Id: newItemId, ParentId: parentId, Price: priceRoubles });
|
||||
this.databaseServer.getTemplates().handbook.Items.push({ Id: newItemId, ParentId: parentId, Price: priceRoubles });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,7 +188,7 @@ export class CustomItemService
|
||||
*/
|
||||
protected addToLocaleDbs(localeDetails: Record<string, LocaleDetails>, newItemId: string): void
|
||||
{
|
||||
const languages = this.tables.locales.languages;
|
||||
const languages = this.databaseServer.getLocales().languages;
|
||||
for (const shortNameKey in languages)
|
||||
{
|
||||
// Get locale details passed in, if not provided by caller use first record in newItemDetails.locales
|
||||
@ -203,9 +199,10 @@ export class CustomItemService
|
||||
}
|
||||
|
||||
// Create new record in locale file
|
||||
this.tables.locales.global[shortNameKey][`${newItemId} Name`] = newLocaleDetails.name;
|
||||
this.tables.locales.global[shortNameKey][`${newItemId} ShortName`] = newLocaleDetails.shortName;
|
||||
this.tables.locales.global[shortNameKey][`${newItemId} Description`] = newLocaleDetails.description;
|
||||
const globals = this.databaseServer.getLocales();
|
||||
globals.global[shortNameKey][`${newItemId} Name`] = newLocaleDetails.name;
|
||||
globals.global[shortNameKey][`${newItemId} ShortName`] = newLocaleDetails.shortName;
|
||||
globals.global[shortNameKey][`${newItemId} Description`] = newLocaleDetails.description;
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,7 +213,7 @@ export class CustomItemService
|
||||
*/
|
||||
protected addToFleaPriceDb(newItemId: string, fleaPriceRoubles: number): void
|
||||
{
|
||||
this.tables.templates.prices[newItemId] = fleaPriceRoubles;
|
||||
this.databaseServer.getTemplates().prices[newItemId] = fleaPriceRoubles;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -225,8 +222,6 @@ export class CustomItemService
|
||||
*/
|
||||
protected addToWeaponShelf(newItemId: string): void
|
||||
{
|
||||
this.databaseServer.getTables().templates.items;
|
||||
|
||||
// Ids for wall stashes in db
|
||||
const wallStashIds = ["6401c7b213d9b818bf0e7dd7", "64381b582bb1c5dedd0fc925", "64381b6e44b37a080d0245b9"];
|
||||
for (const wallId of wallStashIds)
|
||||
@ -259,22 +254,21 @@ export class CustomItemService
|
||||
const baseWeaponModObject = {};
|
||||
|
||||
// Get all slots weapon has and create a dictionary of them with possible mods that slot into each
|
||||
const weaponSltos = weapon[1]._props.Slots;
|
||||
for (const slot of weaponSltos)
|
||||
const weaponSlots = weapon[1]._props.Slots;
|
||||
for (const slot of weaponSlots)
|
||||
{
|
||||
baseWeaponModObject[slot._name] = slot._props.filters[0].Filter;
|
||||
}
|
||||
|
||||
// Get PMCs
|
||||
const usec = this.databaseServer.getTables().bots!.types.usec;
|
||||
const bear = this.databaseServer.getTables().bots!.types.bear;
|
||||
const botTypes = this.databaseServer.getBots().types;
|
||||
|
||||
// Add weapon base+mods into bear/usec data
|
||||
usec.inventory.mods[weaponTpl] = baseWeaponModObject;
|
||||
bear.inventory.mods[weaponTpl] = baseWeaponModObject;
|
||||
botTypes.usec.inventory.mods[weaponTpl] = baseWeaponModObject;
|
||||
botTypes.bear.inventory.mods[weaponTpl] = baseWeaponModObject;
|
||||
|
||||
// Add weapon to array of allowed weapons + weighting to be picked
|
||||
usec.inventory.equipment[weaponSlot][weaponTpl] = weaponWeight;
|
||||
bear.inventory.equipment[weaponSlot][weaponTpl] = weaponWeight;
|
||||
botTypes.usec.inventory.equipment[weaponSlot][weaponTpl] = weaponWeight;
|
||||
botTypes.bear.inventory.equipment[weaponSlot][weaponTpl] = weaponWeight;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user