2021-03-22 12:09:25 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Data.Models;
|
|
|
|
|
using IW4MAdmin.Plugins.Stats.Client.Game;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using Stats.Client.Abstractions;
|
2021-07-10 22:37:51 -04:00
|
|
|
|
using Stats.Client.Game;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
|
|
|
|
|
|
|
|
|
namespace Stats.Client
|
|
|
|
|
{
|
|
|
|
|
public class HitInfoBuilder : IHitInfoBuilder
|
|
|
|
|
{
|
|
|
|
|
private readonly IWeaponNameParser _weaponNameParser;
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private const int MaximumDamage = 1000;
|
2021-06-03 11:51:03 -04:00
|
|
|
|
|
2021-03-22 12:09:25 -04:00
|
|
|
|
public HitInfoBuilder(ILogger<HitInfoBuilder> logger, IWeaponNameParser weaponNameParser)
|
|
|
|
|
{
|
|
|
|
|
_weaponNameParser = weaponNameParser;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
2021-06-03 11:51:03 -04:00
|
|
|
|
|
2021-07-10 22:37:51 -04:00
|
|
|
|
public HitInfo Build(string[] log, ParserRegex parserRegex, int entityId, bool isSelf, bool isVictim,
|
|
|
|
|
Server.Game gameName)
|
2021-03-22 12:09:25 -04:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 15:57:44 -04:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 12:09:25 -04:00
|
|
|
|
var hitInfo = new HitInfo()
|
|
|
|
|
{
|
|
|
|
|
EntityId = entityId,
|
|
|
|
|
IsVictim = isVictim,
|
|
|
|
|
HitType = hitType,
|
2021-07-12 15:57:44 -04:00
|
|
|
|
Damage = damage,
|
2021-07-10 22:37:51 -04:00
|
|
|
|
Location = log.Length > parserRegex.GroupMapping[ParserRegex.GroupType.HitLocation]
|
|
|
|
|
? log[parserRegex.GroupMapping[ParserRegex.GroupType.HitLocation]]
|
2021-06-03 11:51:03 -04:00
|
|
|
|
: "Unknown",
|
2021-07-10 22:37:51 -04:00
|
|
|
|
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]]
|
2021-06-03 11:51:03 -04:00
|
|
|
|
: "Unknown",
|
|
|
|
|
Game = (Reference.Game) gameName
|
2021-03-22 12:09:25 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return hitInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|