Пример #1
0
        /// <summary>
        /// 47 00
        /// </summary>
        /// <param name="game"></param>
        public void Create(Game game)
        {
            #region Gera ROOM_NUMBER
            ushort room_number = 2;
            while (Games.Any(g => g.GameId == room_number))
            {
                room_number += 1;
            }

            //Obtém um Room_Number ainda não utilizado
            game.GameId = room_number;

            //Atualiza room_number do player
            //game.Players.GetAll().First().GameID = room_number;

            #endregion

            //Adiciona GAME
            Games.Add(game);

            _lobby.Players.ToList().ForEach(player =>
            {
                player.SendResponse(GameAction(game, GameActionEnum.CREATE));
            });
        }
Пример #2
0
        private void UpdatePlayerRatingsCore()
        {
            if (Games.Any())
            {
                Players.ForEach(player => player.Rating = Constants.BaseRating);

                (double WinnerUpdatedRating, double LoserUpdatedRating)updatedRatings;
                var ratingCalculator = new RatingCalculator(kFactor: 100, baseRating: Constants.BaseRating);

                foreach (Game game in Games)
                {
                    updatedRatings = ratingCalculator.GetNewRatings(game.WasAStalemate, game.Winner.Rating, game.Loser.Rating);

                    Players.First(player => player.RankOnLoad == game.Winner.RankOnLoad).Rating = updatedRatings.WinnerUpdatedRating;
                    Players.First(player => player.RankOnLoad == game.Loser.RankOnLoad).Rating  = updatedRatings.LoserUpdatedRating;
                }
            }
            else
            {
                foreach (Player player in Players)
                {
                    player.Rating = Constants.BaseRating;
                }
            }

            Players = Players.OrderByDescending(player => player.Rating).ThenBy(player => player.FirstName).ToList();

            for (int i = 0; i < Players.Count; i++)
            {
                Players[i].CurrentRank = i + 1;
            }
        }
Пример #3
0
        private async Task OnGetDataCommand()
        {
            _logger.Info("Getting supported games");

            if (Games == null)
            {
                Games = new ObservableCollection <GameModule>();
            }

            var supportedGames = _gameModuleCatalog.GameModules;

            foreach (var game in supportedGames)
            {
                if (Games.Any(x => x.Module == game.Module))
                {
                    continue;
                }

                game.InstalledLocation = await GameLocator.Find(game.Title);

                game.PropertyChanged += Game_PropertyChanged;
                Games.Add(game);
            }

            RaisePropertyChanged(nameof(Games));
            ContinueCommand.RaiseCanExecuteChanged();
        }
Пример #4
0
        public bool AddGame(long gameId)
        {
            if (Games.Any(q => q.GameId == gameId))
            {
                return(false);
            }

            _games.Add(new OrderGame(gameId));
            DomainEvents.Add(new GameRemovedFromOrderEvent(Id, gameId));
            return(true);
        }
Пример #5
0
 /// <summary>
 /// Outputs the message if the Tournament is completed or not.
 /// </summary>
 public void Completed()
 {
     if (Games != null)
     {
         if (Games.Any(g => !g.Completed))
         {
             Console.WriteLine("Tournament is in progress.");
         }
         else
         {
             Console.WriteLine("Tournament is completed.");
         }
     }
 }
