Fix give command for multiple profiles and added blacklist filter (!313)
Co-authored-by: clodan <clodan@clodan.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/313 Co-authored-by: Alex <clodan@noreply.dev.sp-tarkov.com> Co-committed-by: Alex <clodan@noreply.dev.sp-tarkov.com>
This commit is contained in:
parent
a1070f941c
commit
55d913d0f6
@ -8,6 +8,7 @@ import { IUserDialogInfo } from "@spt-aki/models/eft/profile/IAkiProfile";
|
|||||||
import { BaseClasses } from "@spt-aki/models/enums/BaseClasses";
|
import { BaseClasses } from "@spt-aki/models/enums/BaseClasses";
|
||||||
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||||
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
||||||
|
import { ItemFilterService } from "@spt-aki/services/ItemFilterService";
|
||||||
import { LocaleService } from "@spt-aki/services/LocaleService";
|
import { LocaleService } from "@spt-aki/services/LocaleService";
|
||||||
import { MailSendService } from "@spt-aki/services/MailSendService";
|
import { MailSendService } from "@spt-aki/services/MailSendService";
|
||||||
import { HashUtil } from "@spt-aki/utils/HashUtil";
|
import { HashUtil } from "@spt-aki/utils/HashUtil";
|
||||||
@ -29,7 +30,7 @@ export class GiveSptCommand implements ISptCommand
|
|||||||
private static commandRegex = /^spt give (((([a-z]{2,5}) )?"(.+)"|\w+) )?([0-9]+)$/;
|
private static commandRegex = /^spt give (((([a-z]{2,5}) )?"(.+)"|\w+) )?([0-9]+)$/;
|
||||||
private static maxAllowedDistance = 1.5;
|
private static maxAllowedDistance = 1.5;
|
||||||
|
|
||||||
protected savedCommand: SavedCommand;
|
protected savedCommand: Map<string, SavedCommand> = new Map<string, SavedCommand>();
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
@inject("WinstonLogger") protected logger: ILogger,
|
@inject("WinstonLogger") protected logger: ILogger,
|
||||||
@ -40,6 +41,7 @@ export class GiveSptCommand implements ISptCommand
|
|||||||
@inject("MailSendService") protected mailSendService: MailSendService,
|
@inject("MailSendService") protected mailSendService: MailSendService,
|
||||||
@inject("LocaleService") protected localeService: LocaleService,
|
@inject("LocaleService") protected localeService: LocaleService,
|
||||||
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
||||||
|
@inject("ItemFilterService") protected itemFilterService: ItemFilterService,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -76,7 +78,7 @@ export class GiveSptCommand implements ISptCommand
|
|||||||
// This is a reply to a give request previously made pending a reply
|
// This is a reply to a give request previously made pending a reply
|
||||||
if (result[1] === undefined)
|
if (result[1] === undefined)
|
||||||
{
|
{
|
||||||
if (this.savedCommand === undefined)
|
if (!this.savedCommand.has(sessionId))
|
||||||
{
|
{
|
||||||
this.mailSendService.sendUserMessageToPlayer(
|
this.mailSendService.sendUserMessageToPlayer(
|
||||||
sessionId,
|
sessionId,
|
||||||
@ -85,7 +87,8 @@ export class GiveSptCommand implements ISptCommand
|
|||||||
);
|
);
|
||||||
return request.dialogId;
|
return request.dialogId;
|
||||||
}
|
}
|
||||||
if (+result[6] > this.savedCommand.potentialItemNames.length)
|
const savedCommand = this.savedCommand.get(sessionId);
|
||||||
|
if (+result[6] > savedCommand.potentialItemNames.length)
|
||||||
{
|
{
|
||||||
this.mailSendService.sendUserMessageToPlayer(
|
this.mailSendService.sendUserMessageToPlayer(
|
||||||
sessionId,
|
sessionId,
|
||||||
@ -94,16 +97,19 @@ export class GiveSptCommand implements ISptCommand
|
|||||||
);
|
);
|
||||||
return request.dialogId;
|
return request.dialogId;
|
||||||
}
|
}
|
||||||
item = this.savedCommand.potentialItemNames[+result[6] - 1];
|
item = savedCommand.potentialItemNames[+result[6] - 1];
|
||||||
quantity = this.savedCommand.quantity;
|
quantity = savedCommand.quantity;
|
||||||
locale = this.savedCommand.locale;
|
locale = savedCommand.locale;
|
||||||
isItemName = true;
|
isItemName = true;
|
||||||
this.savedCommand = undefined;
|
this.savedCommand.delete(sessionId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// A new give request was entered, we need to ignore the old saved command
|
// A new give request was entered, we need to ignore the old saved command
|
||||||
this.savedCommand = undefined;
|
if (this.savedCommand.has(sessionId))
|
||||||
|
{
|
||||||
|
this.savedCommand.delete(sessionId);
|
||||||
|
}
|
||||||
isItemName = result[5] !== undefined;
|
isItemName = result[5] !== undefined;
|
||||||
item = result[5] ? result[5] : result[2];
|
item = result[5] ? result[5] : result[2];
|
||||||
quantity = +result[6];
|
quantity = +result[6];
|
||||||
@ -134,9 +140,9 @@ export class GiveSptCommand implements ISptCommand
|
|||||||
|
|
||||||
const closestItemsMatchedByName = closestMatch(
|
const closestItemsMatchedByName = closestMatch(
|
||||||
item.toLowerCase(),
|
item.toLowerCase(),
|
||||||
this.itemHelper.getItems().filter((i) => i._type !== "Node").map((i) =>
|
this.itemHelper.getItems().filter((i) => i._type !== "Node").filter((i) =>
|
||||||
localizedGlobal[`${i?._id} Name`]?.toLowerCase()
|
!this.itemFilterService.isItemBlacklisted(i._id)
|
||||||
).filter((i) => i !== undefined),
|
).map((i) => localizedGlobal[`${i?._id} Name`]?.toLowerCase()).filter((i) => i !== undefined),
|
||||||
true,
|
true,
|
||||||
) as string[];
|
) as string[];
|
||||||
|
|
||||||
@ -156,7 +162,7 @@ export class GiveSptCommand implements ISptCommand
|
|||||||
const slicedItems = closestItemsMatchedByName.slice(0, 10);
|
const slicedItems = closestItemsMatchedByName.slice(0, 10);
|
||||||
// max 10 item names and map them
|
// max 10 item names and map them
|
||||||
const itemList = slicedItems.map((itemName) => `${i++}. ${itemName}`).join("\n");
|
const itemList = slicedItems.map((itemName) => `${i++}. ${itemName}`).join("\n");
|
||||||
this.savedCommand = new SavedCommand(quantity, slicedItems, locale);
|
this.savedCommand.set(sessionId, new SavedCommand(quantity, slicedItems, locale));
|
||||||
this.mailSendService.sendUserMessageToPlayer(
|
this.mailSendService.sendUserMessageToPlayer(
|
||||||
sessionId,
|
sessionId,
|
||||||
commandHandler,
|
commandHandler,
|
||||||
@ -185,7 +191,7 @@ export class GiveSptCommand implements ISptCommand
|
|||||||
// If item is an item name, we need to search using that item name and the locale which one we want otherwise
|
// If item is an item name, we need to search using that item name and the locale which one we want otherwise
|
||||||
// item is just the tplId.
|
// item is just the tplId.
|
||||||
const tplId = isItemName
|
const tplId = isItemName
|
||||||
? this.itemHelper.getItems().find((i) =>
|
? this.itemHelper.getItems().filter((i) => !this.itemFilterService.isItemBlacklisted(i._id)).find((i) =>
|
||||||
this.databaseServer.getTables().locales.global[locale][`${i?._id} Name`]?.toLowerCase() === item
|
this.databaseServer.getTables().locales.global[locale][`${i?._id} Name`]?.toLowerCase() === item
|
||||||
)._id
|
)._id
|
||||||
: item;
|
: item;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user