void HandlePlayerKilledEvent(KilledEventPayload payload) { var killerScore = currentRoundScores.GetScoreForPlayer <UndeadScore>(payload.playerNumberOfKiller); var killedScore = currentRoundScores.GetScoreForPlayer <UndeadScore>(payload.playerNumberOfKilledPlayer); if (killerScore.Undead && killedScore.Undead) { // Undead player killed another undead player. // This is uninteresting. Won't generate a Scoring event return; } if (payload.playerNumberOfKilledPlayer == payload.playerNumberOfKiller) { // Player killed itself, should become undead. Won't generate a Scoring event killedScore.Undead = true; MakeUndead(PlayerFetcher.FindPlayerByPlayerNumber(killedScore.PlayerNumber())); } else { // Player killed another player. Will generate a Scoring event var scoreForKillV2 = killerScore.Undead ? UndeadKillPoints : AliveKillPoints; killerScore.IncreaseScoreBy(scoreForKillV2); if (!killedScore.Undead) { killedScore.Undead = true; MakeUndead(PlayerFetcher.FindPlayerByPlayerNumber(killedScore.PlayerNumber())); } AFEventManager.INSTANCE.PostEvent(AFEvents.Score(payload.playerNumberOfKiller, killerScore.Score(), killerScore.Score())); } killedScore.Deaths++; if (currentRoundScores.DoTrueForAllCheck(score => ((UndeadScore)score).Undead)) { if (IsEntireGameOver()) { Debug.Log("Game over, all players are undead!"); var winningScoreForRound = currentRoundScores.SortedByDescendingScores()[0]; AFEventManager.INSTANCE.PostEvent(AFEvents.GameOver(winningScoreForRound.PlayerNumber(), winningScoreForRound.Score(), winningScoreForRound.PlayerColor())); } else { Debug.Log("Round over, all players are undead!"); var winningScore = currentRoundScores.SortedByDescendingScores()[0]; AFEventManager.INSTANCE.PostEvent(AFEvents.RoundOver(winningScore.PlayerNumber(), winningScore.Score(), winningScore.PlayerColor())); } } }
private bool HandleKilledEvent(KilledEventPayload payload) { if (payload.playerNumberOfKiller == payload.playerNumberOfKilledPlayer) { // Player killed itself, no score event generated for this... return(false); } var playerScore = currentRoundScores.GetScoreForPlayer <SimpleScore>(payload.playerNumberOfKiller); var newScore = playerScore.IncreaseScoreBy(1); AFEventManager.INSTANCE.PostEvent(AFEvents.Score(payload.playerNumberOfKiller, newScore, maxScore)); if (newScore == maxScore) { countDownTimerInstance.StopTimer(); HandleGameOver(); } //if (playerScores.ContainsKey(payload.playerNumberOfKiller)) //{ // var oldScore = playerScores[payload.playerNumberOfKiller]; // var newScore = oldScore + 1; // playerScores[payload.playerNumberOfKiller] = newScore; // AFEventManager.INSTANCE.PostEvent(AFEvents.Score(payload.playerNumberOfKiller, newScore, maxScore)); // if (newScore == maxScore) // { // countDownTimerInstance.StopTimer(); // HandleGameOver(); // } //} //else //{ // playerScores.Remove(payload.playerNumberOfKilledPlayer); //} return(false); }