예제 #1
0
        private static async Task HandleNpcSkillBuyRequest(IPlayerEntity player, ShopBuyEvent shopBuy, Shop shop)
        {
            ShopSkillDto skillShop = shop.Skills.FirstOrDefault(s => s.SkillId == shopBuy.Slot);

            if (skillShop == null)
            {
                return;
            }

            // check use sp
            if (player.HasSpWeared)
            {
                return;
            }

            // check skill cooldown
            if (player.SkillComponent.CooldownsBySkillId.Any(s => s.Item2 == shopBuy.Slot))
            {
                return;
            }

            // check skill already exists in player skills
            if (player.SkillComponent.Skills.ContainsKey(shopBuy.Slot))
            {
                return;
            }

            // check skill class
            if ((byte)player.Character.Class != skillShop.Skill.Class)
            {
                return;
            }

            // check skill price
            if (player.Character.Gold < skillShop.Skill.Price)
            {
                return;
            }

            // check skill cp
            if (player.GetCp() < skillShop.Skill.CpCost)
            {
                return;
            }

            // check skill minimum level
            byte minimumLevel = 1;

            switch (player.Character.Class)
            {
            case CharacterClassType.Adventurer:
                minimumLevel = skillShop.Skill.MinimumAdventurerLevel;
                break;

            case CharacterClassType.Swordman:
                minimumLevel = skillShop.Skill.MinimumSwordmanLevel;
                break;

            case CharacterClassType.Archer:
                minimumLevel = skillShop.Skill.MinimumArcherLevel;
                break;

            case CharacterClassType.Magician:
                minimumLevel = skillShop.Skill.MinimumMagicianLevel;
                break;

            case CharacterClassType.Wrestler:
                minimumLevel = skillShop.Skill.MinimumWrestlerLevel;
                break;

            case CharacterClassType.Unknown:
                break;
            }

            if (skillShop.Skill.MinimumSwordmanLevel == 0 && skillShop.Skill.MinimumArcherLevel == 0 && skillShop.Skill.MinimumMagicianLevel == 0)
            {
                minimumLevel = skillShop.Skill.MinimumAdventurerLevel;
            }

            if (minimumLevel == 0)
            {
                // can't learn the skill
                return;
            }

            // level is required for passive skills
            if (player.Character.Level < minimumLevel && skillShop.Skill.Id <= 200)
            {
                return;
            }

            // job level requirement
            if (player.Character.JobLevel < minimumLevel && skillShop.SkillId >= 200)
            {
                return;
            }

            if (skillShop.SkillId < 200)
            {
                foreach (CharacterSkillDto skill in player.SkillComponent.CharacterSkills.Select(s => s.Value))
                {
                    if (skillShop.Skill.CastId == skill.Skill.CastId && skill.Skill.Id < 200)
                    {
                        player.SkillComponent.CharacterSkills.Remove(skill.Id);
                    }
                }
            }

            // check skill upgrades
            // remove old upgrade
            if (skillShop.SkillId >= 200 && skillShop.Skill.UpgradeSkill != 0)
            {
                CharacterSkillDto oldupgrade = player.SkillComponent.CharacterSkills.FirstOrDefault(s =>
                                                                                                    s.Value.Skill.UpgradeSkill == skillShop.Skill.UpgradeSkill && s.Value.Skill.UpgradeType == skillShop.Skill.UpgradeType && s.Value.Skill.UpgradeSkill != 0).Value;
                if (oldupgrade != null)
                {
                    player.SkillComponent.CharacterSkills.Remove(oldupgrade.Id);
                }
            }

            await player.AddCharacterSkillAsync(new CharacterSkillDto
            {
                Id          = Guid.NewGuid(),
                SkillId     = skillShop.SkillId,
                Skill       = skillShop.Skill,
                CharacterId = player.Id
            });

            player.Character.Gold -= skillShop.Skill.Price;
            await player.ActualizeUiGold();

            await player.ActualizeUiSkillList();

            await player.ActualizeUiQuicklist();

            await player.SendChatMessageAsync(PlayerMessages.SKILL_YOU_LEARNED_SKILL_X, SayColorType.LightGreen);

            await player.ActualizeUiExpBar();
        }