change how we format reliquary sub property

This commit is contained in:
Lightczx
2023-08-25 15:15:21 +08:00
parent 486e7fffd2
commit 800ecb07d7
3 changed files with 67 additions and 19 deletions

View File

@@ -130,6 +130,19 @@ internal static partial class EnumerableExtension
return results;
}
public static TSource SingleOrAdd<TSource>(this List<TSource> list, Func<TSource, bool> predicate, Func<TSource> valueFactory)
where TSource : class
{
if (list.SingleOrDefault(predicate) is { } source)
{
return source;
}
TSource value = valueFactory();
list.Add(value);
return value;
}
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public static List<TSource> SortBy<TSource, TKey>(this List<TSource> list, Func<TSource, TKey> keySelector)
where TKey : IComparable

View File

@@ -1,6 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Intrinsic.Format;
using Snap.Hutao.Model.Metadata.Converter;
@@ -58,7 +59,7 @@ internal sealed class SummaryReliquaryFactory
Description = reliquary.Description,
// EquipBase
Level = $"+{equip.Reliquary.Level - 1}",
Level = $"+{equip.Reliquary.Level - 1U}",
Quality = reliquary.RankLevel,
};
@@ -68,9 +69,7 @@ internal sealed class SummaryReliquaryFactory
result.SecondarySubProperties = subProperty.GetRange(^affixCount..);
ArgumentNullException.ThrowIfNull(equip.Flat.ReliquarySubstats);
result.ComposedSubProperties = equip.Flat.ReliquarySubstats.SelectList(CreateComposedSubProperty);
ApplyAffixEnhancedCount(result.ComposedSubProperties, equip.Reliquary.AppendPropIdList);
result.ComposedSubProperties = CreateComposedSubProperties(equip.Reliquary.AppendPropIdList);
ReliquaryMainAffixLevel relicLevel = metadataContext.ReliquaryLevels.Single(r => r.Level == equip.Reliquary.Level && r.Rank == reliquary.RankLevel);
FightProperty property = metadataContext.IdReliquaryMainAffixMap[equip.Reliquary.MainPropId];
@@ -115,13 +114,29 @@ internal sealed class SummaryReliquaryFactory
};
}
private void ApplyAffixEnhancedCount(List<ReliquaryComposedSubProperty> composed, List<ReliquarySubAffixId> appendProps)
private List<ReliquaryComposedSubProperty> CreateComposedSubProperties(List<ReliquarySubAffixId> appendProps)
{
List<SummaryReliquarySubPropertyCompositionInfo> infos = new();
foreach (ref readonly ReliquarySubAffixId subAffixId in CollectionsMarshal.AsSpan(appendProps))
{
ReliquarySubAffix subAffix = metadataContext.IdReliquarySubAffixMap[subAffixId];
composed.Single(prop => prop.Type == subAffix.Type).EnhancedCount++;
SummaryReliquarySubPropertyCompositionInfo info = infos.SingleOrAdd(prop => prop.Type == subAffix.Type, () => new(subAffix.Type));
info.Count++;
info.Value += subAffix.Value;
}
if (infos.Count > 4)
{
ThrowHelper.InvalidOperation("无效的圣遗物数据");
}
List<ReliquaryComposedSubProperty> results = new();
foreach (ref readonly SummaryReliquarySubPropertyCompositionInfo info in CollectionsMarshal.AsSpan(infos))
{
results.Add(info.ToReliquaryComposedSubProperty());
}
return results;
}
private float ScoreReliquary(FightProperty property, MetadataReliquary reliquary, ReliquaryMainAffixLevel relicLevel, List<ReliquarySubProperty> subProperties)
@@ -150,19 +165,6 @@ internal sealed class SummaryReliquaryFactory
}
}
private ReliquaryComposedSubProperty CreateComposedSubProperty(ReliquarySubstat substat)
{
FormatMethod method = substat.AppendPropId.GetFormatMethod();
string valueFormatted = method switch
{
FormatMethod.Integer => $"{MathF.Round(substat.StatValue, MidpointRounding.AwayFromZero)}",
FormatMethod.Percent => $"{substat.StatValue}%", // Different from FightPropertyFormat.FormatValue
_ => $"{substat.StatValue}",
};
return new(substat.AppendPropId, valueFormatted, 0);
}
[SuppressMessage("", "SH002")]
private ReliquarySubProperty CreateSubProperty(ReliquarySubAffixId appendPropId)
{

View File

@@ -0,0 +1,33 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Intrinsic.Format;
using Snap.Hutao.Model.Metadata.Converter;
using Snap.Hutao.Model.Metadata.Reliquary;
using Snap.Hutao.Model.Primitive;
using Snap.Hutao.ViewModel.AvatarProperty;
using Snap.Hutao.Web.Enka.Model;
using System.Runtime.InteropServices;
using MetadataReliquary = Snap.Hutao.Model.Metadata.Reliquary.Reliquary;
using ModelAvatarInfo = Snap.Hutao.Web.Enka.Model.AvatarInfo;
namespace Snap.Hutao.Service.AvatarInfo.Factory;
internal sealed class SummaryReliquarySubPropertyCompositionInfo
{
public SummaryReliquarySubPropertyCompositionInfo(FightProperty type)
{
Type = type;
}
public FightProperty Type { get; set; }
public float Value { get; set; }
public uint Count { get; set; }
public ReliquaryComposedSubProperty ToReliquaryComposedSubProperty()
{
return new(Type, FightPropertyFormat.FormatValue(Type, Value), 0);
}
}