Example #1
0
        public async Task <Unit> Handle(ShowMasterCommand command, CancellationToken cancellationToken)
        {
            var playerId = command.PlayerId;
            var player   = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }
            var myMasterModel = new MyMasterModel
            {
            };

            var playerRelation = await _playerRelationDomainService.Get(x => x.Type == PlayerRelationTypeEnum.师父 && x.PlayerId == playerId);

            if (playerRelation != null)
            {
                var master = await _npcDomainService.Get(playerRelation.RelationId);

                if (master != null)
                {
                    myMasterModel.Master = _mapper.Map <PlayerBaseInfo>(master);
                }
            }

            await _mudProvider.ShowMaster(playerId, myMasterModel);

            return(Unit.Value);
        }
Example #2
0
        public async Task <IActionResult> Edit(int id)
        {
            var npc = await _npcDomainService.Get(id);

            await _bus.RaiseEvent(new EntityUpdatedEvent <NpcEntity>(npc)).ConfigureAwait(false);

            return(Ok());
        }
Example #3
0
        public async Task Execute(NpcStatusModel model)
        {
            int playerId = model.TargetId;
            int npcId    = model.NpcId;
            var player   = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                await StopAction(npcId);

                return;
            }
            var npc = await _npcDomainService.Get(npcId);

            if (npc == null)
            {
                await StopAction(npcId);

                return;
            }

            var npcFightingPlayerId = await _redisDb.StringGet <int>(string.Format(RedisKey.NpcFighting, npc.Id));

            if (npcFightingPlayerId != playerId)
            {
                await _mudProvider.ShowMessage(player.Id, $"【切磋】{npcFightingPlayerId},{playerId},{npcId}");
                await StopAction(npcId);

                return;
            }

            await _mudProvider.ShowMessage(player.Id, $"【切磋】[{npc.Name}]正在攻击你。。。");


            await _mudProvider.AddFightingTarget(player.Id, new FightingTargetModel
            {
                TargetId   = npcId,
                TargetName = npc.Name,
                Hp         = npc.Hp,
                Mp         = npc.Mp,
                MaxHp      = npc.MaxHp,
                MaxMp      = npc.MaxMp,
                TargetType = TargetTypeEnum.Npc
            });
        }
Example #4
0
        private async Task Fighting(PlayerEntity player, TargetTypeEnum?targetType, int targetId)
        {
            if (targetType == TargetTypeEnum.Npc)
            {
                var npc = await _npcDomainService.Get(targetId);

                if (npc == null)
                {
                    await StopAction(player);

                    return;
                }

                var npcFightingPlayerId = await _redisDb.StringGet <int>(string.Format(RedisKey.NpcFighting, npc.Id));

                if (npcFightingPlayerId != player.Id)
                {
                    await StopAction(player);

                    return;
                }

                await _redisDb.StringSet(string.Format(RedisKey.NpcFighting, npc.Id), player.Id, DateTime.Now.AddSeconds(60));

                await FightingNpc(player, npc);
            }
            else if (targetType == TargetTypeEnum.玩家)
            {
                var target = await _playerDomainService.Get(targetId);

                if (target == null)
                {
                    await StopAction(player);

                    return;
                }

                await FightingPlayer(player, target);
            }
            else
            {
                await StopAction(player);
            }
        }
Example #5
0
        public async Task Execute(NpcStatusModel model)
        {
            int playerId = model.TargetId;
            int npcId    = model.NpcId;



            var npc = await _npcDomainService.Get(npcId);

            if (npc == null)
            {
                await StopAction(npcId);

                return;
            }

            switch (model.Status)
            {
            case NpcStatusEnum.切磋:
                var player = await _playerDomainService.Get(playerId);

                if (player == null)
                {
                    await StopAction(npcId);

                    return;
                }

                await Fighting(npc, player);

                break;

            case NpcStatusEnum.移动:

                break;

            case NpcStatusEnum.空闲:

                break;
            }
        }
