implemented TraderSptCommand

This commit is contained in:
Chomp
2025-02-03 11:44:01 +00:00
parent 67e8ddef30
commit 6eee6eb203
2 changed files with 93 additions and 18 deletions
@@ -133,9 +133,10 @@ public class ProfileSptCommand(
SlotId = "main",
},
],
null,
999999,
[profileChangeEvent]
);
return request.DialogId;
}
@@ -1,18 +1,25 @@
using SptCommon.Annotations;
using System.Text.RegularExpressions;
using Core.Models.Eft.Common.Tables;
using Core.Models.Eft.Dialog;
using Core.Models.Eft.Profile;
using Core.Services;
using System.Text.RegularExpressions;
using Core.Models.Enums;
using Core.Models.Spt.Dialog;
using Core.Models.Utils;
using Core.Services;
using Core.Utils;
using SptCommon.Annotations;
namespace Core.Helpers.Dialog.Commando.SptCommands.TraderCommand;
[Injectable]
public class TraderSptCommand(
ISptLogger<TraderSptCommand> _logger,
HashUtil _hashUtil,
TraderHelper _traderHelper,
MailSendService _mailSendService) : ISptCommand
{
protected Regex _commandRegex = new(@"^spt trader (?<trader>[\w]+) (?<command>rep|spend) (?<quantity>(?!0+)[0-9]+)$"
protected Regex _commandRegex = new(
@"^spt trader (?<trader>[\w]+) (?<command>rep|spend) (?<quantity>(?!0+)[0-9]+)$"
);
public string GetCommand()
@@ -22,23 +29,90 @@ public class TraderSptCommand(
public string GetCommandHelp()
{
return "spt trader\n========\nSets the reputation or money spent to the input quantity through the message system.\n\n\tspt trader [trader] rep [quantity]\n\t\tEx: spt trader prapor rep 2\n\n\tspt trader [trader] spend [quantity]\n\t\tEx: spt trader therapist spend 1000000";
return
"spt trader\n========\nSets the reputation or money spent to the input quantity through the message system.\n\n\tspt trader [trader] rep [quantity]\n\t\tEx: spt trader prapor rep 2\n\n\tspt trader [trader] spend [quantity]\n\t\tEx: spt trader therapist spend 1000000";
}
public string PerformAction(UserDialogInfo commandHandler, string sessionId, SendMessageRequest request)
{
if (!_commandRegex.IsMatch(request.Text))
{
_mailSendService.SendUserMessageToPlayer(
sessionId,
commandHandler,
"Invalid use of trader command. Use 'help' for more information.");
return request.DialogId;
}
if (!_commandRegex.IsMatch(request.Text))
{
_mailSendService.SendUserMessageToPlayer(
sessionId,
commandHandler,
"Invalid use of trader command. Use 'help' for more information."
);
return request.DialogId;
}
// TODO: implement remaining, copy from give command
_logger.Error("NOT IMPLEMENTED: TraderSptCommand");
return request.DialogId;
var result = _commandRegex.Match(request.Text);
var trader = result.Groups["trader"].Captures[0].Value;
var command = result.Groups["command"].Captures[0].Value;
var quantity = int.Parse(result.Groups["quantity"].Captures[0].Value);
var dbTrader = _traderHelper.GetTrader(trader, sessionId);
if (dbTrader == null)
{
_mailSendService.SendUserMessageToPlayer(
sessionId,
commandHandler,
"Invalid use of trader command, the trader was not found. Use 'help' for more information."
);
return request.DialogId;
}
ProfileChangeEventType profileChangeEventType;
switch (command)
{
case "rep":
quantity /= 100;
profileChangeEventType = ProfileChangeEventType.TraderStanding;
break;
case "spend":
profileChangeEventType = ProfileChangeEventType.TraderSalesSum;
break;
default:
{
_mailSendService.SendUserMessageToPlayer(
sessionId,
commandHandler,
"Invalid use of trader command, ProfileChangeEventType was not found. Use 'help' for more information."
);
return request.DialogId;
}
}
_mailSendService.SendSystemMessageToPlayer(
sessionId,
"A single ruble is being attached, required by BSG logic.",
[
new Item
{
Id = _hashUtil.Generate(),
Template = Money.ROUBLES,
Upd = new Upd { StackObjectsCount = 1 },
ParentId = _hashUtil.Generate(),
SlotId = "main"
}
],
999999,
[CreateProfileChangeEvent(profileChangeEventType, quantity, dbTrader.Id)]
);
return request.DialogId;
}
protected ProfileChangeEvent CreateProfileChangeEvent(ProfileChangeEventType profileChangeEventType, int quantity, string dbTraderId)
{
return new ProfileChangeEvent
{
Id = _hashUtil.Generate(),
Type = profileChangeEventType,
Value = quantity,
Entity = dbTraderId
};
}
}