Browse Source

Refactor some commands

feature_improvement
Anton Tarasenko 2 years ago
parent
commit
14e359e510
  1. 10
      sources/Commands/ACommandDosh.uc
  2. 4
      sources/Commands/ACommandDosh_Announcer.uc
  3. 14
      sources/Commands/ACommandNick.uc

10
sources/Commands/ACommandDosh.uc

@ -53,22 +53,22 @@ protected function BuildData(CommandDataBuilder builder)
protected function ExecutedFor(
EPlayer target,
CallData result,
CallData arguments,
EPlayer instigator)
{
local int oldAmount, newAmount;
local int amount, minValue, maxValue;
// Find min and max value boundaries
minValue = result.options.GetIntBy(P("/min/minValue"), 0);
maxValue = result.options.GetIntBy(P("/max/maxValue"), MaxInt);
minValue = arguments.options.GetIntBy(P("/min/minValue"), 0);
maxValue = arguments.options.GetIntBy(P("/max/maxValue"), MaxInt);
if (minValue > maxValue) {
maxValue = minValue;
}
// Change dosh
oldAmount = target.GetDosh();
amount = result.parameters.GetInt(P("amount"));
if (result.subCommandName.IsEmpty()) {
amount = arguments.parameters.GetInt(P("amount"));
if (arguments.subCommandName.IsEmpty()) {
newAmount = oldAmount + amount;
}
else {

4
sources/Commands/ACommandDosh_Announcer.uc

@ -65,13 +65,13 @@ public final function AnnounceLostDosh(int doshAmount)
{
lostDosh.initialized = true;
lostDosh.toSelfReport = _.text.MakeTemplate_S(
"You {$TextPositive successfully took} {$TypeNumber %1} do$h from"
"You {$TextNegative took} {$TypeNumber %1} do$h from"
@ "yourself!");
lostDosh.toSelfPublic = _.text.MakeTemplate_S(
"%%instigator%% {$TextNegative took} {$TypeNumber %1} do$h from"
@ "themselves!");
lostDosh.toOtherReport = _.text.MakeTemplate_S(
"You {$TextPositive successfully took} {$TypeNumber %1} do$h from"
"You {$TextNegative took} {$TypeNumber %1} do$h from"
@ "%%target%%!");
lostDosh.toOtherPrivate = _.text.MakeTemplate_S(
"%%instigator%% {$TextNegative took} {$TypeNumber %1} do$h from"

14
sources/Commands/ACommandNick.uc

@ -54,19 +54,19 @@ protected function BuildData(CommandDataBuilder builder)
}
protected function Executed(
CallData result,
CallData arguments,
EPlayer callerPlayer)
{
local Text givenName;
local array<FormattingErrorsReport.FormattedStringError> errors;
givenName = result.parameters.GetText(P("nick"));
givenName = arguments.parameters.GetText(P("nick"));
// `newName`'s reference persists between different command calls and
// only deallocated when we need this variable for the next execution.
// "Leaking" a single `Text` like that is insignificant.
_.memory.Free(newName);
newName = _.text.Empty();
if (result.options.HasKey(P("plain"))) {
if (arguments.options.HasKey(P("plain"))) {
newName = givenName.MutableCopy();
}
else
@ -75,10 +75,10 @@ protected function Executed(
.ParseFormatted(givenName, newName, true);
}
foundErrors = false;
if (result.options.HasKey(P("color")))
if (arguments.options.HasKey(P("color")))
{
foundErrors = !TryChangeDefaultColor(
result.options.GetTextBy(P("/color/default_color")));
arguments.options.GetTextBy(P("/color/default_color")));
}
foundErrors = foundErrors || (errors.length > 0);
class'FormattingReportTool'.static.Report(callerConsole, errors);
@ -87,12 +87,12 @@ protected function Executed(
protected function ExecutedFor(
EPlayer target,
CallData result,
CallData arguments,
EPlayer instigator)
{
local Text alteredVersion;
if (!foundErrors || result.options.HasKey(P("fix")))
if (!foundErrors || arguments.options.HasKey(P("fix")))
{
announcer.Setup(target, instigator, othersConsole);
target.SetName(newName);

Loading…
Cancel
Save