Exemple #1
0
        public async Task EnterRoom(string connectionId, CS_EnterRoom cs)
        {
            var method = "EnterRoom";

            try
            {
                var result = false;
                var user   = GetUserById(cs.User.Id);
                if (user != null)
                {
                    cs.User.ConnectionId = connectionId;
                    cs.User.Name         = user.Name;

                    result = _roomService.Enter(cs.GroupName, cs.User);
                }

                if (result)
                {
                    await _context.Clients(connectionId).SendCoreAsync(method, PayloadPack.Success(new SC_EnterRoom()
                    {
                        User      = cs.User,
                        GroupName = cs.GroupName
                    }));
                }
                else
                {
                    await _context.Clients(connectionId).SendCoreAsync(method, PayloadPack.Fail(PayloadCode.Failure));
                }
            }
            catch (Exception ex)
            {
                await _context.Clients(connectionId).SendCoreAsync(method, PayloadPack.Error(ex));
            }
        }
Exemple #2
0
        public async Task Login(string connectionId, string id, string name)
        {
            var method = "Login";

            try
            {
                var duplicationUser = GetUserById(id);
                if (duplicationUser != null)
                {   //중복
                    _users.Remove(duplicationUser);
                }

                var user = new User()
                {
                    Id           = id,
                    Name         = name,
                    ConnectionId = connectionId,
                };

                _users.Add(user);

                await _context.Clients(connectionId).SendCoreAsync(method, PayloadPack.Success(new SC_Login()
                {
                    User = user,
                }));
            }
            catch (Exception ex)
            {
                await _context.Clients(connectionId).SendCoreAsync(method, PayloadPack.Error(ex));
            }
        }
Exemple #3
0
        public async Task EnterMatch(string connectionId, string id)
        {
            var method = "EnterMatch";

            try
            {
                var result = false;
                var user   = GetUserById(id);
                if (user != null)
                {
                    result = _matchService.Enter(user);
                }

                if (result)
                {
                    await _context.Clients(connectionId).SendCoreAsync(method, PayloadPack.Success(new SC_EnterMatch()
                    {
                        Id = id,
                    }));
                }
                else
                {
                    await _context.Clients(connectionId).SendCoreAsync(method, PayloadPack.Fail(PayloadCode.Failure));
                }
            }
            catch (Exception ex)
            {
                await _context.Clients(connectionId).SendCoreAsync(method, PayloadPack.Error(ex));
            }
        }
Exemple #4
0
 public void CSID_DeleteCube(CS_DeleteCube cs)
 {
     _context.ClientsExceptById(_users, cs.Id).SendCoreAsync("DeleteCube", PayloadPack.Success(new SC_DeleteCube()
     {
         Id          = cs.Id,
         DeleteCubes = cs.DeleteCubes,
     }));
 }
Exemple #5
0
 public void CSID_CreateCube(CS_CreateCube cs)
 {
     _context.ClientsExceptById(_users, cs.Id).SendCoreAsync("CreateCube", PayloadPack.Success(new SC_CreateCube()
     {
         Id      = cs.Id,
         NewCube = cs.NewCube,
     }));
 }
Exemple #6
0
 public void CSID_DieMonster(CS_DieMonster cs)
 {
     _context.ClientsExceptById(_users, cs.Id).SendCoreAsync("DieMonster", PayloadPack.Success(new SC_DieMonster()
     {
         Id         = cs.Id,
         MonsterSeq = cs.MonsterSeq,
     }));
 }
Exemple #7
0
 public void CSID_ShotMissile(CS_ShotMissile cs)
 {
     _context.ClientsExceptById(_users, cs.Id).SendCoreAsync("ShotMissile", PayloadPack.Success(new SC_ShotMissile()
     {
         Id         = cs.Id,
         CubeSeq    = cs.CubeSeq,
         MonsterSeq = cs.MonsterSeq,
     }));
 }
