Ejemplo n.º 1
0
        private async Task <KillmailInvolved> InsertParsedKillMailInvolved(IDbConnection connection, Killmail killMail, ParsedKillMailInvolved involved)
        {
            var killMailInvolvedToInsert = new KillmailInvolved();

            killMailInvolvedToInsert.killmail_id       = killMail.id;
            killMailInvolvedToInsert.attacker_guild_id = await GetOrInsertGuild(connection, involved.AttackerGuild);

            killMailInvolvedToInsert.attacker_level = involved.AttackerLevel;
            killMailInvolvedToInsert.attacker_id    = await GetOrInsertCharacter(connection, involved.AttackerName, involved.AttackerIsNpc, killMailInvolvedToInsert.attacker_guild_id, involved.AttackerLevel, involved.AttackerClass);

            killMailInvolvedToInsert.melee_damage = involved.MeleeDamage;
            killMailInvolvedToInsert.melee_hits   = involved.MeleeHits;
            killMailInvolvedToInsert.spell_damage = involved.SpellDamage;
            killMailInvolvedToInsert.spell_hits   = involved.SpellHits;
            killMailInvolvedToInsert.dispel_slots = involved.DispelSlots;

            var insertQuery =
                @"INSERT INTO killmail_involved (killmail_id, attacker_id, attacker_guild_id, attacker_level, melee_damage, melee_hits, spell_damage, spell_hits, dispel_slots)
            VALUES (@killmail_id, @attacker_id, @attacker_guild_id, @attacker_level, @melee_damage, @melee_hits, @spell_damage, @spell_hits, @dispel_slots)
            ON CONFLICT (killmail_id, attacker_id) DO NOTHING;
            ";

            await connection.ExecuteAsync(insertQuery, killMailInvolvedToInsert);

            return(killMailInvolvedToInsert);
        }
Ejemplo n.º 2
0
        private static async Task ParseInvolved(ParsedKillMail killMail, string involvedText)
        {
            var involvedMatches = Regex.Matches(involvedText, InvolvedPattern);

            foreach (Match involvedMatch in involvedMatches)
            {
                if (involvedMatch.Success)
                {
                    var parsedInvolved = new ParsedKillMailInvolved();
                    foreach (Group group in involvedMatch.Groups.Where(x => x.Success))
                    {
                        switch (group.Name)
                        {
                        case "attacker":
                            parsedInvolved.AttackerName = group.Value.Trim();
                            break;

                        case "contribution":
                            var contributionText = group.Value.Trim();
                            var meleeDamageMatch = Regex.Match(contributionText, MeleeDamagePattern)?.Groups.FirstOrDefault(x => x.Name == "meleeDamage");
                            var meleeHitMatch    = Regex.Match(contributionText, MeleeDamagePattern)?.Groups.FirstOrDefault(x => x.Name == "meleeHit");
                            var spellDamageMatch = Regex.Match(contributionText, SpellDamagePattern)?.Groups.FirstOrDefault(x => x.Name == "spellDamage");
                            var spellHitMatch    = Regex.Match(contributionText, SpellDamagePattern)?.Groups.FirstOrDefault(x => x.Name == "spellHit");
                            var dispelMatch      = Regex.Match(contributionText, DispelPattern)?.Groups.FirstOrDefault(x => x.Name == "dispelSlots");

                            if (meleeDamageMatch != null && int.TryParse(meleeDamageMatch.Value.Trim(), out var meleeDamage))
                            {
                                parsedInvolved.MeleeDamage = meleeDamage;
                            }
                            if (meleeHitMatch != null && int.TryParse(meleeHitMatch.Value.Trim(), out var meleeHit))
                            {
                                parsedInvolved.MeleeHits = meleeHit;
                            }
                            if (spellDamageMatch != null && int.TryParse(spellDamageMatch.Value.Trim(), out var spellDamage))
                            {
                                parsedInvolved.SpellDamage = spellDamage;
                            }
                            if (spellHitMatch != null && int.TryParse(spellHitMatch.Value.Trim(), out var spellHit))
                            {
                                parsedInvolved.SpellHits = spellHit;
                            }
                            if (dispelMatch != null && int.TryParse(dispelMatch.Value.Trim(), out var dispelSlots))
                            {
                                parsedInvolved.DispelSlots = dispelSlots;
                            }
                            break;

                        default:
                            break;
                        }
                    }

                    // Get level and class and guild for each char
                    var attackerScraper = new CharBrowserScraper(parsedInvolved.AttackerName);
                    await attackerScraper.Fetch();

                    parsedInvolved.AttackerGuild = attackerScraper.Guild;
                    parsedInvolved.AttackerLevel = attackerScraper.Level;
                    parsedInvolved.AttackerClass = attackerScraper.Class;
                    parsedInvolved.AttackerIsNpc = attackerScraper.IsNpc;

                    killMail.Involved.Add(parsedInvolved);
                }
            }
        }