Example #1
0
        /// <summary>
        /// Logs a station creation to this game's dataset
        /// </summary>
        /// <param name="time">The time this station was created</param>
        /// <param name="teamID">The ID of the team that created this station</param>
        /// <param name="teamName">The name of the team that created this station</param>
        /// <param name="stationName">The name of the created station</param>
        public void LogStationCreated(DateTime time, int teamID, string teamName,
                                      string stationName)
        {
            // Store the techpath of the created station
            GameDataset.TeamRow Team = _gameDataset.Team.FindByTeamID(teamID);
            if (Team != null)
            {
                if (stationName.IndexOf("Tactical") > -1)
                {
                    Team.ResearchedTactical = true;
                }

                if (stationName.IndexOf("Expansion") > -1)
                {
                    Team.ResearchedExpansion = true;
                }

                if (stationName.IndexOf("Supremacy") > -1)
                {
                    Team.ResearchedSupremacy = true;
                }

                if (stationName.IndexOf("Shipyard") > -1 || stationName.IndexOf("Drydock") > -1)
                {
                    Team.ResearchedShipyard = true;
                }

                if (stationName.IndexOf("Starbase") > -1)
                {
                    Team.ResearchedStarbase = true;
                }
            }

            _gameDataset.GameEvent.AddGameEventRow(GameRow, (int)HandledEventIDs.StationCreated, time, GameRow.GameID, GameRow.GameName, teamID, teamName, -1, stationName);
        }
Example #2
0
 /// <summary>
 /// Adds the specified player to the team with default join/leave times
 /// </summary>
 /// <param name="callsign">The callsign of the player to add</param>
 /// <param name="teamIndex">The index of the team</param>
 /// <param name="startTime">The time this player joined the team</param>
 public void AddTeamMember(string callsign, int teamIndex, DateTime startTime)
 {
     GameDataset.TeamRow TeamRow = _gameDataset.Team.FindByTeamID(teamIndex);
     if (TeamRow != null)
     {
         _gameDataset.TeamMember.AddTeamMemberRow(TeamRow, callsign, 0, startTime, DateTime.MinValue);
     }
 }
Example #3
0
 /// <summary>
 /// Sets the specified team's name, faction, and commander
 /// </summary>
 /// <param name="teamNumber">The index of the team to initialize</param>
 /// <param name="teamName">The name of the team being initialized</param>
 /// <param name="teamFaction">The team's faction</param>
 /// <param name="teamCommander">The team's commander</param>
 public void InitializeTeam(int teamNumber, string teamName, string teamFaction, string teamCommander)
 {
     GameDataset.TeamRow TeamRow = _gameDataset.Team.FindByTeamID(teamNumber);
     if (TeamRow != null)
     {
         TeamRow["TeamName"]  = teamName;
         TeamRow["Commander"] = teamCommander;
         TeamRow["Faction"]   = teamFaction;
     }
 }
Example #4
0
        /// <summary>
        /// Logs a player joining a team to this game's dataset
        /// </summary>
        /// <param name="time">The time this player joined the team</param>
        /// <param name="playerID">The ID of the player joining the team</param>
        /// <param name="playerName">The name of the player joining the team</param>
        /// <param name="teamID">The ID of the team being joined</param>
        /// <param name="teamName">The name of the team being joined</param>
        public void LogPlayerJoinedTeam(DateTime time, int playerID, string playerName,
                                        int teamID, string teamName)
        {
            // Were they already on the team?
            string TeamMemberSelect = string.Concat("Callsign = '", playerName, "' AND TeamID = ", teamID.ToString());

            GameDataset.TeamMemberRow[] TeamMembers = (GameDataset.TeamMemberRow[])_gameDataset.TeamMember.Select(TeamMemberSelect);
            if (TeamMembers.Length > 0)
            {                   // They were on a team. Adjust existing teammember time
                GameDataset.TeamMemberRow TeamMember = TeamMembers[0];

                // If the player is rejoining...
                if (TeamMember.LeaveTime != DateTime.MinValue)
                {
                    // Get the difference between when they last left and now
                    TimeSpan Difference = time.Subtract(TeamMember.LeaveTime);
                    // Add difference to StartTime
                    TeamMember.JoinTime = TeamMember.JoinTime.Add(Difference);

                    // Reset LeaveTime because they haven't left yet
                    TeamMember.LeaveTime = DateTime.MinValue;
                }
            }
            else             // They weren't on this team before. Add them.
            {
                // Retrieve the TeamRow.
                GameDataset.TeamRow TeamRow = _gameDataset.Team.FindByTeamID(teamID);
                if (TeamRow != null)
                {
                    // Add teamrow with "Minimum" leavetime
                    _gameDataset.TeamMember.AddTeamMemberRow(TeamRow, playerName, 0, time, DateTime.MinValue);
                }
            }

            // Log event
            _gameDataset.GameEvent.AddGameEventRow(GameRow, (int)HandledEventIDs.JoinedTeam, time, playerID, playerName, teamID, teamName, -1, string.Empty);
        }