Exemple #8
0
 public void CSID_CombineCube(CS_CombineCube cs)
 {
     _context.ClientsExceptById(_users, cs.Id).SendCoreAsync("CombineCube", PayloadPack.Success(new SC_CombineCube()
     {
         Id        = cs.Id,
         OwnerSeq  = cs.OwnerSeq,
         TargetSeq = cs.TargetSeq,
     }));
 }
Exemple #9
0
        private void SCID_Loading()
        {
            _state = RoomState.Loading;

            _context.Clients(_users).SendCoreAsync("Loading", PayloadPack.Success(new SC_Loading()
            {
                Users = _users,
            }));
        }
Exemple #10
0
 public void CSID_UpdateSlot(CS_UpdateSlot cs)
 {
     _context.ClientsExceptById(_users, cs.Id).SendCoreAsync("UpdateSlot", PayloadPack.Success(new SC_UpdateSlot()
     {
         Id        = cs.Id,
         SlotIndex = cs.SlotIndex,
         SlotLv    = cs.SlotLv,
     }));
 }
Exemple #11
0
 public void CSID_MoveCube(CS_MoveCube cs)
 {
     _context.ClientsExceptById(_users, cs.Id).SendCoreAsync("MoveCube", PayloadPack.Success(new SC_MoveCube()
     {
         Id        = cs.Id,
         CubeSeq   = cs.CubeSeq,
         PositionX = cs.PositionX,
         PositionY = cs.PositionY,
     }));
 }
Exemple #12
0
        public void Release()
        {
            _context.Clients(_users).SendCoreAsync("DeleteRoom", PayloadPack.Success(new SC_DeleteRoom()
            {
            }));

            _state = RoomState.End;
            _timer.Stop();
            _users.Clear();
        }
Exemple #13
0
        private void SCID_Play()
        {
            if (!CheckUserState(UserState.CompleteLoading))
            {
                return; //아직 전부 로딩이 안되었음
            }
            SetUserState(UserState.Play);

            _context.Clients(_users).SendCoreAsync("Play", PayloadPack.Success(new SC_Play()
            {
            }));

            _state = RoomState.Play;

            SCID_Wave();
        }
Exemple #14
0
        private void CheckMatching()
        {
            var curtime = DateTime.UtcNow;
            var users   = _users.OrderBy(x => x.MatchTime).Take(ServerDefine.MAX_GAME_USER).ToList();

            if (users.Count >= ServerDefine.MAX_GAME_USER)
            {   //매칭 성공
                var groupName     = Guid.NewGuid().ToString("d");
                var connectionIds = users.Select(x => x.ConnectionId).ToArray();
                _context.Clients(connectionIds).SendCoreAsync("SuccessMatch", PayloadPack.Success(new SC_SuccessMatch()
                {
                    GroupName = groupName,
                }));

                users.ForEach(x => _users.Remove(x));
            }
        }
Exemple #15
0
        private void Result()
        {
            _state = RoomState.Result;

            var users = _users.OrderByDescending(x => x.Life).ToList();

            users.ForEach((x, i) =>
            {
                x.Rank  = i;
                x.Money = ServerDefine.Rank2Money(i);
            });

            _context.Clients(_users).SendCoreAsync("Result", PayloadPack.Success(new SC_Result()
            {
                Users = users,
            }));

            OnGameEnd?.Invoke(_groupName);
        }
Exemple #16
0
        public void CSID_EscapeMonster(CS_EscapeMonster cs)
        {
            _context.ClientsExceptById(_users, cs.Id).SendCoreAsync("EscapeMonster", PayloadPack.Success(new SC_EscapeMonster()
            {
                Id         = cs.Id,
                MonsterSeq = cs.MonsterSeq,
            }));

            var user = GetUserById(cs.Id);

            if (user != null)
            {
                user.Life -= 1;

                if (user.Life <= 0)
                {   //게임 종료
                    Result();
                }
            }
        }
Exemple #17
0
 private void SCID_Wave()
 {
     _context.Clients(_users).SendCoreAsync("Wave", PayloadPack.Success(new SC_Wave()
     {
     }));
 }
Exemple #18
0
 public void SendLocalAI(string method, object args)
 {
     OnInvocation(method, ParsingType.Json, PayloadPack.Success(args));
 }