Ejemplo n.º 1
0
        /// <summary>
        /// Credits a player if they successfully kill another player during the Capture The Flag game.
        ///
        /// NOTE: If the <see cref="MySqlDatabase"/> is not loaded then the kill is not accumulated to the attackers total kill count.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="eventArgs">The arguments for when the player (or players) was/were reset.</param>
        private void OnPlayerReset(CaptureTheFlagBot ctfBot, PlayerResetEventArgs eventArgs)
        {
            if (eventArgs.PlayersReset.Count == 1)
            {
                Player killedPlayer = eventArgs.PlayersReset[0];

                if (killedPlayer.LastAttacker != Player.None)
                {
                    ctfBot.SendPrivateMessage(killedPlayer, $"You were killed by player {killedPlayer.LastAttacker.Username}!");
                    ctfBot.SendPrivateMessage(killedPlayer.LastAttacker, $"You killed player {killedPlayer.Username}!");

                    if (MySqlDatabase.Loaded)
                    {
                        PlayerData playerData = MySqlDatabase.GetRow(killedPlayer.LastAttacker.Username);

                        if (playerData != null)
                        {
                            playerData.Statistics.TotalKills++;
                        }
                    }

                    ctfBot.CurrentGameRound.IncreaseGameFund(GameFundIncreaseReason.PlayerKilledEnemy);
                }

                killedPlayer.LastAttacker = Player.None;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Ends the Capture The Flag game by awarding the winning team with .
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="winningTeam">The team what won the game.</param>
        public void End(CaptureTheFlagBot ctfBot, Team winningTeam)
        {
            ctfBot.SayChatMessage($"Game over! Team {winningTeam.GetStringName()} has won the game.");

            int coinsWon = GetGameFundShare(ctfBot.JoinedWorld.Players, winningTeam);

            foreach (Player player in ctfBot.JoinedWorld.Players.Values)
            {
                PlayerData playerData = MySqlDatabase.GetRow(player.Username);

                if (playerData != null && player.IsPlayingGame)
                {
                    if (player.Team == winningTeam)
                    {
                        playerData.Statistics.TotalWins++;
                        playerData.Statistics.Coins += coinsWon;

                        ctfBot.SendPrivateMessage(player, $"You received {coinsWon} coin{(coinsWon == 1 ? "" : "s")} for winning!");
                    }
                    else
                    {
                        playerData.Statistics.TotalLosses++;
                    }
                }
            }

            ResetRoundStatistics();
            MySqlDatabase.Save();

            ctfBot.ResetLevel();
        }
 /// <summary>
 /// Event handler for when a player leaves the Everybody Edits world. This method removes the player from the <see cref="m_lastPlayerTickMs"/> dictionary if they exist
 /// in it.
 /// </summary>
 /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
 /// <param name="player">The player that left the world.</param>
 private void OnPlayerLeft(CaptureTheFlagBot ctfBot, Player player)
 {
     if (m_lastPlayerTickMs.ContainsKey(player))
     {
         m_lastPlayerTickMs.Remove(player);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles a player if they tap left or right on a block with the id of <see cref="DoorBlockId"/>.
        /// </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 (ctfBot.JoinedWorld.Blocks == null || !player.IsPlayingGame || player.IsInGodMode || player.IsPressingSpacebar)
            {
                return;
            }

            if (IsDelayOver(player))
            {
                bool handled;

                if (handled = (player.Location.X > 0 &&
                               player.HorizontalDirection == HorizontalDirection.Left &&
                               ctfBot.JoinedWorld.Blocks[(uint)BlockLayer.Foreground, player.Location.X - 1, player.Location.Y].Id == DoorBlockId)) // Teleport to left
                {
                    ctfBot.TeleportPlayer(player, player.Location.X - 2, player.Location.Y);
                }
                else if (handled = (player.Location.X < ctfBot.JoinedWorld.Width &&
                                    player.HorizontalDirection == HorizontalDirection.Right &&
                                    ctfBot.JoinedWorld.Blocks[(uint)BlockLayer.Foreground, player.Location.X + 1, player.Location.Y].Id == DoorBlockId)) // Teleport to right
                {
                    ctfBot.TeleportPlayer(player, player.Location.X + 2, player.Location.Y);
                }

                if (handled) // Player successfully was teleported
                {
                    UpdatePlayerCurrentTick(player);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles players fighting in the Capture The Flag game.
        /// </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.IsPlayingGame || player.IsInGodMode)
            {
                return;
            }

            foreach (Player enemyPlayer in ctfBot.JoinedWorld.Players.Values)
            {
                if (player == enemyPlayer)
                {
                    continue;
                }

                if (player.IsEnemiesWith(enemyPlayer) && player.IsNearPlayer(enemyPlayer))
                {
                    enemyPlayer.Attack(player);

                    HandleHealthStatusWarning(ctfBot, enemyPlayer);

                    if (enemyPlayer.Health <= 0)
                    {
                        enemyPlayer.Die(ctfBot);
                    }
                }
            }
        }
        /// <summary>
        /// Abstract class which keeps track of <see cref="Player"/> time ticks, in milliseconds.
        /// </summary>
        /// <param name="delayMs">The delay in milliseconds all players must wait in order to perform an action again.</param>
        public DelayedAction(CaptureTheFlagBot ctfBot, int delayMs)
        {
            DelayMs            = delayMs;
            m_lastPlayerTickMs = new Dictionary <Player, long>();

            ctfBot.OnPlayerJoined += OnPlayerJoined;
            ctfBot.OnPlayerLeft   += OnPlayerLeft;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Main entry point of the program.
        /// </summary>
        static void Main()
        {
            Console.Title = ProgramTitle;
            Console.WriteLine($"{TitleArt}\n");
            Console.WriteLine("Type \"help\" for a list of commands.\n");

            CaptureTheFlagBot ctfBot = new CaptureTheFlagBot();

#nullable enable
Ejemplo n.º 8
0
        /// <summary>
        /// Handles a player cheating if they enter God mode. A player is considered cheating when they are holding the enemy flag their <see cref="Player.IsInGodMode"/> status
        /// is set to true.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player to be handled.</param>
        private void OnGodModeToggled(CaptureTheFlagBot ctfBot, Player player)
        {
            // Remove flag from player if they have the enemy flag and enter God mode
            if (player.IsPlayingGame && player.IsInGodMode && player.HasEnemyFlag(ctfBot))
            {
                ctfBot.SayChatMessage($"ANTI-CHEAT! Player {player.Username} has used God mode while carrying the {player.Team.GetOppositeTeam().GetStringName()} teams flag!");

                ctfBot.FlagSystem.Flags[player.Team.GetOppositeTeam()].Return(ctfBot, null, false);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// States whether a player can dig left in the Everybody Edits world or not.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player to be checked whether they can dig left or not.</param>
        /// <param name="blockId">The diggable block id.</param>
        /// <returns>True if the player can dig left, if not, false.</returns>
        private bool CanDigLeft(CaptureTheFlagBot ctfBot, Player player, int blockId)
        {
            if (ctfBot.JoinedWorld.Blocks is null)
            {
                return(false);
            }

            return(player.HorizontalDirection == HorizontalDirection.Left &&
                   player.Location.X > 0 &&
                   ctfBot.JoinedWorld.Blocks[(uint)BlockLayer.Foreground, player.Location.X - 1, player.Location.Y].Id == blockId);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// States whether a player can dig down in the Everybody Edits world or not.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player to be checked whether they can dig down or not.</param>
        /// <param name="blockId">The diggable block id.</param>
        /// <returns>True if the player can dig down, if not, false.</returns>
        private bool CanDigDown(CaptureTheFlagBot ctfBot, Player player, int blockId)
        {
            if (ctfBot.JoinedWorld.Blocks is null)
            {
                return(false);
            }

            return(player.VerticalDirection == VerticalDirection.Down &&
                   player.Location.Y < ctfBot.JoinedWorld.Height &&
                   ctfBot.JoinedWorld.Blocks[(uint)BlockLayer.Foreground, player.Location.X, player.Location.Y + 1].Id == blockId);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Handles all traps in the Everybody Edits worlds. Traps can only be triggered when certain conditions are met. Refer to <see cref="Trap.CanTriggerTrap(Player)"/>
        /// for more information.
        /// </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)
        {
            foreach (Trap trap in traps)
            {
                if (!IsPlayerOnTrapTrigger(player, trap))
                {
                    continue;
                }

                trap.Handle(ctfBot, player);
            }
        }
        /// <summary>
        /// Notifies a player via a private message if they wear a special smiley.
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player to be handled.</param>
        private void OnSmileyChanged(CaptureTheFlagBot ctfBot, Player player)
        {
            if (!player.IsPlayingGame)
            {
                return;
            }

            if (HealSystem.CanHealTeammates(player))
            {
                ctfBot.SendPrivateMessage(player, "You are now a healer for your team!");
            }
            else if (DigSystem.WearingDiggableSmiley(player))
            {
                ctfBot.SendPrivateMessage(player, "You can now dig dirt in the world!");
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Handles the trap that is located in the blue teams base. This trap can only be activated by the blue team.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player that is triggering the trap.</param>
        public override void Handle(CaptureTheFlagBot ctfBot, Player player)
        {
            if (!CanTriggerTrap(player))
            {
                return;
            }

            Task.Run(async() =>
            {
                TrapActivated = true;

                // Close gate
                ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(45, 135), Blocks.Foreground.Caution);
                ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(45, 136), Blocks.Foreground.Caution);

                // Pour lava
                for (int i = 132; i <= 136; i++)
                {
                    ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(47, i), Blocks.Foreground.Lava);
                    ctfBot.PlaceBlock(BlockLayer.Background, new Point(47, i), Blocks.Background.DarkOrangeLava);

                    await Task.Delay(100);
                }

                await Task.Delay(TrapCooldownMs);

                // Remove lava
                for (int i = 132; i <= 136; i++)
                {
                    ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(47, i), Blocks.None);
                    ctfBot.PlaceBlock(BlockLayer.Background, new Point(47, i), Blocks.Background.BrownBrick);

                    await Task.Delay(100);
                }

                // Open gate
                ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(45, 135), Blocks.None);
                ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(45, 136), Blocks.None);

                await Task.Delay(TrapCooldownMs);

                TrapActivated = false;
            });
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Handles all warp pipes in the Everybody Edits. If a player presses down on the block id <see cref="WarpPipeEntranceBlockId"/>, they they are teleported down
        /// one block.
        /// </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 (ctfBot.JoinedWorld.Blocks == null || !player.IsPlayingGame)
            {
                return;
            }

            if (IsDelayOver(player))
            {
                if (player.Location.Y < ctfBot.JoinedWorld.Height &&
                    player.VerticalDirection == VerticalDirection.Down &&
                    ctfBot.JoinedWorld.Blocks[(uint)BlockLayer.Foreground, player.Location.X, player.Location.Y + 1].Id == WarpPipeEntranceBlockId)
                {
                    ctfBot.TeleportPlayer(player, player.Location.X, player.Location.Y + 1);

                    UpdatePlayerCurrentTick(player);
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Handles the trap that is located in the red teams base. This trap can only be activated by the red team.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player that is triggering the trap.</param>
        public override void Handle(CaptureTheFlagBot ctfBot, Player player)
        {
            if (!CanTriggerTrap(player))
            {
                return;
            }

            Task.Run(async() =>
            {
                TrapActivated = true;

                // Close gate
                ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(354, 135), Blocks.Foreground.Caution);
                ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(354, 136), Blocks.Foreground.Caution);

                // Remove bridge
                for (int x = 347; x <= 353; x++)
                {
                    ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(x, 137), Blocks.None);

                    await Task.Delay(100);
                }

                await Task.Delay(TrapCooldownMs);

                // Show bridge
                for (int x = 347; x <= 353; x++)
                {
                    ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(x, 137), Blocks.Foreground.FactoryWood);

                    await Task.Delay(100);
                }

                // Remove gate
                ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(354, 135), Blocks.None);
                ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(354, 136), Blocks.None);

                await Task.Delay(TrapCooldownMs);

                TrapActivated = false;
            });
        }
        /// <summary>
        /// Respawns a player in the Capture The Flag game. If this method is called on a player that is either not playing or is respawning then this method does nothing. The
        /// location where the player respawns depends on their team.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player to respawn.</param>
        private void RespawnPlayer(CaptureTheFlagBot ctfBot, Player player)
        {
            if (!player.IsPlayingGame || player.IsRespawning)
            {
                return;
            }

            player.RestoreHealth();

            Task.Run(async() =>
            {
                Point respawnCooldownLocation = player.Team == Team.Blue ? BlueRespawnCooldownLocation : RedRespawnCooldownLocation;
                ctfBot.TeleportPlayer(player, respawnCooldownLocation.X, respawnCooldownLocation.Y);

                await Task.Delay(RespawnCooldownMs);

                Point respawnLocation = player.Team == Team.Blue ? BlueCheckpointLocation : RedCheckpointLocation;
                ctfBot.TeleportPlayer(player, respawnLocation.X, respawnLocation.Y);
            });
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Handles the daily bonus system. If the player is eligible to receive a daily bonus, they are rewarded N coins defined in the <see cref="CoinsAwardAmount"/>
        /// variable.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player to be handled.</param>
        private void OnPlayerJoined(CaptureTheFlagBot ctfBot, Player player)
        {
            if (MySqlDatabase.Loaded && MySqlDatabase.PlayerExists(player.Username))
            {
                PlayerData playerData = MySqlDatabase.GetRow(player.Username);

                if (playerData != null && DateTime.Today > playerData.LastVisitDate)
                {
                    playerData.Statistics.Coins += CoinsAwardAmount;
                    playerData.LastVisitDate     = DateTime.Today;

                    Task.Run(async() =>
                    {
                        await Task.Delay(PrivateMessageDelayMs);

                        ctfBot.SendPrivateMessage(player, $"Daily bonus! You have been awarded {CoinsAwardAmount} coins for revisiting the world.");
                    });
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Handles the trap that is located in the lava lake. This trap can be activated by both the blue team and the red team, however, the player must be wearing the Fire Demon
        /// smiley.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player that is triggering the trap.</param>
        public override void Handle(CaptureTheFlagBot ctfBot, Player player)
        {
            if (!CanTriggerTrap(player))
            {
                return;
            }

            if (!TrapActivated)
            {
                Task.Run(async() =>
                {
                    ctfBot.SendPrivateMessage(player, "You triggered a secret trap!");

                    TrapActivated = true;

                    // Place wall
                    for (int y = 133; y >= 129; y--)
                    {
                        ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(259, y), Blocks.Foreground.Caution);
                        ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(306, y), Blocks.Foreground.Caution);

                        await Task.Delay(100);
                    }

                    await Task.Delay(TrapCooldownMs);

                    // Remove wall
                    for (int y = 129; y <= 133; y++)
                    {
                        ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(259, y), Blocks.None);
                        ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(306, y), Blocks.None);

                        await Task.Delay(100);
                    }

                    await Task.Delay(TrapCooldownMs);

                    TrapActivated = false;
                });
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Handles a player cheating if they take an effect they did not legally purchase in the <see cref="Shop"/>. If there are at least two zombies or more in the
        /// Everybody Edits world then the anti-cheat system does not check for zombie cheaters.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="eventArgs">The arguments for when the player received/lost an effect.</param>
        private void OnEffectToggled(CaptureTheFlagBot ctfBot, EffectToggledEventArgs eventArgs)
        {
            if (!ctfBot.FinishedInit || !eventArgs.IsEffectEnabled || eventArgs.Effect == Effect.Fire)
            {
                return;
            }

            if (eventArgs.Effect == Effect.Zombie && ctfBot.JoinedWorld.TotalZombiePlayers >= 2 ||
                eventArgs.Effect == Effect.Curse && DateTimeOffset.Now.ToUnixTimeMilliseconds() - ctfBot.JoinedWorld.LastCurseRemoveTickMs <= CurseEnabledMessageMs)
            {
                return;
            }

            if (eventArgs.Effect != eventArgs.Player.PurchasedEffectFlag)
            {
                ctfBot.KickPlayer(eventArgs.Player.Username, "You were auto kicked for attemping to cheat!");
            }

            // Reset the flag variable
            eventArgs.Player.PurchasedEffectFlag = Effect.None;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Handles team balance in the Capture The Flag game. If a player joins a team with more players than the other team, then they are transferred to the other team
        /// with less players.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player to be handled.</param>
        private void OnTeamChanged(CaptureTheFlagBot ctfBot, Player player)
        {
            if (!player.IsPlayingGame)
            {
                return;
            }

            string resultMsg = $"You joined the {player.Team.GetStringName()} team!";
            int    joinedTeamTotalPlayers   = GetTeamPlayersCount(ctfBot.JoinedWorld.Players, player.Team) - 1;
            int    oppositeTeamTotalPlayers = GetTeamPlayersCount(ctfBot.JoinedWorld.Players, player.Team.GetOppositeTeam());

            if (joinedTeamTotalPlayers > oppositeTeamTotalPlayers)
            {
                resultMsg = "Unbalanced teams! You have been transferred to the other team!";

                Point teleLocation = player.Team == Team.Blue ? RespawnSystem.RedCheckpointLocation : RespawnSystem.BlueCheckpointLocation;
                ctfBot.TeleportPlayer(player, teleLocation.X, teleLocation.Y);
            }

            ctfBot.SendPrivateMessage(player, resultMsg);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Places a firework above teams flag. This method should only be called when a player captures a flag. This method will throw an exception if the
        /// team is set to <see cref="Team.None"/>.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="team">The team that captured the flag.</param>
        private void CelebrateCapture(CaptureTheFlagBot ctfBot, Team team)
        {
            if (team == Team.None)
            {
                throw new Exception("Unsupported team type!");
            }

            Task.Run(async() =>
            {
                MorphableBlock firework = team == Team.Blue ? Blocks.Foreground.BlueFirework : Blocks.Foreground.RedFirework;
                Point placeLocation     = (team == Team.Blue ? Flags[Team.Blue].HomeLocation : Flags[Team.Red].HomeLocation);

                await Task.Delay(500);

                placeLocation.Offset(0, -3);
                ctfBot.PlaceBlock(BlockLayer.Foreground, placeLocation, firework);

                await Task.Delay(1000);

                ctfBot.PlaceBlock(BlockLayer.Foreground, placeLocation, Blocks.None);
            });
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Handles a player digging in during the Capture The Flag game.
        /// </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 (ctfBot.JoinedWorld.Blocks == null || !player.IsPlayingGame || player.IsInGodMode || player.IsPressingSpacebar || !WearingDiggableSmiley(player))
            {
                return;
            }

            if (IsDelayOver(player))
            {
                bool handled;

                foreach (int blockId in m_diggableBlocks)
                {
                    if (handled = CanDigLeft(ctfBot, player, blockId))
                    {
                        ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(player.Location.X - 1, player.Location.Y), Blocks.Foreground.SlowGravityDot);
                    }
                    else if (handled = CanDigRight(ctfBot, player, blockId))
                    {
                        ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(player.Location.X + 1, player.Location.Y), Blocks.Foreground.SlowGravityDot);
                    }
                    else if (handled = CanDigUp(ctfBot, player, blockId))
                    {
                        ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(player.Location.X, player.Location.Y - 1), Blocks.Foreground.SlowGravityDot);
                    }
                    else if (handled = CanDigDown(ctfBot, player, blockId))
                    {
                        ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(player.Location.X, player.Location.Y + 1), Blocks.Foreground.SlowGravityDot);
                    }

                    if (handled) // Player digged a block successfully
                    {
                        UpdatePlayerCurrentTick(player);

                        break; // No need to check the other blocks
                    }
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Sends a player a private message if their health is at a certain level. The private message is to warn them that they are close to being killed by an enemy player.
        /// </summary>
        /// <param name="ctfBot">The Capture The Flag bot instance.</param>
        /// <param name="player">The player to warn about their health.</param>
        private void HandleHealthStatusWarning(CaptureTheFlagBot ctfBot, Player player)
        {
            string healthDescription = string.Empty;

            switch (player.Health)
            {
            case 35:
                healthDescription = "low";
                break;

            case 10:
                healthDescription = "critically low";
                break;
            }

            if (healthDescription != string.Empty)
            {
                string msg = $"Warning! Your health is {healthDescription} ({player.Health} HP).";

                ctfBot.SendPrivateMessage(player, msg);
            }
        }
Ejemplo n.º 24
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);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Handles when a player wants to purchase an item at the shop in the Everybody Edits world. All shop items are defined in the <see cref="m_shopItems"/> array.
        /// </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 (!MySqlDatabase.Loaded || !player.IsPlayingGame || player.IsInGodMode || player.VerticalDirection != VerticalDirection.Down)
            {
                return;
            }

            PlayerData playerData = MySqlDatabase.GetRow(player.Username);

            if (playerData != null)
            {
                foreach (ShopItem shopItem in m_shopItems)
                {
                    if (player.Location == shopItem.PurchaseLocation) // Player wants to purchase an item
                    {
                        string msgResult = "You don't have enough coins to purchase this item.";

                        if (playerData.Statistics.Coins >= shopItem.Cost)
                        {
                            playerData.Statistics.Coins -= shopItem.Cost;
                            msgResult = $"You have successfully bought the {shopItem.Name} for {shopItem.Cost} coin{(playerData.Statistics.Coins == 1 ? "" : "s")}.";

                            // Set flag variable for the anti-cheat system
                            if (m_effectNameMap.ContainsValue(shopItem.Name))
                            {
                                player.PurchasedEffectFlag = m_effectNameMap.FirstOrDefault(x => x.Value == shopItem.Name).Key;
                            }

                            ctfBot.TeleportPlayer(player, shopItem.PurchaseTeleportLocation.X, shopItem.PurchaseTeleportLocation.Y);
                        }

                        ctfBot.SendPrivateMessage(player, msgResult);

                        break; // Player attempted to purchase the item, no need to check the other shop items
                    }
                }
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Handles the bridge trap. This trap can be activated by both the blue team and the red team.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="player">The player that is triggering the trap.</param>
        public override void Handle(CaptureTheFlagBot ctfBot, Player player)
        {
            if (!base.CanTriggerTrap(player))
            {
                return;
            }

            if (!TrapActivated)
            {
                Task.Run(async() =>
                {
                    TrapActivated = true;

                    // Remove bridge
                    for (int x = 94; x <= 105; x++)
                    {
                        ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(x, 137), Blocks.None);

                        await Task.Delay(100);
                    }

                    await Task.Delay(TrapCooldownMs);

                    // Place bridge
                    for (int x = 94; x <= 105; x++)
                    {
                        ctfBot.PlaceBlock(BlockLayer.Foreground, new Point(x, 137), Blocks.Foreground.FactoryWood);

                        await Task.Delay(100);
                    }

                    await Task.Delay(TrapCooldownMs);

                    TrapActivated = false;
                });
            }
        }
        /// <summary>
        /// Handles the respawn system for the Capture The Flag game. The respawn system teleports a player to their respective respawn cooldown location, which depends on
        /// which team they are currently on. If a player is holding the flag and this method gets called, then the flag that they're holding is returned to its base.
        /// </summary>
        /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
        /// <param name="eventArgs">The arguments for when the player (or players) was/were reset.</param>
        private void OnPlayerReset(CaptureTheFlagBot ctfBot, PlayerResetEventArgs eventArgs)
        {
            if (!eventArgs.PropertiesReset)
            {
                foreach (Player player in eventArgs.PlayersReset)
                {
                    if (player.HasEnemyFlag(ctfBot))
                    {
                        Team enemyTeam = player.Team.GetOppositeTeam();

                        if (ctfBot.FlagSystem.Flags[enemyTeam].Holder == player)
                        {
                            ctfBot.SayChatMessage($"Player {player.Username} died while holding {enemyTeam.GetStringName()} teams flag.");

                            ctfBot.FlagSystem.Flags[enemyTeam].Return(ctfBot, null, false);
                        }

                        ctfBot.RemoveEffects(player);
                    }

                    RespawnPlayer(ctfBot, player);
                }
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Handles a player trying to heal their teammate(s).
        /// </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.IsPlayingGame || player.IsInGodMode || !CanHealTeammates(player))
            {
                return;
            }

            foreach (Player allyPlayer in ctfBot.JoinedWorld.Players.Values)
            {
                if (player == allyPlayer)
                {
                    continue;
                }

                if (!player.IsEnemiesWith(allyPlayer) && player.IsNearPlayer(allyPlayer) && allyPlayer.Health < 100)
                {
                    if (allyPlayer.Heal())
                    {
                        ctfBot.SendPrivateMessage(allyPlayer, $"You were healed player {player.Username}");
                        ctfBot.SendPrivateMessage(player, $"You fully healed player {allyPlayer.Username}");
                    }
                }
            }
        }
 /// <summary>
 /// Game mechanic which handles players changing their smiley to a special smiley. This class only notified players via a private message if they wear a special smiley.
 /// A special smiley is able to perform a unique trait in the Capture The Flag game. For example, the nurse smiley can heal teammates.
 /// </summary>
 /// <param name="ctfBot">The <see cref="CaptureTheFlagBot"/> instance.</param>
 public SmileyRoleNotification(CaptureTheFlagBot ctfBot)
 {
     ctfBot.OnSmileyChanged += OnSmileyChanged;
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Handles a trap in the Everybody Edits worlds. Implementation will vary.
 /// </summary>
 /// <param name="ctfBot">The Capture The Flag bot instance.</param>
 /// <param name="player">The player to be handled.</param>
 public abstract void Handle(CaptureTheFlagBot ctfBot, Player player);