diff --git a/sources/Commands/ACommandDosh.uc b/sources/Commands/ACommandDosh.uc
index 014c201..be4f007 100644
--- a/sources/Commands/ACommandDosh.uc
+++ b/sources/Commands/ACommandDosh.uc
@@ -1,6 +1,6 @@
/**
* Command for changing amount of money players have.
- * Copyright 2021 Anton Tarasenko
+ * Copyright 2021 - 2022 Anton Tarasenko
*------------------------------------------------------------------------------
* This file is part of Acedia.
*
@@ -19,9 +19,13 @@
*/
class ACommandDosh extends Command;
-var protected const int TGOTTEN, TLOST, TYOU_GAVE, TYOU_TAKEN, TOTHER_GAVE;
-var protected const int TOTHER_TAKEN, TDOSH_FROM, TDOSH_TO, TYOURSELF, TDOSH;
-var protected const int TTHEMSELVES;
+var private ACommandDosh_Announcer announcer;
+
+protected function Finalizer()
+{
+ _.memory.Free(announcer);
+ super.Finalizer();
+}
protected function BuildData(CommandDataBuilder builder)
{
@@ -43,15 +47,18 @@ protected function BuildData(CommandDataBuilder builder)
.Describe(F("Players will have at most this amount of dosh after"
@ "the command's execution. In case of conflict, it is overridden"
@ "by '{$TextEmphasis --min}' option."));
+ announcer = ACommandDosh_Announcer(
+ _.memory.Allocate(class'ACommandDosh_Announcer'));
}
protected function ExecutedFor(
- EPlayer player,
+ EPlayer target,
CallData result,
- EPlayer callerPlayer)
+ 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);
@@ -59,7 +66,7 @@ protected function ExecutedFor(
maxValue = minValue;
}
// Change dosh
- oldAmount = player.GetDosh();
+ oldAmount = target.GetDosh();
amount = result.parameters.GetInt(P("amount"));
if (result.subCommandName.IsEmpty()) {
newAmount = oldAmount + amount;
@@ -69,99 +76,17 @@ protected function ExecutedFor(
newAmount = amount;
}
newAmount = Clamp(newAmount, minValue, maxValue);
+ target.SetDosh(newAmount);
// Announce dosh change, if necessary
- if (!result.options.HasKey(P("silent"))) {
- AnnounceDoshChange(player, callerPlayer, oldAmount, newAmount);
- }
- player.SetDosh(newAmount);
-}
-
-protected function AnnounceDoshChange(
- EPlayer player,
- EPlayer callerPlayer,
- int oldAmount,
- int newAmount)
-{
- local bool affectingSelf;
- local Text amountDeltaAsText;
- local Text targetName, yourTargetName, callerName;
- callerName = callerPlayer.GetName();
- affectingSelf = callerPlayer.SameAs(player);
- if (affectingSelf)
- {
- yourTargetName = T(TYOURSELF).Copy();
- targetName = player.GetName();
- }
- else
- {
- yourTargetName = T(TTHEMSELVES).Copy();
- targetName = player.GetName();
- }
- if (newAmount > oldAmount)
- {
- amountDeltaAsText = _.text.FromInt(newAmount - oldAmount);
- if (!affectingSelf)
- {
- targetConsole.Write(T(TGOTTEN))
- .Write(amountDeltaAsText)
- .WriteLine(T(TDOSH));
- }
- callerConsole.Write(T(TYOU_GAVE))
- .Write(amountDeltaAsText)
- .Write(T(TDOSH_TO))
- .WriteLine(yourTargetName);
- othersConsole.Write(callerName)
- .Write(T(TOTHER_GAVE))
- .Write(amountDeltaAsText)
- .Write(T(TDOSH_TO))
- .WriteLine(targetName);
+ announcer.Setup(target, instigator, othersConsole);
+ if (newAmount > oldAmount) {
+ announcer.AnnounceGainedDosh(newAmount - oldAmount);
}
- if (newAmount < oldAmount)
- {
- amountDeltaAsText = _.text.FromInt(oldAmount - newAmount);
- if (!affectingSelf)
- {
- targetConsole.Write(T(TLOST))
- .Write(amountDeltaAsText)
- .WriteLine(T(TDOSH));
- }
- callerConsole.Write(T(TYOU_TAKEN))
- .Write(amountDeltaAsText)
- .Write(T(TDOSH_FROM))
- .WriteLine(yourTargetName);
- othersConsole.Write(callerName)
- .Write(T(TOTHER_TAKEN))
- .Write(amountDeltaAsText)
- .Write(T(TDOSH_FROM))
- .WriteLine(targetName);
+ if (newAmount < oldAmount) {
+ announcer.AnnounceLostDosh(oldAmount - newAmount);
}
- _.memory.Free(amountDeltaAsText);
- _.memory.Free(targetname);
- _.memory.Free(callerName);
}
defaultproperties
{
- TGOTTEN = 0
- stringConstants(0) = "You've {$TextPositive gotten} "
- TLOST = 1
- stringConstants(1) = "You've {$TextNegative lost} "
- TYOU_GAVE = 2
- stringConstants(2) = "You {$TextPositive gave} "
- TYOU_TAKEN = 3
- stringConstants(3) = "You {$TextNegative took} "
- TOTHER_GAVE = 4
- stringConstants(4) = " {$TextPositive gave} "
- TOTHER_TAKEN = 5
- stringConstants(5) = " {$TextNegative taken} "
- TDOSH = 6
- stringConstants(6) = " dosh"
- TDOSH_FROM = 7
- stringConstants(7) = " dosh from "
- TDOSH_TO = 8
- stringConstants(8) = " dosh to "
- TYOURSELF = 9
- stringConstants(9) = "yourself"
- TTHEMSELVES = 10
- stringConstants(10) = "themselves"
}
\ No newline at end of file
diff --git a/sources/Commands/ACommandDosh_Announcer.uc b/sources/Commands/ACommandDosh_Announcer.uc
new file mode 100644
index 0000000..ed5c48f
--- /dev/null
+++ b/sources/Commands/ACommandDosh_Announcer.uc
@@ -0,0 +1,92 @@
+/**
+ * Announcer for `ACommandDosh`.
+ * Copyright 2022 Anton Tarasenko
+ *------------------------------------------------------------------------------
+ * This file is part of Acedia.
+ *
+ * Acedia is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Acedia is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Acedia. If not, see .
+ */
+class ACommandDosh_Announcer extends CommandAnnouncer;
+
+var private AnnouncementVariations gainedDosh, lostDosh;
+
+protected function Finalizer()
+{
+ FreeVariations(gainedDosh);
+ FreeVariations(lostDosh);
+ super.Finalizer();
+}
+
+public final function AnnounceGainedDosh(int doshAmount)
+{
+ local int i;
+ local array templates;
+
+ if (!gainedDosh.initialized)
+ {
+ gainedDosh.initialized = true;
+ gainedDosh.toSelfReport = _.text.MakeTemplate_S(
+ "You {$TextPositive gave} yourself {$TypeNumber %1} do$h!");
+ gainedDosh.toSelfPublic = _.text.MakeTemplate_S(
+ "%%instigator%% {$TextPositive gave} themselves {$TypeNumber %1}"
+ @ "do$h!");
+ gainedDosh.toOtherReport = _.text.MakeTemplate_S(
+ "You {$TextPositive gave} %%target%% {$TypeNumber %1} do$h!");
+ gainedDosh.toOtherPrivate = _.text.MakeTemplate_S(
+ "%%instigator%% {$TextPositive gave} you {$TypeNumber %1} do$h!");
+ gainedDosh.toOtherPublic = _.text.MakeTemplate_S(
+ "%%instigator%% {$TextPositive gave} %%target%% {$TypeNumber %1}"
+ @ "do$h!");
+ }
+ templates = MakeArray(gainedDosh);
+ for (i = 0; i < templates.length; i += 1) {
+ templates[i].Reset().ArgInt(doshAmount);
+ }
+ MakeAnnouncement(gainedDosh);
+}
+
+public final function AnnounceLostDosh(int doshAmount)
+{
+ local int i;
+ local array templates;
+
+ if (!lostDosh.initialized)
+ {
+ lostDosh.initialized = true;
+ lostDosh.toSelfReport = _.text.MakeTemplate_S(
+ "You {$TextPositive successfully 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"
+ @ "%%target%%!");
+ lostDosh.toOtherPrivate = _.text.MakeTemplate_S(
+ "%%instigator%% {$TextNegative took} {$TypeNumber %1} do$h from"
+ @ "you!");
+ lostDosh.toOtherPublic = _.text.MakeTemplate_S(
+ "%%instigator%% {$TextNegative took} {$TypeNumber %1} do$h from"
+ @ "%%target%%!");
+ }
+ templates = MakeArray(lostDosh);
+ for (i = 0; i < templates.length; i += 1) {
+ templates[i].Reset().ArgInt(doshAmount);
+ }
+ MakeAnnouncement(lostDosh);
+}
+
+defaultproperties
+{
+}
\ No newline at end of file