Пример #6
0
        /// <summary>
        /// Helper method, handles logic for adding a Game to this Match.
        /// Adds the Game to the list, updates score and finished status.
        /// Also sorts the Games list by GameNumber.
        /// If the Match is finished or not ready, an exception is thrown.
        /// If the new GameNumber is already present, an exception is thrown.
        /// If the Game has invalid (negative) score, an exception is thrown.
        /// </summary>
        /// <param name="_game">Game to add</param>
        /// <returns>Model of added Game</returns>
        private GameModel AddGame(IGame _game)
        {
            if (!IsReady)
            {
                throw new InactiveMatchException
                          ("Cannot add games to an inactive match!");
            }
            if (IsFinished && !IsManualWin)
            {
                throw new InactiveMatchException
                          ("Cannot add games to a finished match!");
            }
            if (PlayerSlot.unspecified == _game.WinnerSlot)
            {
                throw new NotImplementedException
                          ("No tie games allowed / enter a winner slot!");
            }
            if (_game.Score[0] < 0 || _game.Score[1] < 0)
            {
                throw new ScoreException
                          ("Score cannot be negative!");
            }
            if (Games.Any(g => g.GameNumber == _game.GameNumber))
            {
                throw new DuplicateObjectException
                          ("Match already contains duplicate game data!");
            }

            // If the Match is a "Manual Win," Games can still be added,
            // though the score will NOT be updated.
            if (!IsFinished)
            {
                if (PlayerSlot.Defender == _game.WinnerSlot ||
                    PlayerSlot.Challenger == _game.WinnerSlot)
                {
                    // The AddWin method handles the logic of updating the Match.
                    // Call this to update the score and match status:
                    AddWin(_game.WinnerSlot);
                }
            }

            // Add the new Game to the list and sort it, then return a Model:
            Games.Add(_game);
            Games.Sort((first, second) => first.GameNumber.CompareTo(second.GameNumber));
            return(GetGameModel(_game));
        }
Пример #7
0
        public static void Startgame(Message msg, string[] args)
        {
            if (UpdateBot)
            {
                Bot.Reply(Methods.GetString(msg, "CantStartGameUpdating"), msg);
                return;
            }

            if (Games.Any(x => x.GroupId == msg.Chat.Id))
            {
                Bot.Reply(Methods.GetString(msg, "AlreadyPlaying"), msg);
                return;
            }

            var  pin = Bot.Reply(Methods.GetString(msg, "InitializingGame"), msg);
            Game g   = new Game(pin);

            Games.Add(g);
        }
Пример #8
0
        private void AddGame()
        {
            var w = new GameSelectionWindow();

            w.DataContext = this;
            var res = w.ShowDialog();

            if (res == true && SelectedGame != null)
            {
                if (Games.Any(g => g.AppId == SelectedGame.AppId))
                {
                    return;
                }
                Storage.Games.Add(SelectedGame.AppId);
                Storage.Save();
                SelectedGame.PropertyChanged += BadgeIdleStatusChanged;
                Games.Insert(Games.Count - 1, SelectedGame);
            }
            StorePageUrl = String.Empty;
        }
Пример #9
0
        private void AddGame(object o)
        {
            var selectedGame = o as GameIdentity;

            if (selectedGame == null)
            {
                return;
            }

            if (Games.Any(g => g.AppId == selectedGame.appid))
            {
                return;
            }
            Storage.Games.Add(selectedGame.appid);
            Storage.Save();
            var game = new BadgeModel(selectedGame.appid, selectedGame.name);

            game.PropertyChanged += BadgeIdleStatusChanged;
            Games.Add(game);
            GameSearch = string.Empty;
        }
