2023-11-05 21:11:52 +01:00
|
|
|
import "reflect-metadata";
|
2023-11-10 23:21:20 +01:00
|
|
|
import { container } from "tsyringe";
|
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
2023-11-05 21:11:52 +01:00
|
|
|
|
2023-11-13 17:43:37 +01:00
|
|
|
import { BotGenerator } from "@spt-aki/generators/BotGenerator";
|
|
|
|
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
|
|
|
|
|
2023-11-05 21:11:52 +01:00
|
|
|
describe("BotGenerator", () =>
|
|
|
|
{
|
|
|
|
let botGenerator: any;
|
|
|
|
|
2023-11-06 20:39:12 +01:00
|
|
|
beforeEach(() =>
|
2023-11-05 21:11:52 +01:00
|
|
|
{
|
|
|
|
botGenerator = container.resolve<BotGenerator>("BotGenerator");
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() =>
|
|
|
|
{
|
|
|
|
vi.restoreAllMocks();
|
|
|
|
});
|
|
|
|
|
2023-11-06 18:23:33 +01:00
|
|
|
// describe("prepareAndGenerateBots", () =>
|
|
|
|
// {
|
|
|
|
// it("should return a single generated assault bot", () =>
|
|
|
|
// {
|
|
|
|
// const mockPlayerProfile = {
|
|
|
|
// Info: {
|
|
|
|
// Nickname: "Player Nickname",
|
|
|
|
// Level: 1
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
|
|
|
|
// vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
// vi.spyOn(botGenerator.botEquipmentFilterService.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
// vi.spyOn(botGenerator.botInventoryGenerator.botWeaponGenerator.botEquipmentModGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
|
|
|
|
// const sessionId = "12345";
|
|
|
|
// const generationDetails: BotGenerationDetails = {
|
|
|
|
// isPmc: false,
|
|
|
|
// role: "assault",
|
|
|
|
// side: "Savage",
|
|
|
|
// playerLevel: 1,
|
|
|
|
// botRelativeLevelDeltaMax: 10,
|
|
|
|
// botCountToGenerate: 1,
|
|
|
|
// botDifficulty: "easy",
|
|
|
|
// isPlayerScav: false
|
|
|
|
// };
|
|
|
|
|
|
|
|
// const result = botGenerator.prepareAndGenerateBots(sessionId, generationDetails);
|
|
|
|
|
|
|
|
// expect(result.length).toBe(1);
|
|
|
|
// expect(result[0].Info.Side).toBe("Savage");
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
describe("generateBotNickname", () =>
|
2023-11-05 21:11:52 +01:00
|
|
|
{
|
2024-04-12 03:12:43 +02:00
|
|
|
it("should choose random firstname for non player scav assault bot", () =>
|
2023-11-06 18:23:33 +01:00
|
|
|
{
|
2024-04-12 03:12:43 +02:00
|
|
|
const botJsonTemplate = { firstName: ["one", "two"], lastName: [] };
|
|
|
|
const botGenerationDetails = { isPlayerScav: false, isPmc: true, allPmcsHaveSameNameAsPlayer: false };
|
|
|
|
const botRole = "assault";
|
|
|
|
|
2023-11-06 18:23:33 +01:00
|
|
|
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 0;
|
|
|
|
|
2023-11-13 18:38:16 +01:00
|
|
|
const mockPlayerProfile = { Info: { Nickname: "Player Nickname", Level: 1 } };
|
2023-11-06 18:23:33 +01:00
|
|
|
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
const result = botGenerator.generateBotNickname(botJsonTemplate, botGenerationDetails, botRole);
|
|
|
|
|
|
|
|
expect(result).toMatch(/(one|two)/);
|
|
|
|
});
|
2023-11-06 18:23:33 +01:00
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
it("should choose random lastname for non player scav assault bot", () =>
|
|
|
|
{
|
|
|
|
const botJsonTemplate = { firstName: [], lastName: [["one", "two"]] };
|
|
|
|
const botGenerationDetails = { isPlayerScav: false, isPmc: true, allPmcsHaveSameNameAsPlayer: false };
|
2023-11-06 18:23:33 +01:00
|
|
|
const botRole = "assault";
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 0;
|
|
|
|
|
|
|
|
const mockPlayerProfile = { Info: { Nickname: "Player Nickname", Level: 1 } };
|
|
|
|
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
|
|
|
|
const result = botGenerator.generateBotNickname(botJsonTemplate, botGenerationDetails, botRole);
|
|
|
|
|
|
|
|
expect(result).toMatch(/(one|two)/);
|
2023-11-06 18:23:33 +01:00
|
|
|
});
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
it("should choose random firstname and lastname for non player scav assault bot", () =>
|
2023-11-05 21:11:52 +01:00
|
|
|
{
|
2024-04-12 03:12:43 +02:00
|
|
|
const botJsonTemplate = { firstName: ["first-one", "first-two"], lastName: [["last-one", "last-two"]] };
|
|
|
|
const botGenerationDetails = { isPlayerScav: false, isPmc: true, allPmcsHaveSameNameAsPlayer: false };
|
|
|
|
const botRole = "assault";
|
|
|
|
|
|
|
|
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 0;
|
2023-11-06 18:23:33 +01:00
|
|
|
|
2023-11-13 18:38:16 +01:00
|
|
|
const mockPlayerProfile = { Info: { Nickname: "Player Nickname", Level: 1 } };
|
2023-11-06 18:23:33 +01:00
|
|
|
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
const result = botGenerator.generateBotNickname(botJsonTemplate, botGenerationDetails, botRole);
|
2023-11-06 18:23:33 +01:00
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
expect(result).toMatch(/first-(one|two) last-(one|two)/);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should choose random firstname for player scav assault bot", () =>
|
|
|
|
{
|
|
|
|
const botJsonTemplate = { firstName: ["one", "two"], lastName: [] };
|
|
|
|
const botGenerationDetails = { isPlayerScav: true, isPmc: false, allPmcsHaveSameNameAsPlayer: false };
|
2023-11-06 18:23:33 +01:00
|
|
|
const botRole = "assault";
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 0;
|
|
|
|
|
|
|
|
const mockPlayerProfile = { Info: { Nickname: "Player Nickname", Level: 1 } };
|
|
|
|
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
|
|
|
|
const result = botGenerator.generateBotNickname(botJsonTemplate, botGenerationDetails, botRole);
|
|
|
|
|
|
|
|
expect(result).toMatch(/(one|two)/);
|
2023-11-06 18:23:33 +01:00
|
|
|
});
|
2023-11-05 21:11:52 +01:00
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
it("should choose random lastname for player scav assault bot", () =>
|
2023-11-06 18:23:33 +01:00
|
|
|
{
|
2024-04-12 03:12:43 +02:00
|
|
|
const botJsonTemplate = { firstName: [], lastName: [["one", "two"]] };
|
|
|
|
const botGenerationDetails = { isPlayerScav: true, isPmc: false, allPmcsHaveSameNameAsPlayer: false };
|
|
|
|
const botRole = "assault";
|
2023-11-06 18:23:33 +01:00
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 0;
|
|
|
|
|
|
|
|
const mockPlayerProfile = { Info: { Nickname: "Player Nickname", Level: 1 } };
|
2023-11-06 18:23:33 +01:00
|
|
|
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
const result = botGenerator.generateBotNickname(botJsonTemplate, botGenerationDetails, botRole);
|
2023-11-06 18:23:33 +01:00
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
expect(result).toMatch(/(one|two)/);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should choose random firstname and lastname for player scav assault bot", () =>
|
|
|
|
{
|
|
|
|
const botJsonTemplate = { firstName: ["first-one", "first-two"], lastName: [["last-one", "last-two"]] };
|
|
|
|
const botGenerationDetails = { isPlayerScav: true, isPmc: false, allPmcsHaveSameNameAsPlayer: false };
|
2023-11-06 18:23:33 +01:00
|
|
|
const botRole = "assault";
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 0;
|
|
|
|
|
|
|
|
const mockPlayerProfile = { Info: { Nickname: "Player Nickname", Level: 1 } };
|
|
|
|
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
|
|
|
|
const result = botGenerator.generateBotNickname(botJsonTemplate, botGenerationDetails, botRole);
|
|
|
|
|
|
|
|
expect(result).toMatch(/first-(one|two) last-(one|two)/);
|
2023-11-06 18:23:33 +01:00
|
|
|
});
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
it("should append bot type to end of name when showTypeInNickname option is enabled ", () =>
|
2023-11-06 18:23:33 +01:00
|
|
|
{
|
2024-04-12 03:12:43 +02:00
|
|
|
const botJsonTemplate = { firstName: ["firstname"], lastName: ["lastname"] };
|
|
|
|
const botGenerationDetails = { isPlayerScav: false, isPmc: true, allPmcsHaveSameNameAsPlayer: false };
|
|
|
|
const botRole = "assault";
|
2023-11-06 18:23:33 +01:00
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 0;
|
|
|
|
botGenerator.botConfig.showTypeInNickname = true;
|
|
|
|
|
|
|
|
const mockPlayerProfile = { Info: { Nickname: "Player Nickname", Level: 1 } };
|
2023-11-06 18:23:33 +01:00
|
|
|
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
const result = botGenerator.generateBotNickname(botJsonTemplate, botGenerationDetails, botRole);
|
2023-11-06 18:23:33 +01:00
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
expect(result).toBe("firstname lastname assault");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return name prefix for PMC bot with same name as player if allPmcsHaveSameNameAsPlayer is enabled", () =>
|
|
|
|
{
|
|
|
|
const botJsonTemplate = { firstName: ["player"], lastName: [] };
|
|
|
|
const botGenerationDetails = { isPlayerScav: false, isPmc: true, allPmcsHaveSameNameAsPlayer: true };
|
2023-11-06 18:23:33 +01:00
|
|
|
const botRole = "assault";
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
botGenerator.botConfig.showTypeInNickname = false;
|
|
|
|
botGenerator.pmcConfig.addPrefixToSameNamePMCAsPlayerChance = 100;
|
|
|
|
|
|
|
|
const mockPlayerProfile = { Info: { Nickname: "player", Level: 1 } };
|
|
|
|
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
|
|
|
|
const getRandomTextThatMatchesPartialKeySpy = vi.spyOn(
|
|
|
|
(botGenerator as any).localisationService,
|
|
|
|
"getRandomTextThatMatchesPartialKey",
|
|
|
|
).mockReturnValue("test");
|
|
|
|
|
|
|
|
const result = botGenerator.generateBotNickname(botJsonTemplate, botGenerationDetails, botRole);
|
|
|
|
|
|
|
|
expect(getRandomTextThatMatchesPartialKeySpy).toHaveBeenCalled();
|
|
|
|
expect(result).toBe("test player");
|
2023-11-06 18:23:33 +01:00
|
|
|
});
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
it("should generate PMC name in brackets behind scav name when chanceAssaultScavHasPlayerScavName is enabled", () =>
|
2023-11-06 18:23:33 +01:00
|
|
|
{
|
2024-04-12 03:12:43 +02:00
|
|
|
const botJsonTemplate = { firstName: ["scav"], lastName: [] };
|
|
|
|
const botGenerationDetails = { isPlayerScav: false, isPmc: true, allPmcsHaveSameNameAsPlayer: false };
|
|
|
|
const botRole = "assault";
|
|
|
|
|
2023-11-06 18:23:33 +01:00
|
|
|
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 100;
|
2024-04-12 03:12:43 +02:00
|
|
|
botGenerator.databaseServer.getTables().bots.types.usec.firstName = ["player"];
|
2023-11-13 17:51:02 +01:00
|
|
|
botGenerator.databaseServer.getTables().bots.types.bear.firstName = [];
|
2023-11-06 18:23:33 +01:00
|
|
|
|
2023-11-13 18:38:16 +01:00
|
|
|
const mockPlayerProfile = { Info: { Nickname: "Player", Level: 1 } };
|
2023-11-05 21:11:52 +01:00
|
|
|
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
|
|
|
|
|
2024-04-12 03:12:43 +02:00
|
|
|
const result = botGenerator.generateBotNickname(botJsonTemplate, botGenerationDetails, botRole);
|
|
|
|
expect(result).toBe("scav (player)");
|
2023-11-05 21:11:52 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|