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

4
sources/Commands/ACommandDosh_Announcer.uc

@ -65,13 +65,13 @@ public final function AnnounceLostDosh(int doshAmount)
{ {
lostDosh.initialized = true; lostDosh.initialized = true;
lostDosh.toSelfReport = _.text.MakeTemplate_S( lostDosh.toSelfReport = _.text.MakeTemplate_S(
"You {$TextPositive successfully took} {$TypeNumber %1} do$h from" "You {$TextNegative took} {$TypeNumber %1} do$h from"
@ "yourself!"); @ "yourself!");
lostDosh.toSelfPublic = _.text.MakeTemplate_S( lostDosh.toSelfPublic = _.text.MakeTemplate_S(
"%%instigator%% {$TextNegative took} {$TypeNumber %1} do$h from" "%%instigator%% {$TextNegative took} {$TypeNumber %1} do$h from"
@ "themselves!"); @ "themselves!");
lostDosh.toOtherReport = _.text.MakeTemplate_S( lostDosh.toOtherReport = _.text.MakeTemplate_S(
"You {$TextPositive successfully took} {$TypeNumber %1} do$h from" "You {$TextNegative took} {$TypeNumber %1} do$h from"
@ "%%target%%!"); @ "%%target%%!");
lostDosh.toOtherPrivate = _.text.MakeTemplate_S( lostDosh.toOtherPrivate = _.text.MakeTemplate_S(
"%%instigator%% {$TextNegative took} {$TypeNumber %1} do$h from" "%%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( protected function Executed(
CallData result, CallData arguments,
EPlayer callerPlayer) EPlayer callerPlayer)
{ {
local Text givenName; local Text givenName;
local array<FormattingErrorsReport.FormattedStringError> errors; 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 // `newName`'s reference persists between different command calls and
// only deallocated when we need this variable for the next execution. // only deallocated when we need this variable for the next execution.
// "Leaking" a single `Text` like that is insignificant. // "Leaking" a single `Text` like that is insignificant.
_.memory.Free(newName); _.memory.Free(newName);
newName = _.text.Empty(); newName = _.text.Empty();
if (result.options.HasKey(P("plain"))) { if (arguments.options.HasKey(P("plain"))) {
newName = givenName.MutableCopy(); newName = givenName.MutableCopy();
} }
else else
@ -75,10 +75,10 @@ protected function Executed(
.ParseFormatted(givenName, newName, true); .ParseFormatted(givenName, newName, true);
} }
foundErrors = false; foundErrors = false;
if (result.options.HasKey(P("color"))) if (arguments.options.HasKey(P("color")))
{ {
foundErrors = !TryChangeDefaultColor( foundErrors = !TryChangeDefaultColor(
result.options.GetTextBy(P("/color/default_color"))); arguments.options.GetTextBy(P("/color/default_color")));
} }
foundErrors = foundErrors || (errors.length > 0); foundErrors = foundErrors || (errors.length > 0);
class'FormattingReportTool'.static.Report(callerConsole, errors); class'FormattingReportTool'.static.Report(callerConsole, errors);
@ -87,12 +87,12 @@ protected function Executed(
protected function ExecutedFor( protected function ExecutedFor(
EPlayer target, EPlayer target,
CallData result, CallData arguments,
EPlayer instigator) EPlayer instigator)
{ {
local Text alteredVersion; local Text alteredVersion;
if (!foundErrors || result.options.HasKey(P("fix"))) if (!foundErrors || arguments.options.HasKey(P("fix")))
{ {
announcer.Setup(target, instigator, othersConsole); announcer.Setup(target, instigator, othersConsole);
target.SetName(newName); target.SetName(newName);

Loading…
Cancel
Save