Skip to content

Commit

Permalink
gachaevent statistics fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Dec 5, 2023
1 parent c777c56 commit 716abc1
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Snap.Hutao.Server.Service.GachaLog;

namespace Snap.Hutao.Server.Model.Metadata;

[Table("gacha_events")]
Expand All @@ -21,5 +23,19 @@ public sealed class GachaEventInfo
[Column(TypeName = "datetime")]
public DateTime To { get; set; }

public uint UpOrangeItem1 { get; set; }

public uint UpOrangeItem2 { get; set; }

public uint UpPurpleItem1 { get; set; }

public uint UpPurpleItem2 { get; set; }

public uint UpPurpleItem3 { get; set; }

public uint UpPurpleItem4 { get; set; }

public uint UpPurpleItem5 { get; set; }

public GachaConfigType Type { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Snap.Hutao.Server.Model.Entity.GachaLog;

namespace Snap.Hutao.Server.Model.Metadata;

public static class GachaEventInfoExtension
{
public static IEnumerable<int> GetUpOrangeItems(this GachaEventInfo info)
{
if (info.UpOrangeItem1 != 0U)
{
yield return (int)info.UpOrangeItem1;
}

if (info.UpOrangeItem2 != 0U)
{
yield return (int)info.UpOrangeItem2;
}
}

public static bool ItemInThisEvent(this GachaEventInfo info, EntityGachaItem item)
{
if (item.GachaType == info.Type && item.Time >= info.From && item.Time <= info.To)
{
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Snap.Hutao.Server.Extension;
using Snap.Hutao.Server.Model.Context;
using Snap.Hutao.Server.Model.Entity;
using Snap.Hutao.Server.Model.Entity.GachaLog;
using Snap.Hutao.Server.Model.GachaLog;
using Snap.Hutao.Server.Model.Metadata;
Expand All @@ -18,6 +17,9 @@ public sealed class GachaLogStatisticsTracker
private readonly GachaEventInfo currentAvatarEvent1;
private readonly GachaEventInfo currentAvatarEvent2;
private readonly GachaEventInfo currentWeaponEvent;
private readonly FrozenSet<int> currentAvatarEvent1Star5Ids;
private readonly FrozenSet<int> currentAvatarEvent2Star5Ids;
private readonly FrozenSet<int> currentWeaponEventStar5Ids;

private readonly HashSet<string> invalidGachaUids = [];

Expand All @@ -42,6 +44,10 @@ internal GachaLogStatisticsTracker(Map<int, int> idQualityMap, GachaEventBundle
currentAvatarEvent1 = bundle.AvatarEvent1;
currentAvatarEvent2 = bundle.AvatarEvent2;
currentWeaponEvent = bundle.WeaponEvent;

currentAvatarEvent1Star5Ids = currentAvatarEvent1.GetUpOrangeItems().ToFrozenSet();
currentAvatarEvent2Star5Ids = currentAvatarEvent2.GetUpOrangeItems().ToFrozenSet();
currentWeaponEventStar5Ids = currentWeaponEvent.GetUpOrangeItems().ToFrozenSet();
}

/// <summary>
Expand Down Expand Up @@ -177,7 +183,7 @@ private void TrackForSpecficQueryTypeWish(EntityGachaItem item, ref bool star5Fo
{
++lastStar5Counter;
++totalPullsCounter;
TryIncreaseCurrentWishItemCounter(item);
TryIncreaseCurrentWishItemCounter(item, 3);
}

break;
Expand All @@ -186,7 +192,7 @@ private void TrackForSpecficQueryTypeWish(EntityGachaItem item, ref bool star5Fo
{
++lastStar5Counter;
++totalPullsCounter;
TryIncreaseCurrentWishItemCounter(item);
TryIncreaseCurrentWishItemCounter(item, 4);
}

break;
Expand All @@ -195,7 +201,7 @@ private void TrackForSpecficQueryTypeWish(EntityGachaItem item, ref bool star5Fo
{
++lastStar5Counter;
++totalPullsCounter;
TryIncreaseCurrentWishItemCounter(item);
TryIncreaseCurrentWishItemCounter(item, 5);

if (lastStar5Counter > pullMaxThreshold)
{
Expand All @@ -212,19 +218,35 @@ private void TrackForSpecficQueryTypeWish(EntityGachaItem item, ref bool star5Fo
}
}

private void TryIncreaseCurrentWishItemCounter(EntityGachaItem item)
private void TryIncreaseCurrentWishItemCounter(EntityGachaItem item, int quality)
{
if (item.GachaType == GachaConfigType.AvatarEventWish && item.Time >= currentAvatarEvent1.From && item.Time <= currentAvatarEvent1.To)
// TODO: Handle quality 4
if (currentAvatarEvent1.ItemInThisEvent(item))
{
currentAvatarEvent1Counter.IncreaseOne(item.ItemId);

if (quality is 5 && !(currentAvatarEvent1Star5Ids.Contains(item.ItemId) || SpecializedGachaLogItems.IsAvatarStandardWishItem(item)))
{
invalidGachaUids.Add(Uid);
}
}
else if (item.GachaType == GachaConfigType.AvatarEventWish2 && item.Time >= currentAvatarEvent2.From && item.Time <= currentAvatarEvent2.To)
else if (currentAvatarEvent2.ItemInThisEvent(item))
{
currentAvatarEvent2Counter.IncreaseOne(item.ItemId);

if (quality is 5 && !(currentAvatarEvent2Star5Ids.Contains(item.ItemId) || SpecializedGachaLogItems.IsAvatarStandardWishItem(item)))
{
invalidGachaUids.Add(Uid);
}
}
else if (item.GachaType == GachaConfigType.WeaponEventWish && item.Time >= currentWeaponEvent.From && item.Time <= currentWeaponEvent.To)
else if (currentWeaponEvent.ItemInThisEvent(item))
{
currentWeaponEventCounter.IncreaseOne(item.ItemId);

if (quality is 5 && !(currentWeaponEventStar5Ids.Contains(item.ItemId) || SpecializedGachaLogItems.IsWeaponStandardWishItem(item)))
{
invalidGachaUids.Add(Uid);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Snap.Hutao.Server.Model.Entity.GachaLog;
using Snap.Hutao.Server.Model.Metadata;

namespace Snap.Hutao.Server.Service.GachaLog;

internal static class SpecializedGachaLogItems
{
// 10000003 琴
// 10000016 迪卢克
// 10000035 七七
// 10000041 莫娜
// 10000042 刻晴
// 10000069 提纳里 3.1 2022/9/28 6
// 10000079 迪西雅 3.6 2023/4/12 6
// 11501 风鹰剑
// 11502 天空之刃
// 12501 天空之傲
// 12502 狼的末路
// 13502 天空之脊
// 13505 和璞鸢
// 14501 天空之卷
// 14502 四风原典
// 15501 天空之翼
// 15502 阿莫斯之弓
private static readonly DateTimeOffset MinAllowedTime31 = new(2022, 9, 28, 6, 0, 0, new(8, 0, 0));
private static readonly DateTimeOffset MinAllowedTime36 = new(2023, 4, 12, 6, 0, 0, new(8, 0, 0));
private static readonly FrozenSet<int> DefiniteStandardAvatars = FrozenSet.ToFrozenSet([10000003, 10000016, 10000035, 10000041, 10000042]);
private static readonly FrozenSet<int> DefiniteStandardWeapons = FrozenSet.ToFrozenSet([11501, 11502, 12501, 12502, 13502, 13505, 14501, 14502, 15501, 15502]);

public static bool IsStandardWishItem(EntityGachaItem item)
{
if (item.QueryType is GachaConfigType.AvatarEventWish)
{
if (DefiniteStandardAvatars.Contains(item.ItemId))
{
return true;
}

if (item.ItemId is 10000069 && item.Time > MinAllowedTime31)
{
return true;
}

if (item.ItemId is 10000079 && item.Time > MinAllowedTime36)
{
return true;
}

return false;
}
else if (item.QueryType is GachaConfigType.WeaponEventWish)
{
if (DefiniteStandardWeapons.Contains(item.ItemId))
{
return true;
}

return false;
}

return true;
}

public static bool IsAvatarStandardWishItem(EntityGachaItem item)
{
if (DefiniteStandardAvatars.Contains(item.ItemId))
{
return true;
}

if (item.ItemId is 10000069 && item.Time > MinAllowedTime31)
{
return true;
}

if (item.ItemId is 10000079 && item.Time > MinAllowedTime36)
{
return true;
}

return false;
}

public static bool IsWeaponStandardWishItem(EntityGachaItem item)
{
if (DefiniteStandardWeapons.Contains(item.ItemId))
{
return true;
}

return false;
}
}

0 comments on commit 716abc1

Please sign in to comment.