Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from slimDebug/develop
Browse files Browse the repository at this point in the history
added uprank/derank prognosis if you hover over the MMR value
  • Loading branch information
slimDebug authored May 22, 2022
2 parents 1a5e201 + e015272 commit 0b01db1
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ internal class IsEqualOrGreaterThanUshortVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is ushort ushortValue && parameter is string stringParameter &&
ushort.TryParse(stringParameter, NumberStyles.Integer, CultureInfo.InvariantCulture, out var ushortParameter))
if (value is ushort ushortValue && parameter is ushort ushortParameter)
return ushortValue >= ushortParameter ? Visibility.Visible : Visibility.Hidden;

return Visibility.Hidden;
Expand Down
112 changes: 112 additions & 0 deletions HuntMmrReader/Converters/MmrConverterBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using HuntMmrReader.Models.BaseModels;

namespace HuntMmrReader.Converters;

internal abstract class MmrConverterBase : IValueConverter
{
private static readonly Brush CloseToUpRankBrush = Brushes.Green;
private static readonly Brush CloseToDeRankBrush = Brushes.Red;
private static readonly Brush NeutralRankBrush = Brushes.Orange;

public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);
public abstract object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture);

protected static ushort GetStarsFromMmr(ushort mmr)
{
return mmr switch
{
>= HuntBaseEntity.SixStarMinimumMmr => 6,
>= HuntBaseEntity.FiveStarMinimumMmr => 5,
>= HuntBaseEntity.FourStarMinimumMmr => 4,
>= HuntBaseEntity.ThreeStarMinimumMmr => 3,
>= HuntBaseEntity.TwoStarMinimumMmr => 2,
_ => 1
};
}

protected static Brush GetBrushPrognosis(ushort mmr)
{
var stars = GetStarsFromMmr(mmr);
return stars switch
{
1 => CloseToUpRankBrush,
2 => HuntBaseEntity.ThreeStarMinimumMmr - mmr < mmr - HuntBaseEntity.TwoStarMinimumMmr
? CloseToUpRankBrush
: HuntBaseEntity.ThreeStarMinimumMmr - mmr > mmr - HuntBaseEntity.TwoStarMinimumMmr
? CloseToDeRankBrush
: NeutralRankBrush,
3 => HuntBaseEntity.FourStarMinimumMmr - mmr < mmr - HuntBaseEntity.ThreeStarMinimumMmr
? CloseToUpRankBrush
: HuntBaseEntity.FourStarMinimumMmr - mmr > mmr - HuntBaseEntity.ThreeStarMinimumMmr
? CloseToDeRankBrush
: NeutralRankBrush,
4 => HuntBaseEntity.FiveStarMinimumMmr - mmr < mmr - HuntBaseEntity.FourStarMinimumMmr
? CloseToUpRankBrush
: HuntBaseEntity.FiveStarMinimumMmr - mmr > mmr - HuntBaseEntity.FourStarMinimumMmr
? CloseToDeRankBrush
: NeutralRankBrush,
5 => HuntBaseEntity.SixStarMinimumMmr - mmr < mmr - HuntBaseEntity.FiveStarMinimumMmr
? CloseToUpRankBrush
: HuntBaseEntity.SixStarMinimumMmr - mmr > mmr - HuntBaseEntity.FiveStarMinimumMmr
? CloseToDeRankBrush
: NeutralRankBrush,
_ => CloseToUpRankBrush
};
}

protected static ushort GetUpRankDeRankPrognosis(ushort mmr)
{
var stars = GetStarsFromMmr(mmr);
return stars switch
{
1 => (ushort) (HuntBaseEntity.TwoStarMinimumMmr - mmr),
2 => (ushort) (HuntBaseEntity.ThreeStarMinimumMmr - mmr <= mmr - HuntBaseEntity.TwoStarMinimumMmr
? HuntBaseEntity.ThreeStarMinimumMmr - mmr
: 1 + mmr - HuntBaseEntity.TwoStarMinimumMmr),
3 => (ushort) (HuntBaseEntity.FourStarMinimumMmr - mmr <= mmr - HuntBaseEntity.ThreeStarMinimumMmr
? HuntBaseEntity.FourStarMinimumMmr - mmr
: 1 + mmr - HuntBaseEntity.ThreeStarMinimumMmr),
4 => (ushort) (HuntBaseEntity.FiveStarMinimumMmr - mmr <= mmr - HuntBaseEntity.FourStarMinimumMmr
? HuntBaseEntity.FiveStarMinimumMmr - mmr
: 1 + mmr - HuntBaseEntity.FourStarMinimumMmr),
5 => (ushort) (HuntBaseEntity.SixStarMinimumMmr - mmr <= mmr - HuntBaseEntity.FiveStarMinimumMmr
? HuntBaseEntity.SixStarMinimumMmr - mmr
: 1 + mmr - HuntBaseEntity.FiveStarMinimumMmr),
_ => (ushort) (1 + mmr - HuntBaseEntity.SixStarMinimumMmr)
};
}

