Browse Source

Merge pull request #297 from aws-lumberyard-dev/ServerLogMatchResults

Server.log Match Results
Gene Walters 2 years ago
parent
commit
d143d0a8d6
1 changed files with 21 additions and 0 deletions
  1. 21 0
      Gem/Code/Source/Components/NetworkMatchComponent.cpp

+ 21 - 0
Gem/Code/Source/Components/NetworkMatchComponent.cpp

@@ -343,6 +343,27 @@ namespace MultiplayerSample
             results.m_playerStates.push_back(state);
         }
 
+        // Print the player results to server.log for tracking tournament winners.
+        // Sort the players by score (highest score is 1st)
+        // If scores are matching, then sort by remaining armor.
+        AZStd::sort(results.m_playerStates.begin(), results.m_playerStates.end(), [](const PlayerState& a, const PlayerState& b)
+            {
+                if (a.m_score == b.m_score)
+                {
+                    return a.m_remainingArmor > b.m_remainingArmor;
+                }
+                return a.m_score > b.m_score;
+            });
+
+        AZStd::string prettyPrintMatchResults = "";
+        prettyPrintMatchResults += AZStd::string::format("Match Results (%u players)\n", results.m_playerStates.size());
+        for (const PlayerState& playerState : results.m_playerStates)
+        {
+            prettyPrintMatchResults += AZStd::string::format("\tPlayer %s score %u, armor %u.\n", playerState.m_playerName.c_str(), playerState.m_score, playerState.m_remainingArmor);
+        }
+        AZ_Info("NetworkMatchComponentController", prettyPrintMatchResults.c_str());
+
+
         FindWinner(results, potentialWinners);
 
         RPC_EndMatch(results);