From 716abc1f9bb55630bca35d4407266dfdddd0e772 Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Tue, 5 Dec 2023 23:14:12 +0800 Subject: [PATCH] gachaevent statistics fix --- .../Model/Metadata/GachaEventInfo.cs | 16 ++++ .../Model/Metadata/GachaEventInfoExtension.cs | 32 +++++++ .../GachaLog/GachaLogStatisticsTracker.cs | 38 ++++++-- .../GachaLog/SpecializedGachaLogItems.cs | 96 +++++++++++++++++++ 4 files changed, 174 insertions(+), 8 deletions(-) create mode 100644 src/Snap.Hutao.Server/Snap.Hutao.Server/Model/Metadata/GachaEventInfoExtension.cs create mode 100644 src/Snap.Hutao.Server/Snap.Hutao.Server/Service/GachaLog/SpecializedGachaLogItems.cs diff --git a/src/Snap.Hutao.Server/Snap.Hutao.Server/Model/Metadata/GachaEventInfo.cs b/src/Snap.Hutao.Server/Snap.Hutao.Server/Model/Metadata/GachaEventInfo.cs index c76c072..16e7c42 100644 --- a/src/Snap.Hutao.Server/Snap.Hutao.Server/Model/Metadata/GachaEventInfo.cs +++ b/src/Snap.Hutao.Server/Snap.Hutao.Server/Model/Metadata/GachaEventInfo.cs @@ -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")] @@ -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; } } \ No newline at end of file diff --git a/src/Snap.Hutao.Server/Snap.Hutao.Server/Model/Metadata/GachaEventInfoExtension.cs b/src/Snap.Hutao.Server/Snap.Hutao.Server/Model/Metadata/GachaEventInfoExtension.cs new file mode 100644 index 0000000..65e2a73 --- /dev/null +++ b/src/Snap.Hutao.Server/Snap.Hutao.Server/Model/Metadata/GachaEventInfoExtension.cs @@ -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 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; + } +} diff --git a/src/Snap.Hutao.Server/Snap.Hutao.Server/Service/GachaLog/GachaLogStatisticsTracker.cs b/src/Snap.Hutao.Server/Snap.Hutao.Server/Service/GachaLog/GachaLogStatisticsTracker.cs index 46d8aad..cfe8f88 100644 --- a/src/Snap.Hutao.Server/Snap.Hutao.Server/Service/GachaLog/GachaLogStatisticsTracker.cs +++ b/src/Snap.Hutao.Server/Snap.Hutao.Server/Service/GachaLog/GachaLogStatisticsTracker.cs @@ -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; @@ -18,6 +17,9 @@ public sealed class GachaLogStatisticsTracker private readonly GachaEventInfo currentAvatarEvent1; private readonly GachaEventInfo currentAvatarEvent2; private readonly GachaEventInfo currentWeaponEvent; + private readonly FrozenSet currentAvatarEvent1Star5Ids; + private readonly FrozenSet currentAvatarEvent2Star5Ids; + private readonly FrozenSet currentWeaponEventStar5Ids; private readonly HashSet invalidGachaUids = []; @@ -42,6 +44,10 @@ internal GachaLogStatisticsTracker(Map idQualityMap, GachaEventBundle currentAvatarEvent1 = bundle.AvatarEvent1; currentAvatarEvent2 = bundle.AvatarEvent2; currentWeaponEvent = bundle.WeaponEvent; + + currentAvatarEvent1Star5Ids = currentAvatarEvent1.GetUpOrangeItems().ToFrozenSet(); + currentAvatarEvent2Star5Ids = currentAvatarEvent2.GetUpOrangeItems().ToFrozenSet(); + currentWeaponEventStar5Ids = currentWeaponEvent.GetUpOrangeItems().ToFrozenSet(); } /// @@ -177,7 +183,7 @@ private void TrackForSpecficQueryTypeWish(EntityGachaItem item, ref bool star5Fo { ++lastStar5Counter; ++totalPullsCounter; - TryIncreaseCurrentWishItemCounter(item); + TryIncreaseCurrentWishItemCounter(item, 3); } break; @@ -186,7 +192,7 @@ private void TrackForSpecficQueryTypeWish(EntityGachaItem item, ref bool star5Fo { ++lastStar5Counter; ++totalPullsCounter; - TryIncreaseCurrentWishItemCounter(item); + TryIncreaseCurrentWishItemCounter(item, 4); } break; @@ -195,7 +201,7 @@ private void TrackForSpecficQueryTypeWish(EntityGachaItem item, ref bool star5Fo { ++lastStar5Counter; ++totalPullsCounter; - TryIncreaseCurrentWishItemCounter(item); + TryIncreaseCurrentWishItemCounter(item, 5); if (lastStar5Counter > pullMaxThreshold) { @@ -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); + } } } } \ No newline at end of file diff --git a/src/Snap.Hutao.Server/Snap.Hutao.Server/Service/GachaLog/SpecializedGachaLogItems.cs b/src/Snap.Hutao.Server/Snap.Hutao.Server/Service/GachaLog/SpecializedGachaLogItems.cs new file mode 100644 index 0000000..6a31663 --- /dev/null +++ b/src/Snap.Hutao.Server/Snap.Hutao.Server/Service/GachaLog/SpecializedGachaLogItems.cs @@ -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 DefiniteStandardAvatars = FrozenSet.ToFrozenSet([10000003, 10000016, 10000035, 10000041, 10000042]); + private static readonly FrozenSet 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; + } +} \ No newline at end of file