-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
286 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
{ | ||
"prefix": "{red}GANGS {darkred}> {grey}", | ||
"command.gang.not_in_gang": "%prefix%You are not in a gang. Type {gold}/gang create [name]{grey} to create one.", | ||
"generic.player.not_found": "%prefix%Could not find a player using {darkred}{0}{grey}.", | ||
"color.default": "{grey}", | ||
"color.emph": "{white}", | ||
"color.number": "{yellow}", | ||
"color.special": "{lightblue}", | ||
"color.command": "{blue}", | ||
"color.currency": "{gold}", | ||
"color.target": "{green}", | ||
"prefix": "{red}GANGS {darkred}>%color.default% ", | ||
"command.gang.not_in_gang": "%prefix%You are not in a gang. Type %color.blue%/gang create [name]%color.default% to create one.", | ||
"command.balance": "%prefix%You have %color.currency%{0} %currency.player%{grey}.", | ||
"command.balance.plural": "%prefix%You have %color.currency%{0} %currency.player.plural%{grey}.", | ||
"command.balance.none": "%prefix%You have no %currency.player.plural%.", | ||
"command.balance.other": "%prefix%%color.target%{0}%color.default% has %color.currency%{1} %currency.player%%color.default%.", | ||
"command.balance.other.plural": "%prefix%%color.target%{0}%color.default% has %color.currency%{1} %currency.player.plural%%color.default%.", | ||
"command.balance.other.none": "%prefix%%color.target%{0}%color.default% has no %currency.player.plural%.", | ||
"command.balance.set": "%prefix%Set %color.target%{0}%color.default%'s %color.currency%%currency.player.plural% to %color.currency%{1} %color.default%.", | ||
"command.usage": "%prefix%Usage: %color.command%{0}", | ||
"command.invalid_parameter": "%prefix%Invalid parameter %color.emph%\"{0}\"%color.default%, expected %color.special%{1}%color.default%.", | ||
"generic.player.not_found": "%prefix%Could not find a player using {darkred}\"{0}\"{grey}.", | ||
"generic.player.found_multiple": "%prefix%Found multiple players using {darkred}\"{0}\"{grey}.", | ||
"generic.soontm": "%prefix%{grey}SoonTM!", | ||
"generic.player.only": "%prefix%{red}Only players can use this.", | ||
"generic.no_permission": "%prefix%{red}You do not have permission to use this command.", | ||
"generic.no_permission.node": "%prefix%{red}You are missing the {darkred}{0}{red} permission.", | ||
"generic.no_permission.rank": "%prefix%{red}You must be {darkred}{0}{red} to use this command." | ||
"generic.no_permission.rank": "%prefix%{red}You must be {darkred}{0}{red} to use this command.", | ||
"generic.error": "%prefix%%color.error%An unknown error occured.", | ||
"generic.error.info": "%prefix%%color.error%An error occured: {0}.", | ||
"currency.player": "credit", | ||
"currency.gang": "%currency.player%", | ||
"currency.player.plural": "credits", | ||
"currency.gang.plural": "%currency.player.plural%" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Modules.Commands.Targeting; | ||
using CounterStrikeSharp.API.Modules.Utils; | ||
using GangsAPI; | ||
using GangsAPI.Data; | ||
using GangsAPI.Data.Command; | ||
using GangsAPI.Services.Commands; | ||
using GangsAPI.Services.Player; | ||
using Microsoft.Extensions.Localization; | ||
using Stats; | ||
|
||
namespace Commands; | ||
|
||
public class BalanceCommand(IPlayerStatManager playerMgr, | ||
IStringLocalizer testLocalizer) : ICommand { | ||
public string Name => "css_balance"; | ||
|
||
public string[] Usage => ["", "<player>", "<player> <amount>"]; | ||
public string[] Aliases => ["css_balance", "css_credit", "css_credits"]; | ||
|
||
private string id = new BalanceStat().StatId; | ||
private IStringLocalizer localizer = testLocalizer; | ||
|
||
public void Start(BasePlugin? plugin, bool hotReload) { | ||
if (plugin != null) localizer = plugin.Localizer; | ||
} | ||
|
||
public async Task<CommandResult> Execute(PlayerWrapper? executor, | ||
CommandInfoWrapper info) { | ||
if (executor == null) return CommandResult.PLAYER_ONLY; | ||
|
||
if (info.ArgCount == 1 || !executor.HasFlags("@css/ban")) { | ||
var (success, balance) = | ||
await playerMgr.GetForPlayer<int>(executor.Steam, id); | ||
|
||
if (!success) { | ||
info.ReplySync(localizer.Get(MSG.COMMAND_BALANCE_NONE)); | ||
return CommandResult.SUCCESS; | ||
} | ||
|
||
info.ReplySync(localizer.Get( | ||
balance == 1 ? MSG.COMMAND_BALANCE : MSG.COMMAND_BALANCE_PLURAL, | ||
balance)); | ||
return CommandResult.SUCCESS; | ||
} | ||
|
||
// TODO: Add Unit Test Support | ||
// Would require a mock of some type of Server state | ||
// for Utilities to wrap around. | ||
var target = new Target(info[1]); | ||
var result = target.GetTarget(null).Players; | ||
if (result.Count != 1) { | ||
info.ReplySync(localizer.Get( | ||
result.Count > 1 ? | ||
MSG.GENERIC_PLAYER_FOUND_MULTIPLE : | ||
MSG.GENERIC_PLAYER_NOT_FOUND, info[1])); | ||
return CommandResult.INVALID_ARGS; | ||
} | ||
|
||
var subject = result[0]; | ||
|
||
if (info.ArgCount == 2 || !executor.HasFlags("@css/root")) { | ||
var (success, balance) = | ||
await playerMgr.GetForPlayer<int>(subject.SteamID, id); | ||
|
||
if (!success) { | ||
info.ReplySync(localizer.Get(MSG.COMMAND_BALANCE_NONE)); | ||
return CommandResult.SUCCESS; | ||
} | ||
|
||
info.ReplySync(localizer.Get( | ||
balance == 1 ? | ||
MSG.COMMAND_BALANCE_OTHER : | ||
MSG.COMMAND_BALANCE_OTHER_PLURAL, balance)); | ||
} | ||
|
||
|
||
if (info.ArgCount != 3) return CommandResult.PRINT_USAGE; | ||
|
||
if (!int.TryParse(info[2], out var amount)) { | ||
info.ReplySync(localizer.Get(MSG.COMMAND_INVALID_PARAM, info[2], | ||
"an integer")); | ||
return CommandResult.INVALID_ARGS; | ||
} | ||
|
||
var pass = await playerMgr.SetForPlayer(subject.SteamID, id, amount); | ||
if (!pass) { | ||
info.ReplySync(localizer.Get(MSG.GENERIC_ERROR)); | ||
return CommandResult.ERROR; | ||
} | ||
|
||
info.ReplySync(localizer.Get(MSG.COMMAND_BALANCE_SET, subject.PlayerName, | ||
amount)); | ||
return CommandResult.SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/GangsTest/API/Services/Commands/Command/Concrete/BalanceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Commands; | ||
using GangsAPI; | ||
using GangsAPI.Data.Command; | ||
using GangsAPI.Services.Commands; | ||
using GangsAPI.Services.Player; | ||
using GangsTest.TestLocale; | ||
using Microsoft.Extensions.Localization; | ||
using Stats; | ||
|
||
namespace GangsTest.API.Services.Commands.Command.Concrete; | ||
|
||
public class BalanceTests(ICommandManager commands, IPlayerStatManager statMgr, | ||
IStringLocalizer locale) : TestParent(commands, | ||
new BalanceCommand(statMgr, StringLocalizer.Instance)) { | ||
private static readonly string STAT_ID = new BalanceStat().StatId; | ||
|
||
[Fact] | ||
public async Task None() { | ||
Assert.Equal("css_balance", Command.Name); | ||
Assert.Equal(CommandResult.SUCCESS, | ||
await Commands.ProcessCommand(TestPlayer, Command.Name)); | ||
Assert.Contains(locale.Get(MSG.COMMAND_BALANCE_NONE), | ||
TestPlayer.ConsoleOutput); | ||
} | ||
|
||
[Fact] | ||
public async Task One() { | ||
await statMgr.SetForPlayer(TestPlayer.Steam, STAT_ID, 1); | ||
Assert.Equal(CommandResult.SUCCESS, | ||
await Commands.ProcessCommand(TestPlayer, Command.Name)); | ||
Assert.Contains(locale.Get(MSG.COMMAND_BALANCE, 1), | ||
TestPlayer.ConsoleOutput); | ||
} | ||
|
||
[Theory] | ||
[InlineData(2)] | ||
[InlineData(5)] | ||
[InlineData(10000)] | ||
[InlineData(-1)] | ||
[InlineData(-1000)] | ||
public async Task Multiple(int bal) { | ||
await statMgr.SetForPlayer(TestPlayer.Steam, STAT_ID, bal); | ||
Assert.Equal(CommandResult.SUCCESS, | ||
await Commands.ProcessCommand(TestPlayer, Command.Name)); | ||
Assert.Contains(locale.Get(MSG.COMMAND_BALANCE_PLURAL, bal), | ||
TestPlayer.ConsoleOutput); | ||
} | ||
} |
Oops, something went wrong.