public async Task Drop(WareAction wareAction) { var result = await DoCommand(async() => { var playerId = _account.PlayerId; var command = new DropWareCommand(playerId, wareAction.MyWareId); await _bus.SendCommand(command); }); }
public async Task <Unit> Handle(DropWareCommand command, CancellationToken cancellationToken) { var myWareId = command.MyWareId; var playerId = command.PlayerId; var player = await _playerDomainService.Get(playerId); if (player == null) { await _bus.RaiseEvent(new DomainNotification($"角色不存在!")); return(Unit.Value); } var playerWare = await _playerWareDomainService.Get(myWareId); if (playerWare == null || playerWare.PlayerId != playerId) { await _bus.RaiseEvent(new DomainNotification($"物品不存在!")); return(Unit.Value); } if (playerWare.Status != WareStatusEnum.卸下) { await _bus.RaiseEvent(new DomainNotification($"该物品{ playerWare.Status }中,不能丢弃!")); return(Unit.Value); } var ware = await _wareDomainService.Get(playerWare.WareId); if (ware == null) { await _bus.RaiseEvent(new DomainNotification($"物品状态异常!")); return(Unit.Value); } await _playerWareDomainService.Delete(playerWare); var wareModel = _mapper.Map <WareModel>(ware); wareModel.PlayerWareId = playerWare.Id; await _mudProvider.DropWare(playerId, wareModel); await _mudProvider.ShowMessage(playerId, $"你丢掉了 [{wareModel.Name}]!"); return(Unit.Value); }