diff --git a/src/Snap.Hutao/Snap.Hutao/Model/IEntityWithMetadata.cs b/src/Snap.Hutao/Snap.Hutao/Model/IEntityWithMetadata.cs index f894963e..9fd4d1a5 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/IEntityWithMetadata.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/IEntityWithMetadata.cs @@ -9,7 +9,7 @@ namespace Snap.Hutao.Model; /// 实体 /// 元数据 [HighQuality] -internal interface IEntityWithMetadata +internal interface IEntityWithMetadata { /// /// 实体 diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Abstraction/DbStoreOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/Abstraction/DbStoreOptions.cs index 9078c0a9..9419a94c 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Abstraction/DbStoreOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Abstraction/DbStoreOptions.cs @@ -29,13 +29,15 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions值 protected string GetOption(ref string? storage, string key, string defaultValue = "") { - if (storage == null) + if (storage is not null) { - using (IServiceScope scope = serviceProvider.CreateScope()) - { - AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); - storage = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value ?? defaultValue; - } + return storage; + } + + using (IServiceScope scope = serviceProvider.CreateScope()) + { + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + storage = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value ?? defaultValue; } return storage; @@ -50,14 +52,16 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions值 protected bool GetOption(ref bool? storage, string key, bool defaultValue = false) { - if (storage == null) + if (storage is not null) { - using (IServiceScope scope = serviceProvider.CreateScope()) - { - AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); - string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; - storage = value == null ? defaultValue : bool.Parse(value); - } + return storage.Value; + } + + using (IServiceScope scope = serviceProvider.CreateScope()) + { + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; + storage = value == null ? defaultValue : bool.Parse(value); } return storage.Value; @@ -72,14 +76,16 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions值 protected int GetOption(ref int? storage, string key, int defaultValue = 0) { - if (storage == null) + if (storage is not null) { - using (IServiceScope scope = serviceProvider.CreateScope()) - { - AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); - string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; - storage = value == null ? defaultValue : int.Parse(value); - } + return storage.Value; + } + + using (IServiceScope scope = serviceProvider.CreateScope()) + { + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; + storage = value == null ? defaultValue : int.Parse(value); } return storage.Value; @@ -97,14 +103,16 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions(ref T? storage, string key, Func deserializer, T defaultValue) where T : class { - if (storage == null) + if (storage != null) { - using (IServiceScope scope = serviceProvider.CreateScope()) - { - AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); - string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; - storage = value == null ? defaultValue : deserializer(value); - } + return storage; + } + + using (IServiceScope scope = serviceProvider.CreateScope()) + { + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; + storage = value == null ? defaultValue : deserializer(value); } return storage; @@ -122,14 +130,16 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions(ref T? storage, string key, Func deserializer, T defaultValue) where T : struct { - if (storage == null) + if (storage is not null) { - using (IServiceScope scope = serviceProvider.CreateScope()) - { - AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); - string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; - storage = value == null ? defaultValue : deserializer(value); - } + return storage.Value; + } + + using (IServiceScope scope = serviceProvider.CreateScope()) + { + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value; + storage = value == null ? defaultValue : deserializer(value); } return storage.Value; @@ -144,14 +154,16 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions属性名称 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)) { - using (IServiceScope scope = serviceProvider.CreateScope()) - { - AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); - appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key); - appDbContext.Settings.AddAndSave(new(key, value)); - } + return; + } + + using (IServiceScope scope = serviceProvider.CreateScope()) + { + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key); + appDbContext.Settings.AddAndSave(new(key, value)); } } @@ -166,14 +178,16 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions(); - appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key); - appDbContext.Settings.AddAndSave(new(key, value.ToString())); - } + return set; + } + + using (IServiceScope scope = serviceProvider.CreateScope()) + { + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key); + appDbContext.Settings.AddAndSave(new(key, value.ToString())); } return set; @@ -188,14 +202,16 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions属性名称 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)) { - using (IServiceScope scope = serviceProvider.CreateScope()) - { - AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); - appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key); - appDbContext.Settings.AddAndSave(new(key, value.ToString())); - } + return; + } + + using (IServiceScope scope = serviceProvider.CreateScope()) + { + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key); + appDbContext.Settings.AddAndSave(new(key, value.ToString())); } } @@ -211,14 +227,16 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions(ref T? storage, string key, T value, Func serializer, [CallerMemberName] string? propertyName = null) where T : class { - if (SetProperty(ref storage, value, propertyName)) + if (!SetProperty(ref storage, value, propertyName)) { - using (IServiceScope scope = serviceProvider.CreateScope()) - { - AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); - appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key); - appDbContext.Settings.AddAndSave(new(key, serializer(value))); - } + return; + } + + using (IServiceScope scope = serviceProvider.CreateScope()) + { + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key); + appDbContext.Settings.AddAndSave(new(key, serializer(value))); } } @@ -234,14 +252,16 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions(ref T? storage, string key, T value, Func serializer, [CallerMemberName] string? propertyName = null) where T : struct { - if (SetProperty(ref storage, value, propertyName)) + if (!SetProperty(ref storage, value, propertyName)) { - using (IServiceScope scope = serviceProvider.CreateScope()) - { - AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); - appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key); - appDbContext.Settings.AddAndSave(new(key, serializer(value))); - } + return; + } + + using (IServiceScope scope = serviceProvider.CreateScope()) + { + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == key); + appDbContext.Settings.AddAndSave(new(key, serializer(value))); } } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementDbBulkOperation.cs b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementDbBulkOperation.cs index d8d2d14b..4cd626b3 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementDbBulkOperation.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementDbBulkOperation.cs @@ -61,7 +61,7 @@ internal sealed partial class AchievementDbBulkOperation EntityAchievement? entity = entityEnumerator.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)); add++; @@ -146,7 +146,7 @@ internal sealed partial class AchievementDbBulkOperation EntityAchievement? oldEntity = oldDataEnumerator.Current; EntityAchievement? newEntity = newDataEnumerator.Current; - if (oldEntity == null && newEntity != null) + if (oldEntity is null && newEntity is not null) { appDbContext.Achievements.AddAndSave(newEntity); add++; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs index 183d4b2c..2e28d7df 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs @@ -52,7 +52,7 @@ internal sealed partial class AchievementService : IAchievementService 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); }); } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/AvatarInfoDbBulkOperation.cs b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/AvatarInfoDbBulkOperation.cs index 6a438af7..4f7bb44a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/AvatarInfoDbBulkOperation.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/AvatarInfoDbBulkOperation.cs @@ -6,7 +6,6 @@ using Snap.Hutao.Model.Entity.Database; using Snap.Hutao.Model.Metadata; using Snap.Hutao.Model.Primitive; using Snap.Hutao.Service.AvatarInfo.Transformer; -using Snap.Hutao.Service.Metadata; using Snap.Hutao.ViewModel.User; using Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate; using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord; @@ -105,10 +104,6 @@ internal sealed partial class AvatarInfoDbBulkOperation List characters = charactersResponse.Data.Avatars; GameRecordCharacterAvatarInfoTransformer transformer = serviceProvider.GetRequiredService(); - transformer.IdAvatarMap = await serviceProvider - .GetRequiredService() - .GetIdToAvatarMapAsync(token) - .ConfigureAwait(false); foreach (RecordCharacter character in characters) { diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryAvatarProperties.cs b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryAvatarProperties.cs index 54448d88..dd528419 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryAvatarProperties.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryAvatarProperties.cs @@ -18,9 +18,9 @@ internal static class SummaryAvatarProperties /// /// 属性映射 /// 列表 - public static List Create(Dictionary fightPropMap) + public static List Create(Dictionary? fightPropMap) { - if (fightPropMap == null) + if (fightPropMap is null) { return new(); } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryFactory.cs b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryFactory.cs index cda31d4e..185be74b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryFactory.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryFactory.cs @@ -28,7 +28,7 @@ internal sealed partial class SummaryFactory : ISummaryFactory IdReliquaryAffixWeightMap = await metadataService.GetIdToReliquaryAffixWeightMapAsync(token).ConfigureAwait(false), IdReliquaryMainAffixMap = await metadataService.GetIdToReliquaryMainPropertyMapAsync(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), }; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryHelper.cs b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryHelper.cs index e8f6906c..8691e592 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryHelper.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryHelper.cs @@ -39,9 +39,9 @@ internal static class SummaryHelper /// 额外提升等级映射 /// 技能列表 /// 技能 - public static List CreateSkills(Dictionary skillLevelMap, Dictionary? proudSkillExtraLevelMap, List proudSkills) + public static List CreateSkills(Dictionary? skillLevelMap, Dictionary? proudSkillExtraLevelMap, List proudSkills) { - if (skillLevelMap == null) + if (skillLevelMap is null) { return new(); } @@ -80,7 +80,7 @@ internal static class SummaryHelper /// 最大属性Id public static ReliquarySubAffixId GetAffixMaxId(in ReliquarySubAffixId appendId) { - uint value = (uint)appendId / 100000U; + uint value = appendId / 100000U; uint max = value switch { 1 => 2, @@ -131,9 +131,9 @@ internal static class SummaryHelper /// /// 属性 /// 评分 - public static float ScoreCrit(Dictionary fightPropMap) + public static float ScoreCrit(Dictionary? fightPropMap) { - if (fightPropMap == null) + if (fightPropMap is null) { return 0F; } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryMetadataContext.cs b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryMetadataContext.cs index 6fe88a6e..1aaf4dd3 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryMetadataContext.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryMetadataContext.cs @@ -44,7 +44,7 @@ internal sealed class SummaryMetadataContext /// /// 圣遗物等级 /// - public List ReliqueryLevels { get; set; } = default!; + public List ReliquaryLevels { get; set; } = default!; /// /// 圣遗物 diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryReliquaryFactory.cs b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryReliquaryFactory.cs index fcb4466b..d78197a3 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryReliquaryFactory.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/SummaryReliquaryFactory.cs @@ -66,7 +66,7 @@ internal sealed class SummaryReliquaryFactory result.PrimarySubProperties = new(span[..^affixCount].ToArray()); result.SecondarySubProperties = new(span[^affixCount..].ToArray()); 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]; result.MainProperty = FightPropertyFormat.ToNameValue(property, relicLevel.PropertyMap[property]); @@ -116,7 +116,7 @@ internal sealed class SummaryReliquaryFactory if (equip.Flat.EquipType > EquipType.EQUIP_SHOES) { 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 baseScore = 8 * percent * affixWeight[property]; @@ -136,9 +136,9 @@ internal sealed class SummaryReliquaryFactory FormatMethod method = substat.AppendPropId.GetFormatMethod(); 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}%", - _ => substat.StatValue.ToString(), + _ => $"{substat.StatValue}", }; return new(substat.AppendPropId.GetLocalizedDescription(), valueFormatted, 0); diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Transformer/GameRecordCharacterAvatarInfoTransformer.cs b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Transformer/GameRecordCharacterAvatarInfoTransformer.cs index be4cdb66..ed36557c 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Transformer/GameRecordCharacterAvatarInfoTransformer.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Transformer/GameRecordCharacterAvatarInfoTransformer.cs @@ -15,16 +15,9 @@ namespace Snap.Hutao.Service.AvatarInfo.Transformer; [Injection(InjectAs.Transient)] internal sealed class GameRecordCharacterAvatarInfoTransformer : IAvatarInfoTransformer { - /// - /// Id 角色映射 - /// - public Dictionary? IdAvatarMap { get; set; } - /// public void Transform(ref Web.Enka.Model.AvatarInfo avatarInfo, Character source) { - Model.Metadata.Avatar.Avatar avatar = Must.NotNull(IdAvatarMap!)[source.Id]; - // update fetter avatarInfo.FetterInfo ??= new(); avatarInfo.FetterInfo.ExpLevel = source.Fetter; @@ -45,7 +38,7 @@ internal sealed class GameRecordCharacterAvatarInfoTransformer : IAvatarInfoTran }); Equip? equipTest = avatarInfo.EquipList.LastOrDefault(); - if (equipTest == null || equipTest.Weapon == null) + if (equipTest?.Weapon is null) { // 不存在武器则添加 avatarInfo.EquipList.Add(new()); diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Transformer/IAvatarInfoTransformer.cs b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Transformer/IAvatarInfoTransformer.cs index dd798b79..a6ea9ebe 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Transformer/IAvatarInfoTransformer.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Transformer/IAvatarInfoTransformer.cs @@ -8,7 +8,7 @@ namespace Snap.Hutao.Service.AvatarInfo.Transformer; /// /// 源类型 [HighQuality] -internal interface IAvatarInfoTransformer +internal interface IAvatarInfoTransformer { /// /// 合并到角色信息 diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs index 904bf572..610d9852 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs @@ -110,7 +110,7 @@ internal sealed partial class CultivationService : ICultivationService List materials = await scope.ServiceProvider .GetRequiredService() - .GetMaterialsAsync(default) + .GetMaterialsAsync(token) .ConfigureAwait(false); Guid projectId = cultivateProject.InnerId; @@ -126,13 +126,13 @@ internal sealed partial class CultivationService : ICultivationService 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; } 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)) { - 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; } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteNotifier.cs b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteNotifier.cs index b9e1c183..0387dd48 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteNotifier.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteNotifier.cs @@ -57,8 +57,6 @@ internal sealed class DailyNoteNotifier using (IServiceScope scope = serviceProvider.CreateScope()) { DailyNoteOptions options = scope.ServiceProvider.GetRequiredService(); - BindingClient bindingClient = scope.ServiceProvider.GetRequiredService(); - AuthClient authClient = scope.ServiceProvider.GetRequiredService(); string? attribution = SH.ServiceDailyNoteNotifierAttribution; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaConfigTypeComparar.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaConfigTypeComparer.cs similarity index 85% rename from src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaConfigTypeComparar.cs rename to src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaConfigTypeComparer.cs index fb1a1b77..66146618 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaConfigTypeComparar.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaConfigTypeComparer.cs @@ -10,9 +10,9 @@ namespace Snap.Hutao.Service.GachaLog.Factory; /// /// 祈愿配置类型比较器 /// -internal sealed class GachaConfigTypeComparar : IComparer +internal sealed class GachaConfigTypeComparer : IComparer { - private static readonly GachaConfigTypeComparar InnerShared = new(); + private static readonly GachaConfigTypeComparer InnerShared = new(); private static readonly ImmutableDictionary OrderMap = new Dictionary() { [GachaConfigType.AvatarEventWish] = 0, @@ -25,7 +25,7 @@ internal sealed class GachaConfigTypeComparar : IComparer /// /// 共享的比较器 /// - public static GachaConfigTypeComparar Shared { get => InnerShared; } + public static GachaConfigTypeComparer Shared { get => InnerShared; } /// public int Compare(GachaConfigType x, GachaConfigType y) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaStatisticsExtension.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaStatisticsExtension.cs index 8ee30938..ae0e5f37 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaStatisticsExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaStatisticsExtension.cs @@ -29,6 +29,11 @@ internal static class GachaStatisticsExtension count++; } + if (count == 0) + { + return 0; + } + return unchecked((byte)(sum / count)); } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaStatisticsFactory.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaStatisticsFactory.cs index 273800cc..70df4bec 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaStatisticsFactory.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/GachaStatisticsFactory.cs @@ -123,7 +123,7 @@ internal sealed partial class GachaStatisticsFactory : IGachaStatisticsFactory HistoryWishes = historyWishBuilders .Where(b => isEmptyHistoryWishVisible || (!b.IsEmpty)) .OrderByDescending(builder => builder.From) - .ThenBy(builder => builder.ConfigType, GachaConfigTypeComparar.Shared) + .ThenBy(builder => builder.ConfigType, GachaConfigTypeComparer.Shared) .Select(builder => builder.ToHistoryWish()) .ToList(), diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/TypedWishSummaryBuilder.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/TypedWishSummaryBuilder.cs index 9b14e459..5714f161 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/TypedWishSummaryBuilder.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/TypedWishSummaryBuilder.cs @@ -31,8 +31,8 @@ internal sealed class TypedWishSummaryBuilder public static readonly Func IsWeaponEventWish = type => type is GachaConfigType.WeaponEventWish; private readonly string name; - private readonly int guarenteeOrangeThreshold; - private readonly int guarenteePurpleThreshold; + private readonly int guaranteeOrangeThreshold; + private readonly int guaranteePurpleThreshold; private readonly Func typeEvaluator; private readonly List averageOrangePullTracker = new(); @@ -57,14 +57,14 @@ internal sealed class TypedWishSummaryBuilder /// /// 祈愿配置 /// 祈愿类型判断器 - /// 五星保底 - /// 四星保底 - public TypedWishSummaryBuilder(string name, Func typeEvaluator, int guarenteeOrangeThreshold, int guarenteePurpleThreshold) + /// 五星保底 + /// 四星保底 + public TypedWishSummaryBuilder(string name, Func typeEvaluator, int guaranteeOrangeThreshold, int guaranteePurpleThreshold) { this.name = name; this.typeEvaluator = typeEvaluator; - this.guarenteeOrangeThreshold = guarenteeOrangeThreshold; - this.guarenteePurpleThreshold = guarenteePurpleThreshold; + this.guaranteeOrangeThreshold = guaranteeOrangeThreshold; + this.guaranteePurpleThreshold = guaranteePurpleThreshold; } /// @@ -142,9 +142,9 @@ internal sealed class TypedWishSummaryBuilder MaxOrangePull = maxOrangePullTracker, MinOrangePull = minOrangePullTracker, LastOrangePull = lastOrangePullTracker, - GuaranteeOrangeThreshold = guarenteeOrangeThreshold, + GuaranteeOrangeThreshold = guaranteeOrangeThreshold, LastPurplePull = lastPurplePullTracker, - GuaranteePurpleThreshold = guarenteePurpleThreshold, + GuaranteePurpleThreshold = guaranteePurpleThreshold, TotalOrangePull = totalOrangePullTracker, TotalPurplePull = totalPurplePullTracker, TotalBluePull = totalBluePullTracker, diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryProviderExtension.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryProviderExtension.cs index 57642db0..aef7ec09 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryProviderExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryProviderExtension.cs @@ -21,7 +21,7 @@ internal static class GachaLogQueryProviderExtension string? name = option switch { RefreshOption.WebCache => nameof(GachaLogQueryWebCacheProvider), - RefreshOption.SToken => nameof(GachaLogQuerySTokenProvider), + RefreshOption.SToken => nameof(GachaLogQuerySToken2Provider), RefreshOption.ManualInput => nameof(GachaLogQueryManualInputProvider), _ => null, }; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryStokenProvider.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQuerySToken2Provider.cs similarity index 91% rename from src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryStokenProvider.cs rename to src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQuerySToken2Provider.cs index 3c1e11f4..7b2e0c8e 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryStokenProvider.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQuerySToken2Provider.cs @@ -15,13 +15,13 @@ namespace Snap.Hutao.Service.GachaLog.QueryProvider; [HighQuality] [ConstructorGenerated] [Injection(InjectAs.Transient, typeof(IGachaLogQueryProvider))] -internal sealed partial class GachaLogQuerySTokenProvider : IGachaLogQueryProvider +internal sealed partial class GachaLogQuerySToken2Provider : IGachaLogQueryProvider { private readonly BindingClient2 bindingClient2; private readonly IUserService userService; /// - public string Name { get => nameof(GachaLogQuerySTokenProvider); } + public string Name { get => nameof(GachaLogQuerySToken2Provider); } /// public async Task> GetQueryAsync() diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Enka/Model/AvatarInfo.cs b/src/Snap.Hutao/Snap.Hutao/Web/Enka/Model/AvatarInfo.cs index b5f8ac2d..06385553 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Enka/Model/AvatarInfo.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Enka/Model/AvatarInfo.cs @@ -24,6 +24,7 @@ internal sealed class AvatarInfo /// Character Info Properties List /// /// + [MaybeNull] [JsonPropertyName("propMap")] public Dictionary PropMap { get; set; } = default!; @@ -65,6 +66,7 @@ internal sealed class AvatarInfo /// 最后一个为武器 /// List of Equipments: Weapon, Artifacts /// + [MaybeNull] [JsonPropertyName("equipList")] public List EquipList { get; set; } = default!; @@ -72,6 +74,7 @@ internal sealed class AvatarInfo /// 好感度信息 /// Character Friendship Level /// + [MaybeNull] [JsonPropertyName("fetterInfo")] public FetterInfo FetterInfo { get; set; } = default!; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Enka/Model/Weapon.cs b/src/Snap.Hutao/Snap.Hutao/Web/Enka/Model/Weapon.cs index 42f6e2db..d6917f40 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Enka/Model/Weapon.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Enka/Model/Weapon.cs @@ -29,6 +29,7 @@ internal sealed class Weapon /// 精炼 相较于实际等级 -1 /// Weapon Refinement Level [0-4] /// + [MaybeNull] [JsonPropertyName("affixMap")] public Dictionary AffixMap { get; set; } = default!; } \ No newline at end of file