mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 23:31:13 -05:00
update stats plugin to IPluginV2
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Events;
|
||||
|
||||
namespace IW4MAdmin.Plugins.Stats.Client.Abstractions
|
||||
{
|
||||
public interface IClientStatisticCalculator
|
||||
{
|
||||
Task GatherDependencies();
|
||||
Task CalculateForEvent(GameEvent gameEvent);
|
||||
Task CalculateForEvent(CoreEvent coreEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
using IW4MAdmin.Plugins.Stats.Client.Game;
|
||||
using SharedLibraryCore;
|
||||
using Data.Models;
|
||||
using IW4MAdmin.Plugins.Stats.Client.Game;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
|
||||
namespace Stats.Client.Abstractions
|
||||
{
|
||||
public interface IHitInfoBuilder
|
||||
{
|
||||
HitInfo Build(string[] log, ParserRegex parserRegex, int entityId, bool isSelf, bool isVictim, Server.Game gameName);
|
||||
HitInfo Build(string[] log, ParserRegex parserRegex, int entityId, bool isSelf, bool isVictim, Reference.Game gameName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
using SharedLibraryCore;
|
||||
using Data.Models;
|
||||
using Stats.Client.Game;
|
||||
|
||||
namespace Stats.Client.Abstractions
|
||||
namespace Stats.Client.Abstractions;
|
||||
|
||||
public interface IWeaponNameParser
|
||||
{
|
||||
public interface IWeaponNameParser
|
||||
{
|
||||
WeaponInfo Parse(string weaponName, Server.Game gameName);
|
||||
}
|
||||
WeaponInfo Parse(string weaponName, Reference.Game gameName);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,82 +3,80 @@ 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;
|
||||
using Stats.Client.Game;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace Stats.Client
|
||||
namespace Stats.Client;
|
||||
|
||||
public class HitInfoBuilder : IHitInfoBuilder
|
||||
{
|
||||
public class HitInfoBuilder : IHitInfoBuilder
|
||||
private readonly IWeaponNameParser _weaponNameParser;
|
||||
private readonly ILogger _logger;
|
||||
private const int MaximumDamage = 1000;
|
||||
|
||||
public HitInfoBuilder(ILogger<HitInfoBuilder> logger, IWeaponNameParser weaponNameParser)
|
||||
{
|
||||
private readonly IWeaponNameParser _weaponNameParser;
|
||||
private readonly ILogger _logger;
|
||||
private const int MaximumDamage = 1000;
|
||||
_weaponNameParser = weaponNameParser;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public HitInfoBuilder(ILogger<HitInfoBuilder> logger, IWeaponNameParser weaponNameParser)
|
||||
public HitInfo Build(string[] log, ParserRegex parserRegex, int entityId, bool isSelf, bool isVictim,
|
||||
Reference.Game gameName)
|
||||
{
|
||||
var eventType = log[(uint)ParserRegex.GroupType.EventType].First();
|
||||
HitType hitType;
|
||||
|
||||
if (isVictim)
|
||||
{
|
||||
_weaponNameParser = weaponNameParser;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (isSelf)
|
||||
{
|
||||
hitType = HitType.Suicide;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
hitType = eventType == 'D' ? HitType.WasDamaged : HitType.WasKilled;
|
||||
}
|
||||
hitType = HitType.Suicide;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
hitType = eventType == 'D' ? HitType.Damage : HitType.Kill;
|
||||
hitType = eventType == 'D' ? HitType.WasDamaged : HitType.WasKilled;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 = gameName
|
||||
};
|
||||
|
||||
return hitInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ using Stats.Client.Abstractions;
|
||||
using Stats.Client.Game;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SharedLibraryCore;
|
||||
using Data.Models;
|
||||
using Stats.Config;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
@ -20,7 +20,7 @@ namespace Stats.Client
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public WeaponInfo Parse(string weaponName, Server.Game gameName)
|
||||
public WeaponInfo Parse(string weaponName, Reference.Game gameName)
|
||||
{
|
||||
var configForGame = _config.WeaponNameParserConfigurations
|
||||
?.FirstOrDefault(config => config.Game == gameName) ?? new WeaponNameParserConfiguration()
|
||||
|
Reference in New Issue
Block a user