コード例 #1
0
ファイル: NpcCommandHandler.cs プロジェクト: xuebai5/emud
        public async Task <Unit> Handle(ApprenticeToNpcCommand command, CancellationToken cancellationToken)
        {
            var playerId = command.PlayerId;
            var player   = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                return(Unit.Value);
            }

            var npcId = command.NpcId;
            var npc   = await _npcDomainService.Get(npcId);

            if (npc == null)
            {
                return(Unit.Value);
            }

            if (npc.Type != NpcTypeEnum.人物)
            {
                await _bus.RaiseEvent(new DomainNotification($"指令 错误!"));

                return(Unit.Value);
            }

            var npcRelation = await _npcLikingDomainService.Get(x => x.PlayerId == player.Id && x.NpcId == npcId);

            if (npcRelation == null || npcRelation.Liking < 20)
            {
                await _mudProvider.ShowMessage(player.Id, $"[{npc.Name}]并不想收你为徒。");

                return(Unit.Value);
            }

            await _mudProvider.ShowMessage(player.Id, $"你恭恭敬敬地向[{npc.Name}]磕头请安,叫道:「师父!」");

            var playerRelation = await _playerRelationDomainService.Get(x => x.Type == PlayerRelationTypeEnum.师父 && x.PlayerId == playerId && x.RelationId == npcId);

            if (playerRelation != null)
            {
                return(Unit.Value);
            }

            playerRelation = new PlayerRelationEntity
            {
                Type        = PlayerRelationTypeEnum.师父,
                RelationId  = npcId,
                PlayerId    = playerId,
                CreatedTime = DateTime.Now
            };
            await _playerRelationDomainService.Add(playerRelation);



            return(Unit.Value);
        }
コード例 #2
0
        public async Task <Unit> Handle(FriendToCommand command, CancellationToken cancellationToken)
        {
            var playerId   = command.PlayerId;
            var relationId = command.RelationId;
            var player     = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }

            var relation = await _playerDomainService.Get(relationId);

            if (relation == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }

            if (await _redisDb.StringGet <int>(string.Format(RedisKey.RefuseFriend, player.Id, relation.Id)) > 0)
            {
                await _mudProvider.ShowMessage(player.Id, $"【好友】[{relation.Name}]已拒绝你的申请。");

                return(Unit.Value);
            }

            //我加对方
            var playerRelationFrom = await _playerRelationDomainService.Get(x => x.PlayerId == player.Id &&
                                                                            x.RelationId == relation.Id &&
                                                                            x.Type == PlayerRelationTypeEnum.好友);

            //对方加我
            var playerRelationTo = await _playerRelationDomainService.Get(x => x.PlayerId == relation.Id &&
                                                                          x.RelationId == player.Id &&
                                                                          x.Type == PlayerRelationTypeEnum.好友);



            if (playerRelationFrom != null && playerRelationTo != null)
            {
                if (playerRelationTo != null)
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你们已经是好友。");

                    return(Unit.Value);
                }
                else
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你已申请加[{relation.Name}]为好友,请等待对方同意。");

                    return(Unit.Value);
                }
            }



            if (playerRelationFrom == null)
            {
                if (playerRelationTo == null)
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你申请加[{relation.Name}]为好友,请等待对方同意。");

                    var content = $"【好友】[{player.Name}]想和你成为好友,到 '社交'->'好友' 界面可以同意或拒绝对方的申请,你也可以直接添加对方为好友。";

                    await _emailDomainService.Add(new EmailEntity
                    {
                        ExpiryDate = DateTime.Now.AddDays(30),
                        SendDate   = DateTime.Now,
                        Title      = $"{player.Name}想和你成为好友",
                        Content    = content,
                        Type       = EmailTypeEnum.系统,
                        TypeId     = relation.Id
                    });


                    await _mudProvider.ShowMessage(relation.Id, content);
                }
                else
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你成功添加[{relation.Name}]为好友。");


                    var content = $"【好友】[{player.Name}]同意了你的申请,你们已成为了好友。";

                    await _emailDomainService.Add(new EmailEntity
                    {
                        ExpiryDate = DateTime.Now.AddDays(30),
                        SendDate   = DateTime.Now,
                        Title      = $"{player.Name}同意了你的好友申请",
                        Content    = content,
                        Type       = EmailTypeEnum.系统,
                        TypeId     = relation.Id
                    });


                    await _mudProvider.ShowMessage(relation.Id, content);
                }


                playerRelationFrom = new PlayerRelationEntity
                {
                    CreatedTime = DateTime.Now,
                    PlayerId    = player.Id,
                    RelationId  = relation.Id,
                    Type        = PlayerRelationTypeEnum.好友
                };
                await _playerRelationDomainService.Add(playerRelationFrom);



                await _queueHandler.SendQueueMessage(new ReceiveEmailQueue(relation.Id));
            }
            return(Unit.Value);
        }
