Example #1
0
        /*[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 override bool HandleGameEditCommand(SkyPlayer player, GameLevel level, GameLevelInfo gameLevelInfo, params string[] args)
        {
            if (!(gameLevelInfo is MurderLevelInfo murderLevelInfo))
            {
                player.SendMessage("§cThe current levels game info is not in the correct format to be a Murder Level Info.");
                player.SendMessage("§cUpdating as MurderLevelInfo and saving with default options.");

                murderLevelInfo = new MurderLevelInfo(gameLevelInfo.LevelName, gameLevelInfo.WorldTime, gameLevelInfo.LobbyLocation,
                                                      new List <PlayerLocation>(), new List <PlayerLocation>());
            }

            if (args[0].Equals("add"))
            {
                if (args.Length < 2)
                {
                    player.SendMessage("§c/location add <spawn/gunpart>");
                    player.SendMessage("§cNot Enough Arguments.");
                    return(true);
                }

                List <PlayerLocation> locationList = null;
                if (args[1].Equals("spawn"))
                {
                    locationList = murderLevelInfo.PlayerSpawnLocations;
                }
                else if (args[1].Equals("gunpart"))
                {
                    locationList = murderLevelInfo.GunPartLocations;
                }

                if (locationList == null)
                {
                    player.SendMessage($"§cAction invalid. Must be 'spawn' or 'gunpart', but was '{args[1]}'");
                    return(true);
                }

                PlayerLocation addedLocation = (PlayerLocation)player.KnownPosition.Clone();
                addedLocation.X = (float)(Math.Floor(addedLocation.X) + 0.5f);
                addedLocation.Y = (float)Math.Floor(addedLocation.Y);
                addedLocation.Z = (float)(Math.Floor(addedLocation.Z) + 0.5f);

                addedLocation.HeadYaw = (float)Math.Floor(addedLocation.HeadYaw);
                addedLocation.HeadYaw = addedLocation.HeadYaw;
                addedLocation.Pitch   = (float)Math.Floor(addedLocation.Pitch);

                locationList.Add(addedLocation);

                string fileName =
                    $"C:\\Users\\Administrator\\Desktop\\worlds\\{RawName}\\{RawName}-{level.LevelName}.json";

                SkyUtil.log($"Saving as '{fileName}' -> {level.GameType} AND {level.LevelName}");

                File.WriteAllText(fileName, JsonConvert.SerializeObject(gameLevelInfo, Formatting.Indented));

                player.SendMessage($"§cUpdated {args[0]} location list ({locationList.Count}) with current location.");

                //Update current level info
                ((MurderLevel)player.Level).GameLevelInfo = gameLevelInfo;
            }
            else if (args[0].Equals("visualize"))
            {
                if (_currentVisualizationTasks.ContainsKey(player.Username))
                {
                    _currentVisualizationTasks[player.Username].Cancelled = true;

                    _currentVisualizationTasks.Remove(player.Username);

                    player.SendMessage("§eCancelling Visualization Task");
                }
                else
                {
                    player.SendMessage("§eVisualizing Gun Part and Player Spawn Locations...");

                    _currentVisualizationTasks.Add(player.Username, RunnableTask.RunTaskIndefinitely(() =>
                    {
                        foreach (PlayerLocation location in murderLevelInfo.GunPartLocations)
                        {
                            PlayerLocation displayLocation = (PlayerLocation)location.Clone();
                            displayLocation.Y += 0.5f;

                            Vector3 particleLocation = displayLocation.ToVector3();

                            new FlameParticle(player.Level)
                            {
                                Position = particleLocation
                            }.Spawn(new MiNET.Player[] { player });
                        }

                        foreach (PlayerLocation location in murderLevelInfo.PlayerSpawnLocations)
                        {
                            PlayerLocation displayLocation = (PlayerLocation)location.Clone();
                            displayLocation.Y += 0.5f;

                            Vector3 particleLocation = displayLocation.ToVector3();

                            new HeartParticle(player.Level)
                            {
                                Position = particleLocation
                            }.Spawn(new MiNET.Player[] { player });
                        }
                    }, 500));
                }
            }
            else if (args[0].Equals("tp"))
            {
                player.SendMessage("§eTeleporting to a random spawn location");
                player.Teleport(murderLevelInfo.PlayerSpawnLocations[Random.Next(murderLevelInfo.PlayerSpawnLocations.Count)]);
            }
            else
            {
                //Falls through, no specific handling
                return(false);
            }

            //One if-branch was used, this counts enough as usage
            return(true);
        }