Exemplo n.º 1
0
        /// <summary>
        /// Handles a player trying to capture, return, or take a flag in the Capture The Flag game. If the <see cref="MaxScoreToWin"/> is reached once a flag is captured,
        /// then the game is ended via the <see cref="CtfGameRound.End(CaptureTheFlagBot, Team)"/> method.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player to be handled.</param>
        private void OnPlayerMoved(CaptureTheFlagBot ctfBot, Player player)
        {
            if (player.IsInGodMode || !player.IsPlayingGame)
            {
                return;
            }

            Flag friendlyFlag = Flags[player.Team];
            Flag enemyFlag    = Flags[player.Team.GetOppositeTeam()];

            if (enemyFlag.CanBeCapturedBy(player, friendlyFlag))
            {
                enemyFlag.Capture(ctfBot);

                ctfBot.CurrentGameRound.Scores[player.Team]++;
                ctfBot.CurrentGameRound.IncreaseGameFund(GameFundIncreaseReason.FlagCaptured);
                ctfBot.SayChatMessage(ctfBot.CurrentGameRound.GetScoresString());

                if (ctfBot.CurrentGameRound.Scores[player.Team] >= MaxScoreToWin)
                {
                    ctfBot.CurrentGameRound.End(ctfBot, player.Team);
                }
                else
                {
                    CelebrateCapture(ctfBot, player.Team);
                }
            }
            else if (enemyFlag.CanBeTakenBy(player))
            {
                enemyFlag.Take(ctfBot, player);

                ctfBot.CurrentGameRound.IncreaseGameFund(GameFundIncreaseReason.FlagTaken);
            }
            else if (friendlyFlag.CanBeReturnedBy(player))
            {
                friendlyFlag.Return(ctfBot, player, false);
            }
        }