protected async Task <GameActionResponse> SendAction(GameAction <object> action) { string error = null; SendGameActionResponse response = null; try { response = await KokkaKoroService.SendGameAction(new SendGameActionOptions() { Action = action, GameId = m_connectedGameId }); if (response.Response == null) { throw new Exception("An empty response was sent back."); } } catch (Exception e) { error = $"Exception thrown while making call, message: {e.Message}"; } if (!String.IsNullOrWhiteSpace(error)) { return(GameActionResponse.CreateError(GameError.Create(null, ErrorTypes.LocalError, error, false))); } else if (response.Response == null || (!response.Response.Accepted && response.Response.Error == null) || (!response.Response.Accepted && String.IsNullOrWhiteSpace(response.Response.Error.Message))) { return(GameActionResponse.CreateError(GameError.Create(null, ErrorTypes.LocalError, "Result failed but has no error object.", false))); } else { return(response.Response); } }
/// <summary> /// 抛出游戏异常,此操作会直接 /// </summary> /// <param name="code"></param> /// <param name="message"></param> public static void ThrowGameError(GameError code, string message) { StringBuilder stringBuilder = new StringBuilder("错误代码:"); stringBuilder.Append(code.ToString()); stringBuilder.Append("\n"); stringBuilder.Append(message); stringBuilder.Append("\n"); //打印堆栈 var stacktrace = new StackTrace(1, true); for (var i = 0; i < stacktrace.FrameCount; i++) { var frame = stacktrace.GetFrame(i); var method = stacktrace.GetFrame(i).GetMethod(); stringBuilder.Append("\n["); stringBuilder.Append(i); stringBuilder.Append("] "); stringBuilder.Append(method.Name); stringBuilder.Append("\n"); stringBuilder.Append(frame.GetFileName()); stringBuilder.Append(" ("); stringBuilder.Append(frame.GetFileLineNumber()); stringBuilder.Append(":"); stringBuilder.Append(frame.GetFileColumnNumber()); stringBuilder.Append(")"); } GameManager.ForceInterruptGame(); gameGlobalErrorUI.ShowErrorUI(stringBuilder.ToString()); }
public bool PerformRoll() { if (ConsecutiveRolls > 0) { if (!HasScoringDiceGuard(GameAction.Roll)) { return(false); } Board.UpdateScoreFromSelected(); } Board.RollDice(); if (!Board.HasScoringDiceSelected()) { GameError?.Invoke(this, new NoScoringDiceSelected(GameAction.Roll)); // Rolled no scoring dice NextPlayer(); return(false); } ConsecutiveRolls += 1; return(true); }
public bool CanUseItem(IntPtr pointer, out GameError error) { if (_canUseItem == null) { _canUseItem = Manager.Memory.RegisterDelegate <CanUseItemDelegate>((IntPtr)Pointers.Item.CanUseItem); } return(_canUseItem(this.Pointer, pointer, out error)); }
public override Task OnGameError(GameError error) { // OnGameError fires whenever there is an error in the game, either due this player or another player. Some of these errors are just // incorrect requests from other players, while others can be fatal from the game engine. There really isn't too much your bot can do with // the error, except print them out for interest. If this bot creates an error, it will be handed when making the action request. Logger.Log(Log.Warn, $"Game Error - {error.Type.ToString()} : {error.Message}"); return(Task.CompletedTask); }
/// <summary> /// Helps us shutdown. /// </summary> /// <param name="message"></param> /// <param name="e"></param> /// <returns></returns> private async Task Shutdown(string message, GameError e) { Logger.Log(Log.Error, $"That's not good..."); Logger.Log(Log.Error, $" ...we failed to {message}"); Logger.Log(Log.Error, $" ...because {(e != null ? e.Message : "")}"); Logger.Log(Log.Error, $" ...time to give up and shutdown!"); // Send the forfeit command to the game host since we don't know what to do. await m_bot.SendAction(GameAction <object> .CreateForfeitAction()); // Disconnect the bot. await m_bot.Disconnect(); }
private void HandleMessage(DateTimeOffset t, HttpMessage m) { try { var status = Convert <SvData>(m.Response); if (status.api_result != 1) { GameError?.Invoke(t, new Events.GameError(status.api_result, status.api_result_msg)); return; } lock (lockObj) switch (m.Key) { case "api_start2": case "api_start2/getData": if (savedMasterData != null) { savedMasterData.Value = m.Response.ToString(); } masterDataUpdated?.InvokeEach(t, ParseMasterData(Response <MasterDataJson>(m)), HandlerError); break; case "api_get_member/require_info": var requireInfo = Response <GameStartupInfoJson>(m); AllEquipmentUpdated?.InvokeEach(t, requireInfo.api_slot_item, HandlerError); UseItemUpdated?.InvokeEach(t, requireInfo.api_useitem, HandlerError); FreeEquipmentUpdated?.InvokeEach(t, requireInfo.api_unsetslot, HandlerError); BuildingDockUpdated?.InvokeEach(t, requireInfo.api_kdock, HandlerError); break; case "api_req_member/get_incentive": IncentiveRewarded?.InvokeEach(t, Response <IncentiveJson>(m).api_item, HandlerError); break; case "api_port/port": var homeport = Response <HomeportJson>(m); AdmiralUpdated?.InvokeEach(t, homeport.api_basic, HandlerError); RepairingDockUpdated?.InvokeEach(t, homeport.api_ndock, HandlerError); HomeportReturned?.InvokeEach(t, ParseHomeport(homeport), HandlerError); FleetsUpdated?.InvokeEach(t, homeport.api_deck_port, HandlerError); MaterialsUpdated?.InvokeEach(t, homeport.api_material, HandlerError); if (homeport.api_event_object?.api_m_flag2 == true) { EnemyDebuffConfirmed?.InvokeEach(t, default, HandlerError); } break; case "api_get_member/slot_item": AllEquipmentUpdated?.InvokeEach(t, Response <RawEquipment[]>(m), HandlerError); break;
public void DisplayError(GameError error) { switch (error) { case GameError.CellAlreadyOccupied: Console.WriteLine("Bad move: cell is already occupied."); break; case GameError.CouldNotParseMove: Console.WriteLine("Bad move. Valid moves are A1 to C3."); break; default: Console.WriteLine("Something went wrong."); break; } }
private bool HasScoringDiceGuard(GameAction action) { if (!Board.GetDice().Any(x => x.Selected)) { // No selected dice GameError?.Invoke(this, new NoDiceSelected(action)); return(false); } if (!Board.HasScoringDiceSelected()) { // No selected dice with scores GameError?.Invoke(this, new NoScoringDiceSelected(action)); return(false); } return(true); }
public void PerformSelect(IEnumerable <int> selection) { if (ConsecutiveRolls == 0) { GameError?.Invoke(this, new DiceNotRolled(GameAction.Select)); return; } var dice = Board.GetDice(); foreach (var select in selection) { if (dice[select].Selected) { Board.DeselectDice(select); } else { Board.SelectDice(select); } } }
public void Start() { CurrentCard = Board.Deck.Draw(); while (true) { // pass control to player bool passAllowed = AllowPass(); TurnFulfilled = false; Turn?.Invoke(CurrentPlayer); while (true) { CurrentPlayer.Play(this); // make sure the turn was completed if (!TurnFulfilled && !passAllowed && CurrentCard != 7) { GameError?.Invoke(CurrentPlayer, new IncompleteTurnException("Player returned without completing turn")); } else { break; } } if (TurnFulfilled && PlayerWon()) { GameOver?.Invoke(CurrentPlayer); break; } else if (TurnFulfilled || passAllowed) { // end turn if (CurrentCard != 2) { NextPlayer(); } // draw card CurrentCard = Board.Deck.Draw(); } } }
public bool PerformStop() { if (ConsecutiveRolls == 0) { // Haven't rolled GameError?.Invoke(this, new DiceNotRolled(GameAction.Stop)); return(false); } if (!HasScoringDiceGuard(GameAction.Stop)) { return(false); } Board.UpdateScoreFromSelected(); var player = GetCurrentPlayer(); player.IncreaseScore(Board.GetScore()); NextPlayer(); return(true); }
public DisplayGameError(GameError error) : base(ServerOpcodes.DisplayGameError) { Error = error; }
public bool CanUseItem(IntPtr pointer, out GameError error) { if (_canUseItem == null) _canUseItem = Manager.Memory.RegisterDelegate<CanUseItemDelegate>((IntPtr)Pointers.Item.CanUseItem); return _canUseItem(this.Pointer, pointer, out error); }
private void Game_GameError(object sender, IGameError e) { GameError?.Invoke(this, e); }
public static void Assert_Failure(this Result <Unit, GameError> result, GameError expectedError) => result.Should().BeEquivalentTo(Result.Failure <Unit, GameError>(expectedError));
public bool CanUseItem(WoWItem item, out GameError error) { return CanUseItem(WoWItem.GetItemRecordPointerFromId(item.Entry), out error); }
/* * Used for joining the server specified by the ip and port */ public void JoinServer(string ip, int port) { // Connecting the messageReceived event to the handler connection.MessageReceived += parser.OnMessageReceived; connection.ServerIP = ip; connection.ServerPort = port; try { connection.StartConnection(); connection.StartReceiving(); error = GameError.NO_ERROR; } catch(SocketException) { error = GameError.NO_SERVER_DETECTED; } }
public GameException(string message, GameError error) : base(message) { _error = error; }
public static void SetLastErrorAndLog(GameError code, string tag, string message) { LastError = code; GameLogger.Error(tag, message); }
// Fires when the game the bot has connected to has some error. // THIS ERROR ISN'T NECESSARILY FROM THIS BOT - all errors from any players are reported here. public abstract Task OnGameError(GameError error);
public DisplayGameError(GameError error, int arg) : this(error) { Arg.Set(arg); }
private void Initialize() { #region Initializing variables gameEngine = new GameEngine(); connection = new Connection(); parser = new Parser(); ai = new AI(); mode = GameMode.AUTO; state = GameState.IDLE; message = ServerMessage.NO_ISSUES; error = GameError.NO_ERROR; #endregion /* * For collecting all the object discarded ** invoked garbage collector to improve the performance after the game start */ System.GC.Collect(); }
public bool CanUseItem(WoWItem item, out GameError error) { return(CanUseItem(WoWItem.GetItemRecordPointerFromId(item.Entry), out error)); }
public DisplayGameError(GameError error, int arg1, int arg2) : this(error) { Arg.Set(arg1); Arg2.Set(arg2); }
/// <summary> /// 设置错误码并打印日志 /// </summary> /// <param name="code">错误码</param> /// <param name="tag">TAG</param> /// <param name="message">错误信息</param> /// <param name="param">日志信息</param> public static void SetLastErrorAndLog(GameError code, string tag, string message, params object[] param) { LastError = code; GameLogger.Error(tag, message, param); }