Example #6
0
        public async Task <Unit> Handle(FightWithNpcCommand 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.CanFight)
            {
                await _bus.RaiseEvent(new DomainNotification($"你不能与[{npc.Name}]切磋!"));

                return(Unit.Value);
            }


            if (player.RoomId != npc.RoomId)
            {
                await _bus.RaiseEvent(new DomainNotification($"[{npc.Name}]已经离开此地,无法发起切磋!"));

                return(Unit.Value);
            }

            if (npc.IsDead)
            {
                await _bus.RaiseEvent(new DomainNotification($"[{npc.Name}]已经死了,无法发起切磋!"));

                return(Unit.Value);
            }

            var npcFightingPlayerId = await _redisDb.StringGet <int>(string.Format(RedisKey.NpcFighting, npc.Id));

            if (npcFightingPlayerId > 0 && npcFightingPlayerId != playerId)
            {
                await _bus.RaiseEvent(new DomainNotification($"[{npc.Name}]拒绝了你的切磋请求!"));

                return(Unit.Value);
            }



            var hasChangedStatus = await BeginChangeStatus(new PlayerStatusModel
            {
                PlayerId   = playerId,
                Status     = PlayerStatusEnum.切磋,
                TargetType = TargetTypeEnum.Npc,
                TargetId   = npcId
            });

            if (hasChangedStatus)
            {
                await _mudProvider.ShowMessage(playerId, $"【切磋】你对着[{npc.Name}]说道:在下[{player.Name}],领教壮士的高招!");

                await _mudProvider.ShowMessage(playerId, $"【切磋】[{npc.Name}]说道:「既然小兄弟赐教,在下只好奉陪,我们点到为止。」");

                await _redisDb.StringSet(string.Format(RedisKey.NpcFighting, npc.Id), playerId, DateTime.Now.AddSeconds(20));

                int minDelay = npc.Speed;
                int maxDelay = minDelay + 1000;

                var actionPoint = await _redisDb.StringGet <int>(string.Format(RedisKey.ActionPoint, playerId));

                await _mudProvider.ShowActionPoint(playerId, actionPoint);

                await _recurringQueue.Publish($"npc_{npc.Id}", new NpcStatusModel
                {
                    NpcId      = npc.Id,
                    Status     = NpcStatusEnum.切磋,
                    TargetId   = playerId,
                    TargetType = TargetTypeEnum.玩家
                }, minDelay, maxDelay);

                await _mudProvider.ShowBox(playerId, new { boxName = "fighting" });
            }


            return(Unit.Value);
        }
