Esempio n. 1
0
        /// <summary>
        /// OnTick, keeps track of dead/alive players in-game. Starts and stops the game when needed.
        /// </summary>
        /// <returns></returns>
        private async Task ManageNetworkGame()
        {
            maxPlayers = players.Count() > 2 ? players.Count() : 2;

            if (gameStarted)
            {
                if (playersAlive.Count <= 1 || new PlayerList().Count() < 2)
                {
                    var newTime = new Random().Next(0, 2) == 1 ? 12 : 0;
                    TriggerClientEvent("Sumo:FinishGame", playersAlive[0], newTime);
                    gameStarted  = false;
                    playersAlive = new List <string>();
                    players      = new PlayerList();
                    readyPlayers = new List <string>();
                }
            }
            else
            {
                players = new PlayerList();

                if (readyPlayers.Count() >= players.Count() && players.Count() == maxPlayers)
                {
                    foreach (Player p in players)
                    {
                        if (!readyPlayers.Contains(p.Handle))
                        {
                            Debug.WriteLine("Not enough players, somehow...");
                            return;
                        }
                    }

                    await LoadNextMap();

                    if (!gameStarted)
                    {
                        await Delay(1000);

                        var    map = Exports["mapmanager"].getCurrentMap();
                        string suddenDeathCenter = GetResourceMetadata(map, "sudden_death_coords_data_extra", 0) ?? "{\"x\":0.0,\"z\":0.0,\"y\":0.0";

                        suddenDeathCenter = suddenDeathCenter.Replace('}', ',');
                        float x = float.Parse(suddenDeathCenter.Split('x')[1].Split(':')[1].Split(',')[0]);
                        float y = float.Parse(suddenDeathCenter.Split('y')[1].Split(':')[1].Split(',')[0]);
                        float z = float.Parse(suddenDeathCenter.Split('z')[1].Split(':')[1].Split(',')[0]);
                        Debug.Write($"x:{x}\r\ny:{y}\r\nz:{z}\r\n");
                        TriggerClientEvent("Sumo:StartGame", map, x, y, z);
                        round++;
                        await Delay(4500);

                        gameStarted = true;
                        foreach (Player p in players)
                        {
                            playersAlive.Add(p.Handle);
                        }
                    }
                }
                await Delay(0);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        public SumoServer()
        {
            players      = new PlayerList();
            readyPlayers = new List <string>();
            playersAlive = new List <string>();
            maxPlayers   = players.Count() > 2 ? players.Count() : 2;

            EventHandlers.Add("Sumo:MarkReady", new Action <Player>(MarkPlayerReady));
            EventHandlers.Add("playerDropped", new Action <Player>(RemovePlayer));
            EventHandlers.Add("Sumo:RemovePlayer", new Action <Player>(RemovePlayer));
            EventHandlers.Add("Sumo:EndGameTimer", new Action(EndGame));
            Tick += ManageNetworkGame;
            RegisterCommand("vehicle", new Action <int, List <object>, string>(SetVehicle), false);
        }
Esempio n. 3
0
        //Getting random target from online players
        Ped GetRandomTarget()
        {
            //Get the list of players
            PlayerList pl = new PlayerList();

            if (pl.Count <Player>() < 1)
            {
                return(null);
            }

            //Get random player, his Ped and name
            int randomInt = rnd.Next(0, pl.Count <Player>());
            Ped targetPed = pl.ElementAt(randomInt).Character;

            if (pl.ElementAt(randomInt) != null)
            {
                assasinationTargetName = pl.ElementAt(randomInt).Name;
            }

            int i = 0;

            //Retry to set the target if it has selected itself or selected target is dead
            while (targetPed == Game.PlayerPed || pl.ElementAt(randomInt).Character.IsDead)
            {
                randomInt = rnd.Next(0, pl.Count <Player>());
                targetPed = pl.ElementAt(randomInt).Character;
                if (pl.ElementAt(randomInt) != null)
                {
                    assasinationTargetName = pl.ElementAt(randomInt).Name;
                }

                //After 20 tries - abandon
                i++;
                if (i > 20)
                {
                    return(null);
                }
            }

            //Return null if model has not been changed (is still set to Skater01AMY or Skater02AMY)
            //It may happen if player has just spawned and his model hasnt been changed to a random one
            //due to the model load delay
            if (targetPed.Model.GetHashCode().ToString() == "-1342520604" || targetPed.Model.GetHashCode().ToString() == "-1044093321")
            {
                return(null);
            }

            //Return target player ped
            return(targetPed);
        }
Esempio n. 4
0
 private bool IsGameOver(int score)
 {
     if (Test !.ImmediatelyEndGame)
     {
         return(true);
     }
     if (score == 13 && PlayerList.Count() == 2)
     {
         return(true);
     }
     if (score == 9 && PlayerList.Count() == 3)
     {
         return(true);
     }
     if (score == 7 && PlayerList.Count() == 4)
     {
         return(true);
     }
     if (score == 6 && PlayerList.Count() == 5)
     {
         return(true);
     }
     if (score == 5 && PlayerList.Count() == 6)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 5
0
        /// <summary>
        /// Get the Information about the Player
        /// </summary>
        /// <returns></returns>
        public PlayerInfoModel GetNextPlayerInList()
        {
            // Walk the list from top to bottom
            // If Player is found, then see if next player exist, if so return that.
            // If not, return first player (looped)

            // If List is empty, return null
            if (PlayerList.Count == 0)
            {
                return(null);
            }

            // No current player, so set the first one
            if (CurrentAttacker == null)
            {
                return(PlayerList.FirstOrDefault());
            }

            // Find current player in the list
            var index = PlayerList.FindIndex(m => m.Guid.Equals(CurrentAttacker.Guid));

            // If at the end of the list, return the first element
            if (index == PlayerList.Count() - 1)
            {
                return(PlayerList.FirstOrDefault());
            }

            // Return the next element
            return(PlayerList[index + 1]);
        }
        public override async Task EndTurnAsync()
        {
            int oldTurn;

            oldTurn = WhoTurn;
            WhoTurn = await PlayerList !.CalculateWhoTurnAsync(true);
            int howMany = PlayerList.Count(Items => Items.NumberOfRolls == 0);

            if (howMany == 1)
            {
                SingleInfo = PlayerList.GetWhoPlayer();
                var FirstList = PlayerList.ToCustomBasicList();
                FirstList.RemoveSpecificItem(SingleInfo);
                if (FirstList.Any(Items => Items.Score <= 21) == false)
                {
                    await ShowWinAsync();

                    return;
                }
            }
            else if (howMany == 0)
            {
                await StartEndAsync();

                return;
            }
            await StartNewTurnAsync();
        }
Esempio n. 7
0
        private bool GroupAcceptable()
        {
            int x;
            int howmany;
            int y;

            for (x = 1; x <= 3; x++)
            {
                for (y = 1; y <= 2; y++)
                {
                    howmany = _saveRoot !.PlayerList.Count(Items => Items.Table == x && Items.Team == y);

                    if (howmany != 2)
                    {
                        return(false);
                    }
                }
            }
            int mate;

            foreach (var tempPlayer in _saveRoot !.PlayerList)
            {
                mate = FindTeamPlayer(tempPlayer.Id, true); // i think because 0 based
                if (mate == tempPlayer.PreviousMate)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 8
0
        protected override async Task ComputerTurnAsync()
        {
            if (Test !.NoAnimations == false)
            {
                await Delay !.DelaySeconds(.5);
            }
            if (SaveRoot !.RemovePairs == false && SaveRoot.NumberAsked == false)
            {
                if (PlayerList.Count() == 2)
                {
                    await _processes.NumberToAskAsync(_ai.NumberToAsk(SaveRoot));

                    return;
                }
                throw new BasicBlankException("Only 2 players are supported now");
            }
            var thisList = _ai.PairToPlay(SaveRoot);

            if (thisList.Count == 0)
            {
                await EndTurnAsync();

                return;
            }
            if (thisList.Count != 2)
            {
                throw new BasicBlankException("Needed one pair to remove.  Rethink");
            }
            await ProcessPlayAsync(thisList.First().Deck, thisList.Last().Deck);
        }
Esempio n. 9
0
 public override async Task SetUpGameAsync(bool isBeginning)
 {
     if (IsLoaded == false)
     {
         LoadUpDominos();
         if (PlayerList.Count() == 3)
         {
             DominosToPassOut = 7;
         }
         else if (PlayerList.Count() == 4)
         {
             DominosToPassOut = 5;
         }
         else if (PlayerList.Count() == 5)
         {
             DominosToPassOut = 4;
         }
         else
         {
             throw new BasicBlankException("Has to have 3 to 5 players");
         }
     }
     PlayerList !.ForEach(items =>
     {
         items.TotalScore = 0;
         items.DrewYet    = false;
     });
     if (Test !.DoubleCheck == false)
     {
         SaveRoot !.UpTo = 0;
     }
Esempio n. 10
0
        private void Scoring(int knocks, int wins, CustomBasicList <int> scoreList)
        {
            int scores;

            for (int x = 1; x <= PlayerList.Count(); x++)
            {
                if (knocks == 0)
                {
                    scores = scoreList[x - 1];
                }
                else if (knocks > 0 && wins == knocks && knocks == x)
                {
                    scores = 0;
                }
                else if (knocks > 0 && wins != knocks && knocks == x)
                {
                    scores  = scoreList[x - 1];
                    scores *= 2;
                }
                else
                {
                    scores = scoreList[x - 1];
                }

                var thisPlayer = PlayerList ![x];
Esempio n. 11
0
        private bool AcceptPlacement(int table, int team, bool firstMove, int oldMate = -1)
        {
            int howmany;

            if (firstMove == false)
            {
                if (oldMate == -1)
                {
                    throw new Exception("Need to know the old team mate since this is not the first move");
                }
                return(true);
            }
            ;
            howmany = _saveRoot !.PlayerList.Count(Items => Items.Table == table);
            if (howmany == 4)
            {
                return(false);
            }
            howmany = _saveRoot.PlayerList.Count(Items => Items.Table == table && Items.Team == team);
            if (howmany == 2)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 12
0
        // Grabs the next player up to bat
        public PlayerInfo GetNextPlayerInList()
        {
            // Walk the list from top to bottom
            // If Player is found, then see if next player exist, if so return that.
            // If not, return first player (looped)

            // No current player, so set the last one, so it rolls over to the first...
            if (PlayerCurrent == null)
            {
                PlayerCurrent = PlayerList.LastOrDefault();
            }

            // Else go and pick the next player in the list...
            for (var i = 0; i < PlayerList.Count(); i++)
            {
                if (PlayerList[i].Guid == PlayerCurrent.Guid)
                {
                    if (i < PlayerList.Count() - 1) // 0 based...
                    {
                        return(PlayerList[i + 1]);
                    }
                    else
                    {
                        // Return the first in the list...
                        return(PlayerList.FirstOrDefault());
                    }
                }
            }

            return(null);
        }
 private async Task SecondPlayerDidNotGoOutAsync()
 {
     if (PlayerList.Count() > 2)
     {
         throw new BasicBlankException("If there are more than 2 players; then a second person must go out");
     }
     await ScoreRoundAsync();
 }
Esempio n. 14
0
        private void UpdateTitle()
        {
            if (cardScaleform == null)
            {
                return;
            }

            cardScaleform.CallFunction("SET_TITLE", $"FiveM ({playerList.Count()})", $"Page {playerListCurPage}/{playerListMaxPage}");
        }
 protected override bool CanEnablePile1()
 {
     if (_mainGame !.PlayerList.Count() > 2)
     {
         return(!_gameContainer.AlreadyDrew);
     }
     if (_mainGame.SaveRoot !.ExtraTurns < 4)
     {
         return(!_gameContainer.AlreadyDrew);
     }
     return(false);
 }
 private void LoadControls()
 {
     if (IsLoaded == true)
     {
         return;
     }
     if (PlayerList.Count() == 2)
     {
         _model !.Dummy1 !.FirstDummy();
     }
     IsLoaded = true; //i think needs to be here.
 }
Esempio n. 17
0
        private void ActivateTrain()
        {
            var players = new PlayerList();

            if (!TrainSpawned && players.Count() == 1)
            {
                // Should be some way to check if they're the arbitrator?
                TriggerClientEvent(players.First(), @"virakal:startTrain");
                Debug.WriteLine("Starting the trains.");
                TrainSpawned = true;
            }
            else
            {
                // Rerun in 15 seconds
                Task.Delay(15000).ContinueWith((task) => ActivateTrain());

                if (players.Count() == 0)
                {
                    TrainSpawned = false;
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Get the Information about the Player
        /// </summary>
        /// <returns></returns>
        public PlayerInfoModel GetNextPlayerInList()
        {
            // Walk the list from top to bottom
            // If Player is found, then see if next player exist, if so return that.
            // If not, return first player (looped)

            // If List is empty, return null
            if (PlayerList.Count == 0)
            {
                return(null);
            }

            // No current player, so set the first one
            if (PlayerCurrent == null)
            {
                return(PlayerList.FirstOrDefault());
            }

            // Find current player in the list
            //Commenting out untill we figuere out if we need a GUID.
            var index = PlayerList.FindIndex(m => m.Guid.Equals(PlayerCurrent.Guid));

            // If at the end of the list, return the first element
            if (index == PlayerList.Count() - 1)
            {
                return(PlayerList.FirstOrDefault());
            }

            // Return the next element
            return(PlayerList[index + 1]);

            //// Else go and pick the next player in the list...
            //for (var i = 0; i < PlayerCount; i++)
            //{
            //    // Look for current Player in the list
            //    if (PlayerList[i].Guid.Equals(PlayerCurrent.Guid))
            //    {
            //        if (i < PlayerList.Count() - 1) // 0 based...
            //        {
            //            return PlayerList[i + 1];
            //        }
            //        else
            //        {
            //            // Return the first in the list...
            //            return PlayerList.FirstOrDefault();
            //        }
            //    }
            //}

            //            return null;
        }
Esempio n. 19
0
        private void FirstLoad()
        {
            int highest;

            if (PlayerList.Count() < 5)
            {
                highest = 12;
            }
            else
            {
                highest = 15;
            }
            _model.TrainStation1 !.Self = PlayerList !.GetSelf().Id;
            _model.TrainStation1.LoadPlayers(highest, this);
        }
Esempio n. 20
0
        public async void Loop()
        {
            if (Game.IsControlJustPressed(0, Control.MultiplayerInfo))
            {
                playerListCurPage = DEFAULT_PAGE;

                if (playerListOpen)
                {
                    Debug.WriteLine("Close Player List");
                    if (cardScaleform != null)
                    {
                        cardScaleform.Dispose();
                        cardScaleform = null;
                    }

                    Audio.PlaySoundFrontend(CLOSE_SOUND_NAME);
                }
                else
                {
                    Debug.WriteLine("Open Player List");
                    playerList = new PlayerList();
                    await GetPlayerHeadshots(playerList);

                    playerListMaxPage = (int)Math.Ceiling((double)playerList.Count() / PLAYERS_PER_PAGE);

                    cardScaleform = new Scaleform("mp_mm_card_freemode");
                    while (!cardScaleform.IsLoaded)
                    {
                        await BaseScript.Delay(0);
                    }
                    Debug.WriteLine($"IsScaleformLoaded: {cardScaleform}");

                    UpdateTitle();
                    UpdateCard();

                    Audio.PlaySoundFrontend(OPEN_SOUND_NAME);
                }

                playerListOpen = !playerListOpen;
            }

            if (playerListOpen)
            {
                API.SetScriptGfxAlign(76, 84);
                API.DrawScaleformMovie(cardScaleform.Handle, 0.122f, 0.3f, 0.28f, 0.6f, 255, 255, 255, 255, 0);
                API.ResetScriptGfxAlign();
            }
        }
        public static Player GetPlayerFromArgs(string arg, PlayerList pl)
        {
            int id;

            if (Int32.TryParse(arg, out id))
            {
                return(pl[id]);
            }

            if (pl.Count(x => x.Name == arg) == 0)
            {
                return(null);
            }

            return(pl.Single(x => x.Name == arg));
        }
        public async Task GameOverAsync(int teamWon)
        {
            if (PlayerList.Count() <= 3)
            {
                SingleInfo = PlayerList.Single(items => items.Team == teamWon);
                await ShowWinAsync();

                return;
            }
            StrCat cats = new StrCat();

            PlayerList !.ForConditionalItems(thisplayer => thisplayer.Team == teamWon, thisPlayer =>
            {
                cats.AddToString(thisPlayer.NickName, ",");
            });
            await ShowWinAsync(cats.GetInfo());
        }
Esempio n. 23
0
        public async void OpenPlayerList()
        {
            playerList = new PlayerList();
            await GetPlayerHeadshots(playerList);

            playerListMaxPage = (int)Math.Ceiling((double)playerList.Count() / PLAYERS_PER_PAGE);

            cardScaleform = new Scaleform("mp_mm_card_freemode");
            while (!cardScaleform.IsLoaded)
            {
                await BaseScript.Delay(0);
            }

            UpdateTitle();
            UpdateCard();

            Audio.PlaySoundFrontend("OPEN_SOUND_NAME");
        }
Esempio n. 24
0
        private static async void Emit(OutboundMessage message)
        {
            _logger.Trace($"Fire: \"{PrintOutboundMessage(message)}\"");

            // Marshall back to the main thread in order to use a native call.
            await BaseScript.Delay(0);

            if (message.Target != null)
            {
                _logger.Trace($"TriggerClientEvent: Using PlayerList with {(_players.Count() > 1 ? "players" : "player")}");
                BaseScript.TriggerClientEvent(_players[message.Target.Handle], message.Event, message.Pack());
            }
            else
            {
                _logger.Trace("TriggerClientEvent: All clients");
                BaseScript.TriggerClientEvent(message.Event, message.Pack());
            }
        }
 public static void Bring([FromSource] Player source, int bringId)
 {
     try
     {
         var targetPlayer = new PlayerList().Where(p => p.Handle == bringId.ToString());
         if (targetPlayer.Count() > 0)
         {
             Log.Debug($"[DEVTOOLS] Player '{source.Name}' brought '{targetPlayer.First().Name}'");
             BaseScript.TriggerClientEvent(targetPlayer.First(), "Dev.Bring", source.Handle);
         }
         else
         {
             Log.Debug($"[DEVTOOLS] Player '{source.Name}' tried to bring somebody but ID '{bringId}' matched nobody");
         }
     }
     catch (Exception ex)
     {
         Log.Error($"DevTools.DebugSource exception: {ex.Message}");
     }
 }
        public override async Task StartNewTurnAsync()
        {
            await base.StartNewTurnAsync();

            SingleInfo = PlayerList !.GetWhoPlayer();
            if (PlayerList.Count() == 2 && SaveRoot !.FirstPlayerWentOut > 0)
            {
                SaveRoot.ExtraTurns++;
            }
            if (SingleInfo.MainHandList.Count == 0)
            {
                LeftToDraw  = 5;
                _wasStarted = true;
                await DrawAsync();

                return;
            }
            _wasStarted = false;
            await ContinueTurnAsync(); //most of the time, continue turn.  can change to what is needed
        }
Esempio n. 27
0
        private static async Task TimeSync()
        {
            await Delay(8500);

            var plList = new PlayerList();

            Appi.MySql.ExecuteQuery("UPDATE monitoring SET online = '" + plList.Count() + "', last_update='" + Main.GetTimeStamp() + "' where id = '1'");

            if (DateTime.Now.Hour == 11 && DateTime.Now.Minute == 23)
            {
                Server.Sync.Data.Reset(-9999, "IsBlackoutTimeOut");
            }

            if (DateTime.Now.Hour == 3 && DateTime.Now.Minute == 50)
            {
                TriggerClientEvent("ARP:SendPlayerNotification", "Рестарт сервера через 15 минут");
            }
            if (DateTime.Now.Hour == 3 && DateTime.Now.Minute == 59)
            {
                TriggerClientEvent("ARP:SendPlayerNotification", "Рестарт сервера через 5 минут");
            }
            if (DateTime.Now.Hour == 4 && DateTime.Now.Minute == 4)
            {
                Appi.MySql.ExecuteQuery("DELETE FROM items WHERE owner_type = 0 AND timestamp_update < '" + (Main.GetTimeStamp() - (60 * 60 * 24 * 7)) + "'");
                Appi.MySql.ExecuteQuery("DELETE FROM items WHERE owner_type = 9 AND owner_id = 2 AND timestamp_update < '" + (Main.GetTimeStamp() - (60 * 60 * 24 * 7)) + "'");

                if (Main.ServerName != "Venus")
                {
                    foreach (var pl in new PlayerList())
                    {
                        pl.Drop("RESTART. Wait 5 min.");
                    }
                }

                Appi.MySql.ExecuteQuery("UPDATE users SET is_online='0'");
                Appi.MySql.ExecuteQuery("UPDATE monitoring SET online = '0', last_update='0' where id = '1'");
            }

            VirtualWorldToClient();
        }
Esempio n. 28
0
        public async void Loop()
        {
            if (Game.IsControlJustPressed(0, Control.MultiplayerInfo))
            {
                playerListCurPage = DEFAULT_PAGE;

                if (playerListOpen)
                {
                    ClosePlayerList();
                }
                else
                {
                    playerList = new PlayerList();
                    await GetPlayerHeadshots(playerList);

                    playerListMaxPage = (int)Math.Ceiling((double)playerList.Count() / PLAYERS_PER_PAGE);

                    cardScaleform = new Scaleform("mp_mm_card_freemode");
                    while (!cardScaleform.IsLoaded)
                    {
                        await BaseScript.Delay(0);
                    }

                    UpdateTitle();
                    UpdateCard();

                    Audio.PlaySoundFrontend("OPEN_SOUND_NAME");
                }

                playerListOpen = !playerListOpen;
            }

            if (playerListOpen && Game.IsControlJustPressed(0, Control.InteractionMenu))
            {
                ClosePlayerList();
                playerListOpen = !playerListOpen;
            }
        }
        static public async Task PlayerCountUpdate(int remoteCount)
        {
            int localCount = playerList.Count();

            if (localCount < remoteCount)
            {
                if (lastCheckFailed)
                {
                    BaseScript.TriggerEvent("Chat.Message", "INSTANCED", "#FF0000", "The playercount as reported by your local client is lower than the one reported by the server. You will be dropped in 60 seconds.");
                    await BaseScript.Delay(60000);

                    BaseScript.TriggerServerEvent("InstancingChecker.RequestDrop");
                }
                else
                {
                    lastCheckFailed = true;
                }
            }
            else
            {
                lastCheckFailed = false;
            }
        }
Esempio n. 30
0
        PlayerList QuickSortBestHand(PlayerList myPlayers)
        {
            Player pivot;
            Random ran = new Random();

            if (myPlayers.Count() <= 1)
                return myPlayers;
            pivot = myPlayers[ran.Next(myPlayers.Count())];
            myPlayers.Remove(pivot);

            var less = new PlayerList();
            var greater = new PlayerList();
            // Assign values to less or greater list
            foreach (Player player in myPlayers)
            {
                if (HandCombination.getBestHand(new Hand(player.getHand())) > HandCombination.getBestHand(new Hand(pivot.getHand())))
                {
                    greater.Add(player);
                }
                else if (HandCombination.getBestHand(new Hand(player.getHand())) <= HandCombination.getBestHand(new Hand(pivot.getHand())))
                {
                    less.Add(player);
                }
            }
            // Recurse for less and greaterlists
            var list = new PlayerList();
            list.AddRange(QuickSortBestHand(greater));
            list.Add(pivot);
            list.AddRange(QuickSortBestHand(less));
            return list;
        }
 }                                                 //maybe here.
 internal void LoadDiscards()
 {
     if (_gameContainer !.PlayerList.Count() == 2)
     {
         _gameContainer.MaxDiscard = 5;
     }