Exemplo n.º 1
0
        public async Task <MatchRequestResult> RequestMatch(ActiveUser activeUser,
                                                            string oppoId)
        {
            var dUser = await _masterRepo.GetUserByIdAsyc(activeUser.Id);

            if (dUser.Money < Room.MinBet)
            {
                throw new BadUserInputException();
            }

            //BadUserInputException is thrown when something is wrong but should've been
            //validated by the client

            var oppoUser = await _masterRepo.GetUserByIdAsyc(oppoId);

            var friendship = _masterRepo.GetFriendship(activeUser.Id, oppoId);

            if (friendship is FriendShip.None or FriendShip.Follower && !oppoUser.EnableOpenMatches)
            {
                throw new BadUserInputException();
            }

            if (!_sessionRepo.IsUserActive(oppoId))
            {
                return(MatchRequestResult.Offline);
            }

            if (_sessionRepo.DoesRoomUserExist(oppoId))
            {
                return(MatchRequestResult.Playing);
            }

            if (oppoUser.Money < Room.MinBet)
            {
                return(MatchRequestResult.NoMoney);
            }

            //can't call again because this fun domain is lobby.idle only
            activeUser.Domain = typeof(UserDomain.App.Lobby.Pending);

            activeUser.ChallengeRequestTarget = oppoId;

            var oppoAU = _sessionRepo.GetActiveUser(oppoId);
            //oppo is 100% active at this satage

            await _masterHub.SendOrderedAsync(oppoAU, "ChallengeRequest",
                                              Mapper.UserToMinUserInfoFunc(dUser));

            return(MatchRequestResult.Available);
        }
Exemplo n.º 2
0
        private async Task InitialDistribute(Room room)
        {
            room.GroundCards = room.Deck.CutRange(RoomActor.HandSize);

            foreach (var roomActor in room.RoomActors)
            {
                roomActor.Hand = room.Deck.CutRange(RoomActor.HandSize);
            }

            foreach (var roomUser in room.RoomUsers)
            {
                await _masterHub.SendOrderedAsync(roomUser.ActiveUser, "StartRoomRpc", roomUser.Hand, roomUser.Room.GroundCards);
            }
        } //the cut part can be tested, but it's relatively easy
Exemplo n.º 3
0
        private async Task AddMoney(ActiveUser activeUser, int amount)
        {
            var dUser = await _masterRepo.GetUserByIdAsyc(activeUser.Id);

            dUser.Money += amount;

            await _masterRepo.SaveChangesAsync();

            await _masterHub.SendOrderedAsync(activeUser, "AddMoney", amount);
        }
Exemplo n.º 4
0
        /// <summary>
        /// check current level against xp to level up and send to client
        /// functions that takes data user as param doesn't save changes
        /// </summary>
        private async Task LevelWorks(User roomDataUser, ActiveUser activeUser)
        {
            var calcedLevel = Room.GetLevelFromXp(roomDataUser.XP);

            if (calcedLevel > roomDataUser.Level)
            {
                var increasedLevels  = calcedLevel - roomDataUser.Level;
                var totalMoneyReward = 0;
                for (int j = 0; j < increasedLevels; j++)
                {
                    totalMoneyReward += 100;
                    //todo give level up rewards (money equation), add to test
                    //todo test this function logic
                }

                roomDataUser.Level  = calcedLevel;
                roomDataUser.Money += totalMoneyReward;

                if (activeUser != null)
                {
                    await _masterHub.SendOrderedAsync(activeUser, "LevelUp", calcedLevel, totalMoneyReward);
                }
            }
        } //separate this to be called on every XP change