public async Task <ResultDto> Update(int id, NpcInput item, List <int> scriptIds) { var result = new ResultDto { Message = "" }; try { var npc = await _npcDomainService.Get(id); if (npc == null) { result.Message = $"Npc {id} 不存在!"; return(result); } var content = npc.ComparisonTo(item); _mapper.Map(item, npc); await _npcDomainService.Update(npc); var npcScripts = (await _npcScriptDomainService.GetAll()).Where(x => x.NpcId == id); foreach (var npcScript in npcScripts) { if (!scriptIds.Contains(npcScript.ScriptId)) { await _npcScriptDomainService.Delete(npcScript); } else { scriptIds.Remove(npcScript.ScriptId); } } foreach (var scriptId in scriptIds) { await _npcScriptDomainService.Add(new NpcScriptEntity { NpcId = id, ScriptId = scriptId }); } await _operatorLogDomainService.AddSuccess(new OperatorLogEntity { Type = OperatorLogType.修改Npc, Content = $"Id = {id},Data = {content}" }); await Commit(); result.IsSuccess = true; } catch (Exception ex) { result.Message = ex.Message; await _operatorLogDomainService.AddError(new OperatorLogEntity { Type = OperatorLogType.修改Npc, Content = $"Data={JsonConvert.SerializeObject(item)},ErrorMessage={result.Message}" }); await Commit(); } return(result); }
public async Task <Unit> Handle(ShowNpcCommand command, CancellationToken cancellationToken) { var playerId = command.PlayerId; var npcId = command.NpcId; var npcInfo = new NpcInfo() { Descriptions = new List <string>(), Actions = new List <NpcAction>(), Id = npcId }; var npc = await _npcDomainService.Get(npcId); if (npc == null) { return(Unit.Value); } npcInfo.Name = npc.Name; string genderStr = npc.Gender.ToGender(); if (npc.Type == NpcTypeEnum.人物) { //npcInfo.Actions.Add(new NpcAction { Name = NpcActionEnum.给予.ToString() }); } if (npc.CanFight) { npcInfo.Actions.Add(new NpcAction { Name = NpcActionEnum.切磋.ToString() }); } if (npc.CanKill) { npcInfo.Actions.Add(new NpcAction { Name = NpcActionEnum.杀死.ToString() }); } var player = await _playerDomainService.Get(playerId); npcInfo.Descriptions.Add(npc.Description ?? ""); npcInfo.Descriptions.Add($"{genderStr}{npc.Age.ToAge()}"); npcInfo.Descriptions.Add($"{genderStr}{npc.Per.ToPer(npc.Age, npc.Gender)}"); npcInfo.Descriptions.Add($"{genderStr}{npc.Exp.ToKunFuLevel(player.Exp)}"); var npcScripts = (await _npcScriptDomainService.GetAll()).Where(x => x.NpcId == npc.Id).ToList(); foreach (var npcScript in npcScripts) { var script = await _scriptDomainService.Get(npcScript.ScriptId); if (script != null) { npcInfo.Actions.Add(new NpcAction { Name = script.Name, ScriptId = script.Id, CommandId = 0 }); } } await _mudProvider.ShowNpc(playerId, npcInfo); await _bus.RaiseEvent(new ChatWithNpcEvent(playerId, npc.Id)).ConfigureAwait(false); return(Unit.Value); }
public async Task <Unit> Handle(ShowNpcCommand command, CancellationToken cancellationToken) { var playerId = command.PlayerId; var npcId = command.NpcId; var npcInfo = new NpcInfo() { Descriptions = new List <string>(), Actions = new List <NpcAction>(), Id = npcId }; var npc = await _npcDomainService.Get(npcId); if (npc == null) { return(Unit.Value); } npcInfo.Name = npc.Name; string genderStr = npc.Gender.ToGender(); if (npc.CanChat) { npcInfo.Actions.Add(new NpcAction { Name = NpcActionEnum.闲聊.ToString() }); } if (npc.Type == NpcTypeEnum.人物) { //npcInfo.Actions.Add(new NpcAction { Name = NpcActionEnum.给予.ToString() }); } if (npc.CanFight) { npcInfo.Actions.Add(new NpcAction { Name = NpcActionEnum.切磋.ToString() }); } if (npc.CanKill) { npcInfo.Actions.Add(new NpcAction { Name = NpcActionEnum.杀死.ToString(), IsConfirm = true, Message = $"要杀死{npc.Name}吗?" }); } var npcLiking = await _npcLikingDomainService.Get(x => x.PlayerId == playerId && x.NpcId == npcId); if (npcLiking?.Liking > 20) { var playerRelation = await _playerRelationDomainService.Get(x => x.Type == PlayerRelationTypeEnum.师父 && x.PlayerId == playerId && x.RelationId == npcId); if (playerRelation == null) { npcInfo.Actions.Add(new NpcAction { Name = NpcActionEnum.拜师.ToString(), IsConfirm = true, Message = $"要拜{npc.Name}为师吗?" }); } else { npcInfo.Actions.Add(new NpcAction { Name = NpcActionEnum.出师.ToString(), IsConfirm = true, Message = $"要与{npc.Name}断绝师徒关系吗?" }); npcInfo.Actions.Add(new NpcAction { Name = NpcActionEnum.查看武功.ToString() }); } } var player = await _playerDomainService.Get(playerId); npcInfo.Descriptions.Add(npc.Description ?? ""); npcInfo.Descriptions.Add($"{genderStr}{npc.Age.ToAge()}"); npcInfo.Descriptions.Add($"{genderStr}{npc.Per.ToPer(npc.Age, npc.Gender)}"); npcInfo.Descriptions.Add($"{genderStr}{npc.Exp.ToKunFuLevel(player.Exp)}"); var npcScripts = (await _npcScriptDomainService.GetAll()).Where(x => x.NpcId == npc.Id).ToList(); foreach (var npcScript in npcScripts) { var script = await _scriptDomainService.Get(npcScript.ScriptId); if (script != null) { npcInfo.Actions.Add(new NpcAction { Name = script.Name, ScriptId = script.Id, CommandId = 0 }); } } await _mudProvider.ShowNpc(playerId, npcInfo); return(Unit.Value); }