Пример #10
0
        public static void MessageHandler(Message msg)
        {
            try
            {
                if (!Groups.Any(x => x.Id == msg.Chat.Id) && msg.Chat.Type != ChatType.Private)
                {
                    Bot.Reply("Hey there! This bot isn't for every group! If you want to farm achievements with me, join a group in @WWAchievement! <b>Bye.</b>", msg);
                    Bot.Api.LeaveChatAsync(msg.Chat.Id);
                    Bot.Send($"<b>{msg.From.FirstName} {msg.From.LastName}</b> (@{msg.From.Username}) (<code>{msg.From.Id}</code>) just interacted me with me in <b>{msg.Chat.Title}</b> (<code>{msg.Chat.Id}</code>), which I left because it isn't an allowed group.", testgroup.Id);
                    return;
                }
                if (DateTime.UtcNow.AddSeconds(-5) > msg.Date.ToUniversalTime())
                {
                    return;
                }

                if (msg.Chat.Type == ChatType.Supergroup)
                {
                    var grp = Groups.First(x => x.Id == msg.Chat.Id);
                    if (msg.Chat.Title.FormatHTML() != grp.Name)
                    {
                        grp.Name = msg.Chat.Title.FormatHTML();
                        SQL.ChangeGroup(grp);
                    }
                    if (Games.Any(x => x.GroupId == grp.Id))
                    {
                        Games.First(x => x.GroupId == grp.Id).LastUpdate = DateTime.UtcNow;
                    }
                }

                var text = msg.Text;
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }

                var args = text.Contains(' ')
                    ? new[] { text.Split(' ')[0], text.Remove(0, text.IndexOf(' ') + 1) }
                    : new[] { text, null };

                if (!args[0].StartsWith("!") & !args[0].StartsWith("/") & args[0].ToLower() != "#ping")
                {
                    return;
                }

                var cmd = args[0].StartsWith("/") | args[0].StartsWith("!")
                    ? args[0].ToLower().Remove(0, 1).Replace('@' + Bot.Me.Username.ToLower(), "").Replace("@werewolfbot", "")
                    : args[0].ToLower().Replace('@' + Bot.Me.Username.ToLower(), "").Replace("@werewolfbot", "");

                var command = Bot.Commands.FirstOrDefault(x => String.Equals(x.Trigger, cmd, StringComparison.CurrentCultureIgnoreCase));
                if (command == null)
                {
                    return;
                }

                if (msg.Chat.Id == TranslationGroup && !Admins.Contains(msg.From.Id))
                {
                    Bot.Reply("You may not use commands in here!", msg);
                    return;
                }

                if (command.DevOnly & !Devs.Contains(msg.From.Id))
                {
                    Bot.Reply(Methods.GetString(msg, "NotDev"), msg);
                    return;
                }

                if (command.AdminOnly & !Admins.Contains(msg.From.Id))
                {
                    Bot.Reply(Methods.GetString(msg, "NotAdmin"), msg);
                    return;
                }

                if (command.InGroupOnly & msg.Chat.Type != ChatType.Supergroup)
                {
                    Bot.Reply(Methods.GetString(msg, "MustUseInGroup"), msg);
                    return;
                }

                if (command.InGameOnly)
                {
                    if (msg.Chat.Type != ChatType.Supergroup)
                    {
                        Bot.Reply(Methods.GetString(msg, "MustUseInGroup"), msg);
                        return;
                    }

                    var g = Games.FirstOrDefault(x => x.GroupId == msg.Chat.Id);

                    if (g == null)
                    {
                        Bot.Reply(Methods.GetString(msg, "MustUseInGame"), msg);
                        return;
                    }
                }

                command.Method.Invoke(msg, args);
            }
            catch (Exception e)
            {
                e.Log(true);
                return;
            }
        }
Пример #11
0
        /// <summary>
        /// rename game and forece-update its data
        /// </summary>
        /// <param name="gameId"></param>
        /// <param name="newGameTitle"></param>
        /// <param name="gameChanged"></param>
        public static void RenameGame(string gameId, string newGameTitle, Action <string> gameChanged)
        {
            var oldGameTitle = Games[gameId].Title;

            Log.WriteLine($"RenameGame({ gameId }, { oldGameTitle } -> { newGameTitle })");

            // check if new title already exists
            if (string.IsNullOrEmpty(newGameTitle) || (newGameTitle != oldGameTitle && Games.Any(g => g.Value.Title.ToLower() == newGameTitle.ToLower())))
            {
                gameChanged(null);
                return;
            }

            if (Games.TryRemove(gameId, out GameInfo oldGame))
            {
                if (oldGame.Shortcut != null && !File.Exists(oldGame.Shortcut))
                {
                    oldGame.Shortcut = null;
                }

                var newShortcut = oldGame.Shortcut;

                if (oldGame.Shortcut != null)
                {
                    newShortcut = Path.Combine(GamesDirectory, $"{ newGameTitle }{ new FileInfo(oldGame.Shortcut).Extension }");
                    File.Move(oldGame.Shortcut, newShortcut);
                }

                var newGame = new GameInfo
                {
                    Added          = oldGame.Added,
                    Completed      = oldGame.Completed,
                    TimeStamps     = oldGame.TimeStamps,
                    Title          = newGameTitle,
                    Shortcut       = newShortcut,
                    Data           = new GameData[] { },
                    LastDataUpdate = new ConcurrentDictionary <string, DateTime>(),
                };

                var newGameId = GetGameId(newGame);
                Games.AddOrUpdate(newGameId, newGame, (id, oldValue) => newGame);

                Threading.ThreadAndForget(() =>
                {
                    UpdateGame(newGameId, true);
                    Save();

                    gameChanged(newGameId);
                });
            }
        }