Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes: -Folder Interfaces: • Created interfaces IDamage and IDamageSegment -Folder base: • Created classes Damage and DamageSegment -Interface IDamage: • Added fields (string) Target and (int) AmountDamage -Interface IDamageSegment: • Added fields (int) ID, (Damage Array) Taken and (Damage Array) Given -Class Damage: • Inherit IDamage -Class DamageSegments: • Inherit IDamageSegments -Class LogRegex: • Added Regex StartSegmentDamage -Class Variables: • Added const MessageDamaeUserMinusSeparator • Added MessageDamageUserInSeparator • Update MessageDamageGiven -Class Flags: • Created enumerator DamageFlag with Taken, Given, NoOne Items -Folder Damage: • Created classes: • ExtractDamage. • CreateDamageSegment, • GetDamageSegment, • DamageType, • DamageGiven, • DamageTaken, • DamageFactory -Class ExtractDamage: • Added public method ExtractCurrentMatchDamageFromLogFile to get List of all damage logs, • Added a few helper private methods -Class CreateDamageSegment: • Added public method CreateDamageSegments that returns List of DamageSegment from provided List of all damage logs calculated in ExtractCurrentMatchDamageFromLogFile method. • Added helper private method CheckLineForDamageType -Class GetDamageSegment: (Method that call all damage methods) • Added public method GetActualGameAllDamageSegment to return Array of DamageSegment • Added private helper methods TryGetDamage and IsNewMatch -Class DamageType: • Abstact class applied for implamentation of Factory dessign pattern - Class DamageTaken and DamageGiven • Inherit from DamageType • Override AddDamageObjectToColection method. - Class DamageFactory: • A Factory dessign pattern class to improvement clean code. • Added public method CreateDamageType that assign a right DamageType to provided log line. • Added private helper method IsDamage Class LogReader: • Added public method GetDamageSegmentOfCurrentMatch to return all damage of actual played match saved in DamageSegment objects.
- Loading branch information
Showing
16 changed files
with
478 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using ConsoleLogReaderCSGO.Base.Interfaces; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ConsoleLogReaderCSGO.Base | ||
{ | ||
public struct Damage : IDamage | ||
{ | ||
#region Fields | ||
public string Target { get; set; } | ||
public int AmountDamage { get; set; } | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using ConsoleLogReaderCSGO.Base.Interfaces; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ConsoleLogReaderCSGO.Base | ||
{ | ||
public class DamageSegment : IDamageSegment | ||
{ | ||
#region Fields | ||
public int ID { get; set; } | ||
public Damage[] Taken { get; set; } | ||
public Damage[] Given { get; set; } | ||
#endregion | ||
#region Constructor | ||
public DamageSegment() { } | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ConsoleLogReaderCSGO.Base.Interfaces | ||
{ | ||
public interface IDamage | ||
{ | ||
string Target { get; set; } | ||
int AmountDamage { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ConsoleLogReaderCSGO.Base.Interfaces | ||
{ | ||
interface IDamageSegment | ||
{ | ||
int ID { get; set; } | ||
Damage[] Taken { get; set; } | ||
Damage[] Given { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
ConsoleLogReaderCSGO/Operations/Damage/CreateDamageSegment.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using ConsoleLogReaderCSGO.Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace ConsoleLogReaderCSGO.Operations.Damage | ||
{ | ||
internal static class CreateDamageSegment | ||
{ | ||
#region Field | ||
|
||
private static List<Base.Damage> _taken; | ||
private static List<Base.Damage> _given; | ||
private static List<Base.DamageSegment> _segments; | ||
|
||
#endregion | ||
|
||
#region public method | ||
/// <summary> | ||
/// Method that create List of Damage from provided segments (List of List of strings) | ||
/// </summary> | ||
/// <param name="segments">Segments</param> | ||
/// <returns></returns> | ||
public static List<Base.DamageSegment> CreateDamageSegments(List<List<string>> segments) | ||
{ | ||
_segments = new List<Base.DamageSegment>(); | ||
foreach (var i1 in segments.Select((Value, Index) => (Value, Index)).Where(x => x.Index >= 0)) | ||
{ | ||
_taken = new List<Base.Damage>(); | ||
_given = new List<Base.Damage>(); | ||
|
||
foreach (var line in i1.Value) | ||
{ | ||
CheckLineForDamageType(line); | ||
} | ||
|
||
_segments.Add(new Base.DamageSegment() | ||
{ | ||
ID = i1.Index, | ||
Taken = _taken.ToArray(), | ||
Given = _given.ToArray(), | ||
}) ; | ||
} | ||
return _segments; | ||
} | ||
|
||
#endregion | ||
|
||
#region Private method | ||
/// <summary> | ||
/// <br>Method that checking what type of damage is damage line.</br> | ||
/// <br>If log type is not null then log line data is added to right collection.</br> | ||
/// </summary> | ||
/// <param name="line"></param> | ||
private static void CheckLineForDamageType(string line) | ||
{ | ||
var factory = DamageFactory.CreateDamageType(line); | ||
if(factory != null) { factory.AddDamageObjectToColection(line); } | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using ConsoleLogReaderCSGO.Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ConsoleLogReaderCSGO.Operations.Damage | ||
{ | ||
internal static class DamageFactory | ||
{ | ||
#region Public Method | ||
/// <summary> | ||
/// Method that returns apporpriate DamageType from provided damage log line. | ||
/// </summary> | ||
/// <param name="line"></param> | ||
/// <returns></returns> | ||
public static DamageType CreateDamageType(string line) | ||
{ | ||
if(IsDamage(line, Variables.MessageDamageTaken)) { return new DamageTaken(); } | ||
if(IsDamage(line, Variables.MessageDamageGiven)) { return new DamageGiven(); } | ||
return null; | ||
} | ||
#endregion | ||
#region Private Method | ||
/// <summary> | ||
/// Method that returns true if provided log line starts with comparison parameter. | ||
/// </summary> | ||
/// <param name="line"></param> | ||
/// <param name="comparison"></param> | ||
/// <returns></returns> | ||
private static bool IsDamage(string line, string comparison) | ||
{ | ||
return line.StartsWith(comparison); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ConsoleLogReaderCSGO.Operations.Damage | ||
{ | ||
internal class DamageGiven : DamageType | ||
{ | ||
#region Public Method | ||
internal override Base.Damage AddDamageObjectToColection(string line) | ||
{ | ||
return new Base.Damage() | ||
{ | ||
AmountDamage = CalculateAlmount(line), | ||
Target = CalculateTarget(line, DamageFlag.Given) | ||
}; | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ConsoleLogReaderCSGO.Operations.Damage | ||
{ | ||
internal class DamageTaken : DamageType | ||
{ | ||
#region Public Method | ||
internal override Base.Damage AddDamageObjectToColection(string line) | ||
{ | ||
return new Base.Damage() | ||
{ | ||
AmountDamage = CalculateAlmount(line), | ||
Target = CalculateTarget(line, DamageFlag.Taken) | ||
}; | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using ConsoleLogReaderCSGO.Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ConsoleLogReaderCSGO.Operations.Damage | ||
{ | ||
internal abstract class DamageType | ||
{ | ||
#region Public Method | ||
/// <summary> | ||
/// Method that returns a right Damage object from provided log line. | ||
/// </summary> | ||
/// <param name="line"></param> | ||
/// <returns></returns> | ||
internal abstract Base.Damage AddDamageObjectToColection(string line); | ||
#endregion | ||
|
||
#region Protected Methods | ||
/// <summary> | ||
/// Method that returns right Amount data from provided log line. | ||
/// </summary> | ||
/// <param name="line"></param> | ||
/// <returns></returns> | ||
internal protected int CalculateAlmount(string line) | ||
{ | ||
return int.TryParse(SubstringAmount(line), out int result) ? result : 0; | ||
} | ||
|
||
/// <summary> | ||
/// Method that returns a Target data from provided log line and DamageType. | ||
/// </summary> | ||
/// <param name="line"></param> | ||
/// <param name="type"></param> | ||
/// <returns></returns> | ||
internal protected string CalculateTarget(string line, DamageFlag type) | ||
{ | ||
return SubstringTarget(line, type); | ||
} | ||
#endregion | ||
|
||
#region Private Methods | ||
/// <summary> | ||
/// Method returns a Amount data from provided log damage line. | ||
/// </summary> | ||
/// <param name="line"></param> | ||
/// <returns></returns> | ||
private string SubstringAmount(string line) | ||
{ | ||
return line[(line.IndexOf(Variables.MessageDamageUserMinusSeparator) + 4)..line.IndexOf(Variables.MessageDamageUserInSeparator)]; | ||
} | ||
|
||
/// <summary> | ||
/// Method returns a Target data from provided log damage line and type of damage. | ||
/// </summary> | ||
/// <param name="line"></param> | ||
/// <param name="type"></param> | ||
/// <returns></returns> | ||
private string SubstringTarget(string line, DamageFlag type) | ||
{ | ||
string damageType = type == DamageFlag.Taken ? Variables.MessageDamageTaken | ||
: type == DamageFlag.Given ? Variables.MessageDamageGiven | ||
: string.Empty; | ||
return line[(line.IndexOf(damageType) + damageType.Length + 2)..line.IndexOf(Variables.MessageDamageUserMinusSeparator)]; | ||
} | ||
#endregion | ||
} | ||
} |
Oops, something went wrong.