/// <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); } } }
/// <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); }); }
/// <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); } } }
/// <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); }
/// <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 } } } }