コード例 #1
0
        private static DamageRecord ValidateDamage(DamageRecord record, SpellResist resist = SpellResist.UNDEFINED)
        {
            if (record != null)
            {
                // handle riposte separately
                if (LineModifiersParser.IsRiposte(record.ModifiersMask))
                {
                    record.SubType = Labels.RIPOSTE;
                }

                if (InIgnoreList(record.Defender))
                {
                    record = null;
                }
                else
                {
                    // Needed to replace 'You' and 'you', etc
                    record.Attacker = PlayerManager.Instance.ReplacePlayer(record.Attacker, record.Defender);
                    record.Defender = PlayerManager.Instance.ReplacePlayer(record.Defender, record.Attacker);
                    if (string.IsNullOrEmpty(record.Attacker))
                    {
                        record.Attacker = Labels.ENVDAMAGE;
                    }

                    if (resist != SpellResist.UNDEFINED && ConfigUtil.PlayerName == record.Attacker && record.Defender != record.Attacker)
                    {
                        DataManager.Instance.UpdateNpcSpellResistStats(record.Defender, resist);
                    }
                }
            }

            return(record);
        }
コード例 #2
0
ファイル: DataManager.cs プロジェクト: FunkyBlaze/EQLogParser
        internal void UpdateNpcSpellResistStats(string npc, SpellResist resist, bool resisted = false)
        {
            string lower = npc.ToLower(CultureInfo.CurrentCulture);

            lock (NpcResistStats)
            {
                if (!NpcResistStats.TryGetValue(lower, out Dictionary <SpellResist, ResistCount> stats))
                {
                    stats = new Dictionary <SpellResist, ResistCount>();
                    NpcResistStats[lower] = stats;
                }

                if (!stats.TryGetValue(resist, out ResistCount count))
                {
                    stats[resist] = resisted ? new ResistCount {
                        Resisted = 1
                    } : new ResistCount {
                        Landed = 1
                    };
                }
                else
                {
                    if (resisted)
                    {
                        count.Resisted++;
                    }
                    else
                    {
                        count.Landed++;
                    }
                }
            }

            lock (NpcTotalSpellCounts)
            {
                if (!NpcTotalSpellCounts.TryGetValue(lower, out TotalCount value))
                {
                    value = new TotalCount {
                        Landed = 1
                    };
                    NpcTotalSpellCounts[lower] = value;
                }
                else
                {
                    value.Landed++;
                }
            }
        }
