Browse Source

Fix built-in commands to work better with Acedia

pull/8/head
Anton Tarasenko 4 years ago
parent
commit
e4c2624df9
  1. 53
      sources/Commands/BuiltInCommands/ACommandDosh.uc
  2. 2
      sources/Commands/BuiltInCommands/ACommandNick.uc

53
sources/Commands/BuiltInCommands/ACommandDosh.uc

@ -19,6 +19,8 @@
*/ */
class ACommandDosh extends Command; class ACommandDosh extends Command;
var protected const int TGOTTEN, TLOST, TDOSH;
protected function BuildData(CommandDataBuilder builder) protected function BuildData(CommandDataBuilder builder)
{ {
builder.Name(P("dosh")).Summary(P("Changes amount of money.")); builder.Name(P("dosh")).Summary(P("Changes amount of money."));
@ -50,48 +52,59 @@ protected function ExecutedFor(APlayer player, CommandCall result)
local int amount, minValue, maxValue; local int amount, minValue, maxValue;
local AssociativeArray commandOptions; local AssociativeArray commandOptions;
// Find min and max value boundaries // Find min and max value boundaries
minValue = 0;
maxValue = MaxInt;
commandOptions = result.GetOptions(); commandOptions = result.GetOptions();
if (commandOptions.HasKey(P("min"))) minValue = commandOptions.GetIntByPointer(P("/min/minValue"), 0);
{ maxValue = commandOptions.GetIntByPointer(P("/max/maxValue"), MaxInt);
minValue = IntBox(AssociativeArray(commandOptions.GetItem(P("min")))
.GetItem(P("minValue"))).Get();
}
if (commandOptions.HasKey(P("max"))) {
minValue = IntBox(AssociativeArray(commandOptions.GetItem(P("max")))
.GetItem(P("maxValue"))).Get();
}
if (minValue > maxValue) { if (minValue > maxValue) {
maxValue = minValue; maxValue = minValue;
} }
// Change dosh // Change dosh
oldAmount = player.GetDosh(); oldAmount = player.GetDosh();
amount = IntBox(result.GetParameters().GetItem(P("amount"))).Get(); amount = result.GetParameters().GetInt(P("amount"));
if (result.GetSubCommand().IsEmpty()) { if (result.GetSubCommand().IsEmpty()) {
newAmount = oldAmount + amount; newAmount = oldAmount + amount;
} }
else { else {
// This has to be "dosh set"
newAmount = amount; newAmount = amount;
} }
// Enforce min/max bounds
newAmount = Clamp(newAmount, minValue, maxValue); newAmount = Clamp(newAmount, minValue, maxValue);
if (!commandOptions.HasKey(P("silent"))) // Announce dosh change, if necessary
if (!commandOptions.HasKey(P("silent"))) {
AnnounceDoshChange(player.Console(), oldAmount, newAmount);
}
player.SetDosh(newAmount);
}
protected function AnnounceDoshChange(
ConsoleWriter console,
int oldAmount,
int newAmount)
{ {
local Text amountDeltaAsText;
if (newAmount > oldAmount) if (newAmount > oldAmount)
{ {
player.Console().Say(F("You've {$TextPositive gotten}" amountDeltaAsText = _.text.FromInt(newAmount - oldAmount);
@ newAmount - oldAmount @ "dosh!")); console.Write(T(TGOTTEN))
.Write(amountDeltaAsText)
.WriteLine(T(TDOSH));
} }
if (newAmount < oldAmount) if (newAmount < oldAmount)
{ {
player.Console().Say(F("You've {$TextNegative lost}" amountDeltaAsText = _.text.FromInt(oldAmount - newAmount);
@ oldAmount - newAmount @ "dosh!")); console.Write(T(TLOST))
.Write(amountDeltaAsText)
.WriteLine(T(TDOSH));
} }
} _.memory.Free(amountDeltaAsText);
player.SetDosh(newAmount);
} }
defaultproperties defaultproperties
{ {
TGOTTEN = 0
stringConstants(0) = "You've {$TextPositive gotten} "
TLOST = 1
stringConstants(1) = "You've {$TextNegative lost} "
TDOSH = 2
stringConstants(2) = " dosh!"
} }

2
sources/Commands/BuiltInCommands/ACommandNick.uc

@ -29,7 +29,7 @@ protected function BuildData(CommandDataBuilder builder)
protected function ExecutedFor(APlayer player, CommandCall result) protected function ExecutedFor(APlayer player, CommandCall result)
{ {
player.SetName(Text(result.GetParameters().GetItem(P("nick")))); player.SetName(result.GetParameters().GetText(P("nick")));
} }
defaultproperties defaultproperties

Loading…
Cancel
Save