Skip to content

Commit

Permalink
Merge pull request #65 from lichie567/develop
Browse files Browse the repository at this point in the history
merge version 0.4.0.0 from develop
  • Loading branch information
lichie567 authored Jul 21, 2024
2 parents 1627591 + d077bd3 commit 87f5880
Show file tree
Hide file tree
Showing 40 changed files with 1,883 additions and 1,486 deletions.
47 changes: 42 additions & 5 deletions LMeter/ACT/DataStructures/ActEvent.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using LMeter.Helpers;
using Newtonsoft.Json;

namespace LMeter.Act.DataStructures
{
public class ActEvent
public class ActEvent : IActData<ActEvent>
{
[JsonIgnore]
public static string[] TextTags { get; } =
typeof(ActEvent).GetMembers().Where(x => Attribute.IsDefined(x, typeof(TextTagAttribute))).Select(x => $"[{x.Name.ToLower()}]").ToArray();

private static readonly Dictionary<string, MemberInfo> _textTagMembers =
typeof(ActEvent).GetMembers().Where(x => Attribute.IsDefined(x, typeof(TextTagAttribute))).ToDictionary((x) => x.Name.ToLower());

private bool _parsedActive;
private bool _active;

Expand All @@ -23,6 +33,11 @@ public class ActEvent

[JsonProperty("Combatant")]
public Dictionary<string, Combatant>? Combatants { get; set; }

public string GetFormattedString(string format, string numberFormat)
{
return TextTagFormatter.TextTagRegex.Replace(format, new TextTagFormatter(this, numberFormat, _textTagMembers).Evaluate);
}

public bool IsEncounterActive()
{
Expand All @@ -31,8 +46,7 @@ public bool IsEncounterActive()
return _active;
}

bool.TryParse(this.IsActive, out _active);
_parsedActive = true;
_parsedActive = bool.TryParse(this.IsActive, out _active);
return _active;
}

Expand Down Expand Up @@ -64,11 +78,34 @@ public bool Equals(ActEvent? actEvent)

public static ActEvent GetTestData()
{
return new ActEvent()
Dictionary<string, Combatant> mockCombatants = new()
{
{ "1", GetCombatant("GNB", "DRK", "WAR", "PLD") },
{ "2", GetCombatant("GNB", "DRK", "WAR", "PLD") },
{ "3", GetCombatant("WHM", "AST", "SCH", "SGE") },
{ "4", GetCombatant("WHM", "AST", "SCH", "SGE") },
{ "5", GetCombatant("SAM", "DRG", "MNK", "NIN", "RPR", "VPR") },
{ "6", GetCombatant("SAM", "DRG", "MNK", "NIN", "RPR", "VPR") },
{ "7", GetCombatant("BLM", "SMN", "RDM", "PCT") },
{ "8", GetCombatant("DNC", "MCH", "BRD") },
{ "9", GetCombatant("SAM", "DRG", "MNK", "NIN", "RPR", "VPR") },
{ "10", GetCombatant("SAM", "DRG", "MNK", "NIN", "RPR", "VPR") },
{ "11", GetCombatant("BLM", "SMN", "RDM", "PCT") },
{ "12", GetCombatant("DNC", "MCH", "BRD") }
};

return new()
{
Encounter = Encounter.GetTestData(),
Combatants = Combatant.GetTestData()
Combatants = mockCombatants
};
}

private static Combatant GetCombatant(params string[] jobs)
{
Combatant combatant = Combatant.GetTestData();
combatant.Job = Enum.Parse<Job>(jobs[IActData<ActEvent>.Random.Next(jobs.Length)]);
return combatant;
}
}
}
100 changes: 49 additions & 51 deletions LMeter/ACT/DataStructures/Combatant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,112 +7,133 @@

namespace LMeter.Act.DataStructures;

