コード例 #1
0
ファイル: NpcCommandHandler.cs プロジェクト: csecong/emud
        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);
        }
コード例 #2
0
ファイル: NpcCommandHandler.cs プロジェクト: xuebai5/emud
        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);
        }