Example #5
0
//		/// <summary>
//		/// Logs a game created message to this game's dataset
//		/// </summary>
//		/// <param name="time">The time this game was created</param>
//		/// <param name="gameName">The name of the created game</param>
//		public void LogGameCreated (DateTime time, string gameName)
//		{
//			_gameDataset.GameEvent.AddGameEventRow(GameRow, (int)HandledEventIDs.GameCreated, time, -1, gameName, -1, string.Empty, -1, string.Empty);
//		}
//
//		/// <summary>
//		/// Logs a game destroyed message to this game's dataset
//		/// </summary>
//		/// <param name="time">The time this game was destroyed</param>
//		/// <param name="gameName">The name of the destroyed game</param>
//		public void LogGameDestroyed (DateTime time, string gameName)
//		{
//			_gameDataset.GameEvent.AddGameEventRow(GameRow, (int)HandledEventIDs.GameDestroyed, time, -1, gameName, -1, string.Empty, -1, string.Empty);
//		}

        /// <summary>
        /// Logs a game ended message to this game's dataset
        /// </summary>
        /// <param name="time">The time this game ended</param>
        /// <param name="winningTeamID">The ID of the winning team</param>
        /// <param name="winningTeamName">The name of the winning team</param>
        /// <param name="gameEndedReason">The reason that the game has ended</param>
        public void LogGameEnded(DateTime time, int winningTeamID, string winningTeamName, string gameEndedReason)
        {
            try
            {
                // Set GameEnded time
                GameRow.EndTime = time;

                // Assign winning team by ID if we're using FAZ R2 or later
                if (winningTeamID >= 0)
                {                       // A specific team won. Record it
                    GameDataset.TeamRow Team = _gameDataset.Team.FindByTeamID(winningTeamID);
                    if (Team != null)
                    {
                        Team.Won = true;
                    }
                }
                else
                {
                    // We're using FAZ R1 or earlier. Assign win by teamname...

                    // Clean teamname for lookup - teamnames can't have '
                    string WinningTeamName = winningTeamName.Replace("'", "''");

                    // Look up team
                    string TeamSelect           = string.Concat("TeamName = '", WinningTeamName, "'");
                    GameDataset.TeamRow[] Teams = (GameDataset.TeamRow[])_gameDataset.Team.Select(TeamSelect);
                    if (Teams.Length > 0)
                    {
                        GameDataset.TeamRow Team = Teams[0];
                        Team.Won = true;
                    }
                }

                if (gameEndedReason.Equals("The game was declared a draw"))
                {
                    // It's a draw. Everybody loses!
                    foreach (GameDataset.TeamRow Team in _gameDataset.Team.Rows)
                    {
                        Team.Won = false;
                    }
                }

                TagTrace.WriteLine(TraceLevel.Verbose, "Tabulating durations for {0} TeamMembers...", _gameDataset.TeamMember.Rows.Count);
                // Tabulate teammember durations
                foreach (GameDataset.TeamMemberRow TeamMember in _gameDataset.TeamMember.Rows)
                {
                    // Record leavetime for players in game
                    if (TeamMember.LeaveTime == DateTime.MinValue)
                    {
                        TeamMember.LeaveTime = time;
                    }

                    // Calculate time on team
                    TimeSpan Difference        = TeamMember.LeaveTime.Subtract(TeamMember.JoinTime);
                    int      SecondsDifference = (int)Difference.TotalSeconds;

                    // Record duration
                    TeamMember.Duration = SecondsDifference;
                }

                // Log event
                _gameDataset.GameEvent.AddGameEventRow(GameRow, (int)HandledEventIDs.GameEnded, time, GameRow.GameID, GameRow.GameName, _gameDataset.TeamMember.Rows.Count, winningTeamName, -1, gameEndedReason);
            }
            catch (Exception e)
            {
                TagTrace.WriteLine(TraceLevel.Error, "Error logging GameEnded event: {0}", e.Message);
            }
        }