Example #7
0
        public async Task <Unit> Handle(FightWithNpcCommand 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.CanFight)
            {
                await _bus.RaiseEvent(new DomainNotification($"你不能与[{npc.Name}]切磋!"));

                return(Unit.Value);
            }


            if (player.RoomId != npc.RoomId)
            {
                await _bus.RaiseEvent(new DomainNotification($"[{npc.Name}]已经离开此地,无法发起切磋!"));

                return(Unit.Value);
            }

            if (npc.IsDead)
            {
                await _bus.RaiseEvent(new DomainNotification($"[{npc.Name}]已经死了,无法发起切磋!"));

                return(Unit.Value);
            }

            var npcFightingPlayerId = await _redisDb.StringGet <int>(string.Format(RedisKey.NpcFighting, npc.Id));

            if (npcFightingPlayerId > 0 && npcFightingPlayerId != playerId)
            {
                await _bus.RaiseEvent(new DomainNotification($"[{npc.Name}]拒绝了你的切磋请求!"));

                return(Unit.Value);
            }



            var hasChangedStatus = await BeginChangeStatus(new PlayerStatusModel
            {
                PlayerId   = playerId,
                Status     = PlayerStatusEnum.切磋,
                TargetType = TargetTypeEnum.Npc,
                TargetId   = npcId
            });

            if (hasChangedStatus)
            {
                await _mudProvider.ShowMessage(playerId, $"【切磋】你对着[{npc.Name}]说道:在下[{player.Name}],领教阁下的高招!");

                await _mudProvider.ShowMessage(playerId, $"【切磋】[{npc.Name}]说道:「既然阁下赐教,在下只好奉陪,我们点到为止。」");

                await _redisDb.StringSet(string.Format(RedisKey.NpcFighting, npc.Id), playerId, DateTime.Now.AddSeconds(20));

                int minDelay = npc.Speed;
                int maxDelay = minDelay + 1000;

                var actionPoint = await _redisDb.StringGet <int>(string.Format(RedisKey.ActionPoint, playerId));

                await _mudProvider.ShowActionPoint(playerId, actionPoint);

                await _recurringQueue.Publish($"npc_{npc.Id}", new NpcStatusModel
                {
                    NpcId      = npc.Id,
                    Status     = NpcStatusEnum.切磋,
                    TargetId   = playerId,
                    TargetType = TargetTypeEnum.玩家
                }, minDelay, maxDelay);

                await _mudProvider.ShowBox(playerId, new { boxName = "fighting" });


                var myWeapons = await _playerWareDomainService.GetAllWeapon(playerId);

                var myWeaponIds = myWeapons.Select(x => x.WareId);

                var weapons = (await _wareDomainService.GetAll()).Where(x => x.Category == WareCategoryEnum.武器 && myWeaponIds.Contains(x.Id)).ToList();



                var skillModels = new List <SkillModel>();

                var playerSkills = await _playerSkillDomainService.GetAll(player.Id);

                var ids = playerSkills?.Select(x => x.SkillId);

                var skills = (await _skillDomainService.GetAll()).Where(x => x.Category == SkillCategoryEnum.外功 && ids.Contains(x.Id));
                foreach (var playerSkill in playerSkills)
                {
                    var skill = skills.FirstOrDefault(x => x.Id == playerSkill.SkillId);
                    if (skill != null)
                    {
                        switch (skill.Type)
                        {
                        case SkillTypeEnum.刀法:
                            if (weapons.Count(x => x.Type == WareTypeEnum.刀) == 0)
                            {
                                continue;
                            }
                            break;

                        case SkillTypeEnum.剑法:
                            if (weapons.Count(x => x.Type == WareTypeEnum.剑) == 0)
                            {
                                continue;
                            }
                            break;

                        case SkillTypeEnum.枪棍:
                            if (weapons.Count(x => x.Type == WareTypeEnum.枪) == 0)
                            {
                                continue;
                            }
                            break;
                        }

                        var skillModel = _mapper.Map <SkillModel>(skill);
                        skillModel.ObjectSkillId = playerSkill.Id;
                        skillModel.Level         = playerSkill.Level;
                        skillModel.Exp           = playerSkill.Exp;
                        skillModel.IsDefault     = playerSkill.IsDefault;
                        skillModels.Add(skillModel);
                    }
                }

                if (skillModels.Count(x => (x.Type == SkillTypeEnum.刀法 || x.Type == SkillTypeEnum.剑法 || x.Type == SkillTypeEnum.枪棍) && x.IsDefault) == 0)
                {
                    skillModels.FirstOrDefault(x => x.Type == SkillTypeEnum.拳脚).IsDefault = true;
                }

                await _mudProvider.ShowFightingSkill(playerId, skillModels);
            }


            return(Unit.Value);
        }
Example #8
0
        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);
        }
Example #9
0
 public async Task <NpcEntity> Get(int id)
 {
     return(await _npcDomainService.Get(id));
 }
Example #10
0
        public async Task <Unit> Handle(ShowNpcSkillCommand 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);
            }

            var npcSkillInfoModel = new NpcSkillInfoModel
            {
                Npc = _mapper.Map <NpcBaseInfo>(npc)
            };

            var skillModels = new List <NpcSkillModel>();

            var npcSkills = await _npcSkillDomainService.GetAll(npcId);

            var npcSkillIds = npcSkills?.Select(x => x.SkillId);

            var mySkills = await _playerSkillDomainService.GetAll(playerId);

            var skills = (await _skillDomainService.GetAll()).Where(x => npcSkillIds.Contains(x.Id));

            foreach (var npcSkill in npcSkills)
            {
                var mySkill = mySkills.FirstOrDefault(x => x.SkillId == npcSkill.SkillId);

                var skill = skills.FirstOrDefault(x => x.Id == npcSkill.SkillId);
                if (skill != null)
                {
                    var skillModel = _mapper.Map <NpcSkillModel>(skill);
                    skillModel.ObjectSkillId = npcSkill.Id;
                    skillModel.Level         = npcSkill.Level;
                    skillModel.Exp           = npcSkill.Exp;

                    skillModel.MyExp   = mySkill?.Exp ?? 0;
                    skillModel.MyLevel = mySkill?.Exp ?? 0;

                    skillModels.Add(skillModel);
                }
            }

            npcSkillInfoModel.Skills = skillModels;

            await _mudProvider.ShowNpcSkill(playerId, npcSkillInfoModel);


            return(Unit.Value);
        }
Example #11
0
        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);
        }