Skip to content

Commit

Permalink
[W3C-93] New race win icons (#178)
Browse files Browse the repository at this point in the history
* [W3C-93] New race win icons

* use test db
  • Loading branch information
Cepheid-UK authored Jul 12, 2022
1 parent 6f1cdab commit 0f54e92
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 52 deletions.
4 changes: 3 additions & 1 deletion W3C.Domain/CommonValueObjects/AvatarCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public enum AvatarCategory
NE = 4,
UD = 8,
Total = 16,
Special = 32
Special = 32,
Starter = 64,
Tournament = 128,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using W3C.Domain.CommonValueObjects;

namespace W3ChampionsStatisticService.PersonalSettings
{
public class AvatarCategoryToMaxPictureId
{
public AvatarCategory AvatarType { get; }
public long Max { get; }

public AvatarCategoryToMaxPictureId(AvatarCategory avatarType, long max)
{
AvatarType = avatarType;
Max = max;
}
}
}
138 changes: 109 additions & 29 deletions W3ChampionsStatisticService/PersonalSettings/PersonalSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,25 @@ public bool SetProfilePicture(SetPictureCommand cmd)
{
bool isValid = false;

if (cmd.avatarCategory == AvatarCategory.Special)
switch (cmd.avatarCategory)
{
isValid = SpecialPictures == null ? false : SpecialPictures.Any(x => x.PictureId == cmd.pictureId);
}
else
{
var winsPerRace = RaceWins?.GetWinsPerRace((Race)cmd.avatarCategory);
isValid = winsPerRace >= PictureRange.FirstOrDefault(p => p.PictureId == cmd.pictureId)?.NeededWins;
case AvatarCategory.Starter:
isValid = true;
break;

case AvatarCategory.Special:
isValid = SpecialPictures == null ? false : SpecialPictures.Any(x => x.PictureId == cmd.pictureId);
break;

case AvatarCategory.Total:
var totalWins = RaceWins?.GetTotalWins();
isValid = totalWins >= TotalPicturerange.FirstOrDefault(p => p.PictureId == cmd.pictureId)?.NeededWins;
break;

default:
var winsPerRace = RaceWins?.GetWinsPerRace((Race)cmd.avatarCategory);
isValid = winsPerRace >= RacePictureRange.FirstOrDefault(p => p.PictureId == cmd.pictureId)?.NeededWins;
break;
}

if (isValid)
Expand All @@ -87,35 +98,34 @@ public void UpdateSpecialPictures(SpecialPicture[] specialPictures)
SpecialPictures = specialPictures;
}

public List<RaceToMaxPicture> PickablePictures => new List<RaceToMaxPicture>
public List<AvatarCategoryToMaxPictureId> PickablePictures => new List<AvatarCategoryToMaxPictureId>
{
new RaceToMaxPicture(Race.HU, GetMaxOf(RaceWins.GetWinsPerRace(Race.HU)) ),
new RaceToMaxPicture(Race.OC, GetMaxOf(RaceWins.GetWinsPerRace(Race.OC)) ),
new RaceToMaxPicture(Race.NE, GetMaxOf(RaceWins.GetWinsPerRace(Race.NE)) ),
new RaceToMaxPicture(Race.UD, GetMaxOf(RaceWins.GetWinsPerRace(Race.UD)) ),
new RaceToMaxPicture(Race.RnD, GetMaxOf(RaceWins.GetWinsPerRace(Race.RnD)) )
new AvatarCategoryToMaxPictureId(AvatarCategory.HU, GetMaxPictureIdForRace(Race.HU)),
new AvatarCategoryToMaxPictureId(AvatarCategory.OC, GetMaxPictureIdForRace(Race.OC)),
new AvatarCategoryToMaxPictureId(AvatarCategory.NE, GetMaxPictureIdForRace(Race.NE)),
new AvatarCategoryToMaxPictureId(AvatarCategory.UD, GetMaxPictureIdForRace(Race.UD)),
new AvatarCategoryToMaxPictureId(AvatarCategory.RnD, GetMaxPictureIdForRace(Race.RnD)),
new AvatarCategoryToMaxPictureId(AvatarCategory.Total, GetMaxPictureIdForAllWins()),
};

private long GetMaxOf(long getWinsPerRace)
private long GetMaxPictureIdForRace(Race race)
{
return PictureRange.Where(r => r.NeededWins <= getWinsPerRace).Max(r => r.PictureId);
var minimumWinsNeededForRaceIcon = RacePictureRange.First().NeededWins;
var raceWinsForRace = RaceWins.GetWinsPerRace(race);

if (raceWinsForRace < minimumWinsNeededForRaceIcon) return 0;

return RacePictureRange
.Where(r => r.NeededWins <= raceWinsForRace)
.Max(r => r.PictureId);
}

[BsonIgnore]
public List<WinsToPictureId> PictureRange => new List<WinsToPictureId>
private long GetMaxPictureIdForAllWins()
{
new WinsToPictureId(0, 0),
new WinsToPictureId(1, 5),
new WinsToPictureId(2, 20),
new WinsToPictureId(3, 70),
new WinsToPictureId(4, 150),
new WinsToPictureId(5, 250),
new WinsToPictureId(6, 400),
new WinsToPictureId(7, 600),
new WinsToPictureId(8, 900),
new WinsToPictureId(9, 1200),
new WinsToPictureId(10, 1500)
};
return TotalPicturerange
.Where(r => r.NeededWins <= RaceWins.GetTotalWins())
.Max(r => r.PictureId);
}

