Exemple #1
0
        public async Task Learn(WareAction wareAction)
        {
            var result = await DoCommand(async() => {
                var playerId = _account.PlayerId;

                var command = new LearnWareCommand(playerId, wareAction.MyWareId);
                await _bus.SendCommand(command);
            });
        }
Exemple #2
0
        public async Task <Unit> Handle(LearnWareCommand command, CancellationToken cancellationToken)
        {
            var myWareId = command.MyWareId;
            var playerId = command.PlayerId;

            var player = await _playerDomainService.Get(playerId);

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

                return(Unit.Value);
            }

            var playerWare = await _playerWareDomainService.Get(myWareId);

            if (playerWare == null || playerWare.PlayerId != playerId)
            {
                await _bus.RaiseEvent(new DomainNotification($"你什么也没学会!"));

                return(Unit.Value);
            }

            var ware = await _wareDomainService.Get(playerWare.WareId);

            if (ware == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"你什么也没学会!"));

                await _playerWareDomainService.Delete(playerWare);

                return(Unit.Value);
            }

            if (ware.Category != WareCategoryEnum.秘籍)
            {
                await _bus.RaiseEvent(new DomainNotification($"你什么也没学会!"));

                return(Unit.Value);
            }

            var skill = await _skillDomainService.Get(x => x.Name == ware.Name);

            if (skill == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"你什么也没学会!"));

                return(Unit.Value);
            }

            if (player.Pot <= 0)
            {
                await _mudProvider.ShowMessage(player.Id, $"潜能不够,无法修练!");

                return(Unit.Value);
            }

            var needPot = 0;
            var exp     = 0;

            var mySkill = await _playerSkillDomainService.Get(x => x.PlayerId == playerId && x.SkillId == skill.Id);

            if (mySkill == null)
            {
                needPot = 100;
                exp     = 1;
                if (player.Pot <= needPot)
                {
                    await _mudProvider.ShowMessage(player.Id, $"潜能不够,无法修练!");

                    return(Unit.Value);
                }

                mySkill = new PlayerSkillEntity
                {
                    Exp       = 1,
                    Level     = 1,
                    SkillId   = skill.Id,
                    PlayerId  = playerId,
                    SkillName = skill.Name
                };
                await _playerSkillDomainService.Add(mySkill);

                player.Pot -= needPot;
                await _playerDomainService.Update(player);

                await _mudProvider.ShowMessage(player.Id, $"你消耗潜能{needPot},学会了[{skill.Name}]!");

                return(Unit.Value);
            }


            if (player.Level * 10 < mySkill.Level)
            {
                await _mudProvider.ShowMessage(player.Id, $"武功最高等级不能超过自身等级的10倍!");

                return(Unit.Value);
            }

            if (mySkill.Level >= playerWare.Level && !skill.IsBase)
            {
                await _mudProvider.ShowMessage(player.Id, $"你已经无法从秘籍上学到什么了!");

                return(Unit.Value);
            }

            var @int         = player.Int * 3 + player.IntAdd;
            var nextLevelExp = (mySkill.Level + 1) * (mySkill.Level + 1) * 50;
            var levelUpExp   = nextLevelExp - mySkill.Level * mySkill.Level * 50;

            Random random = new Random();

            exp     = random.Next(1, levelUpExp / 10);
            needPot = exp * 100 / @int;

            var effect = exp * 1000 / levelUpExp;

            string effectWords;

            if (effect > 80)
            {
                effectWords = "恍然大悟";
            }
            else if (effect > 50)
            {
                effectWords = "有所顿悟";
            }
            else if (effect > 20)
            {
                effectWords = "略有所获";
            }
            else if (effect > 10)
            {
                effectWords = "略有所获";
            }
            else
            {
                effectWords = "似乎没有什么进展";
            }

            player.Pot -= needPot;
            await _playerDomainService.Update(player);

            mySkill.SkillName = skill.Name;
            mySkill.Exp      += exp;
            await _mudProvider.ShowMessage(player.Id, $"你消耗潜能{needPot},{effectWords},[{skill.Name}]经验增加{exp}!");

            if (mySkill.Exp > nextLevelExp)
            {
                mySkill.Level++;
                await _mudProvider.ShowMessage(player.Id, $"[{skill.Name}]等级上升为 Lv.{mySkill.Level}!");
            }



            await _playerSkillDomainService.Update(mySkill);



            await _bus.RaiseEvent(new PlayerAttributeChangedEvent(player)).ConfigureAwait(false);

            return(Unit.Value);
        }