コード例 #3
0
        private static DamageRecord ParseDamage(string actionPart)
        {
            DamageRecord record    = null;
            ParseType    parseType = ParseType.UNKNOWN;

            string withoutMods    = actionPart;
            int    modifiersIndex = -1;

            if (actionPart[actionPart.Length - 1] == ')')
            {
                // using 4 here since the shortest modifier should at least be 3 even in the future. probably.
                modifiersIndex = actionPart.LastIndexOf('(', actionPart.Length - 4);
                if (modifiersIndex > -1)
                {
                    withoutMods = actionPart.Substring(0, modifiersIndex);
                }
            }

            int  pointsIndex = -1;
            int  forIndex    = -1;
            int  fromIndex   = -1;
            int  byIndex     = -1;
            int  takenIndex  = -1;
            int  hitIndex    = -1;
            int  extraIndex  = -1;
            int  isAreIndex  = -1;
            bool nonMelee    = false;

            List <string> nameList = new List <string>();
            StringBuilder builder  = new StringBuilder();
            var           data     = withoutMods.Split(' ');

            SpellResist resist = SpellResist.UNDEFINED;

            for (int i = 0; i < data.Length; i++)
            {
                switch (data[i])
                {
                case "taken":
                    takenIndex = i;

                    int test1 = i - 1;
                    if (test1 > 0 && data[test1] == "has")
                    {
                        parseType = ParseType.HASTAKEN;

                        int test2 = i + 2;
                        if (data.Length > test2 && data[test2] == "extra" && data[test2 - 1] == "an")
                        {
                            extraIndex = test2;
                        }
                    }
                    else if (test1 >= 1 && data[test1] == "have" && data[test1 - 1] == "You")
                    {
                        parseType = ParseType.YOUHAVETAKEN;
                    }
                    break;

                case "by":
                    byIndex = i;
                    break;

                case "non-melee":
                    nonMelee = true;
                    break;

                case "is":
                case "are":
                    isAreIndex = i;
                    break;

                case "for":
                    int next = i + 1;
                    if (data.Length > next && data[next].Length > 0 && char.IsNumber(data[next][0]))
                    {
                        forIndex = i;
                    }
                    break;

                case "from":
                    fromIndex = i;
                    break;

                case "points":
                    int ofIndex = i + 1;
                    if (ofIndex < data.Length && data[ofIndex] == "of")
                    {
                        parseType   = ParseType.POINTSOF;
                        pointsIndex = i;

                        int resistIndex = ofIndex + 1;
                        if (resistIndex < data.Length && SpellResistMap.TryGetValue(data[resistIndex], out SpellResist value))
                        {
                            resist   = value;
                            nonMelee = true;
                        }
                    }
                    break;

                default:
                    if (HitMap.ContainsKey(data[i]))
                    {
                        hitIndex = i;
                    }
                    break;
                }
            }

            if (parseType == ParseType.POINTSOF && forIndex > -1 && forIndex < pointsIndex && hitIndex > -1)
            {
                record = ParsePointsOf(data, nonMelee, forIndex, byIndex, hitIndex, builder, nameList);
            }
            else if (parseType == ParseType.HASTAKEN && takenIndex < fromIndex && fromIndex > -1)
            {
                record = ParseHasTaken(data, takenIndex, fromIndex, byIndex, builder);
            }
            else if (parseType == ParseType.POINTSOF && extraIndex > -1 && takenIndex > -1 && takenIndex < fromIndex)
            {
                record = ParseExtra(data, takenIndex, extraIndex, fromIndex, nameList);
            }
            // there are more messages without a specificied attacker or spell but do these first
            else if (parseType == ParseType.YOUHAVETAKEN && takenIndex > -1 && fromIndex > -1 && byIndex > fromIndex)
            {
                record = ParseYouHaveTaken(data, takenIndex, fromIndex, byIndex, builder);
            }
            else if (parseType == ParseType.POINTSOF && isAreIndex > -1 && byIndex > isAreIndex && forIndex > byIndex)
            {
                record = ParseDS(data, isAreIndex, byIndex, forIndex);
            }

            if (record != null && modifiersIndex > -1)
            {
                record.ModifiersMask = LineModifiersParser.Parse(actionPart.Substring(modifiersIndex + 1, actionPart.Length - 1 - modifiersIndex - 1));
            }

            return(ValidateDamage(record, resist));
        }
