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(); }
public void Generate(string filePath) { var shopService = ChickenContainer.Instance.Resolve <IShopService>(); var shopSkillService = ChickenContainer.Instance.Resolve <IShopSkillService>(); string[] lines = File.ReadAllText(filePath, Encoding.Default).Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); int counter = 0; byte type = 0; foreach (string line in lines.Where(s => s.StartsWith("n_inv") || s.StartsWith("shopping"))) { try { string[] currentPacket = line.Split('\t', ' '); switch (currentPacket[0]) { case "shopping": if (currentPacket.Length > 3) { type = byte.Parse(currentPacket[1]); } break; case "n_inv": short npcId = short.Parse(currentPacket[2]); if (!shopService.GetByMapNpcId(npcId).Any()) { continue; } for (int i = 5; i < currentPacket.Length; i++) { if (currentPacket[i].Contains(".")) { continue; } var shopItem = new ShopSkillDto { ShopId = shopService.GetByMapNpcId(npcId).FirstOrDefault()?.Id ?? 0, Type = type, Slot = (byte)(i - 5), SkillId = long.Parse(currentPacket[i]) }; if (shopItem.ShopId == 0) { continue; } if (_shopSkills.Any(s => s.SkillId == shopItem.SkillId && s.ShopId == shopItem.ShopId) || shopSkillService.GetByShopId(shopItem.ShopId).Any(s => s.SkillId == shopItem.SkillId)) { continue; } _shopSkills.Add(shopItem); counter++; } break; } } catch (Exception e) { Log.Error("[PARSE]", e); Log.Warn(line); } } shopSkillService.Save(_shopSkills); }