protected static ushort GetClosestRank(ushort mmr)
{
var stars = GetStarsFromMmr(mmr);
return stars switch
{
1 => 2,
2 => (ushort) (HuntBaseEntity.ThreeStarMinimumMmr - mmr < mmr - HuntBaseEntity.TwoStarMinimumMmr
? 3
: HuntBaseEntity.ThreeStarMinimumMmr - mmr > mmr - HuntBaseEntity.TwoStarMinimumMmr
? 2
: 3),
3 => (ushort) (HuntBaseEntity.FourStarMinimumMmr - mmr < mmr - HuntBaseEntity.ThreeStarMinimumMmr
? 4
: HuntBaseEntity.FourStarMinimumMmr - mmr > mmr - HuntBaseEntity.ThreeStarMinimumMmr
? 3
: 4),
4 => (ushort) (HuntBaseEntity.FiveStarMinimumMmr - mmr < mmr - HuntBaseEntity.FourStarMinimumMmr
? 5
: HuntBaseEntity.FiveStarMinimumMmr - mmr > mmr - HuntBaseEntity.FourStarMinimumMmr
? 4
: 5),
5 => (ushort) (HuntBaseEntity.SixStarMinimumMmr - mmr < mmr - HuntBaseEntity.FiveStarMinimumMmr
? 6
: HuntBaseEntity.SixStarMinimumMmr - mmr > mmr - HuntBaseEntity.FiveStarMinimumMmr
? 5
: 6),
_ => 5
};
}
}
20 changes: 20 additions & 0 deletions HuntMmrReader/Converters/MmrToColorConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Globalization;
using System.Windows.Media;

namespace HuntMmrReader.Converters;

internal class MmrToColorConverter : MmrConverterBase
{
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is ushort ushortValue)
return GetBrushPrognosis(ushortValue);
return Brushes.Orange;
}

public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
36 changes: 36 additions & 0 deletions HuntMmrReader/Converters/MmrToMmrRangeString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Globalization;
using HuntMmrReader.Models.BaseModels;

namespace HuntMmrReader.Converters;

internal class MmrToMmrRangeString : MmrConverterBase
{
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not ushort ushortValue)
return string.Empty;
var stars = GetStarsFromMmr(ushortValue);
var baseString =
$"This is a {stars.ToString(CultureInfo.InvariantCulture)} star hunter.{Environment.NewLine}The MMR range of a {stars.ToString(CultureInfo.InvariantCulture)} star hunter goes from ";
return stars switch
{
1 =>
$"{baseString}{HuntBaseEntity.OneStarMinimumMmr.ToString(CultureInfo.InvariantCulture)}-{(HuntBaseEntity.TwoStarMinimumMmr - 1).ToString(CultureInfo.InvariantCulture)}.",
2 =>
$"{baseString}{HuntBaseEntity.TwoStarMinimumMmr.ToString(CultureInfo.InvariantCulture)}-{(HuntBaseEntity.ThreeStarMinimumMmr - 1).ToString(CultureInfo.InvariantCulture)}.",
3 =>
$"{baseString}{HuntBaseEntity.ThreeStarMinimumMmr.ToString(CultureInfo.InvariantCulture)}-{(HuntBaseEntity.FourStarMinimumMmr - 1).ToString(CultureInfo.InvariantCulture)}.",
4 =>
$"{baseString}{HuntBaseEntity.FourStarMinimumMmr.ToString(CultureInfo.InvariantCulture)}-{(HuntBaseEntity.FiveStarMinimumMmr - 1).ToString(CultureInfo.InvariantCulture)}.",
5 =>
$"{baseString}{HuntBaseEntity.FiveStarMinimumMmr.ToString(CultureInfo.InvariantCulture)}-{(HuntBaseEntity.SixStarMinimumMmr - 1).ToString(CultureInfo.InvariantCulture)}.",
_ => $"{baseString}{HuntBaseEntity.SixStarMinimumMmr.ToString(CultureInfo.InvariantCulture)}-{'\u221E'}."
};
}

public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
19 changes: 19 additions & 0 deletions HuntMmrReader/Converters/MmrToPrognosisStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Globalization;

namespace HuntMmrReader.Converters;

internal class MmrToPrognosisStringConverter : MmrConverterBase
{
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value is not ushort ushortValue
? string.Empty
: $"This hunter is only {GetUpRankDeRankPrognosis(ushortValue).ToString(CultureInfo.InvariantCulture)} MMR points away, before becoming a {GetClosestRank(ushortValue).ToString(CultureInfo.InvariantCulture)} star hunter.";
}

