예제 #1
0
        private async Task FightingNpc(PlayerEntity player, NpcEntity npc)
        {
            var actionPoint = await _redisDb.StringGet <int>(string.Format(RedisKey.ActionPoint, player.Id));

            if (actionPoint < 10)
            {
                actionPoint++;
            }

            Random random = new Random();

            actionPoint -= random.Next(0, 4);
            if (actionPoint <= 0)
            {
                actionPoint = 0;
            }

            await _redisDb.StringSet(string.Format(RedisKey.ActionPoint, player.Id), actionPoint);


            await _mudProvider.ShowActionPoint(player.Id, actionPoint);

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

            await _mudProvider.AddFightingTarget(player.Id, new FightingTargetModel
            {
                TargetId   = npc.Id,
                TargetName = npc.Name,
                Hp         = npc.Hp,
                Mp         = npc.Mp,
                MaxHp      = npc.MaxHp,
                MaxMp      = npc.MaxMp,
                TargetType = TargetTypeEnum.Npc
            });
        }
예제 #2
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);
        }
예제 #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);
        }