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

            if (player == null)
            {
                return(Unit.Value);
            }

            var skillModels = new List <SkillModel>();

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

            var baseSkills = await _skillDomainService.GetAllBaseSkills();

            foreach (var baseSkill in baseSkills)
            {
                if (playerSkills.Count(x => x.SkillId == baseSkill.Id) == 0)
                {
                    var playerSkill = new PlayerSkillEntity
                    {
                        Exp       = 0,
                        Level     = 0,
                        PlayerId  = playerId,
                        SkillId   = baseSkill.Id,
                        SkillName = baseSkill.Name
                    };
                    await _playerSkillDomainService.Add(playerSkill);

                    playerSkills.Add(playerSkill);
                }
            }


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

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

            foreach (var playerSkill in playerSkills)
            {
                var skill = skills.FirstOrDefault(x => x.Id == playerSkill.SkillId);
                if (skill != null)
                {
                    var skillModel = _mapper.Map <SkillModel>(skill);
                    skillModel.ObjectSkillId = playerSkill.Id;
                    skillModel.Level         = playerSkill.Level;
                    skillModel.Exp           = playerSkill.Exp;
                    skillModels.Add(skillModel);
                }
            }

            await _mudProvider.ShowMySkill(playerId, skillModels);

            return(Unit.Value);
        }
Example #2
0
        public async Task <Paging <SkillEntity> > GetPaging(string keyword, int pageIndex)
        {
            var query = await _skillDomainService.GetAll();

            if (!string.IsNullOrEmpty(keyword))
            {
                query = query.Where(x => x.Name.Contains(keyword));
            }
            query = query.OrderBy(x => x.Id);

            return(await query.Paged(pageIndex));
        }
Example #3
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);
        }