コード例 #4
0
        public static void Process(LineData lineData)
        {
            bool handled = false;

            try
            {
                string[] split = lineData.Action.Split(' ');

                if (split != null && split.Length >= 2)
                {
                    int stop = split.Length - 1;
                    if (!string.IsNullOrEmpty(split[stop]) && split[stop][split[stop].Length - 1] == ')')
                    {
                        for (int i = stop; i >= 0 && stop > 2; i--)
                        {
                            if (!string.IsNullOrEmpty(split[i]) && split[i][0] == '(')
                            {
                                stop = i - 1;
                                break;
                            }
                        }
                    }

                    // see if it's a died message right away
                    if (split.Length > 1 && stop >= 1 && split[stop] == "died.")
                    {
                        var test = string.Join(" ", split, 0, stop);
                        if (!string.IsNullOrEmpty(test))
                        {
                            UpdateSlain(test, "", lineData);
                            handled = true;
                        }
                    }

                    if (!handled)
                    {
                        int    byIndex = -1, forIndex = -1, pointsOfIndex = -1, endDamage = -1, byDamage = -1, extraIndex = -1;
                        int    fromDamage = -1, hasIndex = -1, haveIndex = -1, hitType = -1, hitTypeAdd = -1, slainIndex = -1;
                        int    takenIndex = -1, tryIndex = -1, yourIndex = -1, isIndex = -1, dsIndex = -1, butIndex = -1;
                        int    missType = -1, nonMeleeIndex = -1;
                        string subType = null;

                        bool found = false;
                        for (int i = 0; i <= stop && !found; i++)
                        {
                            if (!string.IsNullOrEmpty(split[i]))
                            {
                                switch (split[i])
                                {
                                case "healed":
                                    found = true; // short circuit
                                    break;

                                case "but":
                                    butIndex = i;
                                    break;

                                case "is":
                                case "was":
                                    isIndex = i;
                                    break;

                                case "has":
                                    hasIndex = i;
                                    break;

                                case "have":
                                    haveIndex = i;
                                    break;

                                case "by":
                                    byIndex = i;

                                    if (slainIndex > -1)
                                    {
                                        found = true; // short circut
                                    }
                                    else if (i > 4 && split[i - 1] == "damage")
                                    {
                                        byDamage = i - 1;
                                    }
                                    break;

                                case "from":
                                    if (i > 3 && split[i - 1] == "damage")
                                    {
                                        fromDamage = i - 1;
                                        if (pointsOfIndex > -1 && extraIndex > -1)
                                        {
                                            found = true; // short circut
                                        }
                                        else if (stop > (i + 1) && split[i + 1] == "your")
                                        {
                                            yourIndex = i + 1;
                                        }
                                    }
                                    break;

                                case "damage.":
                                    if (i == stop)
                                    {
                                        endDamage = i;
                                    }
                                    break;

                                case "non-melee":
                                    nonMeleeIndex = i;
                                    if (i > 9 && stop == (i + 1) && split[i + 1] == "damage." && pointsOfIndex == (i - 2) && forIndex == (i - 4))
                                    {
                                        dsIndex = i - 5;
                                        found   = true; // short circut
                                    }
                                    break;

                                case "point":
                                case "points":
                                    if (stop >= (i + 1) && split[i + 1] == "of")
                                    {
                                        pointsOfIndex = i;
                                        if (i > 2 && split[i - 2] == "for")
                                        {
                                            forIndex = i - 2;
                                        }
                                    }
                                    break;

                                case "blocks!":
                                    missType = (stop == i && butIndex > -1 && i > tryIndex) ? 0 : missType;
                                    break;

                                case "shield!":
                                case "staff!":
                                    missType = (i > 5 && stop == i && butIndex > -1 && i > tryIndex && split[i - 2] == "with" &&
                                                split[i - 3].StartsWith("block", StringComparison.OrdinalIgnoreCase)) ? 0 : missType;
                                    break;

                                case "dodge!":
                                case "dodges!":
                                    missType = (stop == i && butIndex > -1 && i > tryIndex) ? 1 : missType;
                                    break;

                                case "miss!":
                                case "misses!":
                                    missType = (stop == i && butIndex > -1 && i > tryIndex) ? 2 : missType;
                                    break;

                                case "parries!":
                                    missType = (stop == i && butIndex > -1 && i > tryIndex) ? 3 : missType;
                                    break;

                                case "INVULNERABLE!":
                                    missType = (stop == i && butIndex > -1 && i > tryIndex) ? 4 : missType;
                                    break;

                                case "slain":
                                    slainIndex = i;
                                    break;

                                case "taken":
                                    if (i > 1 && (hasIndex == (i - 1) || haveIndex == (i - 1)))
                                    {
                                        takenIndex = i - 1;

                                        if (stop > (i + 2) && split[i + 1] == "an" && split[i + 2] == "extra")
                                        {
                                            extraIndex = i + 2;
                                        }
                                    }
                                    break;

                                // Old (EQEMU) crit and crippling blow handling
                                case "hit!":
                                    if (stop == i && split.Length > 4 && split[i - 1] == "critical" && split[i - 3] == "scores")
                                    {
                                        LastCrit = new OldCritData {
                                            Attacker = split[0], LineData = lineData
                                        };
                                    }
                                    break;

                                case "Crippling":
                                    if (stop == (i + 1) && split.Length > 4 && split[i + 1].StartsWith("Blow!") && split[i - 2] == "lands")
                                    {
                                        LastCrit = new OldCritData {
                                            Attacker = split[0], LineData = lineData
                                        };
                                    }
                                    break;

                                default:
                                    if (slainIndex == -1 && i > 0 && string.IsNullOrEmpty(subType) && HitMap.TryGetValue(split[i], out subType))
                                    {
                                        hitType = i;
                                        if (i < stop && HitAdditionalMap.ContainsKey(split[i]))
                                        {
                                            hitTypeAdd = i + i;
                                        }

                                        if (i > 2 && split[i - 1] == "to" && (split[i - 2] == "tries" || split[i - 2] == "try"))
                                        {
                                            tryIndex = i - 2;
                                        }
                                    }
                                    break;
                                }
                            }
                        }

                        // [Sun Apr 18 19:36:39 2021] Tantor is pierced by Tolzol's thorns for 6718 points of non-melee damage.
                        // [Mon Apr 19 22:02:52 2021] Honvar is tormented by Reisil's frost for 7809 points of non-melee damage.
                        // [Sun Apr 25 13:47:12 2021] Test One Hundred Three is burned by YOUR flames for 5224 points of non-melee damage.
                        // [Sun Apr 18 14:16:13 2021] A failed reclaimer is pierced by YOUR thorns for 193 points of non-melee damage.
                        if (dsIndex > -1 && pointsOfIndex > dsIndex && isIndex > -1 && isIndex < dsIndex && byIndex > isIndex)
                        {
                            string attacker = string.Join(" ", split, byIndex + 1, dsIndex - byIndex - 1);
                            if (!string.IsNullOrEmpty(attacker))
                            {
                                var valid = attacker == "YOUR";
                                if (!valid && attacker.EndsWith("'s", StringComparison.OrdinalIgnoreCase))
                                {
                                    attacker = attacker.Substring(0, attacker.Length - 2);
                                    valid    = true;
                                }

                                if (valid)
                                {
                                    string defender = string.Join(" ", split, 0, isIndex);
                                    uint   damage   = StatsUtil.ParseUInt(split[pointsOfIndex - 1]);
                                    handled = CreateDamageRecord(lineData, split, stop, attacker, defender, damage, Labels.DS, Labels.DS);
                                }
                            }
                        }
                        // [Mon May 10 22:18:46 2021] A dendridic shard was chilled to the bone for 410 points of non-melee damage.
                        else if (dsIndex > -1 && pointsOfIndex > dsIndex && isIndex > -1 && isIndex < dsIndex && byIndex == -1)
                        {
                            string defender = string.Join(" ", split, 0, isIndex);
                            uint   damage   = StatsUtil.ParseUInt(split[pointsOfIndex - 1]);
                            handled = CreateDamageRecord(lineData, split, stop, Labels.RS, defender, damage, Labels.DS, Labels.DS);
                        }
                        // [Tue Mar 26 22:43:47 2019] a wave sentinel has taken an extra 6250000 points of non-melee damage from Kazint's Greater Fetter spell.
                        else if (extraIndex > -1 && pointsOfIndex == (extraIndex + 2) && fromDamage == (pointsOfIndex + 3) && split[stop] == "spell.")
                        {
                            if (split[fromDamage + 2].EndsWith("'s", StringComparison.OrdinalIgnoreCase))
                            {
                                string      attacker  = split[fromDamage + 2].Substring(0, split[fromDamage + 2].Length - 2);
                                string      defender  = string.Join(" ", split, 0, takenIndex);
                                uint        damage    = StatsUtil.ParseUInt(split[extraIndex + 1]);
                                string      spell     = string.Join(" ", split, fromDamage + 3, stop - fromDamage - 3);
                                var         spellData = DataManager.Instance.GetDamagingSpellByName(spell);
                                SpellResist resist    = spellData != null ? spellData.Resist : SpellResist.UNDEFINED;
                                handled = CreateDamageRecord(lineData, split, stop, attacker, defender, damage, Labels.BANE, spell, resist);
                            }
                        }
                        // [Sun Apr 18 21:26:15 2021] Astralx crushes Sontalak for 126225 points of damage. (Strikethrough Critical)
                        // [Sun Apr 18 20:20:32 2021] Susarrak the Crusader claws Villette for 27699 points of damage. (Strikethrough Wild Rampage)
                        else if (!string.IsNullOrEmpty(subType) && endDamage > -1 && pointsOfIndex == (endDamage - 2) && forIndex > -1 && hitType < forIndex)
                        {
                            int    hitTypeMod = hitTypeAdd > 0 ? 1 : 0;
                            string attacker   = string.Join(" ", split, 0, hitType);
                            string defender   = string.Join(" ", split, hitType + hitTypeMod + 1, forIndex - hitType - hitTypeMod - 1);
                            subType = TextFormatUtils.ToUpper(subType);
                            uint damage = StatsUtil.ParseUInt(split[pointsOfIndex - 1]);
                            handled = CreateDamageRecord(lineData, split, stop, attacker, defender, damage, Labels.MELEE, subType);
                        }
                        // [Sun Apr 18 20:24:56 2021] Sonozen hit Jortreva the Crusader for 38948 points of fire damage by Burst of Flames. (Lucky Critical Twincast)
                        else if (byDamage > 3 && pointsOfIndex == (byDamage - 3) && byIndex == (byDamage + 1) && forIndex > -1 &&
                                 subType == "hits" && hitType < forIndex && split[stop].Length > 0 && split[stop][split[stop].Length - 1] == '.')
                        {
                            string spell = string.Join(" ", split, byIndex + 1, stop - byIndex);
                            if (!string.IsNullOrEmpty(spell) && spell[spell.Length - 1] == '.')
                            {
                                spell = spell.Substring(0, spell.Length - 1);
                                string      attacker = string.Join(" ", split, 0, hitType);
                                string      defender = string.Join(" ", split, hitType + 1, forIndex - hitType - 1);
                                string      type     = GetTypeFromSpell(spell, Labels.DD);
                                uint        damage   = StatsUtil.ParseUInt(split[pointsOfIndex - 1]);
                                SpellResist resist   = SpellResist.UNDEFINED;
                                SpellResistMap.TryGetValue(split[byDamage - 1], out resist);

                                // extra way to check for pets
                                if (spell.StartsWith("Elemental Conversion", StringComparison.Ordinal))
                                {
                                    PlayerManager.Instance.AddVerifiedPet(defender);
                                }

                                handled = CreateDamageRecord(lineData, split, stop, attacker, defender, damage, type, spell, resist);
                            }
                        }
                        // [Sun Apr 18 20:32:39 2021] Dovhesi has taken 173674 damage from Curse of the Shrine by Grendish the Crusader.
                        // [Sun Apr 18 20:32:42 2021] Grendish the Crusader has taken 1003231 damage from Pyre of Klraggek Rk. III by Atvar. (Lucky Critical)
                        // [Thu Mar 18 18:48:10 2021] You have taken 4852 damage from Nectar of Misery by Commander Gartik.
                        // [Thu Mar 18 01:05:46 2021] A gnoll has taken 108790 damage from your Mind Coil Rk. II.
                        // Old (eqemu) [Sat Jan 15 21:09:10 2022] Pixtt Invi Mal has taken 189 damage from Goanna by Tuyen`s Chant of Fire.
                        else if (fromDamage > 3 && takenIndex == (fromDamage - 3) && (byIndex > fromDamage || yourIndex > fromDamage))
                        {
                            string attacker = null;
                            string spell    = null;
                            if (byIndex > -1)
                            {
                                attacker = string.Join(" ", split, byIndex + 1, stop - byIndex);
                                attacker = (!string.IsNullOrEmpty(attacker) && attacker[attacker.Length - 1] == '.') ? attacker.Substring(0, attacker.Length - 1) : null;
                                spell    = string.Join(" ", split, fromDamage + 2, byIndex - fromDamage - 2);
                            }
                            else if (yourIndex > -1)
                            {
                                attacker = split[yourIndex];
                                spell    = string.Join(" ", split, yourIndex + 1, stop - yourIndex);
                                spell    = (!string.IsNullOrEmpty(spell) && spell[spell.Length - 1] == '.') ? spell.Substring(0, spell.Length - 1) : Labels.DOT;
                            }

                            if (!string.IsNullOrEmpty(attacker) && !string.IsNullOrEmpty(spell))
                            {
                                string    type;
                                SpellData spellData = DataManager.Instance.GetDamagingSpellByName(spell);

                                // Old (eqemu) if attacker is actually a spell then swap attacker and spell
                                // Spells dont change on eqemu servers so this should always be a spell even with old spell data
                                if (spellData == null && DataManager.Instance.IsOldSpell(attacker))
                                {
                                    // check that we can't find a spell where the player name is
                                    var temp = attacker;
                                    attacker = spell;
                                    spell    = temp;
                                    type     = Labels.DOT;
                                }
                                else
                                {
                                    type = GetTypeFromSpell(spell, Labels.DOT);
                                }

                                string      defender = string.Join(" ", split, 0, takenIndex);
                                uint        damage   = StatsUtil.ParseUInt(split[fromDamage - 1]);
                                SpellResist resist   = spellData != null ? spellData.Resist : SpellResist.UNDEFINED;
                                handled = CreateDamageRecord(lineData, split, stop, attacker, defender, damage, type, spell, resist);
                            }
                        }
                        // [Mon Apr 26 21:07:21 2021] Lawlstryke has taken 216717 damage by Wisp Explosion.
                        else if (byDamage > -1 && takenIndex == (byDamage - 3))
                        {
                            string defender = string.Join(" ", split, 0, takenIndex);
                            uint   damage   = StatsUtil.ParseUInt(split[byDamage - 1]);
                            string spell    = string.Join(" ", split, byDamage + 2, stop - byDamage - 1);
                            if (!string.IsNullOrEmpty(spell) && spell[spell.Length - 1] == '.')
                            {
                                spell = spell.Substring(0, spell.Length - 1);
                            }

                            SpellResist resist = SpellResist.UNDEFINED;
                            if (DataManager.Instance.GetDamagingSpellByName(spell) is SpellData spellData && spellData != null)
                            {
                                resist = spellData.Resist;
                            }

                            handled = CreateDamageRecord(lineData, split, stop, "", defender, damage, Labels.DOT, spell, resist, true);
                        }
                        // Old (eqemu direct damage) [Sat Jan 15 21:08:54 2022] Jaun hit Pixtt Invi Mal for 150 points of non-melee damage.
                        else if (hitType > -1 && forIndex > -1 && forIndex < pointsOfIndex && nonMeleeIndex > pointsOfIndex)
                        {
                            int    hitTypeMod = hitTypeAdd > 0 ? 1 : 0;
                            string attacker   = string.Join(" ", split, 0, hitType);
                            string defender   = string.Join(" ", split, hitType + hitTypeMod + 1, forIndex - hitType - hitTypeMod - 1);
                            uint   damage     = StatsUtil.ParseUInt(split[pointsOfIndex - 1]);
                            handled = CreateDamageRecord(lineData, split, stop, attacker, defender, damage, Labels.DD, Labels.DD);
                        }
                        // [Mon Aug 05 02:05:12 2019] An enchanted Syldon stalker tries to crush YOU, but misses! (Strikethrough)
                        // [Sat Aug 03 00:20:57 2019] You try to crush a Kar`Zok soldier, but miss! (Riposte Strikethrough)
                        // [Sat Apr 24 01:08:49 2021] Test One Hundred Three tries to punch Kazint, but misses!
                        // [Sat Apr 24 01:08:49 2021] Test One Hundred Three tries to punch Kazint, but Kazint dodges!
                        // [Sat Apr 24 01:10:17 2021] Test One Hundred Three tries to punch YOU, but YOU dodge!
                        // [Sat Apr 24 01:10:17 2021] Kazint tries to crush Test One Hundred Three, but Test One Hundred Three dodges!
                        // [Sun Apr 18 19:45:21 2021] You try to crush a primal guardian, but a primal guardian parries!
                        // [Mon May 31 20:29:49 2021] A bloodthirsty gnawer tries to bite Vandil, but Vandil parries!
                        // [Sun Apr 25 22:56:22 2021] Romance tries to bash Vulak`Aerr, but Vulak`Aerr parries!
                        // [Sun Jul 28 20:12:46 2019] Drogbaa tries to slash Whirlrender Scout, but misses! (Strikethrough)
                        // [Tue Mar 30 16:43:54 2021] You try to crush a desert madman, but a desert madman blocks!
                        // [Mon Apr 26 22:40:10 2021] An ancient warden tries to hit Reisil, but Reisil blocks with his shield!
                        // [Sun Mar 21 00:11:31 2021] A carrion bat tries to bite YOU, but YOU block with your shield!
                        // [Mon Apr 26 14:51:01 2021] A windchill sprite tries to smash YOU, but YOU block with your staff!
                        // [Mon May 10 22:18:46 2021] Tolzol tries to crush Dendritic Golem, but Dendritic Golem is INVULNERABLE!
                        else if (tryIndex > -1 && butIndex > tryIndex && missType > -1)
                        {
                            string label = null;
                            switch (missType)
                            {
                            case 0:
                                label = Labels.BLOCK;
                                break;

                            case 1:
                                label = Labels.DODGE;
                                break;

                            case 2:
                                label = Labels.MISS;
                                break;

                            case 3:
                                label = Labels.PARRY;
                                break;

                            case 4:
                                label = Labels.INVULNERABLE;
                                break;
                            }

                            if (!string.IsNullOrEmpty(label))
                            {
                                int    hitTypeMod = hitTypeAdd > 0 ? 1 : 0;
                                string defender   = string.Join(" ", split, hitType + hitTypeMod + 1, butIndex - hitType - hitTypeMod - 1);
                                if (!string.IsNullOrEmpty(defender) && defender[defender.Length - 1] == ',')
                                {
                                    defender = defender.Substring(0, defender.Length - 1);
                                    string attacker = string.Join(" ", split, 0, tryIndex);
                                    subType = TextFormatUtils.ToUpper(subType);
                                    handled = CreateDamageRecord(lineData, split, stop, attacker, defender, 0, label, subType);
                                }
                            }
                        }
                        // [Sun Apr 18 21:26:20 2021] Strangle`s pet has been slain by Kzerk!
                        else if (slainIndex > -1 && byIndex == (slainIndex + 1) && hasIndex > 0 && stop > (slainIndex + 1) && split[hasIndex + 1] == "been")
                        {
                            string killer = string.Join(" ", split, byIndex + 1, stop - byIndex);
                            killer = killer.Length > 1 && killer[killer.Length - 1] == '!' ? killer.Substring(0, killer.Length - 1) : killer;
                            string slain = string.Join(" ", split, 0, hasIndex);
                            handled = UpdateSlain(slain, killer, lineData);
                            HasOwner(slain, out string t1);
                            HasOwner(killer, out string t2);
                        }
                        // [Mon Apr 19 02:22:09 2021] You have been slain by an armed flyer!
                        else if (stop > 4 && slainIndex == 3 && byIndex == 4 && split[0] == "You" && split[1] == "have" && split[2] == "been")
                        {
                            string killer = string.Join(" ", split, 5, stop - 4);
                            killer = killer.Length > 1 && killer[killer.Length - 1] == '!' ? killer.Substring(0, killer.Length - 1) : killer;
                            string slain = ConfigUtil.PlayerName;
                            handled = UpdateSlain(slain, killer, lineData);
                        }
                        // [Mon Apr 19 02:22:09 2021] You have slain a failed bodyguard!
                        else if (slainIndex == 2 && split[0] == "You" && split[1] == "have")
                        {
                            string killer = ConfigUtil.PlayerName;
                            string slain  = string.Join(" ", split, 3, stop - 2);
                            slain   = slain.Length > 1 && slain[slain.Length - 1] == '!' ? slain.Substring(0, slain.Length - 1) : slain;
                            handled = UpdateSlain(slain, killer, lineData);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LOG.Error(e);
            }

            DebugUtil.UnregisterLine(lineData.LineNumber, handled);
        }
コード例 #5
0
        private static bool CreateDamageRecord(LineData lineData, string[] split, int stop, string attacker, string defender,
                                               uint damage, string type, string subType, SpellResist resist = SpellResist.UNDEFINED, bool attackerIsSpell = false)
        {
            bool success = false;

            if (damage != uint.MaxValue && !string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(subType) && !InIgnoreList(defender))
            {
                // Needed to replace 'You' and 'you', etc
                defender = PlayerManager.Instance.ReplacePlayer(defender, defender);

                if (string.IsNullOrEmpty(attacker))
                {
                    attacker = subType;
                }
                else if (attacker.EndsWith("'s corpse", StringComparison.Ordinal))
                {
                    attacker = attacker.Substring(0, attacker.Length - 9);
                }
                else
                {
                    // Needed to replace 'You' and 'you', etc
                    attacker = PlayerManager.Instance.ReplacePlayer(attacker, attacker);
                }

                if (resist != SpellResist.UNDEFINED && ConfigUtil.PlayerName == attacker && defender != attacker)
                {
                    DataManager.Instance.UpdateNpcSpellResistStats(defender, resist);
                }

                // check for pets
                HasOwner(attacker, out string attackerOwner);
                HasOwner(defender, out string defenderOwner);

                DamageRecord record = new DamageRecord
                {
                    Attacker      = string.Intern(FixName(attacker)),
                    Defender      = string.Intern(FixName(defender)),
                    Type          = string.Intern(type),
                    SubType       = string.Intern(subType),
                    Total         = damage,
                    AttackerOwner = attackerOwner != null?string.Intern(attackerOwner) : null,
                                        DefenderOwner = defenderOwner != null?string.Intern(defenderOwner) : null,
                                                            ModifiersMask   = -1,
                                                            AttackerIsSpell = attackerIsSpell
                };

                var currentTime = DateUtil.ParseLogDate(lineData.Line, out string timeString);

                if (split.Length > stop + 1)
                {
                    // improve this later so maybe the string doesn't have to be re-joined
                    string modifiers = string.Join(" ", split, stop + 1, split.Length - stop - 1);
                    record.ModifiersMask = LineModifiersParser.Parse(record.Attacker, modifiers.Substring(1, modifiers.Length - 2), currentTime);
                }

                if (!double.IsNaN(currentTime))
                {
                    // handle old style crits for eqemu
                    if (LastCrit != null && LastCrit.Attacker == record.Attacker && LastCrit.LineData.LineNumber == (lineData.LineNumber - 1))
                    {
                        var critTime = DateUtil.ParseLogDate(LastCrit.LineData.Line, out string _);
                        if (!double.IsNaN(critTime) && (currentTime - critTime) <= 1)
                        {
                            record.ModifiersMask = (record.ModifiersMask == -1) ? LineModifiersParser.CRIT : record.ModifiersMask | LineModifiersParser.CRIT;
                        }

                        LastCrit = null;
                    }

                    CheckSlainQueue(currentTime);

                    DamageProcessedEvent e = new DamageProcessedEvent()
                    {
                        Record = record, OrigTimeString = timeString, BeginTime = currentTime
                    };
                    EventsDamageProcessed?.Invoke(record, e);
                    success = true;

                    if (record.Type == Labels.DD && SpecialCodes.Keys.FirstOrDefault(special => !string.IsNullOrEmpty(record.SubType) && record.SubType.Contains(special)) is string key &&
                        !string.IsNullOrEmpty(key))
                    {
                        DataManager.Instance.AddSpecial(new SpecialSpell()
                        {
                            Code = SpecialCodes[key], Player = record.Attacker, BeginTime = currentTime
                        });
                    }
                }
            }

            return(success);
        }