public override void HandleLeave(GameLevel gameLevel, SkyPlayer player) { base.HandleLeave(gameLevel, player); if (((MurderLevel)gameLevel).Murderer == player) { //Re-select murderer List <SkyPlayer> players = gameLevel.GetPlayersInTeam(MurderTeam.Innocent); int murdererIdx = Random.Next(players.Count); int i = 0; foreach (SkyPlayer gamePlayer in players) { if (++i == murdererIdx) { gameLevel.SetPlayerTeam(gamePlayer, MurderTeam.Murderer); InitializeMurderer(gamePlayer); gameLevel.DoForAllPlayers(playerLoop => { if (playerLoop == gamePlayer) { return; } TitleUtil.SendCenteredSubtitle(playerLoop, "§fA new §c§lMurderer\n§fhas been selected"); }); break; } } } }
public override void AddSpectator(SkyPlayer player) { player.IsGameSpectator = true; //Set an invisibily effect on top of the scale to completely 'remove' the player player.SetEffect(new Invisibility { Duration = int.MaxValue, Particles = false }); player.SetNameTagVisibility(false); McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.runtimeEntityId = player.EntityId; mcpeSetEntityData.metadata = player.GetMetadata(); mcpeSetEntityData.metadata[(int)Entity.MetadataFlags.Scale] = new MetadataFloat(0.5f); // Scale //Avoid changing the local player's scale foreach (SkyPlayer gamePlayer in GetAllPlayers()) { if (gamePlayer == player) { continue; } gamePlayer.SendPackage(mcpeSetEntityData); } //Update slot held for other players player.Inventory.SetHeldItemSlot(player.Inventory.InHandSlot, false); }
public override void SetPlayerTeam(SkyPlayer player, GameTeam oldTeam, GameTeam team) { if (oldTeam != null) { TeamPlayerDict[oldTeam].Remove(player); } if (team != null) { TeamPlayerDict[team].Add(player); if (team.IsSpectator) { AddSpectator(player); } else { player.IsGameSpectator = false; //Re-update visible characteristics player.RemoveEffect(new Invisibility()); player.BroadcastSetEntityData(); player.SetNameTagVisibility(true); player.Inventory.SetHeldItemSlot(player.Inventory.InHandSlot, false); } } }
public virtual void HandlePlayerChat(SkyPlayer player, string message) { if (PunishCore.GetPunishmentsFor(player.CertificateData.ExtraData.Xuid).HasActive(PunishmentType.Mute)) { player.SendMessage("§c§l(!)§r §cYou cannot chat while you are muted."); return; } message = TextUtils.RemoveFormatting(message); if (message.Length > 200) { player.SendMessage("§c§l(!)§r §cYour message is too long, please shorten it."); return; } /*foreach (char character in message) * { * if (!char.IsLetterOrDigit(character) && !char.IsPunctuation(character) && !char.IsSymbol(character)) * { * player.SendMessage("§c§l(!)§r §cYour message contains invalid characters!"); * return; * } * }*/ string chatColor = ChatColors.White; if (player.PlayerGroup == PlayerGroup.Player) { chatColor = ChatColors.Gray; } player.Level.BroadcastMessage($"{player.GetNameTag(player)}{ChatColors.Gray}: {chatColor}{message}", MessageType.Raw); }
public override bool HandleBlockBreak(GameLevel gameLevel, SkyPlayer player, Block block, List <Item> drops) { BlockCoordinates centreLocation = ((BuildBattleTeam)player.GameTeam).SpawnLocation.GetCoordinates3D(); BlockCoordinates interactLocation = block.Coordinates; return(CanModifyAt(gameLevel, player, centreLocation, interactLocation)); }
public override bool HandleBlockPlace(GameLevel gameLevel, SkyPlayer player, Block existingBlock, Block targetBlock) { BlockCoordinates centreLocation = ((BuildBattleTeam)player.GameTeam).SpawnLocation.GetCoordinates3D(); BlockCoordinates interactLocation = existingBlock.Coordinates; return(CanModifyAt(gameLevel, player, centreLocation, interactLocation)); }
public override void HandleLeave(GameLevel gameLevel, SkyPlayer player) { _afkCheckPlayers.Remove(player); //Simulate removal by setting teams gameLevel.SetPlayerTeam(player, null); }
public void CommandKick(MiNET.Player player, string playerName, string[] reason) { if (!(player is SkyPlayer skyPlayer) || !skyPlayer.PlayerGroup.IsAtLeast(PlayerGroup.Helper)) { player.SendMessage("§c§l(!)§r §cYou do not have permission for this command."); return; } RunnableTask.RunTask(() => { string targetXuid = StatisticsCore.GetXuidForPlayername(playerName); if (targetXuid == null) { player.SendMessage($"§f[PUNISH] §7{playerName} §cis not a Skytonia user."); return; } string punishReason = GetReasonFromArgs(reason); PunishCore.AddKick(targetXuid, punishReason, player.CertificateData.ExtraData.Xuid); SkyPlayer target = SkyCoreAPI.Instance.GetPlayer(playerName); target?.Disconnect($"§cYou have been kicked from the server.\n" + $"§6Reason: {punishReason}"); player.SendMessage($"§f[PUNISH] §7{playerName} §chas been kicked for: §f\"{punishReason}\""); }); }
public ITickableInformation GetTickableInformation(SkyPlayer player) { return(new BuildBattleVoteTickableInformation { NeatTimeRemaining = GetNeatTimeRemaining(GetSecondsLeft()), BuildingPlayer = player }); }
public override void HandleLeave(GameLevel gameLevel, SkyPlayer player) { if (gameLevel.GetGamePlayerCount() <= 2) { //Not enough players for the game to continue! gameLevel.UpdateGameState(new BuildBattlePodiumState(null)); } }
public void ShowEndGameMenu(SkyPlayer player) { var simpleForm = new SimpleForm { Title = GetGameModalTitle(), Content = GetEndOfGameContent(player), Buttons = new List <Button> { new Button { Text = "§2§lPlay Again\n" + "§r§8(Jump into a new game)", Image = new Image { Type = "url", Url = "https://static.skytonia.com/dl/replayiconmenu.png" }, ExecuteAction = delegate { ExternalGameHandler.AddPlayer(player, GameType); } } } }; StateType currentStateType = CurrentState.GetEnumState(this); if (currentStateType != StateType.EndGame && currentStateType != StateType.Closing) { simpleForm.Buttons.Add( new Button { Text = "§6§lSpectate Game\n" + "§r§8(Continue watching this game)", Image = new Image { Type = "url", Url = "https://static.skytonia.com/dl/spectateiconmenu.png" }, ExecuteAction = delegate { SetPlayerTeam(player, GetSpectatorTeam()); } } ); } simpleForm.Buttons.Add( new Button { Text = "§c§lChange Game\n" + "§r§8(Choose a different game)", Image = new Image { Type = "url", Url = "https://static.skytonia.com/dl/comingsooniconmenu.png" }, ExecuteAction = delegate { GameUtil.ShowGameList(player); } } ); player.SendForm(simpleForm); }
private static void RunPunishmentCommand(MiNET.Player player, PunishmentType punishmentType, String playerName, string[] args) { string targetXuid = StatisticsCore.GetXuidForPlayername(playerName); if (targetXuid == null) { player.SendMessage($"§f[PUNISH] §7{playerName} §cis not a Skytonia user."); return; } args = ParseExpiryTime(player, args, out DurationUnit durationUnit, out int durationAmount); if (args == null) { return; //Message printed to player } string punishReason = GetReasonFromArgs(args); DateTime expiry = UpdateExpiryTime(durationUnit, durationAmount); Punishment punishment = new Punishment(punishReason, player.CertificateData.ExtraData.Xuid, true, durationAmount, durationUnit, expiry); PunishCore.AddPunishment(targetXuid, punishmentType, punishment); if (punishmentType == PunishmentType.Ban) { SkyPlayer target = SkyCoreAPI.Instance.GetPlayer(playerName); if (durationUnit == DurationUnit.Permanent) { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been banned permanently for: \"{punishReason}\""); target?.Disconnect(PunishmentMessages.GetPunishmentMessage(target, punishmentType, punishment)); } else { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been banned for: §f{GetNeatDuration(durationAmount, durationUnit)} \"{punishReason}\""); target?.Disconnect(PunishmentMessages.GetPunishmentMessage(target, punishmentType, punishment)); } } else if (punishmentType == PunishmentType.Mute) { SkyPlayer target = SkyCoreAPI.Instance.GetPlayer(playerName); if (durationUnit == DurationUnit.Permanent) { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been muted permanently for: \"{punishReason}\""); target?.SendMessage(PunishmentMessages.GetPunishmentMessage(target, PunishmentType.Mute, punishment)); } else { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been muted for: §f{GetNeatDuration(durationAmount, durationUnit)} \"{punishReason}\""); target?.SendMessage(PunishmentMessages.GetPunishmentMessage(target, PunishmentType.Mute, punishment)); } } }
public GameTeam GetPlayerTeam(SkyPlayer player) { if (PlayerTeamDict.ContainsKey(player.Username)) { return(PlayerTeamDict[player.Username]); } return(GetDefaultTeam()); }
public void SendTickableMessage(GameLevel gameLevel, SkyPlayer player, ITickableInformation tickableInformation) { if (tickableInformation == null) { tickableInformation = GetTickableInformation(player); } player.BarHandler.AddMajorLine( $"{SelectedCategory.ThemeName}§r §7| {((BuildBattleBuildTickableInformation) tickableInformation).NeatTimeRemaining} §fRemaining...§r"); }
private bool DoInteract(GameLevel gameLevel, SkyPlayer player, int interactId) { //SkyUtil.log($"Handling Hub Interacting from {player.Username} ID:{interactId}"); if (player.Inventory.GetItemInHand() is ItemNavigationCompass) { GameUtil.ShowGameList(player); //RunnableTask.RunTaskLater(() => player.Inventory.SetInventorySlot(player.Inventory.InHandSlot, new ItemNavigationCompass()), 250); } return(true); }
public virtual void QueuePlayer(SkyPlayer player) { if (player == null) { return; } if (!QueuedPlayers.Contains(player)) { QueuedPlayers.Enqueue(player); } }
public void InitializeMurderer(SkyPlayer player) { TitleUtil.SendCenteredSubtitle(player, "§c§l Murderer§r\n§7Kill all innocent players!"); player.Inventory.SetInventorySlot(0, new ItemMurderKnife()); player.Inventory.SetInventorySlot(8, new ItemGunParts()); player.Inventory.SetHeldItemSlot(1); //Avoid holding the knife on spawn/select player.HungerManager.Hunger = 20; //Set food to 'able to run' level. player.SendUpdateAttributes(); //PlayerAmmoCounts[player.Username] = 3; //Throwing Knives }
private bool CanModifyAt(GameLevel gameLevel, SkyPlayer player, BlockCoordinates centreLocation, BlockCoordinates interactLocation) { if (Math.Abs(centreLocation.X - interactLocation.X) > PlotRadius || Math.Abs(centreLocation.Z - interactLocation.Z) > PlotRadius || interactLocation.Y < (centreLocation.Y - 5) || interactLocation.Y > MaxHeight) { player.BarHandler.AddMinorLine("§c§l(!)§r §cYou can only build within your build zone §c§l(!)§r"); return(true); } return(false); }
public virtual void HandleHeldItemSlotChange(GameLevel gameLevel, SkyPlayer player, int newHeldItemSlot) { if (this is IMessageTickableState tickableState) { try { tickableState.SendTickableMessage(gameLevel, player, null); } catch (Exception e) { BugSnagUtil.ReportBug(e, this, gameLevel, player); } } }
public override void InitializePlayer(GameLevel gameLevel, SkyPlayer player) { //Runs the join message once the player's permissions have loaded player.AddPostLoginTask(() => { gameLevel.DoForAllPlayers(gamePlayer => { //§f(§e{gameLevel.GetPlayerCount()}/{gameLevel.GetMaxPlayers()}§f) gamePlayer.BarHandler.AddMinorLine($"§e{player.PlayerGroup.Prefix} {player.Username}§r §7entered the game!"); }); }); player.SendPlayerInventory(); }
public static void AddPlayer(SkyPlayer player, string gameName) { if (player == null) { return; } if (!GameRegistrations.ContainsKey(gameName)) { player.SendMessage($"{ChatColors.Red}No game existed for the name '{gameName}'"); return; } RequeuePlayer(player, gameName); }
public virtual bool InstantQueuePlayer(SkyPlayer player, GameInfo gameInfo) { //SkyUtil.log($"Trying to add {QueuedPlayers.Count} players to {GameLevels.Count} games"); lock (GameLevels) { if (!GameLevels.TryGetValue(gameInfo.GameId, out var targetedGame) || !targetedGame.CurrentState.CanAddPlayer(targetedGame)) { return false; } //SkyUtil.log($"(TARGETED) Adding {player.Username} to game {targetedGame.GameId}-({targetedGame.LevelId}-{targetedGame.LevelName})"); targetedGame.AddPlayer(player); return true; } }
public override void SetPlayerTeam(SkyPlayer player, GameTeam oldTeam, GameTeam team) { base.SetPlayerTeam(player, oldTeam, team); if (oldTeam == team) { return; } if (team == MurderTeam.Murderer) { Murderer = player; } else if (team == MurderTeam.Detective) { Detective = player; } //Handle Death else if ((team == null || team == MurderTeam.Spectator) && oldTeam != null) { if (oldTeam == MurderTeam.Innocent || oldTeam == MurderTeam.Detective) { //Check remaining players to see if the game should 'end' if (GetPlayersInTeam(MurderTeam.Innocent, MurderTeam.Detective).Count == 0) { //TODO: End Game UpdateGameState(new MurderEndState()); } else { player.SetEffect(new Blindness { Duration = 60, Particles = false }); //Should be 3 seconds? } } else if (oldTeam == MurderTeam.Murderer) { //TODO: Remove this second check, since if the murderer is changing teams the game must be won? //Check remaining players to see if the game should 'end' if (GetPlayersInTeam(MurderTeam.Murderer).Count == 0) { //TODO: End Game UpdateGameState(new MurderEndState()); } } } }
public static void RequeuePlayer(SkyPlayer player, string gameName) { if (!GameRegistrations.ContainsKey(gameName)) { player.SendMessage($"{ChatColors.Red}No game existed for the name '{gameName}'"); return; } try { GameRegistrations[gameName].AddPlayer(player); } catch (Exception e) { BugSnagUtil.ReportBug(e); } }
public override void HandleDamage(GameLevel gameLevel, Entity source, Entity target, Item item, int damage, DamageCause damageCause) { if (!(target is SkyPlayer) || ((SkyPlayer)target).IsGameSpectator) { return; } if (source is GunProjectile arrow && arrow.Shooter is SkyPlayer) { SkyPlayer shooter = (SkyPlayer)arrow.Shooter; //Ensure this player is alive if (!shooter.IsGameSpectator) { KillPlayer((MurderLevel)gameLevel, (SkyPlayer)target); } }
public override void EnterState(GameLevel gameLevel) { base.EnterState(gameLevel); gameLevel.DoForAllPlayers(player => { player.Inventory.Clear(); player.AddExperience(-1000, true); //Reset gun cooldowns }); //MurderVictoryType victoryType; SkyPlayer murderer = ((MurderLevel)gameLevel).Murderer; //Innocents Win (Murderer Dead) if (gameLevel.GetPlayersInTeam(MurderTeam.Murderer).Count == 0) { //victoryType = MurderVictoryType.MURDERER_DEAD; gameLevel.DoForAllPlayers(player => { TitleUtil.SendCenteredSubtitle(player, $"§a§lInnocents §r§7§lWin§r\n§7{murderer?.Username ?? "An Unknown Player"} §fwas the Murderer!"); }); } //Murderer Wins (Innocents + Detective Dead) else if (gameLevel.GetPlayersInTeam(MurderTeam.Innocent, MurderTeam.Detective).Count == 0) { //victoryType = MurderVictoryType.CONQUEST; gameLevel.DoForAllPlayers(player => { TitleUtil.SendCenteredSubtitle(player, $"§c§lMurderer §r§7§lWins§r\n§7{murderer?.Username ?? "An Unknown Player"} §fwas the Murderer!"); }); } //Innocents Win (Timeout) else { //victoryType = MurderVictoryType.TIMEOUT; gameLevel.DoForAllPlayers(player => { TitleUtil.SendCenteredSubtitle(player, $"§a§lInnocents §r§7Win\n§7{murderer?.Username ?? "An Unknown Player"} §fwas the Murderer!"); }); } }
/*[Command(Name = "gameedit")] * [Authorize(Permission = CommandPermission.Normal)] * public void CommandGameEdit(MiNET.Player player, params string[] args) * { * if (player.CommandPermission < CommandPermission.Admin) * { * player.SendMessage("§c§l(!)§r §cYou do not have permission for this command."); * return; * } * * if (!(player.Level is GameLevel level)) * { * player.SendMessage($"§cYou must be in a {GameName} game to use this command!"); * return; * } * * if (!(level.GameLevelInfo is GameLevelInfo gameLevelInfo)) * { * player.SendMessage("§cThe current level's information could not be loaded."); * return; * } * * if (args[0].Equals("timeleft")) * { * if (args.Length < 2) * { * player.SendMessage("§c/gameedit timeleft <time>"); * return; * } * * if (!int.TryParse(args[1], out var timeRemaining)) * { * player.SendMessage($"§cInvalid time remaining ({args[1]})"); * return; * } * * level.Tick = 0; * ((RunningState)level.CurrentState).EndTick = timeRemaining * 2; * * player.SendMessage($"§eReset in-game timer, and updated end-time to {timeRemaining} seconds"); * } * else if (args[0].Equals("level")) * { * if (args.Length < 2) * { * player.SendMessage("§c/gameedit level <levelname>"); * return; * } * * string fullyQualifiedName = $"C:\\Users\\Administrator\\Desktop\\worlds\\{RawName}\\{args[1]}"; * GameLevel gameLevel; * if (!LevelNames.Contains(fullyQualifiedName) || (gameLevel = InitializeNewGame(fullyQualifiedName)) == null) * { * player.SendMessage($"§cInvalid level name ({args[1]})"); * player.SendMessage($"§cBad Args: \n§c- {string.Join("\n§c- ", LevelNames.Select(x => _removeQualification(x.ToString())).ToArray())}"); * return; * } * * foreach (SkyPlayer gamePlayer in level.GetAllPlayers()) * { * gameLevel.AddPlayer(gamePlayer); * } * * level.UpdateGameState(new VoidGameState()); //'Close' the game eventually * * player.SendMessage($"§cUpdating game level to {args[1]}"); * } * else if (args[0].Equals("nextstate")) * { * GameState nextState = level.CurrentState.GetNextGameState(level); * if (nextState is VoidGameState) * { * player.SendMessage("§cNo Next Available State Available."); * return; * } * * player.SendMessage($"§cProgressing to next state ({level.CurrentState.GetType()} -> {nextState.GetType()})"); * level.UpdateGameState(nextState); * } * else * { * if (!HandleGameEditCommand(player as SkyPlayer, level, gameLevelInfo, args)) * { * player.SendMessage("§c/gameedit timeleft"); * player.SendMessage("§c/gameedit tp"); * player.SendMessage("§c/gameedit nextstate"); * player.SendMessage("§c/gameedit level <level-name>"); * { * string subCommandHelp = GetGameEditCommandHelp(player as SkyPlayer); * if (subCommandHelp != null) * { * player.SendMessage(subCommandHelp); * } * } * player.SendMessage($"§cBad Args: {string.Join(",", args.Select(x => x.ToString()).ToArray())}"); * } * } * }*/ public override bool HandleGameEditCommand(SkyPlayer player, GameLevel gameLevel, GameLevelInfo gameLevelInfo, params string[] args) { if (args[0].Equals("tp")) { if (!(gameLevel is BuildBattleLevel level)) { player.SendMessage("§eWorld is not BuildBattle world!"); return(false); } player.SendMessage("§eTeleporting to a random spawn location"); player.Teleport(level.BuildTeams[Random.Next(level.BuildTeams.Count)].SpawnLocation); } else { return(false); } return(true); }
public virtual GameLevel InstantQueuePlayer(SkyPlayer player, bool join = true) { if (player == null) { if (_isFirstLevelRetrieve) { _isFirstLevelRetrieve = false; //Get Next. Should be used for join. return GameLevels.Values.GetEnumerator().Current; } SkyUtil.log("Attempted to pass null SkyPlayer to InstantQueuePlayer. Bad Join?"); return null; } //SkyUtil.log($"Trying to add {player.Username} player to {GameLevels.Count} games"); lock (GameLevels) { foreach (GameLevel gameLevel in GetMostViableGames()) { if (!gameLevel.CurrentState.CanAddPlayer(gameLevel)) { continue; } if (join) { //SkyUtil.log($"Adding {player.Username} to game {gameLevel.GameId}-({gameLevel.LevelId}-{gameLevel.LevelName})"); gameLevel.AddPlayer(player); } return gameLevel; } //Player shouldn't be here if no games are accessible ExternalGameHandler.AddPlayer(player, "hub"); } return null; }
public static string GetPunishmentMessage(SkyPlayer player, PunishmentType punishmentType, Punishment punishment) { switch (punishmentType) { case PunishmentType.Kick: { return (TextUtils.CenterLine("§d§lSkytonia §f§lNetwork") + "\n" + "\n" + TextUtils.CenterLine("§r§cYou have been kicked from Skytonia!") + "\n" + TextUtils.CenterLine($"§r§7Reason: §f{punishment.PunishReason}") + "\n" + "\n" + TextUtils.CenterLine("§r§7Read our rules at: §e§nwww.skytonia.com/rules")); } case PunishmentType.Ban: { return (TextUtils.CenterLine("§d§lSkytonia §f§lNetwork") + "\n" + "\n" + TextUtils.CenterLine("§r§cYou have been banned from entering Skytonia!") + "\n" + "\n" + (punishment.DurationUnit == DurationUnit.Permanent ? TextUtils.CenterLine($"§r§7Time: §fPermanent") + "\n" : TextUtils.CenterLine($"§r§7Time: §f{GetNeatExpiryForPunishment(punishment)}") + "\n") + TextUtils.CenterLine($"§r§7Reason: §f{punishment.PunishReason}") + "\n" + TextUtils.CenterLine($"§r§7Date: §f{punishment.GetIssueDate()}") + "\n" + "\n" + TextUtils.CenterLine("§r§7Appeal at: §e§nwww.skytonia.com/appeal")); } case PunishmentType.Mute: { return ("§f[PUNISH] §cYou are currently muted from talking in chat.\n" + "§7Read our rules at: §e§nwww.skytonia.com/rules"); } } return(null); }
public override string GetEndOfGameContent(SkyPlayer player) { MurderTeam winningTeam = GetWinningTeam(); //Game still running if (winningTeam == null) { return(""); } return ("\n" + TextUtils.Center("§f§lWinner:§r " + ((MurderTeam)winningTeam).TeamPrefix + winningTeam.DisplayName.ToUpper(), 205) + "\n" + TextUtils.Center("§8§m--------------------§r", 205) + "\n" + TextUtils.Center("§9§lDetective:§r §f" + Detective?.Username, 205) + "\n" + TextUtils.Center("§c§lMurderer:§r §f" + Murderer?.Username, 205) + "\n" + "\n"); }