////////////////////////////////////////////////// ///// STRUCTORS ////////////////////////////////// public GameController(int roundPeriod, int minPlayers, int maxPlayers, List <Boss> bossTable, List <Hero> heroTable, ClientSessionRegistry playerRegistry, EndRoundEventHandler endRoundHandler, EndGameEventHandler endGameHandler) { if (maxPlayers < minPlayers) { throw new ArgumentException("max player limit cannot be less than min player limit"); } MaxPlayers = maxPlayers; MinPlayers = minPlayers; RoundPeriod = roundPeriod; IntialiseRoundTimer(RoundPeriod); RoundCount = 0; GameLog = new GameEventLog(); Rand = new Random(); GameBoss = null; BossTable = bossTable; HeroTable = heroTable; PlayerRegistry = playerRegistry; EndRoundHandler = endRoundHandler; EndGameHandler = endGameHandler; }
/// <summary> /// Notifies all registered listeners to invoke their events. /// </summary> public void Raise() { #if UNITY_EDITOR GameEventLog log = new GameEventLog(new List <IEventListener>(), DateTime.Now); EventStack.Add(log); #endif for (int i = Listeners.Count - 1; i >= 0; i--) { #if UNITY_EDITOR log.Listener.Add(Listeners[i]); #endif try { Listeners[i].OnEventRaised(this); #if UNITY_EDITOR log.IsError.Add(false); #endif } catch (Exception e) { Exception baseException = e.GetBaseException(); #if UNITY_EDITOR log.IsError.Add(true); log.ErrorMessages.Add(baseException.Message); log.StackTraces.Add(baseException.StackTrace); List <GameEventErrorData> errorData = new List <GameEventErrorData>(); StackTrace stackTrace = new StackTrace(baseException, true); for (int j = 0; j < stackTrace.FrameCount; j++) { StackFrame stackFrame = stackTrace.GetFrame(j); int lineNumber = stackFrame.GetFileLineNumber(); if (lineNumber > 0) { errorData.Add(new GameEventErrorData(stackFrame.GetMethod().Name, stackFrame.GetFileName(), stackFrame.GetFileLineNumber())); } } log.ErrorData.Add(errorData); #endif Debug.LogError($"[Game Event Error] {DateTime.Now:T} | {i} | {name} | {(Listeners[i].GetGameObject() == null ? "No Game Object" : Listeners[i].GetGameObject().name)} | {Listeners[i].GetObjectType().Name}"); Debug.LogException(baseException); } finally { #if UNITY_EDITOR GameEventLogWindow.LogEvent(this); #endif } } }
private GameEventLog GetGameEvents(int round) { GameEventLog log = new GameEventLog(); foreach (GameEvent ge in GameLog.GameEventList) { if (ge.Round == round) { log.GameEventList.Add(ge); } } return(log); }
////////////////////////////////////////////////// ///// STRUCTORS ////////////////////////////////// public App() { // Allows WPF windows to be closed without triggering a shutdown Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; Token = null; FriendList = new List <string>(); HeroList = new List <Hero>(); PlayerList = new PlayerListing(); GameLog = new GameEventLog(); UPSConnection = new UserPortalServerConnection(); GSConnection = new GameServerConnection(); HeroSelection = null; GameServerReady = false; }
protected virtual void Awake() { _input = CreateInputController(); _timeController = new TimeController(); _entityController = CreateEntityController(); _mapController = CreateMapController(); _monsterCreator = new MonsterCreator(); _eventLogger = CreateGameLogger(); _result = GameResult.None; _loading = false; InitPlayStates(); InitPlayStateData(); ExtendedInit(); }
public bool StartNewGame() { Console.WriteLine("> [GAME EVENT] Starting New Game"); // Reset game state // GameBoss = null; RoundCount = 0; GameLog = new GameEventLog(); bool success = ( SelectRandomBoss() && StartRoundTimer() // only executes if previous statement returns true ); return(success); }
public void Init(GameEventLog logger, Player player, TimeController timeController, Camera uiCamera) { _timeController = timeController; _canvas.worldCamera = uiCamera; _logger = logger; _logger.OnEventAdded += UpdateLog; _player = player; SetLogText(""); _hpValue.SetText($"{_player.HP}/{_player.MaxHP}"); _turnCountValue.SetText($"{_timeController.Turns}"); _timeUnitsValue.SetText($"{_timeController.TimeUnits}"); _mapPosValue.SetText($"{_player.Coords}"); // InitInventory(_player.BomberTrait.Inventory, _player.BomberTrait.SelectedIdx); }
public void GameServer_OnRoundEnd(BotListing botListing, PlayerListing playerListing, GameEventLog gameLog) { BotList = botListing; PlayerList = playerListing; if (gameLog != null) { gameLog.GameEventList.AddRange(GameLog.GameEventList); GameLog.GameEventList = gameLog.GameEventList; } }
protected virtual GameEventLog CreateGameLogger() { var logger = new GameEventLog(); return(logger); }
public void Game_OnEndRound(GameEventLog gameLog) { Console.WriteLine("> End Round Event Triggered"); BroadcastToPlayers_RoundEnd(GetBotListing(), GetPlayerListing(), gameLog); }
internal void BroadcastToPlayers_RoundEnd(BotListing botListing, PlayerListing playerListing, GameEventLog gameLog) { Console.WriteLine("> Broadcasting to Players: RoundEnd"); foreach (KeyValuePair <string, ClientSession> kvp in PlayerRegistry) { Trigger_OnRoundEnd(botListing, playerListing, gameLog, kvp.Key); } }
internal void Trigger_OnRoundEnd(BotListing botListing, PlayerListing playerListing, GameEventLog gameLog, string userToken) { PlayerSession session = (PlayerSession)PlayerRegistry.GetClientSession(userToken); if (session != null) { IGameServerController_Callback callback = session.CallbackChannel; if (callback != null) { try { callback.GameServer_OnRoundEnd(botListing, playerListing, gameLog); } catch (CommunicationException ex) { Console.WriteLine("> Failed trigger event (CommunicationException): OnRoundEnd\n" + ex.Message); } catch (TimeoutException ex) { Console.WriteLine("> Failed trigger event (TimeoutException): OnRoundEnd\n" + ex.Message); } } else { Console.WriteLine("> Failed trigger event: OnRoundEnd\n" + "callback object null!"); } } else { Console.WriteLine("> Failed trigger event: OnRoundEnd\n" + "PlayerSession not found!"); } }
/// <summary> /// Draws the given <see cref="GameEventLog" />. /// </summary> /// <param name="log"></param> /// <param name="index"></param> private void DrawEventLog(GameEventLog log, int index) { EditorGUILayout.LabelField(log.Listener[index].GetObjectType().Name, SOFlowStyles.BoldCenterLabel); EditorGUILayout.LabelField($"{log.LogTime:T}", SOFlowStyles.CenteredLabel); EditorGUILayout.ObjectField(log.Listener[index].GetGameObject(), typeof(GameObject), true); }
/// <summary> /// Draws the log entry for the given game event. /// </summary> /// <param name="gameEvent"></param> /// <param name="instanceID"></param> private void DrawLogEntry(GameEvent gameEvent, int instanceID) { Vector2 scrollPosition; if (!_eventEntriesScrollPosition.TryGetValue(instanceID, out scrollPosition)) { scrollPosition = Vector2.zero; _eventEntriesScrollPosition.Add(instanceID, scrollPosition); } Color originalGUIColor = GUI.backgroundColor; GUI.backgroundColor = SOFlowEditorSettings.TertiaryLayerColour; scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, true, false, GUI.skin.horizontalScrollbar, GUIStyle.none, SOFlowStyles.HelpBox, GUILayout.Height(EditorGUIUtility.singleLineHeight * 7f), GUILayout.Width(position.width - _entryWidth - 40f)); GUI.backgroundColor = originalGUIColor; EditorGUILayout.BeginHorizontal(); for (int i = gameEvent.EventStack.Count - 1; i >= 0; i--) { int skippedEntries = 0; SOFlowEditorUtilities.DrawSecondaryLayer(() => { EditorGUILayout.LabelField($"Log Entry {i + 1}", SOFlowStyles.CenterTextHelpBox); EditorGUILayout.BeginHorizontal(); for (int j = 0, condition = gameEvent.EventStack[i].Listener.Count; j < condition; j++) { string searchQuery; _eventEntrySearchQuery.TryGetValue(instanceID, out searchQuery); GameEventLog log = gameEvent.EventStack[i]; GameObject gameObject = log.Listener[j].GetGameObject(); if (string.IsNullOrEmpty(searchQuery) || gameObject == null || gameObject.name.ToLower() .Contains(searchQuery.ToLower())) { SOFlowEditorUtilities .DrawColourLayer(log.IsError[j] ? SOFlowEditorSettings.DeclineContextColour : SOFlowEditorSettings.AcceptContextColour, () => DrawEventLog(log, j)); } else { skippedEntries++; } } EditorGUILayout.EndHorizontal(); }, GUILayout.MaxWidth(_entryWidth * (gameEvent.EventStack[i].Listener.Count - skippedEntries))); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); _eventEntriesScrollPosition[instanceID] = scrollPosition; }