public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
13 changes: 10 additions & 3 deletions HuntMmrReader/Models/BaseModels/HuntBaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

namespace HuntMmrReader.Models.BaseModels;

internal abstract class HuntBaseEntity
public abstract class HuntBaseEntity
{
internal HuntBaseEntity(ushort mmr, ushort id)
public const ushort OneStarMinimumMmr = 0;
public const ushort TwoStarMinimumMmr = 2000;
public const ushort ThreeStarMinimumMmr = 2300;
public const ushort FourStarMinimumMmr = 2600;
public const ushort FiveStarMinimumMmr = 2750;
public const ushort SixStarMinimumMmr = 3000;

protected HuntBaseEntity(ushort mmr, ushort id)
{
Mmr = mmr;
Id = id;
}

internal HuntBaseEntity(string? mmr, ushort id)
protected HuntBaseEntity(string? mmr, ushort id)
{
Mmr = ushort.TryParse(mmr, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedMmr)
? parsedMmr
Expand Down
15 changes: 7 additions & 8 deletions HuntMmrReader/Models/HuntPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

namespace HuntMmrReader.Models;

internal class HuntPlayer : HuntBaseEntity
public class HuntPlayer : HuntBaseEntity
{
internal HuntPlayer(string? name, ushort mmr, bool hadBounty, bool hadWellSpring,
public HuntPlayer(string? name, ushort mmr, bool hadBounty, bool hadWellSpring,
ushort killedByMe, ushort killedMe,
ushort playerId) : base(mmr, playerId)
{
Name = name;
Name = name ?? string.Empty;
HadBounty = hadBounty;
HadWellSpring = hadWellSpring;
KilledByMe = killedByMe;
KilledMe = killedMe;
}

internal HuntPlayer(string? name, string? mmr, string? hadBounty,
public HuntPlayer(string? name, string? mmr, string? hadBounty,
string? hadWellSpring, string? killedByMe, string? killedMe, ushort playerId) : base(mmr, playerId)
{
Name = name;
Name = name ?? string.Empty;
HadBounty = bool.TryParse(hadBounty, out var parsedHadBounty) && parsedHadBounty;
HadWellSpring = bool.TryParse(hadWellSpring, out var parsedHadWellSpring) && parsedHadWellSpring;
KilledByMe =
Expand All @@ -31,7 +31,7 @@ internal HuntPlayer(string? name, string? mmr, string? hadBounty,
: ushort.MinValue;
}

public string? Name { get; }
public string Name { get; }

public bool HadBounty { get; }
public bool HadWellSpring { get; }
Expand All @@ -40,7 +40,6 @@ internal HuntPlayer(string? name, string? mmr, string? hadBounty,

public override string ToString()
{
return
$"Player Name: {Name ?? "",-24} | MMR: {Mmr.ToString(CultureInfo.InvariantCulture),4}";
return $"Player Name: {Name,-24} | MMR: {Mmr.ToString(CultureInfo.InvariantCulture),4}";
}
}
9 changes: 5 additions & 4 deletions HuntMmrReader/Models/HuntTeam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@

namespace HuntMmrReader.Models;

internal class HuntTeam : HuntBaseEntity
public class HuntTeam : HuntBaseEntity
{
private readonly List<HuntPlayer> _members;

internal HuntTeam(ushort mmr, ushort id, bool inviteTeam, bool skillBasedMatchMakingEnabled,
public HuntTeam(ushort mmr, ushort id, bool inviteTeam, bool skillBasedMatchMakingEnabled,
List<HuntPlayer> teamMembers) : base(mmr, id)
{
_members = teamMembers;
RandomTeam = teamMembers.Count != 1 && !inviteTeam;
SkillBasedMatchMakingEnabled = skillBasedMatchMakingEnabled;
}

internal HuntTeam(string? mmr, ushort id, string? inviteTeam, string? skillBasedMatchMakingEnabled,
public HuntTeam(string? mmr, ushort id, string? inviteTeam, string? skillBasedMatchMakingEnabled,
List<HuntPlayer> teamMembers) : base(mmr, id)
{
_members = teamMembers;
RandomTeam = !(bool.TryParse(inviteTeam, out var parsedInviteTeam) && parsedInviteTeam) && teamMembers.Count != 1;
RandomTeam = !(bool.TryParse(inviteTeam, out var parsedInviteTeam) && parsedInviteTeam) &&
teamMembers.Count != 1;
SkillBasedMatchMakingEnabled =
bool.TryParse(skillBasedMatchMakingEnabled, out var parsedSkillBasedMatchMakingEnabled) &&
parsedSkillBasedMatchMakingEnabled;
Expand Down
Loading

0 comments on commit 0b01db1

Please sign in to comment.