code style

This commit is contained in:
Lightczx
2023-07-07 22:50:07 +08:00
parent f4fa08a939
commit 133a1a532e
22 changed files with 137 additions and 122 deletions

View File

@@ -9,7 +9,7 @@ namespace Snap.Hutao.Model;
/// <typeparam name="TEntity">实体</typeparam> /// <typeparam name="TEntity">实体</typeparam>
/// <typeparam name="TMetadata">元数据</typeparam> /// <typeparam name="TMetadata">元数据</typeparam>
[HighQuality] [HighQuality]
internal interface IEntityWithMetadata<TEntity, TMetadata> internal interface IEntityWithMetadata<out TEntity, out TMetadata>
{ {
/// <summary> /// <summary>
/// 实体 /// 实体

View File

@@ -29,14 +29,16 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
/// <returns>值</returns> /// <returns>值</returns>
protected string GetOption(ref string? storage, string key, string defaultValue = "") protected string GetOption(ref string? storage, string key, string defaultValue = "")
{ {
if (storage == null) if (storage is not null)
{ {
return storage;
}
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
storage = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value ?? defaultValue; storage = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value ?? defaultValue;
} }
}
return storage; return storage;
} }
@@ -50,15 +52,17 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
/// <returns>值</returns> /// <returns>值</returns>
protected bool GetOption(ref bool? storage, string key, bool defaultValue = false) protected bool GetOption(ref bool? storage, string key, bool defaultValue = false)
{ {
if (storage == null) if (storage is not null)
{ {
return storage.Value;
}
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value;
storage = value == null ? defaultValue : bool.Parse(value); storage = value == null ? defaultValue : bool.Parse(value);
} }
}
return storage.Value; return storage.Value;
} }
@@ -72,15 +76,17 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
/// <returns>值</returns> /// <returns>值</returns>
protected int GetOption(ref int? storage, string key, int defaultValue = 0) protected int GetOption(ref int? storage, string key, int defaultValue = 0)
{ {
if (storage == null) if (storage is not null)
{ {
return storage.Value;
}
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value;
storage = value == null ? defaultValue : int.Parse(value); storage = value == null ? defaultValue : int.Parse(value);
} }
}
return storage.Value; return storage.Value;
} }
@@ -97,15 +103,17 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
protected T GetOption<T>(ref T? storage, string key, Func<string, T> deserializer, T defaultValue) protected T GetOption<T>(ref T? storage, string key, Func<string, T> deserializer, T defaultValue)
where T : class where T : class
{ {
if (storage == null) if (storage != null)
{ {
return storage;
}
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value;
storage = value == null ? defaultValue : deserializer(value); storage = value == null ? defaultValue : deserializer(value);
} }
}
return storage; return storage;
} }
@@ -122,15 +130,17 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
protected T GetOption<T>(ref T? storage, string key, Func<string, T> deserializer, T defaultValue) protected T GetOption<T>(ref T? storage, string key, Func<string, T> deserializer, T defaultValue)
where T : struct where T : struct
{ {
if (storage == null) if (storage is not null)
{ {
return storage.Value;
}
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value;
storage = value == null ? defaultValue : deserializer(value); storage = value == null ? defaultValue : deserializer(value);
} }
}
return storage.Value; return storage.Value;
} }
@@ -144,8 +154,11 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
/// <param name="propertyName">属性名称</param> /// <param name="propertyName">属性名称</param>
protected void SetOption(ref string? storage, string key, string value, [CallerMemberName] string? propertyName = null) protected void SetOption(ref string? storage, string key, string value, [CallerMemberName] string? propertyName = null)
{ {
if (SetProperty(ref storage, value, propertyName)) if (!SetProperty(ref storage, value, propertyName))
{ {
return;
}
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
@@ -153,7 +166,6 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
appDbContext.Settings.AddAndSave(new(key, value)); appDbContext.Settings.AddAndSave(new(key, value));
} }
} }
}
/// <summary> /// <summary>
/// 将值存入数据库 /// 将值存入数据库
@@ -166,15 +178,17 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
protected bool SetOption(ref bool? storage, string key, bool value, [CallerMemberName] string? propertyName = null) protected bool SetOption(ref bool? storage, string key, bool value, [CallerMemberName] string? propertyName = null)
{ {
bool set = SetProperty(ref storage, value, propertyName); bool set = SetProperty(ref storage, value, propertyName);
if (set) if (!set)
{ {
return set;
}
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key); appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key);
appDbContext.Settings.AddAndSave(new(key, value.ToString())); appDbContext.Settings.AddAndSave(new(key, value.ToString()));
} }
}
return set; return set;
} }
@@ -188,8 +202,11 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
/// <param name="propertyName">属性名称</param> /// <param name="propertyName">属性名称</param>
protected void SetOption(ref int? storage, string key, int value, [CallerMemberName] string? propertyName = null) protected void SetOption(ref int? storage, string key, int value, [CallerMemberName] string? propertyName = null)
{ {
if (SetProperty(ref storage, value, propertyName)) if (!SetProperty(ref storage, value, propertyName))
{ {
return;
}
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
@@ -197,7 +214,6 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
appDbContext.Settings.AddAndSave(new(key, value.ToString())); appDbContext.Settings.AddAndSave(new(key, value.ToString()));
} }
} }
}
/// <summary> /// <summary>
/// 将值存入数据库 /// 将值存入数据库
@@ -211,8 +227,11 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
protected void SetOption<T>(ref T? storage, string key, T value, Func<T, string> serializer, [CallerMemberName] string? propertyName = null) protected void SetOption<T>(ref T? storage, string key, T value, Func<T, string> serializer, [CallerMemberName] string? propertyName = null)
where T : class where T : class
{ {
if (SetProperty(ref storage, value, propertyName)) if (!SetProperty(ref storage, value, propertyName))
{ {
return;
}
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
@@ -220,7 +239,6 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
appDbContext.Settings.AddAndSave(new(key, serializer(value))); appDbContext.Settings.AddAndSave(new(key, serializer(value)));
} }
} }
}
/// <summary> /// <summary>
/// 将值存入数据库 /// 将值存入数据库
@@ -234,8 +252,11 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
protected void SetOption<T>(ref T? storage, string key, T value, Func<T, string> serializer, [CallerMemberName] string? propertyName = null) protected void SetOption<T>(ref T? storage, string key, T value, Func<T, string> serializer, [CallerMemberName] string? propertyName = null)
where T : struct where T : struct
{ {
if (SetProperty(ref storage, value, propertyName)) if (!SetProperty(ref storage, value, propertyName))
{ {
return;
}
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
@@ -244,4 +265,3 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions<DbSt
} }
} }
} }
}

