private async Task UnFriend(PlayerEntity player, PlayerEntity relation) { //我加对方 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) { await _playerRelationDomainService.Delete(playerRelationFrom); await _playerRelationDomainService.Delete(playerRelationTo); //1天内不得重复申请 await _redisDb.StringSet(string.Format(RedisKey.RefuseFriend, relation.Id, player.Id), 1, DateTime.Now.AddDays(1)); 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, $"【好友】你们并不是好友。"); } }
public async Task <Unit> Handle(FinishApprenticeToNpcCommand 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 playerRelation = await _playerRelationDomainService.Get(x => x.Type == PlayerRelationTypeEnum.师父 && x.PlayerId == playerId && x.RelationId == npcId); if (playerRelation == null) { return(Unit.Value); } await _mudProvider.ShowMessage(player.Id, $"你与[{npc.Name}]断绝了师徒关系。"); await _playerRelationDomainService.Delete(playerRelation); var npcRelation = await _npcLikingDomainService.Get(x => x.PlayerId == player.Id && x.NpcId == npcId); if (npcRelation != null) { npcRelation.Liking = -20; await _npcLikingDomainService.Update(npcRelation); } return(Unit.Value); }
public async Task <Unit> Handle(RefuseFriendCommand 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); } await _playerRelationDomainService.Delete(playerRelationFrom); //1天内不得重复申请 await _redisDb.StringSet(string.Format(RedisKey.RefuseFriend, relationId, playerId), 1, DateTime.Now.AddDays(1)); 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); }