コード例 #1
0
        public HitInfo Build(string[] log, ParserRegex parserRegex, int entityId, bool isSelf, bool isVictim,
                             Server.Game gameName)
        {
            var     eventType = log[(uint)ParserRegex.GroupType.EventType].First();
            HitType hitType;

            if (isVictim)
            {
                if (isSelf)
                {
                    hitType = HitType.Suicide;
                }

                else
                {
                    hitType = eventType == 'D' ? HitType.WasDamaged : HitType.WasKilled;
                }
            }

            else
            {
                hitType = eventType == 'D' ? HitType.Damage : HitType.Kill;
            }

            var damage = 0;

            try
            {
                damage = Math.Min(MaximumDamage,
                                  log.Length > parserRegex.GroupMapping[ParserRegex.GroupType.Damage]
                        ? int.Parse(log[parserRegex.GroupMapping[ParserRegex.GroupType.Damage]])
                        : 0);
            }
            catch
            {
                // ignored
            }

            var hitInfo = new HitInfo()
            {
                EntityId = entityId,
                IsVictim = isVictim,
                HitType  = hitType,
                Damage   = damage,
                Location = log.Length > parserRegex.GroupMapping[ParserRegex.GroupType.HitLocation]
                    ? log[parserRegex.GroupMapping[ParserRegex.GroupType.HitLocation]]
                    : "Unknown",
                Weapon = log.Length > parserRegex.GroupMapping[ParserRegex.GroupType.Weapon]
                    ? _weaponNameParser.Parse(log[parserRegex.GroupMapping[ParserRegex.GroupType.Weapon]], gameName)
                    : new WeaponInfo {
                    Name = "Unknown"
                },
                MeansOfDeath = log.Length > parserRegex.GroupMapping[ParserRegex.GroupType.MeansOfDeath]
                    ? log[parserRegex.GroupMapping[ParserRegex.GroupType.MeansOfDeath]]
                    : "Unknown",
                Game = (Reference.Game)gameName
            };

            return(hitInfo);
        }
コード例 #2
0
        public WeaponInfo Parse(string weaponName, Server.Game gameName)
        {
            var configForGame = _config.WeaponNameParserConfigurations
                                ?.FirstOrDefault(config => config.Game == gameName) ?? new WeaponNameParserConfiguration()
            {
                Game = gameName
            };

            var splitWeaponName = weaponName.Split(configForGame.Delimiters);

            if (!splitWeaponName.Any())
            {
                _logger.LogError("Could not parse weapon name {Weapon}", weaponName);

                return(new WeaponInfo()
                {
                    Name = "Unknown"
                });
            }

            // remove the _mp suffix
            var filtered = splitWeaponName
                           .Where(part => part != configForGame.WeaponSuffix && part != configForGame.WeaponPrefix)
                           .ToList();
            var baseName    = filtered.First();
            var attachments = new List <string>();

            if (filtered.Count() > 1)
            {
                attachments.AddRange(filtered.Skip(1));
            }

            var weaponInfo = new WeaponInfo()
            {
                RawName     = weaponName,
                Name        = baseName,
                Attachments = attachments.Select(attachment => new AttachmentInfo()
                {
                    Name = attachment
                }).ToList()
            };

            return(weaponInfo);
        }