mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
Merge pull request #1712 from DGP-Studio/feat/v3_cultivation
This commit is contained in:
@@ -5,7 +5,6 @@ using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Snap.Hutao.Core.Abstraction;
|
||||
using Snap.Hutao.Service.Navigation;
|
||||
using Snap.Hutao.View.Helper;
|
||||
using Snap.Hutao.ViewModel.Abstraction;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Snap.Hutao.Win32.Registry;
|
||||
using System.Linq.Expressions;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
@@ -199,6 +199,13 @@ internal static partial class EnumerableExtension
|
||||
return list;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
public static List<TSource> SortBy<TSource, TKey>(this List<TSource> list, Func<TSource, TKey> keySelector, Comparison<TKey> comparison)
|
||||
{
|
||||
list.Sort((left, right) => comparison(keySelector(left), keySelector(right)));
|
||||
return list;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
public static List<TSource> SortByDescending<TSource, TKey>(this List<TSource> list, Func<TSource, TKey> keySelector)
|
||||
where TKey : IComparable
|
||||
@@ -213,4 +220,11 @@ internal static partial class EnumerableExtension
|
||||
list.Sort((left, right) => comparer.Compare(keySelector(right), keySelector(left)));
|
||||
return list;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
public static List<TSource> SortByDescending<TSource, TKey>(this List<TSource> list, Func<TSource, TKey> keySelector, Comparison<TKey> comparison)
|
||||
{
|
||||
list.Sort((left, right) => comparison(keySelector(right), keySelector(left)));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,8 @@ namespace Snap.Hutao.Model.Entity;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Table("inventory_items")]
|
||||
internal sealed class InventoryItem : IDbMappingForeignKeyFrom<InventoryItem, uint>
|
||||
internal sealed class InventoryItem : IDbMappingForeignKeyFrom<InventoryItem, uint>,
|
||||
IDbMappingForeignKeyFrom<InventoryItem, uint, uint>
|
||||
{
|
||||
/// <summary>
|
||||
/// 内部Id
|
||||
@@ -56,4 +57,21 @@ internal sealed class InventoryItem : IDbMappingForeignKeyFrom<InventoryItem, ui
|
||||
ItemId = itemId,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的个数不为0的物品
|
||||
/// </summary>
|
||||
/// <param name="projectId">项目Id</param>
|
||||
/// <param name="itemId">物品Id</param>
|
||||
/// <param name="count">物品个数</param>
|
||||
/// <returns>新的个数不为0的物品</returns>
|
||||
public static InventoryItem From(in Guid projectId, in uint itemId, in uint count)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
ProjectId = projectId,
|
||||
ItemId = itemId,
|
||||
Count = count,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace Snap.Hutao.Model.InterChange.GachaLog;
|
||||
/// UIGF物品
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal sealed class UIGFItem : GachaLogItem, IMappingFrom<UIGFItem, GachaItem, INameQuality>
|
||||
internal sealed class UIGFItem : GachaLogItem, IMappingFrom<UIGFItem, GachaItem, INameQualityAccess>
|
||||
{
|
||||
/// <summary>
|
||||
/// 额外祈愿映射
|
||||
@@ -22,7 +22,7 @@ internal sealed class UIGFItem : GachaLogItem, IMappingFrom<UIGFItem, GachaItem,
|
||||
[JsonEnum(JsonSerializeType.NumberString)]
|
||||
public GachaType UIGFGachaType { get; set; } = default!;
|
||||
|
||||
public static UIGFItem From(GachaItem item, INameQuality nameQuality)
|
||||
public static UIGFItem From(GachaItem item, INameQualityAccess nameQuality)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Abstraction;
|
||||
|
||||
internal interface ICultivationItemsAccess
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
List<MaterialId> CultivationItems { get; }
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Abstraction;
|
||||
|
||||
internal interface IItemSource
|
||||
internal interface IItemConvertible
|
||||
{
|
||||
Model.Item ToItem();
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
|
||||
/// 物品与星级
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal interface INameQuality
|
||||
internal interface INameQualityAccess
|
||||
{
|
||||
/// <summary>
|
||||
/// 名称
|
||||
@@ -9,7 +9,7 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
|
||||
/// 指示该类为统计物品的源
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal interface IStatisticsItemSource
|
||||
internal interface IStatisticsItemConvertible
|
||||
{
|
||||
/// <summary>
|
||||
/// 转换到统计物品
|
||||
@@ -10,19 +10,9 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
|
||||
/// 指示该类为简述统计物品的源
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal interface ISummaryItemSource
|
||||
internal interface ISummaryItemConvertible
|
||||
{
|
||||
/// <summary>
|
||||
/// 星级
|
||||
/// </summary>
|
||||
QualityType Quality { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 转换到简述统计物品
|
||||
/// </summary>
|
||||
/// <param name="lastPull">距上个五星</param>
|
||||
/// <param name="time">时间</param>
|
||||
/// <param name="isUp">是否为Up物品</param>
|
||||
/// <returns>简述统计物品</returns>
|
||||
SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp);
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Calculable;
|
||||
using Snap.Hutao.Model.Metadata.Abstraction;
|
||||
using Snap.Hutao.Model.Metadata.Converter;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.ViewModel.Complex;
|
||||
using Snap.Hutao.ViewModel.GachaLog;
|
||||
using Snap.Hutao.ViewModel.Wiki;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Avatar;
|
||||
|
||||
/// <summary>
|
||||
/// 角色的接口实现部分
|
||||
/// </summary>
|
||||
internal partial class Avatar : IStatisticsItemSource, ISummaryItemSource, IItemSource, INameQuality, ICalculableSource<ICalculableAvatar>
|
||||
{
|
||||
/// <summary>
|
||||
/// [非元数据] 搭配数据
|
||||
/// TODO:Add View suffix.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public AvatarCollocationView? Collocation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// [非元数据] 烹饪奖励
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public CookBonusView? CookBonusView { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// [非元数据] 养成物品视图
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public List<Material>? CultivationItemsView { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大等级
|
||||
/// </summary>
|
||||
[SuppressMessage("", "CA1822")]
|
||||
public uint MaxLevel { get => GetMaxLevel(); }
|
||||
|
||||
public static uint GetMaxLevel()
|
||||
{
|
||||
return 90U;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ICalculableAvatar ToCalculable()
|
||||
{
|
||||
return CalculableAvatar.From(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为基础物品
|
||||
/// </summary>
|
||||
/// <returns>基础物品</returns>
|
||||
public Model.Item ToItem()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public StatisticsItem ToStatisticsItem(int count)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
|
||||
Count = count,
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
|
||||
Time = time,
|
||||
LastPull = lastPull,
|
||||
IsUp = isUp,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,99 +1,118 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Calculable;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Metadata.Abstraction;
|
||||
using Snap.Hutao.Model.Metadata.Converter;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.ViewModel.Complex;
|
||||
using Snap.Hutao.ViewModel.GachaLog;
|
||||
using Snap.Hutao.ViewModel.Wiki;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Avatar;
|
||||
|
||||
/// <summary>
|
||||
/// 角色
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal partial class Avatar
|
||||
internal partial class Avatar : INameQualityAccess,
|
||||
IStatisticsItemConvertible,
|
||||
ISummaryItemConvertible,
|
||||
IItemConvertible,
|
||||
ICalculableSource<ICalculableAvatar>,
|
||||
ICultivationItemsAccess
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
public AvatarId Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 突破提升 Id 外键
|
||||
/// </summary>
|
||||
public PromoteId PromoteId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序号
|
||||
/// </summary>
|
||||
public uint Sort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 体型
|
||||
/// </summary>
|
||||
public BodyType Body { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 正面图标
|
||||
/// </summary>
|
||||
public string Icon { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 侧面图标
|
||||
/// </summary>
|
||||
public string SideIcon { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 角色加入游戏时间
|
||||
/// </summary>
|
||||
public DateTimeOffset BeginTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 星级
|
||||
/// </summary>
|
||||
public QualityType Quality { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 武器类型
|
||||
/// </summary>
|
||||
public WeaponType Weapon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 基础数值
|
||||
/// </summary>
|
||||
public AvatarBaseValue BaseValue { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 生长曲线
|
||||
/// </summary>
|
||||
public List<TypeValue<FightProperty, GrowCurveType>> GrowCurves { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 技能
|
||||
/// </summary>
|
||||
public SkillDepot SkillDepot { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 好感信息/基本信息
|
||||
/// </summary>
|
||||
public FetterInfo FetterInfo { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 皮肤
|
||||
/// </summary>
|
||||
public List<Costume> Costumes { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 养成物品
|
||||
/// </summary>
|
||||
public List<MaterialId> CultivationItems { get; set; } = default!;
|
||||
|
||||
[JsonIgnore]
|
||||
public AvatarCollocationView? CollocationView { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public CookBonusView? CookBonusView { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<Material>? CultivationItemsView { get; set; }
|
||||
|
||||
[SuppressMessage("", "CA1822")]
|
||||
public uint MaxLevel { get => GetMaxLevel(); }
|
||||
|
||||
public static uint GetMaxLevel()
|
||||
{
|
||||
return 90U;
|
||||
}
|
||||
|
||||
public ICalculableAvatar ToCalculable()
|
||||
{
|
||||
return CalculableAvatar.From(this);
|
||||
}
|
||||
|
||||
public Model.Item ToItem()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
};
|
||||
}
|
||||
|
||||
public StatisticsItem ToStatisticsItem(int count)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
|
||||
Count = count,
|
||||
};
|
||||
}
|
||||
|
||||
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
|
||||
Time = time,
|
||||
LastPull = lastPull,
|
||||
IsUp = isUp,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Calculable;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Metadata.Abstraction;
|
||||
using Snap.Hutao.Model.Metadata.Converter;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.ViewModel.Complex;
|
||||
using Snap.Hutao.ViewModel.GachaLog;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Weapon;
|
||||
|
||||
/// <summary>
|
||||
/// 武器的接口实现
|
||||
/// </summary>
|
||||
internal sealed partial class Weapon : IStatisticsItemSource, ISummaryItemSource, IItemSource, INameQuality, ICalculableSource<ICalculableWeapon>
|
||||
{
|
||||
/// <summary>
|
||||
/// [非元数据] 搭配数据
|
||||
/// TODO:Add View suffix.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public WeaponCollocationView? Collocation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// [非元数据] 养成物品视图
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public List<Material>? CultivationItemsView { get; set; }
|
||||
|
||||
/// <inheritdoc cref="INameQuality.Quality" />
|
||||
[JsonIgnore]
|
||||
public QualityType Quality
|
||||
{
|
||||
get => RankLevel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 最大等级
|
||||
/// </summary>
|
||||
internal uint MaxLevel { get => GetMaxLevelByQuality(Quality); }
|
||||
|
||||
public static uint GetMaxLevelByQuality(QualityType quality)
|
||||
{
|
||||
return quality >= QualityType.QUALITY_BLUE ? 90U : 70U;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ICalculableWeapon ToCalculable()
|
||||
{
|
||||
return CalculableWeapon.From(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为基础物品
|
||||
/// </summary>
|
||||
/// <returns>基础物品</returns>
|
||||
public Model.Item ToItem()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Quality = RankLevel,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换到统计物品
|
||||
/// </summary>
|
||||
/// <param name="count">个数</param>
|
||||
/// <returns>统计物品</returns>
|
||||
public StatisticsItem ToStatisticsItem(int count)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Quality = RankLevel,
|
||||
Count = count,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换到简述统计物品
|
||||
/// </summary>
|
||||
/// <param name="lastPull">距上个五星</param>
|
||||
/// <param name="time">时间</param>
|
||||
/// <param name="isUp">是否为Up物品</param>
|
||||
/// <returns>简述统计物品</returns>
|
||||
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Time = time,
|
||||
Quality = RankLevel,
|
||||
LastPull = lastPull,
|
||||
IsUp = isUp,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,69 +1,105 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Calculable;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Metadata.Abstraction;
|
||||
using Snap.Hutao.Model.Metadata.Converter;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.ViewModel.Complex;
|
||||
using Snap.Hutao.ViewModel.GachaLog;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Weapon;
|
||||
|
||||
/// <summary>
|
||||
/// 武器
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal sealed partial class Weapon
|
||||
internal sealed partial class Weapon : INameQualityAccess,
|
||||
IStatisticsItemConvertible,
|
||||
ISummaryItemConvertible,
|
||||
IItemConvertible,
|
||||
ICalculableSource<ICalculableWeapon>,
|
||||
ICultivationItemsAccess
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
public WeaponId Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 突破 Id
|
||||
/// </summary>
|
||||
public PromoteId PromoteId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 武器类型
|
||||
/// </summary>
|
||||
public WeaponType WeaponType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 等级
|
||||
/// </summary>
|
||||
public QualityType RankLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 图标
|
||||
/// </summary>
|
||||
public string Icon { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 觉醒图标
|
||||
/// </summary>
|
||||
public string AwakenIcon { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 生长曲线
|
||||
/// </summary>
|
||||
public List<WeaponTypeValue> GrowCurves { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 被动信息, 无被动的武器为 <see langword="null"/>
|
||||
/// </summary>
|
||||
public NameDescriptions? Affix { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 养成物品
|
||||
/// </summary>
|
||||
public List<MaterialId> CultivationItems { get; set; } = default!;
|
||||
|
||||
[JsonIgnore]
|
||||
public WeaponCollocationView? CollocationView { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<Material>? CultivationItemsView { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public QualityType Quality
|
||||
{
|
||||
get => RankLevel;
|
||||
}
|
||||
|
||||
internal uint MaxLevel { get => GetMaxLevelByQuality(Quality); }
|
||||
|
||||
public static uint GetMaxLevelByQuality(QualityType quality)
|
||||
{
|
||||
return quality >= QualityType.QUALITY_BLUE ? 90U : 70U;
|
||||
}
|
||||
|
||||
public ICalculableWeapon ToCalculable()
|
||||
{
|
||||
return CalculableWeapon.From(this);
|
||||
}
|
||||
|
||||
public Model.Item ToItem()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Quality = RankLevel,
|
||||
};
|
||||
}
|
||||
|
||||
public StatisticsItem ToStatisticsItem(int count)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Quality = RankLevel,
|
||||
Count = count,
|
||||
};
|
||||
}
|
||||
|
||||
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Time = time,
|
||||
Quality = RankLevel,
|
||||
LastPull = lastPull,
|
||||
IsUp = isUp,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1568,6 +1568,9 @@
|
||||
<data name="ViewModelCultivationProjectInvalidName" xml:space="preserve">
|
||||
<value>不能添加名称无效的计划</value>
|
||||
</data>
|
||||
<data name="ViewModelCultivationRefreshInventoryProgress" xml:space="preserve">
|
||||
<value>正在同步背包物品</value>
|
||||
</data>
|
||||
<data name="ViewModelCultivationRemoveProjectContent" xml:space="preserve">
|
||||
<value>此操作不可逆,此计划的养成物品与背包材料将会丢失</value>
|
||||
</data>
|
||||
@@ -1925,6 +1928,9 @@
|
||||
<data name="ViewPageCultivationNavigateAction" xml:space="preserve">
|
||||
<value>前往</value>
|
||||
</data>
|
||||
<data name="ViewPageCultivationRefreshInventory" xml:space="preserve">
|
||||
<value>同步背包物品</value>
|
||||
</data>
|
||||
<data name="ViewPageCultivationRemoveEntry" xml:space="preserve">
|
||||
<value>删除清单</value>
|
||||
</data>
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Snap.Hutao.Service;
|
||||
[Injection(InjectAs.Scoped, typeof(IAnnouncementService))]
|
||||
internal sealed partial class AnnouncementService : IAnnouncementService
|
||||
{
|
||||
private static readonly string CacheKey = $"{nameof(AnnouncementService)}.Cache.{nameof(AnnouncementWrapper)}";
|
||||
private const string CacheKey = $"{nameof(AnnouncementService)}.Cache.{nameof(AnnouncementWrapper)}";
|
||||
|
||||
private readonly IServiceScopeFactory serviceScopeFactory;
|
||||
private readonly ITaskContext taskContext;
|
||||
|
||||
@@ -16,16 +16,6 @@ internal sealed partial class CultivationDbService : ICultivationDbService
|
||||
|
||||
public IServiceProvider ServiceProvider { get => serviceProvider; }
|
||||
|
||||
public List<InventoryItem> GetInventoryItemListByProjectId(Guid projectId)
|
||||
{
|
||||
return this.List<InventoryItem>(i => i.ProjectId == projectId);
|
||||
}
|
||||
|
||||
public ValueTask<List<InventoryItem>> GetInventoryItemListByProjectIdAsync(Guid projectId, CancellationToken token = default)
|
||||
{
|
||||
return this.ListAsync<InventoryItem>(i => i.ProjectId == projectId, token);
|
||||
}
|
||||
|
||||
public ValueTask<List<CultivateEntry>> GetCultivateEntryListByProjectIdAsync(Guid projectId, CancellationToken token = default)
|
||||
{
|
||||
return this.ListAsync<CultivateEntry>(e => e.ProjectId == projectId, token);
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core.Database;
|
||||
using Snap.Hutao.Model;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Model.Entity.Primitive;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.Service.Inventory;
|
||||
using Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
using Snap.Hutao.ViewModel.Cultivation;
|
||||
using System.Collections.ObjectModel;
|
||||
using CalculateItem = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Item;
|
||||
using ModelItem = Snap.Hutao.Model.Item;
|
||||
|
||||
namespace Snap.Hutao.Service.Cultivation;
|
||||
|
||||
@@ -51,22 +50,6 @@ internal sealed partial class CultivationService : ICultivationService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public List<InventoryItemView> GetInventoryItemViews(CultivateProject cultivateProject, ICultivationMetadataContext context, ICommand saveCommand)
|
||||
{
|
||||
Guid projectId = cultivateProject.InnerId;
|
||||
List<InventoryItem> entities = cultivationDbService.GetInventoryItemListByProjectId(projectId);
|
||||
|
||||
List<InventoryItemView> results = [];
|
||||
foreach (Material meta in context.EnumerateInventoryMaterial())
|
||||
{
|
||||
InventoryItem entity = entities.SingleOrDefault(e => e.ItemId == meta.Id) ?? InventoryItem.From(projectId, meta.Id);
|
||||
results.Add(new(entity, meta, saveCommand));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async ValueTask<ObservableCollection<CultivateEntryView>> GetCultivateEntriesAsync(CultivateProject cultivateProject, ICultivationMetadataContext context)
|
||||
{
|
||||
@@ -86,7 +69,7 @@ internal sealed partial class CultivationService : ICultivationService
|
||||
entryItems.Add(new(cultivateItem, context.GetMaterial(cultivateItem.ItemId)));
|
||||
}
|
||||
|
||||
Item item = entry.Type switch
|
||||
ModelItem item = entry.Type switch
|
||||
{
|
||||
CultivateType.AvatarAndSkill => context.GetAvatar(entry.Id).ToItem(),
|
||||
CultivateType.Weapon => context.GetWeapon(entry.Id).ToItem(),
|
||||
@@ -130,7 +113,7 @@ internal sealed partial class CultivationService : ICultivationService
|
||||
}
|
||||
}
|
||||
|
||||
foreach (InventoryItem inventoryItem in await cultivationDbService.GetInventoryItemListByProjectIdAsync(projectId, token).ConfigureAwait(false))
|
||||
foreach (InventoryItem inventoryItem in await inventoryDbService.GetInventoryItemListByProjectIdAsync(projectId, token).ConfigureAwait(false))
|
||||
{
|
||||
if (resultItems.SingleOrDefault(i => i.Inner.Id == inventoryItem.ItemId) is { } existedItem)
|
||||
{
|
||||
@@ -147,12 +130,6 @@ internal sealed partial class CultivationService : ICultivationService
|
||||
await cultivationDbService.RemoveCultivateEntryByIdAsync(entryId).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void SaveInventoryItem(InventoryItemView item)
|
||||
{
|
||||
inventoryDbService.UpdateInventoryItem(item.Entity);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void SaveCultivateItem(CultivateItemView item)
|
||||
{
|
||||
|
||||
@@ -7,8 +7,7 @@ using System.Collections.ObjectModel;
|
||||
|
||||
namespace Snap.Hutao.Service.Cultivation;
|
||||
|
||||
internal interface ICultivationDbService : IAppDbService<InventoryItem>,
|
||||
IAppDbService<CultivateEntryLevelInformation>,
|
||||
internal interface ICultivationDbService : IAppDbService<CultivateEntryLevelInformation>,
|
||||
IAppDbService<CultivateProject>,
|
||||
IAppDbService<CultivateEntry>,
|
||||
IAppDbService<CultivateItem>
|
||||
@@ -29,10 +28,6 @@ internal interface ICultivationDbService : IAppDbService<InventoryItem>,
|
||||
|
||||
ObservableCollection<CultivateProject> GetCultivateProjectCollection();
|
||||
|
||||
List<InventoryItem> GetInventoryItemListByProjectId(Guid projectId);
|
||||
|
||||
ValueTask<List<InventoryItem>> GetInventoryItemListByProjectIdAsync(Guid projectId, CancellationToken token = default);
|
||||
|
||||
ValueTask AddCultivateEntryAsync(CultivateEntry entry, CancellationToken token = default);
|
||||
|
||||
ValueTask AddCultivateItemRangeAsync(IEnumerable<CultivateItem> toAdd, CancellationToken token = default);
|
||||
|
||||
@@ -27,8 +27,6 @@ internal interface ICultivationService
|
||||
|
||||
ValueTask<ObservableCollection<CultivateEntryView>> GetCultivateEntriesAsync(CultivateProject cultivateProject, ICultivationMetadataContext context);
|
||||
|
||||
List<InventoryItemView> GetInventoryItemViews(CultivateProject cultivateProject, ICultivationMetadataContext context, ICommand saveCommand);
|
||||
|
||||
ValueTask<ObservableCollection<StatisticsCultivateItem>> GetStatisticsCultivateItemCollectionAsync(
|
||||
CultivateProject cultivateProject, ICultivationMetadataContext context, CancellationToken token);
|
||||
|
||||
@@ -54,12 +52,6 @@ internal interface ICultivationService
|
||||
/// <param name="item">养成物品</param>
|
||||
void SaveCultivateItem(CultivateItemView item);
|
||||
|
||||
/// <summary>
|
||||
/// 保存单个物品
|
||||
/// </summary>
|
||||
/// <param name="item">物品</param>
|
||||
void SaveInventoryItem(InventoryItemView item);
|
||||
|
||||
/// <summary>
|
||||
/// 异步尝试添加新的项目
|
||||
/// </summary>
|
||||
|
||||
@@ -49,7 +49,7 @@ internal static class GachaStatisticsExtension
|
||||
/// <param name="dict">计数器</param>
|
||||
/// <returns>统计物品列表</returns>
|
||||
public static List<StatisticsItem> ToStatisticsList<TItem>(this Dictionary<TItem, int> dict)
|
||||
where TItem : IStatisticsItemSource
|
||||
where TItem : IStatisticsItemConvertible
|
||||
{
|
||||
IOrderedEnumerable<StatisticsItem> result = dict
|
||||
.Select(kvp => kvp.Key.ToStatisticsItem(kvp.Value))
|
||||
|
||||
@@ -27,7 +27,7 @@ internal sealed partial class GachaStatisticsSlimFactory : IGachaStatisticsSlimF
|
||||
return CreateCore(context, items, uid);
|
||||
}
|
||||
|
||||
private static void Track(INameQuality nameQuality, ref int orangeTracker, ref int purpleTracker)
|
||||
private static void Track(INameQualityAccess nameQuality, ref int orangeTracker, ref int purpleTracker)
|
||||
{
|
||||
switch (nameQuality.Quality)
|
||||
{
|
||||
@@ -69,7 +69,7 @@ internal sealed partial class GachaStatisticsSlimFactory : IGachaStatisticsSlimF
|
||||
// O(n) operation
|
||||
foreach (ref readonly GachaItem item in CollectionsMarshal.AsSpan(items))
|
||||
{
|
||||
INameQuality nameQuality = context.GetNameQualityByItemId(item.ItemId);
|
||||
INameQualityAccess nameQuality = context.GetNameQualityByItemId(item.ItemId);
|
||||
switch (item.QueryType)
|
||||
{
|
||||
case GachaType.Standard:
|
||||
|
||||
@@ -16,11 +16,11 @@ internal sealed class HistoryWishBuilder
|
||||
{
|
||||
private readonly GachaEvent gachaEvent;
|
||||
|
||||
private readonly Dictionary<IStatisticsItemSource, int> orangeUpCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemSource, int> purpleUpCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemSource, int> orangeCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemSource, int> purpleCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemSource, int> blueCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemConvertible, int> orangeUpCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemConvertible, int> purpleUpCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemConvertible, int> orangeCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemConvertible, int> purpleCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemConvertible, int> blueCounter = [];
|
||||
|
||||
private int totalCountTracker;
|
||||
|
||||
@@ -37,18 +37,18 @@ internal sealed class HistoryWishBuilder
|
||||
switch (ConfigType)
|
||||
{
|
||||
case GachaType.ActivityAvatar or GachaType.SpecialActivityAvatar:
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemSource)a, a => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemSource)a, a => 0);
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemConvertible)a, a => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemConvertible)a, a => 0);
|
||||
break;
|
||||
case GachaType.ActivityWeapon:
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemSource)w, w => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemSource)w, w => 0);
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemConvertible)w, w => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemConvertible)w, w => 0);
|
||||
break;
|
||||
case GachaType.ActivityCity:
|
||||
|
||||
// Avatars are less than weapons, so we try to get the value from avatar map first
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => (IStatisticsItemSource?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => (IStatisticsItemSource?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => (IStatisticsItemConvertible?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => (IStatisticsItemConvertible?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ internal sealed class HistoryWishBuilder
|
||||
/// </summary>
|
||||
/// <param name="item">物品</param>
|
||||
/// <returns>是否为Up物品</returns>
|
||||
public bool IncreaseOrange(IStatisticsItemSource item)
|
||||
public bool IncreaseOrange(IStatisticsItemConvertible item)
|
||||
{
|
||||
orangeCounter.IncreaseOne(item);
|
||||
++totalCountTracker;
|
||||
@@ -86,7 +86,7 @@ internal sealed class HistoryWishBuilder
|
||||
/// 计数四星物品
|
||||
/// </summary>
|
||||
/// <param name="item">物品</param>
|
||||
public void IncreasePurple(IStatisticsItemSource item)
|
||||
public void IncreasePurple(IStatisticsItemConvertible item)
|
||||
{
|
||||
purpleUpCounter.TryIncreaseOne(item);
|
||||
purpleCounter.IncreaseOne(item);
|
||||
@@ -97,7 +97,7 @@ internal sealed class HistoryWishBuilder
|
||||
/// 计数三星武器
|
||||
/// </summary>
|
||||
/// <param name="item">武器</param>
|
||||
public void IncreaseBlue(IStatisticsItemSource item)
|
||||
public void IncreaseBlue(IStatisticsItemConvertible item)
|
||||
{
|
||||
blueCounter.IncreaseOne(item);
|
||||
++totalCountTracker;
|
||||
|
||||
@@ -55,7 +55,7 @@ internal sealed class HutaoStatisticsFactory
|
||||
|
||||
foreach (ref readonly ItemCount item in CollectionsMarshal.AsSpan(items))
|
||||
{
|
||||
IStatisticsItemSource source = item.Item.StringLength() switch
|
||||
IStatisticsItemConvertible source = item.Item.StringLength() switch
|
||||
{
|
||||
8U => context.GetAvatar(item.Item),
|
||||
5U => context.GetWeapon(item.Item),
|
||||
|
||||
@@ -44,7 +44,7 @@ internal sealed class TypedWishSummaryBuilder
|
||||
/// <param name="item">祈愿物品</param>
|
||||
/// <param name="source">对应武器</param>
|
||||
/// <param name="isUp">是否为Up物品</param>
|
||||
public void Track(GachaItem item, ISummaryItemSource source, bool isUp)
|
||||
public void Track(GachaItem item, ISummaryItemConvertible source, bool isUp)
|
||||
{
|
||||
if (!context.TypeEvaluator(item.GachaType))
|
||||
{
|
||||
|
||||
@@ -59,7 +59,7 @@ internal sealed class GachaLogServiceMetadataContext : IMetadataContext,
|
||||
return result;
|
||||
}
|
||||
|
||||
public INameQuality GetNameQualityByItemId(uint id)
|
||||
public INameQualityAccess GetNameQualityByItemId(uint id)
|
||||
{
|
||||
uint place = id.StringLength();
|
||||
return place switch
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.Memory;
|
||||
using System.Diagnostics;
|
||||
using static Snap.Hutao.Win32.Kernel32;
|
||||
|
||||
|
||||
@@ -2,16 +2,21 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
|
||||
namespace Snap.Hutao.Service.Inventory;
|
||||
|
||||
internal interface IInventoryDbService
|
||||
internal interface IInventoryDbService : IAppDbService<InventoryItem>
|
||||
{
|
||||
ValueTask AddInventoryItemRangeByProjectId(List<InventoryItem> items);
|
||||
ValueTask AddInventoryItemRangeByProjectIdAsync(List<InventoryItem> items, CancellationToken token = default);
|
||||
|
||||
ValueTask RemoveInventoryItemRangeByProjectId(Guid projectId);
|
||||
ValueTask RemoveInventoryItemRangeByProjectIdAsync(Guid projectId, CancellationToken token = default);
|
||||
|
||||
void UpdateInventoryItem(InventoryItem item);
|
||||
|
||||
ValueTask UpdateInventoryItemAsync(InventoryItem item);
|
||||
ValueTask UpdateInventoryItemAsync(InventoryItem item, CancellationToken token = default);
|
||||
|
||||
List<InventoryItem> GetInventoryItemListByProjectId(Guid projectId);
|
||||
|
||||
ValueTask<List<InventoryItem>> GetInventoryItemListByProjectIdAsync(Guid projectId, CancellationToken token = default);
|
||||
}
|
||||
@@ -1,8 +1,17 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Service.Cultivation;
|
||||
using Snap.Hutao.ViewModel.Cultivation;
|
||||
|
||||
namespace Snap.Hutao.Service.Inventory;
|
||||
|
||||
internal interface IInventoryService
|
||||
{
|
||||
List<InventoryItemView> GetInventoryItemViews(CultivateProject cultivateProject, ICultivationMetadataContext context, ICommand saveCommand);
|
||||
|
||||
void SaveInventoryItem(InventoryItemView item);
|
||||
|
||||
ValueTask RefreshInventoryAsync(CultivateProject project);
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Snap.Hutao.Core.Database;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Model.Entity.Database;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
|
||||
namespace Snap.Hutao.Service.Inventory;
|
||||
|
||||
@@ -14,43 +12,35 @@ internal sealed partial class InventoryDbService : IInventoryDbService
|
||||
{
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
|
||||
public async ValueTask RemoveInventoryItemRangeByProjectId(Guid projectId)
|
||||
public IServiceProvider ServiceProvider { get => serviceProvider; }
|
||||
|
||||
public async ValueTask RemoveInventoryItemRangeByProjectIdAsync(Guid projectId, CancellationToken token = default)
|
||||
{
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
{
|
||||
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
await appDbContext.InventoryItems
|
||||
.AsNoTracking()
|
||||
.Where(a => a.ProjectId == projectId && a.ItemId != 202U) // 摩拉
|
||||
.ExecuteDeleteAsync()
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
await this.DeleteAsync(i => i.ProjectId == projectId, token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async ValueTask AddInventoryItemRangeByProjectId(List<InventoryItem> items)
|
||||
public async ValueTask AddInventoryItemRangeByProjectIdAsync(List<InventoryItem> items, CancellationToken token = default)
|
||||
{
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
{
|
||||
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
await appDbContext.InventoryItems.AddRangeAndSaveAsync(items).ConfigureAwait(false);
|
||||
}
|
||||
await this.AddRangeAsync(items, token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public void UpdateInventoryItem(InventoryItem item)
|
||||
{
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
{
|
||||
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
appDbContext.InventoryItems.UpdateAndSave(item);
|
||||
}
|
||||
this.Update(item);
|
||||
}
|
||||
|
||||
public async ValueTask UpdateInventoryItemAsync(InventoryItem item)
|
||||
public async ValueTask UpdateInventoryItemAsync(InventoryItem item, CancellationToken token = default)
|
||||
{
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
{
|
||||
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
await appDbContext.InventoryItems.UpdateAndSaveAsync(item).ConfigureAwait(false);
|
||||
}
|
||||
await this.UpdateAsync(item, token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public List<InventoryItem> GetInventoryItemListByProjectId(Guid projectId)
|
||||
{
|
||||
return this.List(i => i.ProjectId == projectId);
|
||||
}
|
||||
|
||||
public ValueTask<List<InventoryItem>> GetInventoryItemListByProjectIdAsync(Guid projectId, CancellationToken token = default)
|
||||
{
|
||||
return this.ListAsync(i => i.ProjectId == projectId, token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,83 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.Service.Cultivation;
|
||||
using Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
using Snap.Hutao.Service.Notification;
|
||||
using Snap.Hutao.Service.User;
|
||||
using Snap.Hutao.ViewModel.Cultivation;
|
||||
using Snap.Hutao.ViewModel.User;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
|
||||
using Snap.Hutao.Web.Response;
|
||||
|
||||
namespace Snap.Hutao.Service.Inventory;
|
||||
|
||||
[Injection(InjectAs.Transient)]
|
||||
internal sealed class InventoryService : IInventoryService
|
||||
[ConstructorGenerated]
|
||||
[Injection(InjectAs.Singleton, typeof(IInventoryService))]
|
||||
internal sealed partial class InventoryService : IInventoryService
|
||||
{
|
||||
private readonly MinimalPromotionDelta minimalPromotionDelta;
|
||||
private readonly IServiceScopeFactory serviceScopeFactory;
|
||||
private readonly IInventoryDbService inventoryDbService;
|
||||
private readonly IInfoBarService infoBarService;
|
||||
private readonly IUserService userService;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public List<InventoryItemView> GetInventoryItemViews(CultivateProject cultivateProject, ICultivationMetadataContext context, ICommand saveCommand)
|
||||
{
|
||||
Guid projectId = cultivateProject.InnerId;
|
||||
List<InventoryItem> entities = inventoryDbService.GetInventoryItemListByProjectId(projectId);
|
||||
|
||||
List<InventoryItemView> results = [];
|
||||
foreach (Material meta in context.EnumerateInventoryMaterial())
|
||||
{
|
||||
InventoryItem entity = entities.SingleOrDefault(e => e.ItemId == meta.Id) ?? InventoryItem.From(projectId, meta.Id);
|
||||
results.Add(new(entity, meta, saveCommand));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void SaveInventoryItem(InventoryItemView item)
|
||||
{
|
||||
inventoryDbService.UpdateInventoryItem(item.Entity);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async ValueTask RefreshInventoryAsync(CultivateProject project)
|
||||
{
|
||||
List<AvatarPromotionDelta> deltas = await minimalPromotionDelta.GetAsync().ConfigureAwait(false);
|
||||
|
||||
BatchConsumption? batchConsumption = default;
|
||||
using (IServiceScope scope = serviceScopeFactory.CreateScope())
|
||||
{
|
||||
if (!UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid))
|
||||
{
|
||||
infoBarService.Warning(SH.MustSelectUserAndUid);
|
||||
return;
|
||||
}
|
||||
|
||||
CalculateClient calculateClient = scope.ServiceProvider.GetRequiredService<CalculateClient>();
|
||||
|
||||
Response<BatchConsumption>? resp = await calculateClient
|
||||
.BatchComputeAsync(userAndUid, deltas, true)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!resp.IsOk())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
batchConsumption = resp.Data;
|
||||
}
|
||||
|
||||
if (batchConsumption is { OverallConsume: { } items })
|
||||
{
|
||||
await inventoryDbService.RemoveInventoryItemRangeByProjectIdAsync(project.InnerId).ConfigureAwait(false);
|
||||
await inventoryDbService.AddInventoryItemRangeByProjectIdAsync(items.SelectList(item => InventoryItem.From(project.InnerId, item.Id, (uint)((int)item.Num - item.LackNum)))).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Google.OrTools.LinearSolver;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Model.Metadata.Abstraction;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.Service.Metadata;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
|
||||
using System.Runtime.InteropServices;
|
||||
using MetadataAvatar = Snap.Hutao.Model.Metadata.Avatar.Avatar;
|
||||
using MetadataWeapon = Snap.Hutao.Model.Metadata.Weapon.Weapon;
|
||||
|
||||
namespace Snap.Hutao.Service.Inventory;
|
||||
|
||||
[ConstructorGenerated]
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class MinimalPromotionDelta
|
||||
{
|
||||
private const string CacheKey = $"{nameof(MinimalPromotionDelta)}.Cache";
|
||||
|
||||
private readonly IMetadataService metadataService;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
|
||||
public async ValueTask<List<AvatarPromotionDelta>> GetAsync()
|
||||
{
|
||||
if (memoryCache.TryGetRequiredValue(CacheKey, out List<AvatarPromotionDelta>? cache))
|
||||
{
|
||||
return cache;
|
||||
}
|
||||
|
||||
List<ICultivationItemsAccess> cultivationItemsEntryList =
|
||||
[
|
||||
.. (await metadataService.GetAvatarListAsync().ConfigureAwait(false)).Where(a => a.BeginTime <= DateTimeOffset.Now),
|
||||
.. (await metadataService.GetWeaponListAsync().ConfigureAwait(false)).Where(w => w.Quality >= Model.Intrinsic.QualityType.QUALITY_BLUE),
|
||||
];
|
||||
|
||||
List<ICultivationItemsAccess> minimal = Minimize(cultivationItemsEntryList);
|
||||
|
||||
// Gurantee the order of avatar and weapon
|
||||
// Make sure weapons can have avatar to attach
|
||||
minimal.Sort(CultivationItemsAccessComparer.Shared);
|
||||
return memoryCache.Set(CacheKey, ToPromotionDeltaList(minimal));
|
||||
}
|
||||
|
||||
private static List<ICultivationItemsAccess> Minimize(List<ICultivationItemsAccess> cultivationItems)
|
||||
{
|
||||
using (Solver? solver = Solver.CreateSolver("SCIP"))
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(solver);
|
||||
|
||||
Objective objective = solver.Objective();
|
||||
objective.SetMinimization();
|
||||
|
||||
Dictionary<ICultivationItemsAccess, Variable> itemVariableMap = [];
|
||||
foreach (ref readonly ICultivationItemsAccess item in CollectionsMarshal.AsSpan(cultivationItems))
|
||||
{
|
||||
Variable variable = solver.MakeBoolVar(item.Name);
|
||||
itemVariableMap[item] = variable;
|
||||
objective.SetCoefficient(variable, 1);
|
||||
}
|
||||
|
||||
Dictionary<MaterialId, Constraint> materialConstraintMap = [];
|
||||
foreach (ref readonly ICultivationItemsAccess item in CollectionsMarshal.AsSpan(cultivationItems))
|
||||
{
|
||||
foreach (ref readonly MaterialId materialId in CollectionsMarshal.AsSpan(item.CultivationItems))
|
||||
{
|
||||
ref Constraint? constraint = ref CollectionsMarshal.GetValueRefOrAddDefault(materialConstraintMap, materialId, out _);
|
||||
constraint ??= solver.MakeConstraint(1, double.PositiveInfinity, $"{materialId}");
|
||||
constraint.SetCoefficient(itemVariableMap[item], 1);
|
||||
}
|
||||
}
|
||||
|
||||
Solver.ResultStatus status = solver.Solve();
|
||||
HutaoException.ThrowIf(status != Solver.ResultStatus.OPTIMAL, "Unable to solve minimal item set");
|
||||
|
||||
List<ICultivationItemsAccess> results = [];
|
||||
foreach ((ICultivationItemsAccess item, Variable variable) in itemVariableMap)
|
||||
{
|
||||
if (variable.SolutionValue() > 0.5)
|
||||
{
|
||||
results.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<AvatarPromotionDelta> ToPromotionDeltaList(List<ICultivationItemsAccess> cultivationItems)
|
||||
{
|
||||
List<AvatarPromotionDelta> deltas = [];
|
||||
int currentWeaponEmptyAvatarIndex = 0;
|
||||
|
||||
foreach (ref readonly ICultivationItemsAccess item in CollectionsMarshal.AsSpan(cultivationItems))
|
||||
{
|
||||
switch (item)
|
||||
{
|
||||
case MetadataAvatar avatar:
|
||||
deltas.Add(new()
|
||||
{
|
||||
AvatarId = avatar.Id,
|
||||
AvatarLevelCurrent = 1,
|
||||
AvatarLevelTarget = 90,
|
||||
SkillList = avatar.SkillDepot.CompositeSkillsNoInherents().SelectList(skill => new PromotionDelta()
|
||||
{
|
||||
Id = skill.GroupId,
|
||||
LevelCurrent = 1,
|
||||
LevelTarget = 10,
|
||||
}),
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case MetadataWeapon weapon:
|
||||
AvatarPromotionDelta delta;
|
||||
if (currentWeaponEmptyAvatarIndex < deltas.Count)
|
||||
{
|
||||
delta = deltas[currentWeaponEmptyAvatarIndex++];
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = new();
|
||||
deltas.Add(delta);
|
||||
}
|
||||
|
||||
delta.Weapon = new()
|
||||
{
|
||||
Id = weapon.Id,
|
||||
LevelCurrent = 1,
|
||||
LevelTarget = 90,
|
||||
};
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return deltas;
|
||||
}
|
||||
|
||||
private sealed class CultivationItemsAccessComparer : IComparer<ICultivationItemsAccess>
|
||||
{
|
||||
private static readonly LazySlim<CultivationItemsAccessComparer> LazyShared = new(() => new());
|
||||
|
||||
public static CultivationItemsAccessComparer Shared { get => LazyShared.Value; }
|
||||
|
||||
public int Compare(ICultivationItemsAccess? x, ICultivationItemsAccess? y)
|
||||
{
|
||||
return (x, y) switch
|
||||
{
|
||||
(MetadataAvatar, MetadataWeapon) => -1,
|
||||
(MetadataWeapon, MetadataAvatar) => 1,
|
||||
_ => 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -313,6 +313,7 @@
|
||||
<PackageReference Include="CommunityToolkit.WinUI.Controls.TokenizingTextBox" Version="8.0.240109" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI.Media" Version="8.0.240109" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI.Notifications" Version="7.1.2" />
|
||||
<PackageReference Include="Google.OrTools" Version="9.10.4067" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
xmlns:mxi="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:shc="using:Snap.Hutao.Control"
|
||||
xmlns:shcb="using:Snap.Hutao.Control.Behavior"
|
||||
xmlns:shcca="using:Snap.Hutao.Control.Collection.Alternating"
|
||||
xmlns:shci="using:Snap.Hutao.Control.Image"
|
||||
xmlns:shcm="using:Snap.Hutao.Control.Markup"
|
||||
xmlns:shcp="using:Snap.Hutao.Control.Panel"
|
||||
|
||||
@@ -269,6 +269,10 @@
|
||||
Style="{ThemeResource CommandBarComboBoxStyle}"/>
|
||||
</shc:SizeRestrictedContentControl>
|
||||
</AppBarElementContainer>
|
||||
<AppBarButton
|
||||
Command="{Binding RefreshInventoryCommand}"
|
||||
Icon="{shcm:FontIcon Glyph=}"
|
||||
Label="{shcm:ResourceString Name=ViewPageCultivationRefreshInventory}"/>
|
||||
<AppBarButton
|
||||
Command="{Binding AddProjectCommand}"
|
||||
Icon="{shcm:FontIcon Glyph=}"
|
||||
|
||||
@@ -571,7 +571,7 @@
|
||||
Grid.Column="0"
|
||||
ItemTemplate="{StaticResource CollocationTemplate}"
|
||||
ItemsPanel="{StaticResource StackPanelSpacing4Template}"
|
||||
ItemsSource="{Binding Selected.Collocation.Avatars}"/>
|
||||
ItemsSource="{Binding Selected.CollocationView.Avatars}"/>
|
||||
<TextBlock
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
@@ -582,7 +582,7 @@
|
||||
Grid.Column="1"
|
||||
ItemTemplate="{StaticResource CollocationTemplate}"
|
||||
ItemsPanel="{StaticResource StackPanelSpacing4Template}"
|
||||
ItemsSource="{Binding Selected.Collocation.Weapons}"/>
|
||||
ItemsSource="{Binding Selected.CollocationView.Weapons}"/>
|
||||
<TextBlock
|
||||
Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
@@ -593,7 +593,7 @@
|
||||
Grid.Column="2"
|
||||
ItemTemplate="{StaticResource CollocationReliquaryTemplate}"
|
||||
ItemsPanel="{StaticResource StackPanelSpacing4Template}"
|
||||
ItemsSource="{Binding Selected.Collocation.ReliquarySets}"/>
|
||||
ItemsSource="{Binding Selected.CollocationView.ReliquarySets}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
|
||||
@@ -336,7 +336,7 @@
|
||||
<Border Padding="16" Style="{ThemeResource BorderCardStyle}">
|
||||
<StackPanel Spacing="16">
|
||||
<TextBlock Style="{StaticResource BaseTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageWiKiAvatarTeamCombinationHeader}"/>
|
||||
<ItemsControl ItemTemplate="{StaticResource CollocationTemplate}" ItemsSource="{Binding Selected.Collocation.Avatars}">
|
||||
<ItemsControl ItemTemplate="{StaticResource CollocationTemplate}" ItemsSource="{Binding Selected.CollocationView.Avatars}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<cwc:UniformGrid
|
||||
|
||||
@@ -25,6 +25,7 @@ using Windows.Graphics.Imaging;
|
||||
using Windows.Storage.Streams;
|
||||
using Windows.UI;
|
||||
using CalculatorAvatarPromotionDelta = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.AvatarPromotionDelta;
|
||||
using CalculatorBatchConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.BatchConsumption;
|
||||
using CalculatorClient = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.CalculateClient;
|
||||
using CalculatorConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Consumption;
|
||||
using CalculatorItem = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Item;
|
||||
@@ -175,7 +176,7 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
|
||||
return;
|
||||
}
|
||||
|
||||
if (userService.Current is null)
|
||||
if (!UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid))
|
||||
{
|
||||
infoBarService.Warning(SH.MustSelectUserAndUid);
|
||||
return;
|
||||
@@ -196,17 +197,20 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
|
||||
return;
|
||||
}
|
||||
|
||||
CultivateCoreResult result = await CultivateCoreAsync(userService.Current.Entity, delta, avatar).ConfigureAwait(false);
|
||||
Response<CalculatorBatchConsumption> response = await calculatorClient.BatchComputeAsync(userAndUid, delta).ConfigureAwait(false);
|
||||
|
||||
switch (result)
|
||||
if (!response.IsOk())
|
||||
{
|
||||
case CultivateCoreResult.Ok:
|
||||
infoBarService.Success(SH.ViewModelCultivationEntryAddSuccess);
|
||||
break;
|
||||
case CultivateCoreResult.SaveConsumptionFailed:
|
||||
infoBarService.Warning(SH.ViewModelCultivationEntryAddWarning);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await SaveCultivationAsync(response.Data.Items.Single(), delta).ConfigureAwait(false))
|
||||
{
|
||||
infoBarService.Warning(SH.ViewModelCultivationEntryAddWarning);
|
||||
return;
|
||||
}
|
||||
|
||||
infoBarService.Success(SH.ViewModelCultivationEntryAddSuccess);
|
||||
}
|
||||
|
||||
[Command("BatchCultivateCommand")]
|
||||
@@ -217,7 +221,7 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
|
||||
return;
|
||||
}
|
||||
|
||||
if (userService.Current is null)
|
||||
if (!UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid))
|
||||
{
|
||||
infoBarService.Warning(SH.MustSelectUserAndUid);
|
||||
return;
|
||||
@@ -237,9 +241,11 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
|
||||
ContentDialog progressDialog = await contentDialogFactory
|
||||
.CreateForIndeterminateProgressAsync(SH.ViewModelAvatarPropertyBatchCultivateProgressTitle)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
BatchCultivateResult result = default;
|
||||
using (await progressDialog.BlockAsync(taskContext).ConfigureAwait(false))
|
||||
{
|
||||
BatchCultivateResult result = default;
|
||||
List<CalculatorAvatarPromotionDelta> deltas = [];
|
||||
foreach (AvatarView avatar in avatars)
|
||||
{
|
||||
if (!baseline.TryGetNonErrorCopy(avatar, out CalculatorAvatarPromotionDelta? copy))
|
||||
@@ -248,75 +254,64 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
|
||||
continue;
|
||||
}
|
||||
|
||||
CultivateCoreResult coreResult = await CultivateCoreAsync(userService.Current.Entity, copy, avatar).ConfigureAwait(false);
|
||||
deltas.Add(copy);
|
||||
}
|
||||
|
||||
switch (coreResult)
|
||||
{
|
||||
case CultivateCoreResult.Ok:
|
||||
++result.SucceedCount;
|
||||
break;
|
||||
case CultivateCoreResult.ComputeConsumptionFailed:
|
||||
result.Interrupted = true;
|
||||
break;
|
||||
case CultivateCoreResult.SaveConsumptionFailed:
|
||||
result.Interrupted = true;
|
||||
break;
|
||||
}
|
||||
Response<CalculatorBatchConsumption> response = await calculatorClient.BatchComputeAsync(userAndUid, deltas).ConfigureAwait(false);
|
||||
|
||||
if (result.Interrupted)
|
||||
if (!response.IsOk())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ((CalculatorConsumption consumption, CalculatorAvatarPromotionDelta delta) in response.Data.Items.Zip(deltas))
|
||||
{
|
||||
if (!await SaveCultivationAsync(consumption, delta).ConfigureAwait(false))
|
||||
{
|
||||
result.Interrupted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.Interrupted)
|
||||
{
|
||||
infoBarService.Warning(SH.FormatViewModelCultivationBatchAddIncompletedFormat(result.SucceedCount, result.SkippedCount));
|
||||
}
|
||||
else
|
||||
{
|
||||
infoBarService.Success(SH.FormatViewModelCultivationBatchAddCompletedFormat(result.SucceedCount, result.SkippedCount));
|
||||
++result.SucceedCount;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.Interrupted)
|
||||
{
|
||||
infoBarService.Warning(SH.FormatViewModelCultivationBatchAddIncompletedFormat(result.SucceedCount, result.SkippedCount));
|
||||
}
|
||||
else
|
||||
{
|
||||
infoBarService.Success(SH.FormatViewModelCultivationBatchAddCompletedFormat(result.SucceedCount, result.SkippedCount));
|
||||
}
|
||||
}
|
||||
|
||||
private async ValueTask<CultivateCoreResult> CultivateCoreAsync(Model.Entity.User user, CalculatorAvatarPromotionDelta delta, AvatarView avatar)
|
||||
private async ValueTask<bool> SaveCultivationAsync(CalculatorConsumption consumption, CalculatorAvatarPromotionDelta delta)
|
||||
{
|
||||
Response<CalculatorConsumption> consumptionResponse = await calculatorClient.ComputeAsync(user, delta).ConfigureAwait(false);
|
||||
|
||||
if (!consumptionResponse.IsOk())
|
||||
{
|
||||
return CultivateCoreResult.ComputeConsumptionFailed;
|
||||
}
|
||||
|
||||
CalculatorConsumption consumption = consumptionResponse.Data;
|
||||
LevelInformation levelInformation = LevelInformation.From(delta);
|
||||
|
||||
List<CalculatorItem> items = CalculatorItemHelper.Merge(consumption.AvatarConsume, consumption.AvatarSkillConsume);
|
||||
bool avatarSaved = await cultivationService
|
||||
.SaveConsumptionAsync(CultivateType.AvatarAndSkill, avatar.Id, items, levelInformation)
|
||||
.SaveConsumptionAsync(CultivateType.AvatarAndSkill, delta.AvatarId, items, levelInformation)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(avatar.Weapon);
|
||||
ArgumentNullException.ThrowIfNull(delta.Weapon);
|
||||
|
||||
// Take a hot path if avatar is not saved.
|
||||
bool avatarAndWeaponSaved = avatarSaved && await cultivationService
|
||||
.SaveConsumptionAsync(CultivateType.Weapon, avatar.Weapon.Id, consumption.WeaponConsume.EmptyIfNull(), levelInformation)
|
||||
.SaveConsumptionAsync(CultivateType.Weapon, delta.Weapon.Id, consumption.WeaponConsume.EmptyIfNull(), levelInformation)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!avatarAndWeaponSaved)
|
||||
{
|
||||
return CultivateCoreResult.SaveConsumptionFailed;
|
||||
}
|
||||
return avatarAndWeaponSaved;
|
||||
}
|
||||
catch (HutaoException ex)
|
||||
{
|
||||
infoBarService.Error(ex, SH.ViewModelCultivationAddWarning);
|
||||
}
|
||||
|
||||
return CultivateCoreResult.Ok;
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("ExportAsImageCommand")]
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Snap.Hutao.Control.Extension;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Factory.ContentDialog;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Service.Cultivation;
|
||||
using Snap.Hutao.Service.Inventory;
|
||||
using Snap.Hutao.Service.Metadata;
|
||||
using Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
using Snap.Hutao.Service.Navigation;
|
||||
@@ -29,6 +31,7 @@ internal sealed partial class CultivationViewModel : Abstraction.ViewModel
|
||||
private readonly ICultivationService cultivationService;
|
||||
private readonly ILogger<CultivationViewModel> logger;
|
||||
private readonly INavigationService navigationService;
|
||||
private readonly IInventoryService inventoryService;
|
||||
private readonly IMetadataService metadataService;
|
||||
private readonly IInfoBarService infoBarService;
|
||||
private readonly ITaskContext taskContext;
|
||||
@@ -140,8 +143,8 @@ internal sealed partial class CultivationViewModel : Abstraction.ViewModel
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
CultivateEntries = entries;
|
||||
InventoryItems = cultivationService.GetInventoryItemViews(project, context, SaveInventoryItemCommand);
|
||||
|
||||
await UpdateInventoryItemsAsync().ConfigureAwait(false);
|
||||
await UpdateStatisticsItemsAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -173,11 +176,35 @@ internal sealed partial class CultivationViewModel : Abstraction.ViewModel
|
||||
{
|
||||
if (inventoryItem is not null)
|
||||
{
|
||||
cultivationService.SaveInventoryItem(inventoryItem);
|
||||
inventoryService.SaveInventoryItem(inventoryItem);
|
||||
await UpdateStatisticsItemsAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("RefreshInventoryCommand")]
|
||||
private async Task RefreshInventoryAsync()
|
||||
{
|
||||
if (SelectedProject is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (await EnterCriticalExecutionAsync().ConfigureAwait(false))
|
||||
{
|
||||
ContentDialog dialog = await contentDialogFactory
|
||||
.CreateForIndeterminateProgressAsync(SH.ViewModelCultivationRefreshInventoryProgress)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
using (await dialog.BlockAsync(taskContext).ConfigureAwait(false))
|
||||
{
|
||||
await inventoryService.RefreshInventoryAsync(SelectedProject).ConfigureAwait(false);
|
||||
|
||||
await UpdateInventoryItemsAsync().ConfigureAwait(false);
|
||||
await UpdateStatisticsItemsAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async ValueTask UpdateStatisticsItemsAsync()
|
||||
{
|
||||
if (SelectedProject is not null)
|
||||
@@ -201,6 +228,18 @@ internal sealed partial class CultivationViewModel : Abstraction.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
private async ValueTask UpdateInventoryItemsAsync()
|
||||
{
|
||||
if (SelectedProject is not null)
|
||||
{
|
||||
await taskContext.SwitchToBackgroundAsync();
|
||||
CultivationMetadataContext context = await metadataService.GetContextAsync<CultivationMetadataContext>().ConfigureAwait(false);
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
InventoryItems = inventoryService.GetInventoryItemViews(SelectedProject, context, SaveInventoryItemCommand);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("NavigateToPageCommand")]
|
||||
private void NavigateToPage(string? typeString)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,6 @@ using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
using Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
using Snap.Hutao.Service.Notification;
|
||||
using Snap.Hutao.View.Converter;
|
||||
using Snap.Hutao.ViewModel.Guide;
|
||||
using Snap.Hutao.Web.Hutao.HutaoAsAService;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
|
||||
@@ -20,15 +20,14 @@ using Snap.Hutao.Service.Metadata;
|
||||
using Snap.Hutao.Service.Notification;
|
||||
using Snap.Hutao.Service.User;
|
||||
using Snap.Hutao.View.Dialog;
|
||||
using Snap.Hutao.ViewModel.User;
|
||||
using Snap.Hutao.Web.Response;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using CalculateAvatarPromotionDelta = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.AvatarPromotionDelta;
|
||||
using CalculateBatchConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.BatchConsumption;
|
||||
using CalculateClient = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.CalculateClient;
|
||||
using CalculateConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Consumption;
|
||||
using CalculateItem = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Item;
|
||||
using CalculateItemHelper = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.ItemHelper;
|
||||
|
||||
namespace Snap.Hutao.ViewModel.Wiki;
|
||||
|
||||
@@ -149,7 +148,7 @@ internal sealed partial class WikiAvatarViewModel : Abstraction.ViewModel
|
||||
|
||||
foreach (Avatar avatar in avatars)
|
||||
{
|
||||
avatar.Collocation = hutaoCache.AvatarCollocations.GetValueOrDefault(avatar.Id);
|
||||
avatar.CollocationView = hutaoCache.AvatarCollocations.GetValueOrDefault(avatar.Id);
|
||||
avatar.CookBonusView ??= CookBonusView.Create(avatar.FetterInfo.CookBonus, idMaterialMap);
|
||||
avatar.CultivationItemsView ??= avatar.CultivationItems.SelectList(i => idMaterialMap.GetValueOrDefault(i, Material.Default));
|
||||
}
|
||||
@@ -163,7 +162,7 @@ internal sealed partial class WikiAvatarViewModel : Abstraction.ViewModel
|
||||
return;
|
||||
}
|
||||
|
||||
if (userService.Current is null)
|
||||
if (!UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid))
|
||||
{
|
||||
infoBarService.Warning(SH.MustSelectUserAndUid);
|
||||
return;
|
||||
@@ -178,22 +177,21 @@ internal sealed partial class WikiAvatarViewModel : Abstraction.ViewModel
|
||||
return;
|
||||
}
|
||||
|
||||
Response<CalculateConsumption> consumptionResponse = await calculateClient
|
||||
.ComputeAsync(userService.Current.Entity, delta)
|
||||
Response<CalculateBatchConsumption> response = await calculateClient
|
||||
.BatchComputeAsync(userAndUid, delta)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!consumptionResponse.IsOk())
|
||||
if (!response.IsOk())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CalculateConsumption consumption = consumptionResponse.Data;
|
||||
CalculateBatchConsumption batchConsumption = response.Data;
|
||||
LevelInformation levelInformation = LevelInformation.From(delta);
|
||||
List<CalculateItem> items = CalculateItemHelper.Merge(consumption.AvatarConsume, consumption.AvatarSkillConsume);
|
||||
try
|
||||
{
|
||||
bool saved = await cultivationService
|
||||
.SaveConsumptionAsync(CultivateType.AvatarAndSkill, avatar.Id, items, levelInformation)
|
||||
.SaveConsumptionAsync(CultivateType.AvatarAndSkill, avatar.Id, batchConsumption.OverallConsume, levelInformation)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (saved)
|
||||
|
||||
@@ -20,13 +20,14 @@ using Snap.Hutao.Service.Metadata;
|
||||
using Snap.Hutao.Service.Notification;
|
||||
using Snap.Hutao.Service.User;
|
||||
using Snap.Hutao.View.Dialog;
|
||||
using Snap.Hutao.ViewModel.User;
|
||||
using Snap.Hutao.Web.Response;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using CalculateAvatarPromotionDelta = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.AvatarPromotionDelta;
|
||||
using CalculateBatchConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.BatchConsumption;
|
||||
using CalculateClient = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.CalculateClient;
|
||||
using CalculateConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Consumption;
|
||||
|
||||
namespace Snap.Hutao.ViewModel.Wiki;
|
||||
|
||||
@@ -140,7 +141,7 @@ internal sealed partial class WikiWeaponViewModel : Abstraction.ViewModel
|
||||
|
||||
foreach (Weapon weapon in weapons)
|
||||
{
|
||||
weapon.Collocation = hutaoCache.WeaponCollocations.GetValueOrDefault(weapon.Id);
|
||||
weapon.CollocationView = hutaoCache.WeaponCollocations.GetValueOrDefault(weapon.Id);
|
||||
weapon.CultivationItemsView ??= weapon.CultivationItems.SelectList(i => idMaterialMap.GetValueOrDefault(i, Material.Default));
|
||||
}
|
||||
}
|
||||
@@ -154,7 +155,7 @@ internal sealed partial class WikiWeaponViewModel : Abstraction.ViewModel
|
||||
return;
|
||||
}
|
||||
|
||||
if (userService.Current is null)
|
||||
if (!UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid))
|
||||
{
|
||||
infoBarService.Warning(SH.MustSelectUserAndUid);
|
||||
return;
|
||||
@@ -169,21 +170,21 @@ internal sealed partial class WikiWeaponViewModel : Abstraction.ViewModel
|
||||
return;
|
||||
}
|
||||
|
||||
Response<CalculateConsumption> consumptionResponse = await calculateClient
|
||||
.ComputeAsync(userService.Current.Entity, delta)
|
||||
Response<CalculateBatchConsumption> response = await calculateClient
|
||||
.BatchComputeAsync(userAndUid, delta)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!consumptionResponse.IsOk())
|
||||
if (!response.IsOk())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CalculateConsumption consumption = consumptionResponse.Data;
|
||||
CalculateBatchConsumption batchConsumption = response.Data;
|
||||
LevelInformation levelInformation = LevelInformation.From(delta);
|
||||
try
|
||||
{
|
||||
bool saved = await cultivationService
|
||||
.SaveConsumptionAsync(CultivateType.Weapon, weapon.Id, consumption.WeaponConsume.EmptyIfNull(), levelInformation)
|
||||
.SaveConsumptionAsync(CultivateType.Weapon, weapon.Id, batchConsumption.OverallConsume, levelInformation)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (saved)
|
||||
|
||||
@@ -6,13 +6,13 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
|
||||
internal sealed class BatchConsumption
|
||||
{
|
||||
[JsonPropertyName("items")]
|
||||
public List<Consumption>? Items { get; set; }
|
||||
public List<Consumption> Items { get; set; } = default!;
|
||||
|
||||
[JsonPropertyName("available_material")]
|
||||
public List<Item>? AvailableMaterial { get; set; }
|
||||
|
||||
[JsonPropertyName("overall_consume")]
|
||||
public List<Item>? OverallConsume { get; set; }
|
||||
public List<Item> OverallConsume { get; set; } = default!;
|
||||
|
||||
[JsonPropertyName("has_user_info")]
|
||||
public bool HasUserInfo { get; set; }
|
||||
|
||||
@@ -19,6 +19,7 @@ internal sealed partial class CalculateClient
|
||||
private readonly ILogger<CalculateClient> logger;
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
[Obsolete("Use BatchComputeAsync instead")]
|
||||
public async ValueTask<Response<Consumption>> ComputeAsync(Model.Entity.User user, AvatarPromotionDelta delta, CancellationToken token = default)
|
||||
{
|
||||
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
|
||||
@@ -34,15 +35,18 @@ internal sealed partial class CalculateClient
|
||||
return Response.Response.DefaultIfNull(resp);
|
||||
}
|
||||
|
||||
public async ValueTask<Response<BatchConsumption>> BatchComputeAsync(UserAndUid userAndUid, List<AvatarPromotionDelta> deltas, CancellationToken token = default)
|
||||
public async ValueTask<Response<BatchConsumption>> BatchComputeAsync(UserAndUid userAndUid, AvatarPromotionDelta delta, bool syncInventory = false, CancellationToken token = default)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(deltas.Count, 8);
|
||||
return await BatchComputeAsync(userAndUid, [delta], syncInventory, token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async ValueTask<Response<BatchConsumption>> BatchComputeAsync(UserAndUid userAndUid, List<AvatarPromotionDelta> deltas, bool syncInventory = false, CancellationToken token = default)
|
||||
{
|
||||
BatchConsumptionData data = new()
|
||||
{
|
||||
Items = deltas,
|
||||
Region = userAndUid.Uid.Region,
|
||||
Uid = userAndUid.Uid.ToString(),
|
||||
Region = syncInventory ? userAndUid.Uid.Region : default!,
|
||||
Uid = syncInventory ? userAndUid.Uid.ToString() : default!,
|
||||
};
|
||||
|
||||
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
|
||||
|
||||
@@ -42,5 +42,5 @@ internal sealed class Item
|
||||
public QualityType Level { get; set; }
|
||||
|
||||
[JsonPropertyName("lack_num")]
|
||||
public uint LackNum { get; set; }
|
||||
public int LackNum { get; set; }
|
||||
}
|
||||
@@ -1,12 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Snap.Hutao.Win32.System.SystemInformation;
|
||||
|
||||
internal enum IMAGE_FILE_MACHINE : ushort
|
||||
|
||||
Reference in New Issue
Block a user