private Properties ParseProperties(ParsingItem parsingItem) { switch (parsingItem.Metadata.Category) { case Category.Gem: return(ParseGemProperties(parsingItem)); case Category.Map: case Category.Contract: return(ParseMapProperties(parsingItem)); case Category.Accessory: return(ParseAccessoryProperties(parsingItem)); case Category.Armour: return(ParseArmourProperties(parsingItem)); case Category.Weapon: return(ParseWeaponProperties(parsingItem)); case Category.Jewel: return(ParseJewelProperties(parsingItem)); default: return(new Properties()); } }
private Properties ParseJewelProperties(ParsingItem parsingItem) { return(new Properties() { ItemLevel = GetInt(patterns.ItemLevel, parsingItem), Identified = !GetBool(patterns.Unidentified, parsingItem), Corrupted = GetBool(patterns.Corrupted, parsingItem), }); }
private static OriginalItem ParseOriginal(ParsingItem parsingItem) { return(new OriginalItem() { Name = parsingItem.Blocks[0].Lines.ElementAtOrDefault(2)?.Text, Type = parsingItem.Blocks[0].Lines.ElementAtOrDefault(3)?.Text, Text = parsingItem.Text, }); }
public static bool TryGetMapTierLine(this ParsingItem item, out string mapTierLine) { if (item.SplitSections.Length > 1) { mapTierLine = item.SplitSections[1][0]; return(true); } mapTierLine = null; return(false); }
public static bool TryGetVaalGemName(this ParsingItem item, out string gemName) { if (item.SplitSections.Length > 7) { gemName = item.SplitSections[5][0]; return(true); } gemName = null; return(false); }
private Properties ParseGemProperties(ParsingItem parsingItem) { var propertyBlock = parsingItem.Blocks[1]; return(new Properties() { Corrupted = GetBool(patterns.Corrupted, parsingItem), GemLevel = GetInt(patterns.Level, propertyBlock), Quality = GetInt(patterns.Quality, propertyBlock), AlternateQuality = GetBool(patterns.AlternateQuality, parsingItem), }); }
private void ParseMap(Item item, ParsingItem parsingItem) { var mapBlock = parsingItem.MapPropertiesSection; item.ItemLevel = patterns.GetInt(patterns.ItemLevel, item.Text); item.Identified = !patterns.Unidentified.IsMatch(item.Text); item.Properties.ItemQuantity = patterns.GetInt(patterns.ItemQuantity, mapBlock); item.Properties.ItemRarity = patterns.GetInt(patterns.ItemRarity, mapBlock); item.Properties.MonsterPackSize = patterns.GetInt(patterns.MonsterPackSize, mapBlock); item.Properties.MapTier = patterns.GetInt(patterns.MapTier, mapBlock); item.Properties.Quality = patterns.GetInt(patterns.Quality, mapBlock); item.Properties.Blighted = patterns.Blighted.IsMatch(parsingItem.WholeSections[0]); item.Corrupted = ParseFromEnd(patterns.Corrupted, parsingItem); }
private List <Socket> ParseSockets(ParsingItem parsingItem) { if (TryParseValue(patterns.Socket, parsingItem, out var match)) { var groups = match.Groups.Values .Where(x => !string.IsNullOrEmpty(x.Value)) .Skip(1) .Select((x, Index) => new { x.Value, Index, }) .ToList(); var result = new List <Socket>(); foreach (var group in groups) { var groupValue = group.Value.Replace("-", "").Trim(); while (groupValue.Length > 0) { switch (groupValue[0]) { case 'B': result.Add(new Socket() { Group = group.Index, Colour = SocketColour.Blue }); break; case 'G': result.Add(new Socket() { Group = group.Index, Colour = SocketColour.Green }); break; case 'R': result.Add(new Socket() { Group = group.Index, Colour = SocketColour.Red }); break; case 'W': result.Add(new Socket() { Group = group.Index, Colour = SocketColour.White }); break; case 'A': result.Add(new Socket() { Group = group.Index, Colour = SocketColour.Abyss }); break; } groupValue = groupValue[1..];
public ItemModifiers Parse(ParsingItem parsingItem) { var mods = new ItemModifiers(); ParseModifiers(mods.Explicit, ExplicitPatterns, parsingItem); ParseModifiers(mods.Enchant, EnchantPatterns, parsingItem); ParseModifiers(mods.Implicit, ImplicitPatterns, parsingItem); ParseModifiers(mods.Crafted, CraftedPatterns, parsingItem); ParseModifiers(mods.Fractured, FracturedPatterns, parsingItem); // ParseModifiers(mods.Veiled, VeiledPatterns, parsingItem); mods.Pseudo = pseudoModifierProvider.Parse(mods); return(mods); }
private Properties ParseArmourProperties(ParsingItem parsingItem) { var propertyBlock = parsingItem.Blocks[1]; return(new Properties() { ItemLevel = GetInt(patterns.ItemLevel, parsingItem), Identified = !GetBool(patterns.Unidentified, parsingItem), Corrupted = GetBool(patterns.Corrupted, parsingItem), Quality = GetInt(patterns.Quality, propertyBlock), Armor = GetInt(patterns.Armor, propertyBlock), EnergyShield = GetInt(patterns.EnergyShield, propertyBlock), Evasion = GetInt(patterns.Evasion, propertyBlock), ChanceToBlock = GetInt(patterns.ChanceToBlock, propertyBlock), }); }
private void ParseEquipmentProperties(Item item, ParsingItem parsingItem) { var propertySection = parsingItem.WholeSections[1]; item.ItemLevel = patterns.GetInt(patterns.ItemLevel, item.Text); item.Identified = !ParseFromEnd(patterns.Unidentified, parsingItem); item.Properties.Armor = patterns.GetInt(patterns.Armor, propertySection); item.Properties.EnergyShield = patterns.GetInt(patterns.EnergyShield, propertySection); item.Properties.Evasion = patterns.GetInt(patterns.Evasion, propertySection); item.Properties.ChanceToBlock = patterns.GetInt(patterns.ChanceToBlock, propertySection); item.Properties.Quality = patterns.GetInt(patterns.Quality, propertySection); item.Properties.AttacksPerSecond = patterns.GetDouble(patterns.AttacksPerSecond, propertySection); item.Properties.CriticalStrikeChance = patterns.GetDouble(patterns.CriticalStrikeChance, propertySection); item.Properties.ElementalDps = patterns.GetDps(patterns.ElementalDamage, propertySection, item.Properties.AttacksPerSecond); item.Properties.PhysicalDps = patterns.GetDps(patterns.PhysicalDamage, propertySection, item.Properties.AttacksPerSecond); item.Properties.DamagePerSecond = item.Properties.ElementalDps + item.Properties.PhysicalDps; item.Corrupted = ParseFromEnd(patterns.Corrupted, parsingItem); }
private Properties ParseMapProperties(ParsingItem parsingItem) { var propertyBlock = parsingItem.Blocks[1]; return(new Properties() { ItemLevel = GetInt(patterns.ItemLevel, parsingItem), Identified = !GetBool(patterns.Unidentified, parsingItem), Corrupted = GetBool(patterns.Corrupted, parsingItem), Blighted = patterns.Blighted.IsMatch(parsingItem.Blocks[0].Lines[2].Text), ItemQuantity = GetInt(patterns.ItemQuantity, propertyBlock), ItemRarity = GetInt(patterns.ItemRarity, propertyBlock), MonsterPackSize = GetInt(patterns.MonsterPackSize, propertyBlock), MapTier = GetInt(patterns.MapTier, propertyBlock), Quality = GetInt(patterns.Quality, propertyBlock), }); }
private Properties ParseWeaponProperties(ParsingItem parsingItem) { var propertyBlock = parsingItem.Blocks[1]; var properties = new Properties { ItemLevel = GetInt(patterns.ItemLevel, parsingItem), Identified = !GetBool(patterns.Unidentified, parsingItem), Corrupted = GetBool(patterns.Corrupted, parsingItem), Quality = GetInt(patterns.Quality, propertyBlock), AttacksPerSecond = GetDouble(patterns.AttacksPerSecond, propertyBlock), CriticalStrikeChance = GetDouble(patterns.CriticalStrikeChance, propertyBlock) }; properties.ElementalDps = GetDps(patterns.ElementalDamage, propertyBlock, properties.AttacksPerSecond); properties.PhysicalDps = GetDps(patterns.PhysicalDamage, propertyBlock, properties.AttacksPerSecond); properties.DamagePerSecond = properties.ElementalDps + properties.PhysicalDps; return(properties); }
public ItemModifiers Parse(ParsingItem parsingItem) { var text = NewLinePattern.Replace(parsingItem.Text, "\n"); var mods = new ItemModifiers(); // Make sure the text ends with an empty line for our regexes to work correctly if (!text.EndsWith("\n")) { text += "\n"; } ParseMods(mods.Explicit, ExplicitPatterns, text); ParseMods(mods.Implicit, ImplicitPatterns, text); ParseMods(mods.Enchant, EnchantPatterns, text); ParseMods(mods.Crafted, CraftedPatterns, text); //FillMods(mods.Veiled, VeiledPatterns, text); ParseMods(mods.Fractured, FracturedPatterns, text); mods.Pseudo = pseudoModifierProvider.Parse(mods); return(mods); }
private void ParseModifiers(List <Modifier> modifiers, List <ModifierPatternMetadata> metadatas, ParsingItem item) { foreach (var block in item.Blocks.Where(x => !x.Parsed)) { foreach (var line in block.Lines.Where(x => !x.Parsed)) { foreach (var metadata in metadatas) { foreach (var pattern in metadata.Patterns) { if (pattern.Pattern.IsMatch(line.Text)) { ParseMod(modifiers, metadata, pattern, line.Text); line.Parsed = true; } // Multiline modifiers else if (pattern.LineCount > 1 && pattern.Pattern.IsMatch(string.Join('\n', block.Lines.Skip(line.Index).Take(pattern.LineCount)))) { ParseMod(modifiers, metadata, pattern, string.Join('\n', block.Lines.Skip(line.Index).Take(pattern.LineCount))); foreach (var multiline in block.Lines.Skip(line.Index).Take(pattern.LineCount)) { multiline.Parsed = true; } } } } } } }
/// <summary> /// Parses the item header information /// </summary> /// <param name="parsingItem">The item to parse</param> public ParseItemHeaderCommand(ParsingItem parsingItem) { ParsingItem = parsingItem; }
public Task <Item> Handle(ParseItemCommand request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request.ItemText)) { return(Task.FromResult <Item>(null)); } try { var itemText = new ItemNameTokenizer().CleanString(request.ItemText); var wholeSections = itemText.Split(SEPARATOR_PATTERN, StringSplitOptions.RemoveEmptyEntries); var splitSections = wholeSections .Select(block => newLinePattern .Split(block) .Where(line => line != "") .ToArray() ) .ToArray(); var parsingItem = new ParsingItem(wholeSections, splitSections, request.ItemText); var itemHeader = itemMetadataProvider.Parse(parsingItem, GetRarity(parsingItem.Rarity)); if (itemHeader == null || (string.IsNullOrEmpty(itemHeader.Name) && string.IsNullOrEmpty(itemHeader.Type))) { throw new NotSupportedException("Item not found."); } var item = new Item { Name = itemHeader.Name, Type = itemHeader.Type, Rarity = itemHeader.Rarity, Category = itemHeader.Category, NameLine = parsingItem.NameLine, TypeLine = parsingItem.TypeLine, Text = parsingItem.Text, }; if (item.Rarity == Rarity.Unknown) { item.Rarity = GetRarity(parsingItem.Rarity); } switch (item.Category) { case Category.DivinationCard: case Category.Currency: case Category.Prophecy: break; case Category.Gem: ParseGem(item, parsingItem); break; case Category.Map: ParseMap(item, parsingItem); ParseMods(item, parsingItem); break; default: ParseEquipmentProperties(item, parsingItem); ParseMods(item, parsingItem); ParseSockets(item); ParseInfluences(item, parsingItem); break; } return(Task.FromResult(item)); } catch (Exception e) { logger.LogError(e, "Could not parse item."); return(Task.FromResult <Item>(null)); } }