protected override void OnConfigureStats() { base.OnConfigureStats(); for (int characterIndex = 0; characterIndex < charactersCount; ++characterIndex) { GameObject characterInstance = GetCharacterByIndex(characterIndex); if (characterInstance == null) { continue; } tnCharacterInfo characterInfo = characterInstance.GetComponent <tnCharacterInfo>(); if (characterInfo == null) { continue; } tnCharacterStats characterStats = characterInstance.GetComponent <tnCharacterStats>(); if (characterStats == null) { continue; } // Bind results. { int characterId = characterInfo.characterId; tnBaseMatchCharacterResults characterResults = (tnBaseMatchCharacterResults)GetCharacterResultsById(characterId); characterStats.SetResults(characterResults); } // Bind references. { int characterTeamIndex = characterInfo.teamIndex; for (int teamIndex = 0; teamIndex < teamsCount; ++teamIndex) { if (teamIndex == characterTeamIndex) { continue; } tnGoal goal = GetGoal(teamIndex); if (goal != null) { characterStats.SetOpponentGoal(goal); break; } } } } }
// BUSINESS LOGIC public void SetResults(tnBaseMatchCharacterResults i_Results) { m_Results = i_Results; }
private void FillGoalScoredData(int i_SlotIndex, tnBaseMatchController i_MatchController) { if (i_MatchController == null) { return; } int charcatersCount = i_MatchController.charactersCount; // Compute total shots count. int totalGoalScored = 0; for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex) { tnBaseMatchCharacterResults characterResults = (tnBaseMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex); if (characterResults != null) { totalGoalScored += characterResults.goalScored; } } // Get best character for this stat. int selectedCharacterIndex = -1; int selectedCharacterId = Hash.s_NULL; int selectedPlayerId = Hash.s_NULL; int maxGoalScored = int.MinValue; for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex) { tnBaseMatchCharacterResults characterResults = (tnBaseMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex); if (characterResults != null) { int characterGoalScored = characterResults.goalScored; if (characterGoalScored > maxGoalScored) { selectedCharacterIndex = characterIndex; selectedCharacterId = characterResults.id; selectedPlayerId = characterResults.playerId; maxGoalScored = characterGoalScored; } } } if (selectedCharacterIndex < 0) { return; } // Fill data. string playerName = ""; Sprite playerPortrait = null; Color playerColor = Color.white; { tnCharacterData characterData = tnGameData.GetCharacterDataMain(selectedCharacterId); if (characterData != null) { playerName = characterData.displayName; playerPortrait = characterData.uiIconFacingRight; } tnPlayerData playerData = tnGameData.GetPlayerDataMain(selectedPlayerId); if (playerData != null) { playerColor = playerData.color; } } string statValue = maxGoalScored.ToString(); float partecipationPercentage = 0f; if (totalGoalScored > 0) { partecipationPercentage = (float)maxGoalScored / (float)totalGoalScored; partecipationPercentage *= 100f; partecipationPercentage = Mathf.Clamp(partecipationPercentage, 0f, 100f); } string partecipationValue = partecipationPercentage.ToString("0.00"); partecipationValue += "%"; FillData(i_SlotIndex, playerName, playerPortrait, playerColor, s_StatName_GoalScored, statValue, s_PartecipationLabel, partecipationValue); }
private void FillAttractTimeData(int i_SlotIndex, tnBaseMatchController i_MatchController) { if (i_MatchController == null) { return; } int charcatersCount = i_MatchController.charactersCount; // Compute total shots count. FP totalAttractTime = FP.Zero; for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex) { tnBaseMatchCharacterResults characterResults = (tnBaseMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex); if (characterResults != null) { totalAttractTime += characterResults.attractTime; } } // Get best character for this stat. int selectedCharacterIndex = -1; int selectedCharacterId = Hash.s_NULL; int selectedPlayerId = Hash.s_NULL; FP maxAttractTime = FP.MinValue; for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex) { tnBaseMatchCharacterResults characterResults = (tnBaseMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex); if (characterResults != null) { FP characterAttractTime = characterResults.attractTime; if (characterAttractTime > maxAttractTime) { selectedCharacterIndex = characterIndex; selectedCharacterId = characterResults.id; selectedPlayerId = characterResults.playerId; maxAttractTime = characterAttractTime; } } } if (selectedCharacterIndex < 0) { return; } // Fill data. string playerName = ""; Sprite playerPortrait = null; Color playerColor = Color.white; { tnCharacterData characterData = tnGameData.GetCharacterDataMain(selectedCharacterId); if (characterData != null) { playerName = characterData.displayName; playerPortrait = characterData.uiIconFacingRight; } tnPlayerData playerData = tnGameData.GetPlayerDataMain(selectedPlayerId); if (playerData != null) { playerColor = playerData.color; } } string statValue = maxAttractTime.ToString(2); statValue += " s"; FP partecipationPercentage = FP.Zero; if (totalAttractTime > FP.Zero) { partecipationPercentage = maxAttractTime / totalAttractTime; partecipationPercentage *= 100f; partecipationPercentage = MathFP.Clamp(partecipationPercentage, FP.Zero, 100f); } string partecipationValue = partecipationPercentage.ToString(2); partecipationValue += "%"; FillData(i_SlotIndex, playerName, playerPortrait, playerColor, s_StatName_AttractTime, statValue, s_PartecipationLabel, partecipationValue); }