Example #1
0
 private void ResetGame()
 {
     IsRunning = false;
     _questionAskingStarted = false;
     CurrentPlayers.Clear();
     _automatedActionSystem.RemoveAction(_messageHint1);
     _automatedActionSystem.RemoveAction(_messageHint2);
     _automatedActionSystem.RemoveAction(_oneTimeActionEndingQuestion);
 }
 public void Refresh()
 {
     CurrentPlayers.Clear();
     CurrentVessels.Clear();
     Subspaces.Clear();
     CurrentPlayers.AddRange(ServerContext.Clients.Values.Select(v => v.PlayerName));
     CurrentVessels.AddRange(VesselStoreSystem.CurrentVessels.Values.Select(v => new VesselInfo(v)));
     Subspaces.AddRange(WarpContext.Subspaces.Values);
 }
 public void Refresh()
 {
     CurrentPlayers.Clear();
     CurrentVessels.Clear();
     Subspaces.Clear();
     StartTime = TimeContext.StartTime;
     CurrentPlayers.AddRange(ServerContext.Clients.Values.Select(v => v.PlayerName));
     CurrentVessels.AddRange(VesselStoreSystem.CurrentVessels.Values.Select(v => new VesselInfo(v)));
     Subspaces.AddRange(WarpContext.Subspaces.Values);
     BytesUsed = Environment.WorkingSet;
 }
Example #4
0
 /// <summary>
 /// Resets the server information.
 /// </summary>
 public void Reset()
 {
     CurrentPlayers.Clear();
     CurrentServerGameState    = QlGameStates.Unspecified;
     CurrentServerGameType     = QlGameTypes.Unspecified;
     CurrentServerId           = string.Empty;
     CurrentServerAddress      = string.Empty;
     IsQlConnectedToServer     = false;
     PlayerFollowedForAccuracy = string.Empty;
     ScoreBlueTeam             = 0;
     ScoreRedTeam = 0;
     Log.Write("Reset server information.", _logClassType, _logPrefix);
 }
Example #5
0
        protected virtual void ProcessJsonEvent(JObject evt)
        {
            var eventName = (string)evt["event"];

            CommunicationLogger.LogDebug("received event {EventName}", eventName);

            bool playNow = false;

            switch (eventName)
            {
            case CurrentPlayerEventName:
            {
                // my turn? not my turn? (legacy)
                var currentPlayer = (string)evt["player"];
                playNow = (currentPlayer == ConnectionManager.MyNickname);
                break;
            }

            case CurrentPlayerOrderEventName:
            {
                // my turn? not my turn?
                var upcomingPlayers = (JArray)evt["order"];
                playNow    = ((string)upcomingPlayers[0] == ConnectionManager.MyNickname);
                NextPlayer = (upcomingPlayers.Count > 1)
                        ? (string)upcomingPlayers[1]
                        : null;
                // if upcomingPlayers.Count <= 2, then NextPlayer == PreviousPlayer
                PreviousPlayer = (upcomingPlayers.Count > 2)
                        ? (string)upcomingPlayers.Last
                        : null;
                // if upcomingPlayers.Count <= 2, then NextButOnePlayer == me
                NextButOnePlayer = (upcomingPlayers.Count > 2)
                        ? (string)upcomingPlayers[2]
                        : null;
                CurrentPlayers.Clear();
                CurrentPlayers.UnionWith(upcomingPlayers.Select(tok => (string)tok));
                break;
            }

            case CardCountsEventName:
            {
                var cardCounts = (JArray)evt["counts"];
                CurrentCardCounts.Clear();
                foreach (var playerAndCount in cardCounts.OfType <JObject>())
                {
                    var player = (string)playerAndCount["player"];
                    var count  = (int)playerAndCount["count"];
                    CurrentCardCounts[player] = count;
                }
                break;
            }

            case TopCardEventName:
            {
                var currentCardName = (string)evt["current_card"];
                TopCard = CardUtils.ParseColorAndValue(currentCardName).Value;
                break;
            }

            case HandInfoEventName:
            {
                var handCards = (JArray)evt["hand"];
                CurrentHand = handCards
                              .Select(e => CardUtils.ParseColorAndValue((string)e))
                              .Where(cav => cav.HasValue)
                              .Select(cav => cav.Value)
                              .ToList();
                if (LastHandCount > 0 && Config.ManyCardsCurseThreshold > 0 && CurrentHand.Count - LastHandCount >= Config.ManyCardsCurseThreshold)
                {
                    StrategyLogger.LogDebug("cursing because of overfilled hand");
                    Curse();
                }
                LastHandCount = CurrentHand.Count;
                break;
            }

            case CardDrawnEventName:
            {
                var player = (string)evt["player"];
                if (player == ConnectionManager.MyNickname)
                {
                    playNow = true;
                }
                break;
            }
            }

            if (playNow)
            {
                PlayACard();
            }
        }