コード例 #3
0
        public async Task <Unit> Handle(AgreeFriendCommand command, CancellationToken cancellationToken)
        {
            var playerId   = command.PlayerId;
            var relationId = command.RelationId;
            var player     = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }

            var relation = await _playerDomainService.Get(relationId);

            if (relation == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }

            var playerRelationFrom = await _playerRelationDomainService.Get(x => x.PlayerId == relationId && x.RelationId == playerId && x.Type == PlayerRelationTypeEnum.好友);

            if (playerRelationFrom == null)
            {
                await _mudProvider.ShowMessage(player.Id, $"【好友】[{relation.Name}]没有申请加你为好友,或者已撤销申请。");

                return(Unit.Value);
            }

            var playerRelationTo = await _playerRelationDomainService.Get(x => x.PlayerId == playerId && x.RelationId == relationId && x.Type == PlayerRelationTypeEnum.好友);

            if (playerRelationTo != null)
            {
                await _mudProvider.ShowMessage(player.Id, $"【好友】你和[{relation.Name}]已经是好友了。");

                return(Unit.Value);
            }


            playerRelationTo = new PlayerRelationEntity
            {
                PlayerId    = playerId,
                RelationId  = relationId,
                Type        = PlayerRelationTypeEnum.好友,
                CreatedTime = DateTime.Now
            };
            await _playerRelationDomainService.Add(playerRelationTo);

            await _mudProvider.ShowMessage(player.Id, $"【好友】你同意了[{relation.Name}]的好友申请。");

            var content = $"【好友】[{player.Name}]同意了你的申请,你们已成为了好友。";

            await _emailDomainService.Add(new EmailEntity
            {
                ExpiryDate = DateTime.Now.AddDays(30),
                SendDate   = DateTime.Now,
                Title      = $"{player.Name}同意了你的好友申请",
                Content    = content,
                Type       = EmailTypeEnum.系统,
                TypeId     = relation.Id
            });


            await _mudProvider.ShowMessage(relation.Id, content);

            return(Unit.Value);
        }
コード例 #4
0
 public async Task Delete(PlayerRelationEntity player)
 {
     await _playerRelationRepository.Remove(player);
 }
コード例 #5
0
 public async Task Update(PlayerRelationEntity player)
 {
     await _playerRelationRepository.Update(player);
 }
コード例 #6
0
 public async Task Add(PlayerRelationEntity player)
 {
     await _playerRelationRepository.Add(player);
 }
コード例 #7
0
        private async Task Friend(PlayerEntity player, PlayerEntity relation)
        {
            if (await _redisDb.StringGet <int>(string.Format(RedisKey.RefuseFriend, player.Id, relation.Id)) > 0)
            {
                await _mudProvider.ShowMessage(player.Id, $"【好友】[{relation.Name}]已拒绝你的申请。");

                return;
            }

            //我加对方
            var playerRelationFrom = await _playerRelationDomainService.Get(x => x.PlayerId == player.Id &&
                                                                            x.RelationId == relation.Id &&
                                                                            x.Type == PlayerRelationTypeEnum.好友);

            //对方加我
            var playerRelationTo = await _playerRelationDomainService.Get(x => x.PlayerId == relation.Id &&
                                                                          x.RelationId == player.Id &&
                                                                          x.Type == PlayerRelationTypeEnum.好友);



            if (playerRelationFrom != null && playerRelationTo != null)
            {
                if (playerRelationTo != null)
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你们已经是好友。");

                    return;
                }
                else
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你已申请加[{relation.Name}]为好友,请等待对方同意。");

                    return;
                }
            }



            if (playerRelationFrom == null)
            {
                if (playerRelationTo == null)
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你申请加[{relation.Name}]为好友,请等待对方同意。");

                    var content = $"【好友】[{player.Name}]想和你成为好友,到 '社交'->'好友' 界面可以同意或拒绝对方的申请,你也可以直接添加对方为好友。";

                    await _emailDomainService.Add(new EmailEntity
                    {
                        ExpiryDate = DateTime.Now.AddDays(30),
                        SendDate   = DateTime.Now,
                        Title      = $"{player.Name}想和你成为好友",
                        Content    = content,
                        Type       = EmailTypeEnum.系统,
                        TypeId     = relation.Id
                    });


                    await _mudProvider.ShowMessage(relation.Id, content);
                }
                else
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你成功添加[{relation.Name}]为好友。");


                    var content = $"【好友】[{player.Name}]同意了你的申请,你们已成为了好友。";

                    await _emailDomainService.Add(new EmailEntity
                    {
                        ExpiryDate = DateTime.Now.AddDays(30),
                        SendDate   = DateTime.Now,
                        Title      = $"{player.Name}同意了你的好友申请",
                        Content    = content,
                        Type       = EmailTypeEnum.系统,
                        TypeId     = relation.Id
                    });


                    await _mudProvider.ShowMessage(relation.Id, content);
                }


                playerRelationFrom = new PlayerRelationEntity
                {
                    CreatedTime = DateTime.Now,
                    PlayerId    = player.Id,
                    RelationId  = relation.Id,
                    Type        = PlayerRelationTypeEnum.好友
                };
                await _playerRelationDomainService.Add(playerRelationFrom);



                await _queueHandler.SendQueueMessage(new ReceiveEmailQueue(relation.Id));
            }
        }