Beispiel #1
0
        public void BeforeLeaveGame(BeforeLeaveGameRequest request, long clientId)
        {
            var role = ManagerMediator.RoleManager.GetRoleByClientId(clientId);

            if (role != null)
            {
                if (_roleScoreDict.TryGetValue(role.RoleId, out var score))
                {
                    if (score > 0)
                    {
                        var dbRequest = new GameDBProto.SaveRoleScoreRequest {
                            RoleId = role.RoleId, Score = score
                        };
                        var dbMail = new MailPacket
                        {
                            Id       = (int)GameDBProto.MessageId.SaveRoleScoreRequestId,
                            Content  = dbRequest.ToByteArray(),
                            UserId   = role.UserId,
                            ClientId = role.ClientId
                        };
                        ManagerMediator.Dispatcher.WriteDBMail(dbMail, DBMailQueueType.Role);
                    }
                    _roleScoreDict.Remove(role.RoleId);
                }
            }
        }
Beispiel #2
0
        private void AgentGameOverRequest(MailPacket mail)
        {
            var role = ManagerMediator.RoleManager.GetRoleByClientId(mail.ClientId);

            if (role != null)
            {
                var score = _roleScoreDict.GetValueOrDefault(role.RoleId);
                _roleScoreDict[role.RoleId] = 0;
                var dbRequest = new GameDBProto.SaveRoleScoreRequest {
                    RoleId = role.RoleId, Score = score
                };
                var dbMail = new MailPacket
                {
                    Id       = (int)GameDBProto.MessageId.SaveRoleScoreRequestId,
                    Content  = dbRequest.ToByteArray(),
                    UserId   = role.UserId,
                    ClientId = role.ClientId
                };
                ManagerMediator.Dispatcher.WriteDBMail(dbMail, DBMailQueueType.Role);
            }

            var stoc = new WatermelonGameProto.StoCGameOverReply();

            ManagerMediator.Dispatcher.WriteAgentMail(new MailPacket
            {
                Id       = (int)WatermelonGameProto.MessageId.StoCgameOverReplyId,
                Content  = stoc.ToByteArray(),
                UserId   = mail.UserId,
                ClientId = mail.ClientId
            });
        }