Exemple #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
            });
        }
Exemple #2
0
        private async Task Fighting(NpcEntity npc, PlayerEntity player)
        {
            var npcFightingPlayerId = await _redisDb.StringGet <int>(string.Format(RedisKey.NpcFighting, npc.Id));

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

                return;
            }

            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
            });
        }
Exemple #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
            });
        }