Example #6
0
 public void ClearPlayerList()
 {
     CurrentPlayers.Clear();
     ComPlayerAmount   = 0;
     HumanPlayerAmount = 0;
 }
Example #7
0
        public static void Update(IMongoDatabase db)
        {
            //            db.DropCollection("Games");
            //            db.DropCollection("W1Games");
            //            db.DropCollection("RunningGames");
            db.DropCollection("GameWeeks");
            Ladder.Clear();
            CurrentPlayers.Clear();
            OldPlayers.Clear();

// Have to get them piecemeal because we've hit the limit of how many games snellman will return
            List <Game> AllGames = GetGamesFromSnellman("FireIceLadderW0%")
                                   .Concat(GetGamesFromSnellman("FireIceLadderW1%"))
                                   .Concat(GetGamesFromSnellman("FireIceLadderW2%"))
                                   .Concat(GetGamesFromSnellman("FireIceLadderW3%"))
                                   .Concat(GetGamesFromSnellman("FireIceLadderW4%"))
                                   .Concat(GetGamesFromSnellman("FireIceLadderW5%"))
                                   .Concat(GetGamesFromSnellman("FireIceLadderW6%"))
                                   .Concat(GetGamesFromSnellman("FireIceLadderW7%"))
                                   .Concat(GetGamesFromSnellman("FireIceLadderW8%"))
                                   .Concat(GetGamesFromSnellman("FireIceLadderW9%"))
                                   .ToList();


            // First create GameWeek 1

            GameWeek GW1 = new GameWeek();

            GW1.Name            = "Week 1";
            GW1.ProcessingOrder = 1;
            GW1.Games           = new List <Game>();

            List <Game> FinishedW1Games = AllGames.Where(x => (x.WeekNumber == 1 && x.finished == 1 && x.aborted == 0))
                                          .OrderByDescending(x => x.seconds_since_update).ToList();


            foreach (Game GameData in FinishedW1Games)
            {
                ProcessGame(GameData);
                GameData.index = GW1.Games.Count();
                GW1.Games.Add(GameData);
            }

            for (int rank = 1; rank < 5; rank++)
            {
                foreach (Game GameData in FinishedW1Games)
                {
                    foreach (GamePlayer gameplayer in GameData.GamePlayers.Where(x => x.rank == rank && x.dropped != 1).OrderBy(x => x.playername))
                    {
                        Ladder.Add(new LadderPlayer(gameplayer.playername, Ladder.Count() + 1));
                    }
                }
            }


            GW1.Ladder = Ladder;
            SaveGameWeek(GW1, db);
            foreach (LadderPlayer LadderPlayer in Ladder)
            {
                LadderPlayer.OldPosition = LadderPlayer.Position;
            }


            // Now gameweeks 2 - 7

            int      i         = 2;
            GameWeek CurrentGW = new GameWeek();

            CurrentGW.ProcessingOrder = i;
            CurrentGW.Name            = "Week ~" + i.ToString();
            CurrentGW.Games           = new List <Game>();
            foreach (Game GameData in AllGames.Where(x => (x.aborted == 0 && x.WeekNumber > 1 && x.WeekNumber < 8))
                     .OrderByDescending(x => x.seconds_since_update))
            {
                ProcessGame(GameData);

                if (CurrentGW.Games.Count() > 15)
                {
                    CurrentGW.Ladder = Ladder;
                    SaveGameWeek(CurrentGW, db);
                    foreach (LadderPlayer LadderPlayer in Ladder)
                    {
                        LadderPlayer.OldPosition = LadderPlayer.Position;
                    }
                    i = Math.Min(7, i + 1);
                    CurrentGW.Name = "Week ~" + i.ToString();
                    CurrentGW.Games.Clear();
                    CurrentGW.ProcessingOrder = i;
                }
                GameData.index = CurrentGW.Games.Count();
                CurrentGW.Games.Add(GameData);


                if (GameData.finished == 1)
                {
                    AddGameToLadder(GameData);
                }
            }
            CurrentGW.Ladder = Ladder;
            SaveGameWeek(CurrentGW, db);
            foreach (LadderPlayer LadderPlayer in Ladder)
            {
                LadderPlayer.OldPosition = LadderPlayer.Position;
            }


            // Now gameweeks 8+
            int CurrentWeekNumber = 8;

            CurrentPlayers            = AllGames.Where(x => (x.aborted == 0 && x.WeekNumber == CurrentWeekNumber)).SelectMany(x => x.usernames).ToList();
            CurrentGW.ProcessingOrder = CurrentWeekNumber;
            CurrentGW.Name            = "Week " + CurrentWeekNumber.ToString();
            CurrentGW.Games.Clear();
            foreach (Game GameData in AllGames.Where(x => (x.aborted == 0 && x.WeekNumber >= 8 && x.WeekNumber < 38))
                     .OrderBy(x => x.WeekNumber).ThenByDescending(x => x.GameNumber))
            {
                ProcessGame(GameData);

                if (GameData.WeekNumber != CurrentWeekNumber)
                {
                    CurrentGW.Ladder = PurgeNonPlayers(Ladder, AllGames, CurrentWeekNumber);
                    SaveGameWeek(CurrentGW, db);
                    foreach (LadderPlayer LadderPlayer in Ladder)
                    {
                        LadderPlayer.OldPosition = LadderPlayer.Position;
                    }
                    CurrentWeekNumber = GameData.WeekNumber;
                    CurrentPlayers    = AllGames.Where(x => (x.aborted == 0 && x.WeekNumber == CurrentWeekNumber)).SelectMany(x => x.usernames).ToList();
                    CurrentGW.Name    = "Week " + CurrentWeekNumber.ToString();
                    CurrentGW.Games.Clear();
                    CurrentGW.ProcessingOrder = CurrentWeekNumber;
                }

                GameData.index = CurrentGW.Games.Count();
                CurrentGW.Games.Add(GameData);


                if (GameData.finished == 1)
                {
                    AddGameToLadder(GameData);
                }
            }

            CurrentGW.Ladder = PurgeNonPlayers(Ladder, AllGames, CurrentWeekNumber);
            SaveGameWeek(CurrentGW, db);
            foreach (LadderPlayer LadderPlayer in Ladder)
            {
                LadderPlayer.OldPosition = LadderPlayer.Position;
            }


            // Now gameweeks 38 onwards
            // Process all games in a gameweek at once and then order everyone properly at the end
            // No longer purge or drop down non players - just hide them somehow (probably in the front end)
            while (true)
            {
                CurrentWeekNumber += 1;
                CurrentGW.Games    = AllGames.Where(x => (x.aborted == 0 && x.WeekNumber == CurrentWeekNumber)).OrderBy(x => x.GameNumber).ToList();
                if (CurrentGW.Games.Count == 0)
                {
                    break;
                }
                CurrentGW.Name            = "Week " + CurrentWeekNumber.ToString();
                CurrentGW.ProcessingOrder = CurrentWeekNumber;
                int InitialLadderSize = Ladder.Max(x => x.Playing ? x.Position : 0);
                if (InitialLadderSize == 0)
                {
                    InitialLadderSize = Ladder.Max(x => x.Position);
                }
                foreach (LadderPlayer LP in Ladder)
                {
                    LP.Playing     = false;
                    LP.OldPosition = LP.Position;
                    // see note below
                    if (CurrentWeekNumber == 38)
                    {
                        LP.TemporaryPositionDouble = LP.Position;
                    }
                }

                foreach (Game GameData in CurrentGW.Games.OrderByDescending(x => x.GameNumber))
                {
                    ProcessGame(GameData);
                    GameData.index = 0 - GameData.GameNumber;
                    UpdateLadderBasedOnGame(GameData, InitialLadderSize + 1);
                }

                // then put everyone in the right place on the ladder
                // NOTE that for GW 38 we have to account for the fact everyone's moving a long way up the ladder. This means moving non-players up too, hence the "|| CurrentWeekNumber = 38". This works because we've set their temporary position above too.
                int newpos = 1;
                foreach (LadderPlayer LadderPlayer in Ladder.Where(x => x.Playing || CurrentWeekNumber == 38).OrderBy(x => x.TemporaryPositionDouble).ThenBy(x => x.OldPosition).ThenBy(x => x.Games.Last().Value.GameNumber).ThenBy(x => x.Games.Count()))
                {
                    LadderPlayer.Position = newpos;
                    if (LadderPlayer.Playing)
                    {
                        newpos++;
                    }
                }

                CurrentGW.Ladder = Ladder;
                SaveGameWeek(CurrentGW, db);
            }
        }
Example #8
0
 private void ResetGame()
 {
     IsRunning = false;
     _questionAskingStarted = false;
     CurrentPlayers.Clear();
 }