// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // namespace MUnique.OpenMU.GameLogic.PlugIns.ChatCommands; using System.Runtime.InteropServices; using MUnique.OpenMU.PlugIns; /// /// A chat command plugin which sets a character's money. /// [Guid("00AA4F0E-911D-49FE-8D88-114C7496D383")] [PlugIn] [Display(Name = nameof(PlugInResources.SetMoneyChatCommandPlugIn_Name), Description = nameof(PlugInResources.SetMoneyChatCommandPlugIn_Description), ResourceType = typeof(PlugInResources))] [ChatCommandHelp(Command, "Sets money of a player. Usage: /setmoney (amount) (optional:character)", null)] public class SetMoneyChatCommandPlugIn : ChatCommandPlugInBase, IDisabledByDefault { private const string Command = "/setmoney"; private const CharacterStatus MinimumStatus = CharacterStatus.GameMaster; /// public override string Key => Command; /// public override CharacterStatus MinCharacterStatusRequirement => MinimumStatus; /// protected override async ValueTask DoHandleCommandAsync(Player player, Arguments arguments) { var targetPlayer = player; if (arguments?.CharacterName is { } characterName) { targetPlayer = player.GameContext.GetPlayerByCharacterName(characterName); if (targetPlayer?.SelectedCharacter is null || !targetPlayer.SelectedCharacter.Name.Equals(characterName, StringComparison.OrdinalIgnoreCase)) { await player.ShowLocalizedBlueMessageAsync(nameof(PlayerMessage.CharacterNotFound), characterName).ConfigureAwait(false); return; } } if (targetPlayer.SelectedCharacter?.Inventory is null) { return; } if (targetPlayer.GameContext?.Configuration?.MaximumInventoryMoney is not int maxMoney) { return; } if (arguments is null || arguments.Amount < 0 || arguments.Amount > maxMoney) { await player.ShowLocalizedBlueMessageAsync(nameof(PlayerMessage.InvalidMoneyAmount), maxMoney).ConfigureAwait(false); return; } targetPlayer.Money = checked(arguments.Amount); await player.ShowLocalizedBlueMessageAsync(nameof(PlayerMessage.SetMoneyResult), arguments.Amount).ConfigureAwait(false); } /// /// Arguments for the Set Money chat command. /// public class Arguments : ArgumentsBase { /// /// Gets or sets the amount of money to set. /// public int Amount { get; set; } /// /// Gets or sets the character name to set money for. /// public string? CharacterName { get; set; } } }