public void Update(PersonalSettingsDTO dto)
{
Expand All @@ -132,5 +142,75 @@ public void Update(PersonalSettingsDTO dto)
}

public DateTimeOffset LastUpdated { get; set; }

[BsonIgnore]
public List<WinsToPictureId> RacePictureRange => new List<WinsToPictureId>
{
new WinsToPictureId(1, 5),
new WinsToPictureId(2, 10),
new WinsToPictureId(3, 25),
new WinsToPictureId(4, 50),
new WinsToPictureId(5, 100),
new WinsToPictureId(6, 150),
new WinsToPictureId(7, 250),
new WinsToPictureId(8, 350),
new WinsToPictureId(9, 500),
new WinsToPictureId(10, 750),
new WinsToPictureId(11, 1000),
new WinsToPictureId(12, 1250),
new WinsToPictureId(13, 1500),
new WinsToPictureId(14, 1750),
new WinsToPictureId(15, 2000),
new WinsToPictureId(16, 2500),
new WinsToPictureId(17, 3500),
new WinsToPictureId(18, 5000)
};

[BsonIgnore]
public List<WinsToPictureId> TotalPicturerange => new List<WinsToPictureId>
{
new WinsToPictureId(1, 15),
new WinsToPictureId(2, 30),
new WinsToPictureId(3, 75),
new WinsToPictureId(4, 150),
new WinsToPictureId(5, 300),
new WinsToPictureId(6, 450),
new WinsToPictureId(7, 750),
new WinsToPictureId(8, 1000),
new WinsToPictureId(9, 1500),
new WinsToPictureId(10, 2250),
new WinsToPictureId(11, 3000),
new WinsToPictureId(12, 3750),
new WinsToPictureId(13, 4500),
new WinsToPictureId(14, 5250),
new WinsToPictureId(15, 6000),
new WinsToPictureId(16, 7500),
new WinsToPictureId(17, 10000),
new WinsToPictureId(18, 15000)
};

[BsonIgnore]
public List<WinsToPictureId> TournamentPicturerange => new List<WinsToPictureId>
// for future use with autotours
{
new WinsToPictureId(1, 1),
new WinsToPictureId(2, 5),
new WinsToPictureId(3, 10),
new WinsToPictureId(4, 20),
new WinsToPictureId(5, 30),
new WinsToPictureId(6, 50),
new WinsToPictureId(7, 75),
new WinsToPictureId(8, 100),
new WinsToPictureId(9, 125),
new WinsToPictureId(10, 150),
new WinsToPictureId(11, 200),
new WinsToPictureId(12, 300),
new WinsToPictureId(13, 400),
new WinsToPictureId(14, 500),
new WinsToPictureId(15, 750),
new WinsToPictureId(16, 1000),
new WinsToPictureId(17, 1250),
new WinsToPictureId(18, 1500)
};
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using W3C.Domain.CommonValueObjects;
using System;
using W3C.Domain.CommonValueObjects;

namespace W3ChampionsStatisticService.PersonalSettings
{
public class ProfilePicture
{
public static ProfilePicture Default()
{
var random = new Random();
return new ProfilePicture()
{
Race = AvatarCategory.Total,
PictureId = 0
Race = AvatarCategory.Starter,
PictureId = random.Next(1,5),
};
}

Expand Down
16 changes: 0 additions & 16 deletions W3ChampionsStatisticService/PersonalSettings/RaceToMaxPicture.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ public int GetWinsPerRace(Race race)
{
return WinLosses.Single(w => w.Race == race).Wins;
}

public int GetTotalWins()
{
return WinLosses.Sum(w => w.Wins);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void SetProfilePicture_TooFewWins()
SetPictureCommand cmd2 = new SetPictureCommand()
{
avatarCategory = AvatarCategory.HU,
pictureId = 2
pictureId = 3
};
var profilePicture = personalSetting.SetProfilePicture(cmd2);

Expand All @@ -80,7 +80,7 @@ public void SetProfilePicture_AllowedPictures()
}

personalSetting.Players = new List<PlayerOverallStats> { player };
Assert.AreEqual(2, personalSetting.PickablePictures.Single(r => r.Race == Race.HU).Max);
Assert.AreEqual(2, personalSetting.PickablePictures.Single(r => r.AvatarType == AvatarCategory.HU).Max);
}

[Test]
Expand All @@ -98,7 +98,9 @@ public void SetProfilePicture_SpecialAvatar_ButSpecialPicturesNull_DoesNotThrow(
};
Assert.DoesNotThrow(() => personalSetting.SetProfilePicture(cmd));

Assert.AreEqual(expectedProfilePic.PictureId, personalSetting.ProfilePicture.PictureId);
Assert.IsTrue(
personalSetting.ProfilePicture.PictureId >= 1 &&
personalSetting.ProfilePicture.PictureId <= 5);
Assert.AreEqual(expectedProfilePic.Race, personalSetting.ProfilePicture.Race);
}

Expand Down

0 comments on commit 0f54e92

Please sign in to comment.