From 4179e8b428f4e945b5ae209571a747d13977a4b7 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Tue, 23 Mar 2021 16:01:48 -0500 Subject: [PATCH] properly pass game name to game string config finder. add weapon prefix to weapon name parser for (iw5). add some iw3 game strings --- Application/DefaultSettings.json | 46 +++++++++++++++++++ Plugins/Stats/Client/WeaponNameParser.cs | 5 +- Plugins/Stats/Config/StatsConfiguration.cs | 13 ++++++ .../Config/WeaponNameParserConfiguration.cs | 1 + .../Configuration/GameStringConfiguration.cs | 9 ++-- .../Views/Client/Statistics/Advanced.cshtml | 14 +++--- 6 files changed, 74 insertions(+), 14 deletions(-) diff --git a/Application/DefaultSettings.json b/Application/DefaultSettings.json index 9bf26c6f..359270dc 100644 --- a/Application/DefaultSettings.json +++ b/Application/DefaultSettings.json @@ -1069,6 +1069,52 @@ "artillery": "Precision Airstrike", "player": "", "attach": "" + }, + "IW3": { + "torso_upper": "Upper Torso", + "torso_lower": "Lower Torso", + "right_leg_upper": "Upper Right Leg", + "right_leg_lower": "Lower Right Leg", + "right_hand": "Right Hand", + "right_foot": "Right Foot", + "right_arm_upper": "Upper Right Arm", + "right_arm_lower": "Lower Right Arm", + "left_leg_upper": "Upper Left Leg", + "left_leg_lower": "Lower Left Leg", + "left_hand": "Left Hand", + "left_foot": "Left Foot", + "left_arm_upper": "Upper Left Arm", + "left_arm_lower": "Lower Left Arm", + "acog": "ACOG Sight", + "gl": "Grenade Launcher", + "reflex": "Red Dot Sight", + "grip": "Grip", + "m4": "M4 Carbine", + "m40a3": "M40A3", + "ak47": "AK-47", + "ak74u": "AK-74u", + "rpg": "RPG-7", + "deserteagle": "Desert Eagle", + "deserteaglegold": "Desert Eagle Gold", + "m16": "M16A4", + "g36c": "G36C", + "uzi": "Mini-Uzi", + "m60e4": "M60E4", + "mp5": "MP5", + "barrett": "Barrett .50cal", + "mp44": "MP44", + "remington700": "R700", + "rpd": "RDP", + "saw": " M249 SAW", + "usp": "USP .45", + "winchester1200": "W1200", + "concussion": "Stun", + "melee": "Knife", + "Frag" : "Grenade", + "airstrike": "Airstrike", + "helicopter": "Attack Helicopter", + "player": "", + "attach": "" } } } diff --git a/Plugins/Stats/Client/WeaponNameParser.cs b/Plugins/Stats/Client/WeaponNameParser.cs index 62e1503f..9d2f92de 100644 --- a/Plugins/Stats/Client/WeaponNameParser.cs +++ b/Plugins/Stats/Client/WeaponNameParser.cs @@ -48,7 +48,8 @@ namespace Stats.Client } // remove the _mp suffix - var filtered = splitWeaponName.Where(part => part != configForGame.WeaponSuffix); + var filtered = splitWeaponName + .Where(part => part != configForGame.WeaponSuffix && part != configForGame.WeaponPrefix); var baseName = splitWeaponName.First(); var attachments = new List(); @@ -67,8 +68,6 @@ namespace Stats.Client }).ToList() }; - // _logger.LogDebug("Parsed weapon info {@info}", weaponInfo); - return weaponInfo; } } diff --git a/Plugins/Stats/Config/StatsConfiguration.cs b/Plugins/Stats/Config/StatsConfiguration.cs index d1438822..b5003853 100644 --- a/Plugins/Stats/Config/StatsConfiguration.cs +++ b/Plugins/Stats/Config/StatsConfiguration.cs @@ -20,6 +20,12 @@ namespace IW4MAdmin.Plugins.Stats.Config public WeaponNameParserConfiguration[] WeaponNameParserConfigurations { get; set; } = new[] { + new WeaponNameParserConfiguration() + { + Game = Server.Game.IW3, + WeaponSuffix = "mp", + Delimiters = new[] {'_'} + }, new WeaponNameParserConfiguration() { Game = Server.Game.IW4, @@ -27,6 +33,13 @@ namespace IW4MAdmin.Plugins.Stats.Config Delimiters = new[] {'_'} }, new WeaponNameParserConfiguration() + { + Game = Server.Game.IW5, + WeaponSuffix = "mp", + WeaponPrefix = "iw5", + Delimiters = new[] {'_'} + }, + new WeaponNameParserConfiguration() { Game = Server.Game.T6, WeaponSuffix = "mp", diff --git a/Plugins/Stats/Config/WeaponNameParserConfiguration.cs b/Plugins/Stats/Config/WeaponNameParserConfiguration.cs index d824ad9e..84e5e803 100644 --- a/Plugins/Stats/Config/WeaponNameParserConfiguration.cs +++ b/Plugins/Stats/Config/WeaponNameParserConfiguration.cs @@ -7,5 +7,6 @@ namespace Stats.Config public Server.Game Game { get; set; } public char[] Delimiters { get; set; } public string WeaponSuffix { get; set; } + public string WeaponPrefix { get; set; } } } \ No newline at end of file diff --git a/SharedLibraryCore/Configuration/GameStringConfiguration.cs b/SharedLibraryCore/Configuration/GameStringConfiguration.cs index 9f465b2a..4099d817 100644 --- a/SharedLibraryCore/Configuration/GameStringConfiguration.cs +++ b/SharedLibraryCore/Configuration/GameStringConfiguration.cs @@ -1,23 +1,24 @@ using System.Collections.Generic; +using Data.Models; using Humanizer; namespace SharedLibraryCore.Configuration { - public class GameStringConfiguration : Dictionary> + public class GameStringConfiguration : Dictionary> { - public string GetStringForGame(string key, Server.Game game = Server.Game.IW4) + public string GetStringForGame(string key, Reference.Game? game = Reference.Game.IW4) { if (key == null) { return null; } - if (!ContainsKey(game)) + if (!ContainsKey(game.Value)) { return key.Transform(To.TitleCase); } - var strings = this[game]; + var strings = this[game.Value]; return !strings.ContainsKey(key) ? key.Transform(To.TitleCase) : strings[key]; } } diff --git a/WebfrontCore/Views/Client/Statistics/Advanced.cshtml b/WebfrontCore/Views/Client/Statistics/Advanced.cshtml index 86d85966..6ae18282 100644 --- a/WebfrontCore/Views/Client/Statistics/Advanced.cshtml +++ b/WebfrontCore/Views/Client/Statistics/Advanced.cshtml @@ -32,10 +32,10 @@ return null; } var rebuiltName = stat.RebuildWeaponName(); - var name = config.GetStringForGame(rebuiltName); + var name = config.GetStringForGame(rebuiltName, stat.Weapon?.Game); return !rebuiltName.Equals(name, StringComparison.InvariantCultureIgnoreCase) ? name - : config.GetStringForGame(stat.Weapon.Name); + : config.GetStringForGame(stat.Weapon.Name, stat.Weapon.Game); } string GetWeaponAttachmentName(EFWeaponAttachmentCombo attachment) @@ -47,9 +47,9 @@ var attachmentText = string.Join('+', new[] { - config.GetStringForGame(attachment.Attachment1.Name), - config.GetStringForGame(attachment.Attachment2?.Name), - config.GetStringForGame(attachment.Attachment3?.Name) + config.GetStringForGame(attachment.Attachment1.Name, attachment.Attachment1.Game), + config.GetStringForGame(attachment.Attachment2?.Name, attachment.Attachment2?.Game), + config.GetStringForGame(attachment.Attachment3?.Name, attachment.Attachment3?.Game) }.Where(attach => !string.IsNullOrWhiteSpace(attach))); return attachmentText; @@ -404,7 +404,7 @@ @foreach (var hitLocation in filteredHitLocations.Take(8)) { - @config.GetStringForGame(hitLocation.HitLocation.Name) + @config.GetStringForGame(hitLocation.HitLocation.Name, hitLocation.HitLocation.Game) @hitLocation.HitCount @Math.Round((hitLocation.HitCount / (float) totalHits) * 100.0).ToString(Utilities.CurrentLocalization.Culture)% @hitLocation.DamageInflicted.ToNumericalString() @@ -414,7 +414,7 @@ @foreach (var hitLocation in filteredHitLocations.Skip(8)) { - @config.GetStringForGame(hitLocation.HitLocation.Name) + @config.GetStringForGame(hitLocation.HitLocation.Name, hitLocation.HitLocation.Game) @hitLocation.HitCount @Math.Round((hitLocation.HitCount / (float) totalHits) * 100.0).ToString(Utilities.CurrentLocalization.Culture)% @hitLocation.DamageInflicted.ToNumericalString()