public class Combatant
public class Combatant : IActData<Combatant>
{
[JsonIgnore]
public static string[] TextTags { get; } = typeof(Combatant).GetFields().Select(x => $"[{x.Name.ToLower()}]").ToArray();

// TODO: move this to a global place so it can be shared between encounter and combatant
private static readonly Random _rand = new();
private static readonly Dictionary<string, MemberInfo> _members = typeof(Combatant).GetMembers().ToDictionary((x) => x.Name.ToLower());
public static string[] TextTags { get; } =
typeof(Combatant).GetMembers().Where(x => Attribute.IsDefined(x, typeof(TextTagAttribute))).Select(x => $"[{x.Name.ToLower()}]").ToArray();

private static readonly Dictionary<string, MemberInfo> _textTagMembers =
typeof(Combatant).GetMembers().Where(x => Attribute.IsDefined(x, typeof(TextTagAttribute))).ToDictionary((x) => x.Name.ToLower());

[JsonProperty("name")]
public string OriginalName { get; set; } = string.Empty;

public string? NameOverwrite { get; set; } = null;

// These have to be here because newtonsoft and overlayplugin suck
#pragma warning disable 0169
[JsonProperty("ENCDPS")]
private readonly string? _encdps;
[JsonProperty("ENCHPS")]
private readonly string? _enchps;
#pragma warning restore 0169

[TextTag]
[JsonIgnore]
public string Name => NameOverwrite ?? OriginalName;

[TextTag]
[JsonIgnore]
public LazyString<string?>? Name_First;

[TextTag]
[JsonIgnore]
public LazyString<string?>? Name_Last;

[TextTag]
[JsonIgnore]
public string Rank = string.Empty;

[TextTag]
[JsonProperty("Job")]
[JsonConverter(typeof(JobConverter))]
public Job Job { get; set; }

[JsonIgnore]
public LazyString<Job>? JobName;

[TextTag]
[JsonProperty("duration")]
public string DurationRaw { get; set; } = string.Empty;

[TextTag]
[JsonIgnore]
public LazyString<string?>? Duration;


[TextTag]
[JsonProperty("encdps")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? EncDps { get; set; }

[JsonProperty("dps")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? Dps { get; set; }

[TextTag]
[JsonProperty("damage")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? DamageTotal { get; set; }

[TextTag]
[JsonProperty("damage%")]
public string DamagePct { get; set; } = string.Empty;

[TextTag]
[JsonProperty("crithit%")]
public string CritHitPct { get; set; } = string.Empty;

[TextTag]
[JsonProperty("DirectHitPct")]
public string DirectHitPct { get; set; } = string.Empty;

[TextTag]
[JsonProperty("CritDirectHitPct")]
public string CritDirectHitPct { get; set; } = string.Empty;

[TextTag]
[JsonProperty("enchps")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? EncHps { get; set; }

[JsonProperty("hps")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? Hps { get; set; }

[TextTag]
public LazyFloat? EffectiveHealing { get; set; }

[TextTag]
[JsonProperty("healed")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? HealingTotal { get; set; }

[TextTag]
[JsonProperty("healed%")]
public string HealingPct { get; set; }= string.Empty;

[TextTag]
[JsonProperty("overHeal")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? OverHeal { get; set; }

[TextTag]
[JsonProperty("OverHealPct")]
public string OverHealPct { get; set; }= string.Empty;

[TextTag]
[JsonProperty("damagetaken")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? DamageTaken { get; set; }

[TextTag]
[JsonProperty("deaths")]
public string Deaths { get; set; }= string.Empty;

[TextTag]
[JsonProperty("kills")]
public string Kills { get; set; }= string.Empty;

[TextTag]
[JsonProperty("maxhit")]
public string MaxHit { get; set; } = string.Empty;

[JsonProperty("MAXHIT")]
private string _maxHit { get; set; } = string.Empty;

[TextTag]
public LazyString<string?> MaxHitName { get; set; }

[TextTag]
public LazyFloat? MaxHitValue { get; set; }

public Combatant()
Expand All @@ -128,54 +149,31 @@ public Combatant()

public string GetFormattedString(string format, string numberFormat)
{
return TextTagFormatter.TextTagRegex.Replace(format, new TextTagFormatter(this, numberFormat, _members).Evaluate);
}

public static Dictionary<string, Combatant> GetTestData()
{
Dictionary<string, Combatant> mockCombatants = new()
{
{ "1", GetCombatant("GNB", "DRK", "WAR", "PLD") },
{ "2", GetCombatant("GNB", "DRK", "WAR", "PLD") },
{ "3", GetCombatant("WHM", "AST", "SCH", "SGE") },
{ "4", GetCombatant("WHM", "AST", "SCH", "SGE") },
{ "5", GetCombatant("SAM", "DRG", "MNK", "NIN", "RPR") },
{ "6", GetCombatant("SAM", "DRG", "MNK", "NIN", "RPR") },
{ "7", GetCombatant("BLM", "SMN", "RDM") },
{ "8", GetCombatant("DNC", "MCH", "BRD") },
{ "9", GetCombatant("SAM", "DRG", "MNK", "NIN", "RPR") },
{ "10", GetCombatant("SAM", "DRG", "MNK", "NIN", "RPR") },
{ "11", GetCombatant("BLM", "SMN", "RDM") },
{ "12", GetCombatant("DNC", "MCH", "BRD") }
};

return mockCombatants;
return TextTagFormatter.TextTagRegex.Replace(format, new TextTagFormatter(this, numberFormat, _textTagMembers).Evaluate);
}

private static Combatant GetCombatant(params string[] jobs)
public static Combatant GetTestData()
{
int damage = _rand.Next(212345);
int healing = _rand.Next(41234);
float damage = IActData<Combatant>.Random.Next(212345);
float healing = IActData<Combatant>.Random.Next(41234);

return new Combatant()
{
OriginalName = "Firstname Lastname",
DurationRaw = "00:30",
Job = Enum.Parse<Job>(jobs[_rand.Next(jobs.Length)]),
Job = (Job)IActData<Combatant>.Random.Next(Enum.GetNames(typeof(Job)).Length - 1) + 1,
DamageTotal = new LazyFloat(damage.ToString()),
Dps = new LazyFloat((damage / 30).ToString()),
EncDps = new LazyFloat((damage / 30).ToString()),
HealingTotal = new LazyFloat(healing.ToString()),
OverHeal = new LazyFloat(5000),
Hps = new LazyFloat((healing / 30).ToString()),
EncHps = new LazyFloat((healing / 30).ToString()),
DamagePct = "100%",
DamagePct = IActData<Combatant>.Random.Next(100) + "%",
HealingPct = "100%",
CritHitPct = "20%",
DirectHitPct = "25%",
CritDirectHitPct = "5%",
CritHitPct = $"{IActData<Combatant>.Random.Next(50)}%",
DirectHitPct = $"{IActData<Combatant>.Random.Next(50)}%",
CritDirectHitPct = $"{IActData<Combatant>.Random.Next(10)}%",
DamageTaken = new LazyFloat((damage / 20).ToString()),
Deaths = _rand.Next(2).ToString(),
Deaths = IActData<Combatant>.Random.Next(4).ToString(),
MaxHit = "Full Thrust-42069"
};
}
Expand Down
34 changes: 27 additions & 7 deletions LMeter/ACT/DataStructures/Encounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,71 @@

namespace LMeter.Act.DataStructures;

public class Encounter
public class Encounter : IActData<Encounter>
{
[JsonIgnore]
public static string[] TextTags { get; } = typeof(Encounter).GetFields().Select(x => $"[{x.Name.ToLower()}]").ToArray();
public static string[] TextTags { get; } =
typeof(Encounter).GetMembers().Where(x => Attribute.IsDefined(x, typeof(TextTagAttribute))).Select(x => $"[{x.Name.ToLower()}]").ToArray();

private static readonly Random _rand = new();
private static readonly Dictionary<string, MemberInfo> _members = typeof(Encounter).GetMembers().ToDictionary((x) => x.Name.ToLower());
private static readonly Dictionary<string, MemberInfo> _textTagMembers =
typeof(Encounter).GetMembers().Where(x => Attribute.IsDefined(x, typeof(TextTagAttribute))).ToDictionary((x) => x.Name.ToLower());

public string GetFormattedString(string format, string numberFormat)
{
return TextTagFormatter.TextTagRegex.Replace(format, new TextTagFormatter(this, numberFormat, _members).Evaluate);
return TextTagFormatter.TextTagRegex.Replace(format, new TextTagFormatter(this, numberFormat, _textTagMembers).Evaluate);
}


// These have to be here because newtonsoft and overlayplugin suck
#pragma warning disable 0169
[JsonProperty("ENCDPS")]
private readonly string? _encdps;
[JsonProperty("ENCHPS")]
private readonly string? _enchps;
#pragma warning restore 0169

[TextTag]
[JsonProperty("title")]
public string Title { get; set; } = string.Empty;

[TextTag]
[JsonProperty("duration")]
public string DurationRaw { get; set; } = string.Empty;

[TextTag]
[JsonIgnore]
public LazyString<string?>? Duration;

[TextTag]
[JsonProperty("encdps")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? Dps { get; set; }

[TextTag]
[JsonProperty("damage")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? DamageTotal { get; set; }

[TextTag]
[JsonProperty("enchps")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? Hps { get; set; }

[TextTag]
[JsonProperty("healed")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? HealingTotal { get; set; }

[TextTag]
[JsonProperty("damagetaken")]
[JsonConverter(typeof(LazyFloatConverter))]
public LazyFloat? DamageTaken { get; set; }

[TextTag]
[JsonProperty("deaths")]
public string? Deaths { get; set; }

[TextTag]
[JsonProperty("kills")]
public string? Kills { get; set; }

Expand All @@ -61,8 +81,8 @@ public Encounter()

public static Encounter GetTestData()
{
float damage = _rand.Next(212345 * 8);
float healing = _rand.Next(41234 * 8);
float damage = IActData<Encounter>.Random.Next(212345 * 12);
float healing = IActData<Encounter>.Random.Next(41234 * 12);

return new Encounter()
{
Expand Down
Loading

0 comments on commit 87f5880

Please sign in to comment.