View File

@@ -61,7 +61,7 @@ internal sealed partial class AchievementDbBulkOperation
EntityAchievement? entity = entityEnumerator.Current; EntityAchievement? entity = entityEnumerator.Current;
UIAFItem? uiaf = uiafEnumerator.Current; UIAFItem? uiaf = uiafEnumerator.Current;
if (entity == null && uiaf != null) if (entity is null && uiaf is not null)
{ {
appDbContext.Achievements.AddAndSave(EntityAchievement.Create(archiveId, uiaf)); appDbContext.Achievements.AddAndSave(EntityAchievement.Create(archiveId, uiaf));
add++; add++;
@@ -146,7 +146,7 @@ internal sealed partial class AchievementDbBulkOperation
EntityAchievement? oldEntity = oldDataEnumerator.Current; EntityAchievement? oldEntity = oldDataEnumerator.Current;
EntityAchievement? newEntity = newDataEnumerator.Current; EntityAchievement? newEntity = newDataEnumerator.Current;
if (oldEntity == null && newEntity != null) if (oldEntity is null && newEntity is not null)
{ {
appDbContext.Achievements.AddAndSave(newEntity); appDbContext.Achievements.AddAndSave(newEntity);
add++; add++;

View File

@@ -52,7 +52,7 @@ internal sealed partial class AchievementService : IAchievementService
return metadata.SelectList(meta => return metadata.SelectList(meta =>
{ {
EntityAchievement? entity = entityMap.GetValueOrDefault(meta.Id) ?? EntityAchievement.Create(archive.InnerId, meta.Id); EntityAchievement entity = entityMap.GetValueOrDefault(meta.Id) ?? EntityAchievement.Create(archive.InnerId, meta.Id);
return new AchievementView(entity, meta); return new AchievementView(entity, meta);
}); });
} }

View File

@@ -6,7 +6,6 @@ using Snap.Hutao.Model.Entity.Database;
using Snap.Hutao.Model.Metadata; using Snap.Hutao.Model.Metadata;
using Snap.Hutao.Model.Primitive; using Snap.Hutao.Model.Primitive;
using Snap.Hutao.Service.AvatarInfo.Transformer; using Snap.Hutao.Service.AvatarInfo.Transformer;
using Snap.Hutao.Service.Metadata;
using Snap.Hutao.ViewModel.User; using Snap.Hutao.ViewModel.User;
using Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate; using Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord; using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord;
@@ -105,10 +104,6 @@ internal sealed partial class AvatarInfoDbBulkOperation
List<RecordCharacter> characters = charactersResponse.Data.Avatars; List<RecordCharacter> characters = charactersResponse.Data.Avatars;
GameRecordCharacterAvatarInfoTransformer transformer = serviceProvider.GetRequiredService<GameRecordCharacterAvatarInfoTransformer>(); GameRecordCharacterAvatarInfoTransformer transformer = serviceProvider.GetRequiredService<GameRecordCharacterAvatarInfoTransformer>();
transformer.IdAvatarMap = await serviceProvider
.GetRequiredService<IMetadataService>()
.GetIdToAvatarMapAsync(token)
.ConfigureAwait(false);
foreach (RecordCharacter character in characters) foreach (RecordCharacter character in characters)
{ {

View File

@@ -18,9 +18,9 @@ internal static class SummaryAvatarProperties
/// </summary> /// </summary>
/// <param name="fightPropMap">属性映射</param> /// <param name="fightPropMap">属性映射</param>
/// <returns>列表</returns> /// <returns>列表</returns>
public static List<AvatarProperty> Create(Dictionary<FightProperty, float> fightPropMap) public static List<AvatarProperty> Create(Dictionary<FightProperty, float>? fightPropMap)
{ {
if (fightPropMap == null) if (fightPropMap is null)
{ {
return new(); return new();
} }

View File

@@ -28,7 +28,7 @@ internal sealed partial class SummaryFactory : ISummaryFactory
IdReliquaryAffixWeightMap = await metadataService.GetIdToReliquaryAffixWeightMapAsync(token).ConfigureAwait(false), IdReliquaryAffixWeightMap = await metadataService.GetIdToReliquaryAffixWeightMapAsync(token).ConfigureAwait(false),
IdReliquaryMainAffixMap = await metadataService.GetIdToReliquaryMainPropertyMapAsync(token).ConfigureAwait(false), IdReliquaryMainAffixMap = await metadataService.GetIdToReliquaryMainPropertyMapAsync(token).ConfigureAwait(false),
IdReliquarySubAffixMap = await metadataService.GetIdToReliquarySubAffixMapAsync(token).ConfigureAwait(false), IdReliquarySubAffixMap = await metadataService.GetIdToReliquarySubAffixMapAsync(token).ConfigureAwait(false),
ReliqueryLevels = await metadataService.GetReliquaryLevelsAsync(token).ConfigureAwait(false), ReliquaryLevels = await metadataService.GetReliquaryLevelsAsync(token).ConfigureAwait(false),
Reliquaries = await metadataService.GetReliquariesAsync(token).ConfigureAwait(false), Reliquaries = await metadataService.GetReliquariesAsync(token).ConfigureAwait(false),
}; };

View File

@@ -39,9 +39,9 @@ internal static class SummaryHelper
/// <param name="proudSkillExtraLevelMap">额外提升等级映射</param> /// <param name="proudSkillExtraLevelMap">额外提升等级映射</param>
/// <param name="proudSkills">技能列表</param> /// <param name="proudSkills">技能列表</param>
/// <returns>技能</returns> /// <returns>技能</returns>
public static List<SkillView> CreateSkills(Dictionary<SkillId, SkillLevel> skillLevelMap, Dictionary<SkillGroupId, SkillLevel>? proudSkillExtraLevelMap, List<ProudableSkill> proudSkills) public static List<SkillView> CreateSkills(Dictionary<SkillId, SkillLevel>? skillLevelMap, Dictionary<SkillGroupId, SkillLevel>? proudSkillExtraLevelMap, List<ProudableSkill> proudSkills)
{ {
if (skillLevelMap == null) if (skillLevelMap is null)
{ {
return new(); return new();
} }
@@ -80,7 +80,7 @@ internal static class SummaryHelper
/// <returns>最大属性Id</returns> /// <returns>最大属性Id</returns>
public static ReliquarySubAffixId GetAffixMaxId(in ReliquarySubAffixId appendId) public static ReliquarySubAffixId GetAffixMaxId(in ReliquarySubAffixId appendId)
{ {
uint value = (uint)appendId / 100000U; uint value = appendId / 100000U;
uint max = value switch uint max = value switch
{ {
1 => 2, 1 => 2,
@@ -131,9 +131,9 @@ internal static class SummaryHelper
/// </summary> /// </summary>
/// <param name="fightPropMap">属性</param> /// <param name="fightPropMap">属性</param>
/// <returns>评分</returns> /// <returns>评分</returns>
public static float ScoreCrit(Dictionary<FightProperty, float> fightPropMap) public static float ScoreCrit(Dictionary<FightProperty, float>? fightPropMap)
{ {
if (fightPropMap == null) if (fightPropMap is null)
{ {
return 0F; return 0F;
} }

View File

@@ -44,7 +44,7 @@ internal sealed class SummaryMetadataContext
/// <summary> /// <summary>
/// 圣遗物等级 /// 圣遗物等级
/// </summary> /// </summary>
public List<ReliquaryMainAffixLevel> ReliqueryLevels { get; set; } = default!; public List<ReliquaryMainAffixLevel> ReliquaryLevels { get; set; } = default!;
/// <summary> /// <summary>
/// 圣遗物 /// 圣遗物

View File

@@ -66,7 +66,7 @@ internal sealed class SummaryReliquaryFactory
result.PrimarySubProperties = new(span[..^affixCount].ToArray()); result.PrimarySubProperties = new(span[..^affixCount].ToArray());
result.SecondarySubProperties = new(span[^affixCount..].ToArray()); result.SecondarySubProperties = new(span[^affixCount..].ToArray());
result.ComposedSubProperties = equip.Flat.ReliquarySubstats!.SelectList(CreateComposedSubProperty); result.ComposedSubProperties = equip.Flat.ReliquarySubstats!.SelectList(CreateComposedSubProperty);
ReliquaryMainAffixLevel relicLevel = metadataContext.ReliqueryLevels.Single(r => r.Level == equip.Reliquary!.Level && r.Rank == reliquary.RankLevel); ReliquaryMainAffixLevel relicLevel = metadataContext.ReliquaryLevels.Single(r => r.Level == equip.Reliquary!.Level && r.Rank == reliquary.RankLevel);
FightProperty property = metadataContext.IdReliquaryMainAffixMap[equip.Reliquary.MainPropId]; FightProperty property = metadataContext.IdReliquaryMainAffixMap[equip.Reliquary.MainPropId];
result.MainProperty = FightPropertyFormat.ToNameValue(property, relicLevel.PropertyMap[property]); result.MainProperty = FightPropertyFormat.ToNameValue(property, relicLevel.PropertyMap[property]);
@@ -116,7 +116,7 @@ internal sealed class SummaryReliquaryFactory
if (equip.Flat.EquipType > EquipType.EQUIP_SHOES) if (equip.Flat.EquipType > EquipType.EQUIP_SHOES)
{ {
ReliquaryAffixWeight affixWeight = metadataContext.IdReliquaryAffixWeightMap.GetValueOrDefault(avatarInfo.AvatarId, ReliquaryAffixWeight.Default); ReliquaryAffixWeight affixWeight = metadataContext.IdReliquaryAffixWeightMap.GetValueOrDefault(avatarInfo.AvatarId, ReliquaryAffixWeight.Default);
ReliquaryMainAffixLevel maxRelicLevel = metadataContext.ReliqueryLevels.Where(r => r.Rank == reliquary.RankLevel).MaxBy(r => r.Level)!; ReliquaryMainAffixLevel maxRelicLevel = metadataContext.ReliquaryLevels.Where(r => r.Rank == reliquary.RankLevel).MaxBy(r => r.Level)!;
float percent = relicLevel.PropertyMap[property] / maxRelicLevel.PropertyMap[property]; float percent = relicLevel.PropertyMap[property] / maxRelicLevel.PropertyMap[property];
float baseScore = 8 * percent * affixWeight[property]; float baseScore = 8 * percent * affixWeight[property];
@@ -136,9 +136,9 @@ internal sealed class SummaryReliquaryFactory
FormatMethod method = substat.AppendPropId.GetFormatMethod(); FormatMethod method = substat.AppendPropId.GetFormatMethod();
string valueFormatted = method switch string valueFormatted = method switch
{ {
FormatMethod.Integer => Math.Round((double)substat.StatValue, MidpointRounding.AwayFromZero).ToString(), FormatMethod.Integer => $"{MathF.Round(substat.StatValue, MidpointRounding.AwayFromZero)}",
FormatMethod.Percent => $"{substat.StatValue}%", FormatMethod.Percent => $"{substat.StatValue}%",
_ => substat.StatValue.ToString(), _ => $"{substat.StatValue}",
}; };
return new(substat.AppendPropId.GetLocalizedDescription(), valueFormatted, 0); return new(substat.AppendPropId.GetLocalizedDescription(), valueFormatted, 0);

View File

@@ -15,16 +15,9 @@ namespace Snap.Hutao.Service.AvatarInfo.Transformer;
[Injection(InjectAs.Transient)] [Injection(InjectAs.Transient)]
internal sealed class GameRecordCharacterAvatarInfoTransformer : IAvatarInfoTransformer<Character> internal sealed class GameRecordCharacterAvatarInfoTransformer : IAvatarInfoTransformer<Character>
{ {
/// <summary>
/// Id 角色映射
/// </summary>
public Dictionary<AvatarId, Model.Metadata.Avatar.Avatar>? IdAvatarMap { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
public void Transform(ref Web.Enka.Model.AvatarInfo avatarInfo, Character source) public void Transform(ref Web.Enka.Model.AvatarInfo avatarInfo, Character source)
{ {
Model.Metadata.Avatar.Avatar avatar = Must.NotNull(IdAvatarMap!)[source.Id];
// update fetter // update fetter
avatarInfo.FetterInfo ??= new(); avatarInfo.FetterInfo ??= new();
avatarInfo.FetterInfo.ExpLevel = source.Fetter; avatarInfo.FetterInfo.ExpLevel = source.Fetter;
@@ -45,7 +38,7 @@ internal sealed class GameRecordCharacterAvatarInfoTransformer : IAvatarInfoTran
}); });
Equip? equipTest = avatarInfo.EquipList.LastOrDefault(); Equip? equipTest = avatarInfo.EquipList.LastOrDefault();
if (equipTest == null || equipTest.Weapon == null) if (equipTest?.Weapon is null)
{ {
// 不存在武器则添加 // 不存在武器则添加
avatarInfo.EquipList.Add(new()); avatarInfo.EquipList.Add(new());

View File

@@ -8,7 +8,7 @@ namespace Snap.Hutao.Service.AvatarInfo.Transformer;
/// </summary> /// </summary>
/// <typeparam name="TSource">源类型</typeparam> /// <typeparam name="TSource">源类型</typeparam>
[HighQuality] [HighQuality]
internal interface IAvatarInfoTransformer<TSource> internal interface IAvatarInfoTransformer<in TSource>
{ {
/// <summary> /// <summary>
/// 合并到角色信息 /// 合并到角色信息

View File

@@ -110,7 +110,7 @@ internal sealed partial class CultivationService : ICultivationService
List<Material> materials = await scope.ServiceProvider List<Material> materials = await scope.ServiceProvider
.GetRequiredService<IMetadataService>() .GetRequiredService<IMetadataService>()
.GetMaterialsAsync(default) .GetMaterialsAsync(token)
.ConfigureAwait(false); .ConfigureAwait(false);
Guid projectId = cultivateProject.InnerId; Guid projectId = cultivateProject.InnerId;
@@ -126,13 +126,13 @@ internal sealed partial class CultivationService : ICultivationService
continue; continue;
} }
if (resultItems.SingleOrDefault(i => i.Inner.Id == item.ItemId) is StatisticsCultivateItem existedItem) if (resultItems.SingleOrDefault(i => i.Inner.Id == item.ItemId) is { } existedItem)
{ {
existedItem.Count += item.Count; existedItem.Count += item.Count;
} }
else else
{ {
resultItems.Add(new(materials!.Single(m => m.Id == item.ItemId), item)); resultItems.Add(new(materials.Single(m => m.Id == item.ItemId), item));
} }
} }
} }
@@ -141,7 +141,7 @@ internal sealed partial class CultivationService : ICultivationService
foreach (InventoryItem inventoryItem in await GetProjectInventoryAsync(appDbContext, projectId).ConfigureAwait(false)) foreach (InventoryItem inventoryItem in await GetProjectInventoryAsync(appDbContext, projectId).ConfigureAwait(false))
{ {
if (resultItems.SingleOrDefault(i => i.Inner.Id == inventoryItem.ItemId) is StatisticsCultivateItem existedItem) if (resultItems.SingleOrDefault(i => i.Inner.Id == inventoryItem.ItemId) is { } existedItem)
{ {
existedItem.TotalCount += inventoryItem.Count; existedItem.TotalCount += inventoryItem.Count;
} }

View File

@@ -57,8 +57,6 @@ internal sealed class DailyNoteNotifier
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {
DailyNoteOptions options = scope.ServiceProvider.GetRequiredService<DailyNoteOptions>(); DailyNoteOptions options = scope.ServiceProvider.GetRequiredService<DailyNoteOptions>();
BindingClient bindingClient = scope.ServiceProvider.GetRequiredService<BindingClient>();
AuthClient authClient = scope.ServiceProvider.GetRequiredService<AuthClient>();
string? attribution = SH.ServiceDailyNoteNotifierAttribution; string? attribution = SH.ServiceDailyNoteNotifierAttribution;

View File

@@ -10,9 +10,9 @@ namespace Snap.Hutao.Service.GachaLog.Factory;
/// <summary> /// <summary>
/// 祈愿配置类型比较器 /// 祈愿配置类型比较器
/// </summary> /// </summary>
internal sealed class GachaConfigTypeComparar : IComparer<GachaConfigType> internal sealed class GachaConfigTypeComparer : IComparer<GachaConfigType>
{ {
private static readonly GachaConfigTypeComparar InnerShared = new(); private static readonly GachaConfigTypeComparer InnerShared = new();
private static readonly ImmutableDictionary<GachaConfigType, int> OrderMap = new Dictionary<GachaConfigType, int>() private static readonly ImmutableDictionary<GachaConfigType, int> OrderMap = new Dictionary<GachaConfigType, int>()
{ {
[GachaConfigType.AvatarEventWish] = 0, [GachaConfigType.AvatarEventWish] = 0,
@@ -25,7 +25,7 @@ internal sealed class GachaConfigTypeComparar : IComparer<GachaConfigType>
/// <summary> /// <summary>
/// 共享的比较器 /// 共享的比较器
/// </summary> /// </summary>
public static GachaConfigTypeComparar Shared { get => InnerShared; } public static GachaConfigTypeComparer Shared { get => InnerShared; }
/// <inheritdoc/> /// <inheritdoc/>
public int Compare(GachaConfigType x, GachaConfigType y) public int Compare(GachaConfigType x, GachaConfigType y)

View File

@@ -29,6 +29,11 @@ internal static class GachaStatisticsExtension
count++; count++;
} }
if (count == 0)
{
return 0;
}
return unchecked((byte)(sum / count)); return unchecked((byte)(sum / count));
} }

View File

@@ -123,7 +123,7 @@ internal sealed partial class GachaStatisticsFactory : IGachaStatisticsFactory
HistoryWishes = historyWishBuilders HistoryWishes = historyWishBuilders
.Where(b => isEmptyHistoryWishVisible || (!b.IsEmpty)) .Where(b => isEmptyHistoryWishVisible || (!b.IsEmpty))
.OrderByDescending(builder => builder.From) .OrderByDescending(builder => builder.From)
.ThenBy(builder => builder.ConfigType, GachaConfigTypeComparar.Shared) .ThenBy(builder => builder.ConfigType, GachaConfigTypeComparer.Shared)
.Select(builder => builder.ToHistoryWish()) .Select(builder => builder.ToHistoryWish())
.ToList(), .ToList(),

View File

@@ -31,8 +31,8 @@ internal sealed class TypedWishSummaryBuilder
public static readonly Func<GachaConfigType, bool> IsWeaponEventWish = type => type is GachaConfigType.WeaponEventWish; public static readonly Func<GachaConfigType, bool> IsWeaponEventWish = type => type is GachaConfigType.WeaponEventWish;
private readonly string name; private readonly string name;
private readonly int guarenteeOrangeThreshold; private readonly int guaranteeOrangeThreshold;
private readonly int guarenteePurpleThreshold; private readonly int guaranteePurpleThreshold;
private readonly Func<GachaConfigType, bool> typeEvaluator; private readonly Func<GachaConfigType, bool> typeEvaluator;
private readonly List<int> averageOrangePullTracker = new(); private readonly List<int> averageOrangePullTracker = new();
@@ -57,14 +57,14 @@ internal sealed class TypedWishSummaryBuilder
/// </summary> /// </summary>
/// <param name="name">祈愿配置</param> /// <param name="name">祈愿配置</param>
/// <param name="typeEvaluator">祈愿类型判断器</param> /// <param name="typeEvaluator">祈愿类型判断器</param>
/// <param name="guarenteeOrangeThreshold">五星保底</param> /// <param name="guaranteeOrangeThreshold">五星保底</param>
/// <param name="guarenteePurpleThreshold">四星保底</param> /// <param name="guaranteePurpleThreshold">四星保底</param>
public TypedWishSummaryBuilder(string name, Func<GachaConfigType, bool> typeEvaluator, int guarenteeOrangeThreshold, int guarenteePurpleThreshold) public TypedWishSummaryBuilder(string name, Func<GachaConfigType, bool> typeEvaluator, int guaranteeOrangeThreshold, int guaranteePurpleThreshold)
{ {
this.name = name; this.name = name;
this.typeEvaluator = typeEvaluator; this.typeEvaluator = typeEvaluator;
this.guarenteeOrangeThreshold = guarenteeOrangeThreshold; this.guaranteeOrangeThreshold = guaranteeOrangeThreshold;
this.guarenteePurpleThreshold = guarenteePurpleThreshold; this.guaranteePurpleThreshold = guaranteePurpleThreshold;
} }
/// <summary> /// <summary>
@@ -142,9 +142,9 @@ internal sealed class TypedWishSummaryBuilder
MaxOrangePull = maxOrangePullTracker, MaxOrangePull = maxOrangePullTracker,
MinOrangePull = minOrangePullTracker, MinOrangePull = minOrangePullTracker,
LastOrangePull = lastOrangePullTracker, LastOrangePull = lastOrangePullTracker,
GuaranteeOrangeThreshold = guarenteeOrangeThreshold, GuaranteeOrangeThreshold = guaranteeOrangeThreshold,
LastPurplePull = lastPurplePullTracker, LastPurplePull = lastPurplePullTracker,
GuaranteePurpleThreshold = guarenteePurpleThreshold, GuaranteePurpleThreshold = guaranteePurpleThreshold,
TotalOrangePull = totalOrangePullTracker, TotalOrangePull = totalOrangePullTracker,
TotalPurplePull = totalPurplePullTracker, TotalPurplePull = totalPurplePullTracker,
TotalBluePull = totalBluePullTracker, TotalBluePull = totalBluePullTracker,

View File

@@ -21,7 +21,7 @@ internal static class GachaLogQueryProviderExtension
string? name = option switch string? name = option switch
{ {
RefreshOption.WebCache => nameof(GachaLogQueryWebCacheProvider), RefreshOption.WebCache => nameof(GachaLogQueryWebCacheProvider),
RefreshOption.SToken => nameof(GachaLogQuerySTokenProvider), RefreshOption.SToken => nameof(GachaLogQuerySToken2Provider),
RefreshOption.ManualInput => nameof(GachaLogQueryManualInputProvider), RefreshOption.ManualInput => nameof(GachaLogQueryManualInputProvider),
_ => null, _ => null,
}; };

View File

@@ -15,13 +15,13 @@ namespace Snap.Hutao.Service.GachaLog.QueryProvider;
[HighQuality] [HighQuality]
[ConstructorGenerated] [ConstructorGenerated]
[Injection(InjectAs.Transient, typeof(IGachaLogQueryProvider))] [Injection(InjectAs.Transient, typeof(IGachaLogQueryProvider))]
internal sealed partial class GachaLogQuerySTokenProvider : IGachaLogQueryProvider internal sealed partial class GachaLogQuerySToken2Provider : IGachaLogQueryProvider
{ {
private readonly BindingClient2 bindingClient2; private readonly BindingClient2 bindingClient2;
private readonly IUserService userService; private readonly IUserService userService;
/// <inheritdoc/> /// <inheritdoc/>
public string Name { get => nameof(GachaLogQuerySTokenProvider); } public string Name { get => nameof(GachaLogQuerySToken2Provider); }
/// <inheritdoc/> /// <inheritdoc/>
public async Task<ValueResult<bool, GachaLogQuery>> GetQueryAsync() public async Task<ValueResult<bool, GachaLogQuery>> GetQueryAsync()

View File

@@ -24,6 +24,7 @@ internal sealed class AvatarInfo
/// Character Info Properties List /// Character Info Properties List
/// <see cref="PlayerProperty.PROP_EXP"/> /// <see cref="PlayerProperty.PROP_EXP"/>
/// </summary> /// </summary>
[MaybeNull]
[JsonPropertyName("propMap")] [JsonPropertyName("propMap")]
public Dictionary<PlayerProperty, TypeValue> PropMap { get; set; } = default!; public Dictionary<PlayerProperty, TypeValue> PropMap { get; set; } = default!;
@@ -65,6 +66,7 @@ internal sealed class AvatarInfo
/// 最后一个为武器 /// 最后一个为武器
/// List of Equipments: Weapon, Artifacts /// List of Equipments: Weapon, Artifacts
/// </summary> /// </summary>
[MaybeNull]
[JsonPropertyName("equipList")] [JsonPropertyName("equipList")]
public List<Equip> EquipList { get; set; } = default!; public List<Equip> EquipList { get; set; } = default!;
@@ -72,6 +74,7 @@ internal sealed class AvatarInfo
/// 好感度信息 /// 好感度信息
/// Character Friendship Level /// Character Friendship Level
/// </summary> /// </summary>
[MaybeNull]
[JsonPropertyName("fetterInfo")] [JsonPropertyName("fetterInfo")]
public FetterInfo FetterInfo { get; set; } = default!; public FetterInfo FetterInfo { get; set; } = default!;

View File

@@ -29,6 +29,7 @@ internal sealed class Weapon
/// 精炼 相较于实际等级 -1 /// 精炼 相较于实际等级 -1
/// Weapon Refinement Level [0-4] /// Weapon Refinement Level [0-4]
/// </summary> /// </summary>
[MaybeNull]
[JsonPropertyName("affixMap")] [JsonPropertyName("affixMap")]
public Dictionary<EquipAffixId, WeaponAffixLevel> AffixMap { get; set; } = default!; public Dictionary<EquipAffixId, WeaponAffixLevel> AffixMap { get; set; } = default!;
} }