public async Task SelectMoveAsync(ICommandContext context, string moveIdentifier) { PlayerState player = context.User.Id == player1.Gotchi.Gotchi.OwnerId ? player1 : player2; PlayerState other_player = context.User.Id == player1.Gotchi.Gotchi.OwnerId ? player2 : player1; if (player.SelectedMove != null) { // If the player has already selected a move, don't allow them to change it. await BotUtils.ReplyAsync_Info(context, string.Format("You have already selected a move for this turn. Awaiting **{0}**'s move.", (await GetOtherPlayerAsync(context, context.User.Id)).Username)); } else { GotchiMove move = player.Gotchi.Moves.GetMove(moveIdentifier); if (move is null) { // Warn the player if they select an invalid move. await BotUtils.ReplyAsync_Error(context, "The move you have selected is invalid. Please select a valid move."); } else if (move.PP <= 0 && player.Gotchi.Moves.HasPP) { // The selected move cannot be used because it is out of PP. await BotUtils.ReplyAsync_Error(context, "The selected move has no PP left. Please select a different move."); } else { // Lock in the selected move. player.SelectedMove = move; // If the selected move does not have any PP, silently select the "struggle" move (used when no moves have any PP). if (player.SelectedMove.PP <= 0) { player.SelectedMove = await Global.GotchiContext.MoveRegistry.GetMoveAsync("desperation"); } if (!IsBattlingCpu() && other_player.SelectedMove is null) { // If the other user hasn't locked in a move yet, await their move. await BotUtils.ReplyAsync_Info(context, string.Format("Move locked in! Awaiting **{0}**'s move.", (await GetOtherPlayerAsync(context, context.User.Id)).Username)); } else { // If the player is battling a CPU, select a move for them now. if (IsBattlingCpu()) { await _pickCpuMoveAsync(player2); } // Update the battle state. await ExecuteTurnAsync(context); } } } }
public async Task <bool> OnRegisterAsync(GotchiMove move) { if (_script.Globals[OnRegisterName] != null) { await _script.CallAsync(_script.Globals[OnRegisterName], move); return(true); } return(false); }
private async Task _pickCpuMoveAsync(PlayerState player) { GotchiMove move = player.Gotchi.Moves.GetRandomMove(); if (move is null) { move = await Global.GotchiContext.MoveRegistry.GetMoveAsync("desperation"); } player.SelectedMove = move; }
public void Add(GotchiMove move) { if (!Moves.Any(x => string.Equals(x.Name, move.Name, StringComparison.OrdinalIgnoreCase))) { Moves.Add(move); } if (Moves.Count > MoveLimit) { throw new Exception(string.Format("Number of moves added has exceeded the move limit ({0}).", MoveLimit)); } }
public async Task <GotchiMove> GetMoveAsync(string name) { GotchiMove move = await _getMoveAsync(name); if (move != null) { return(move); } else { throw new Exception(string.Format("No move with the name \"{0}\" exists in the registry.", name)); } }
public async Task RegisterAsync(string filePath) { try { GotchiMove move = new GotchiMove { LuaScriptFilePath = filePath }; if (await new GotchiMoveLuaScript(move.LuaScriptFilePath).OnRegisterAsync(move)) { _addMoveToRegistry(move); } } catch (Exception) { await _logAsync(LogSeverity.Error, string.Format("Failed to register move {0}", System.IO.Path.GetFileName(filePath))); } }
private void _addMoveToRegistry(GotchiMove move) { Registry.Add(move.Name.ToLower(), move); }