Esempio n. 1
0
        private IEnumerable <OpenMatchViewModel> GetOpenMatches(string userId, string displayName)
        {
            var matches = OpenMatchQuery()
                          .FilterByUser(displayName)
                          .ToList();

            _opponentChecker.LoadOpponents(userId);

            return(matches.Select(x =>
            {
                var host = x.GetHost();
                var vm = OpenMatchViewModel.GetOpenMatch(x, userId);
                vm.CanJoin = !vm.CanClose && !_opponentChecker.AreOpponents(host.UserId, userId);
                return vm;
            }));
        }
Esempio n. 2
0
        public void AddOpponent(Match match, UserInformation user)
        {
            if (match.Status != Status.Open && match.Status != Status.Invite)
            {
                throw new CantJoinMatchException("Can't join an active match.");
            }
            if (user.Joined >= user.JoinedLimit)
            {
                throw new CantJoinMatchException("Join limit reached.");
            }
            if (match.UserInRole(user.Id, MatchRole.Host))
            {
                throw new CantJoinMatchException("Cant join your own match.");
            }
            _checker.LoadOpponents(user.Id);
            if (_checker.AreOpponents(match.GetHost().UserId, user.Id))
            {
                throw new CantJoinMatchException("Already battling this user.");
            }

            //todo check for invitation

            match.MatchUsers.Add(new MatchUser
            {
                Index  = match.MatchUsers.Count,
                UserId = user.Id,
                User   = user,
                Role   = MatchRole.Opponent
            });

            match.Status = Status.Active;
            user.Joined++;
            match.GetHost().SetGoFlagUpdatePassLock(true, false, false);

            if (match.Mode == Mode.ThreeRoundPass && match.TurnType == TurnType.Blitz)
            {
                match.GetOpponent().SetGoFlagUpdatePassLock(true, false, false);
            }
            else
            {
                match.Turn = match.GetTurnName();
            }

            match.LastUpdate = DateTime.Now;
        }