Пример #1
0
 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));
     }
 }
Пример #2
0
        public override void OnTick(GameLevel gameLevel, int currentTick, out int outTick)
        {
            int currentPlayers  = gameLevel.GetGamePlayerCount(), //Doesn't count incoming players
                requiredPlayers = GetRequiredPlayers(gameLevel);

            string actionBarMessage = null;

            if (currentPlayers < requiredPlayers)
            {
                _startCountdownTick = -1; //Reset the timer

                //Only update action bar every second
                if (currentTick % 2 == 0)
                {
                    actionBarMessage = $"§d§lStarting Soon:§r §7({gameLevel.GetPlayerCount()}/{GetRequiredPlayers(gameLevel)}) §fPlayers Required...";
                }
            }
            else
            {
                if (_startCountdownTick == -1)
                {
                    _startCountdownTick = currentTick;
                }

                //Only update action bar every second
                if (currentTick % 2 == 0)
                {
                    int secondsRemaining = (GetCountdownTicks() - (currentTick - _startCountdownTick)) / 2;
                    if (secondsRemaining <= 0)
                    {
                        if (secondsRemaining == 0)
                        {
                            actionBarMessage = "§d§lGame Starting:§r §fBeginning Now...";

                            gameLevel.UpdateGameState(GetNextGameState(gameLevel));
                        }
                    }
                    else
                    {
                        actionBarMessage = $"§d§lGame Starting:§r §7{secondsRemaining} §fSecond{(secondsRemaining == 1 ? "" : "s")} Remaining...";
                    }
                }
            }

            if (actionBarMessage != null)
            {
                foreach (SkyPlayer player in gameLevel.GetPlayers())
                {
                    player.BarHandler.AddMajorLine(actionBarMessage, 2);
                }
            }

            /*
             * Portal Handler
             */
            if (currentTick % 2 == 0)
            {
                foreach (var player in gameLevel.Players.Values)
                {
                    //Player is not initialized yet.
                    if (player == null || !player.IsConnected || player.KnownPosition == null)
                    {
                        continue;
                    }

                    if (IsInPortal(player.KnownPosition))
                    {
                        PlayerLocation teleportLocation = player.KnownPosition;
                        teleportLocation.Z -= 2;

                        player.Teleport(teleportLocation);

                        try
                        {
                            GameUtil.ShowGameList(player as SkyPlayer);
                        }
                        catch (Exception e)
                        {
                            BugSnagUtil.ReportBug(e, this, player as SkyPlayer);
                        }
                    }
                }
            }

            outTick = currentTick;
        }