public async Task AgreeFriend(RelationAction relationAction) { var result = await DoCommand(async() => { var playerId = _account.PlayerId; var command = new AgreeFriendCommand(playerId, relationAction.RelationId); await _bus.SendCommand(command); }); }
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); }