1
0
mirror of https://github.com/wangdage12/Snap.Hutao.git synced 2026-07-31 04:10:25 +08:00

往养成计划里面添加角色和武器时,使之存在关联

This commit is contained in:
mfkvfhpdx
2026-05-03 21:57:37 +08:00
parent a988a65190
commit 70c0970e2e
17 changed files with 850 additions and 21 deletions
@@ -0,0 +1,668 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Snap.Hutao.Model.Entity.Database;
#nullable disable
namespace Snap.Hutao.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20260503131124_AddCultivateEntryRelatedEntryId")]
partial class AddCultivateEntryRelatedEntryId
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.0");
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<Guid>("ArchiveId")
.HasColumnType("TEXT");
b.Property<uint>("Current")
.HasColumnType("INTEGER");
b.Property<uint>("Id")
.HasColumnType("INTEGER");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("Time")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("ArchiveId");
b.ToTable("achievements");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.AchievementArchive", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("achievement_archives");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.AvatarInfo", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Info2")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("RefreshTime")
.HasColumnType("TEXT");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("avatar_infos");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.AvatarStrategy", b =>
{
b.Property<uint>("AvatarId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("ChineseStrategyId")
.HasColumnType("INTEGER");
b.Property<int>("OverseaStrategyId")
.HasColumnType("INTEGER");
b.HasKey("AvatarId");
b.ToTable("avatar_strategies");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntry", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("Id")
.HasColumnType("INTEGER");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.Property<Guid?>("RelatedEntryId")
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.HasIndex("ProjectId");
b.HasIndex("RelatedEntryId");
b.ToTable("cultivate_entries");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntryLevelInformation", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("AvatarIsPromoting")
.HasColumnType("INTEGER");
b.Property<uint>("AvatarLevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("AvatarLevelTo")
.HasColumnType("INTEGER");
b.Property<Guid>("EntryId")
.HasColumnType("TEXT");
b.Property<uint>("SkillALevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("SkillALevelTo")
.HasColumnType("INTEGER");
b.Property<uint>("SkillELevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("SkillELevelTo")
.HasColumnType("INTEGER");
b.Property<uint>("SkillQLevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("SkillQLevelTo")
.HasColumnType("INTEGER");
b.Property<bool>("WeaponIsPromoting")
.HasColumnType("INTEGER");
b.Property<uint>("WeaponLevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("WeaponLevelTo")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.HasIndex("EntryId")
.IsUnique();
b.ToTable("cultivate_entry_level_informations");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateItem", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("Count")
.HasColumnType("INTEGER");
b.Property<Guid>("EntryId")
.HasColumnType("TEXT");
b.Property<bool>("IsFinished")
.HasColumnType("INTEGER");
b.Property<uint>("ItemId")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.HasIndex("EntryId");
b.ToTable("cultivate_items");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateProject", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<TimeSpan>("ServerTimeZoneOffset")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("cultivate_projects");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.DailyNoteEntry", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("DailyNote")
.HasColumnType("TEXT");
b.Property<bool>("DailyTaskDotVisible")
.HasColumnType("INTEGER");
b.Property<bool>("DailyTaskNotify")
.HasColumnType("INTEGER");
b.Property<bool>("DailyTaskNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<bool>("ExpeditionDotVisible")
.HasColumnType("INTEGER");
b.Property<bool>("ExpeditionNotify")
.HasColumnType("INTEGER");
b.Property<bool>("ExpeditionNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<bool>("HomeCoinDotVisible")
.HasColumnType("INTEGER");
b.Property<bool>("HomeCoinNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<int>("HomeCoinNotifyThreshold")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("RefreshTime")
.HasColumnType("TEXT");
b.Property<bool>("ResinDotVisible")
.HasColumnType("INTEGER");
b.Property<bool>("ResinNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<int>("ResinNotifyThreshold")
.HasColumnType("INTEGER");
b.Property<bool>("TransformerDotVisible")
.HasColumnType("INTEGER");
b.Property<bool>("TransformerNotify")
.HasColumnType("INTEGER");
b.Property<bool>("TransformerNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.Property<Guid>("UserId")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("UserId");
b.ToTable("daily_notes");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GachaArchive", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("gacha_archives");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GachaItem", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<Guid>("ArchiveId")
.HasColumnType("TEXT");
b.Property<int>("GachaType")
.HasColumnType("INTEGER");
b.Property<long>("Id")
.HasColumnType("INTEGER");
b.Property<uint>("ItemId")
.HasColumnType("INTEGER");
b.Property<int>("QueryType")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("Time")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("ArchiveId");
b.ToTable("gacha_items");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GameAccount", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<int>("Index")
.HasColumnType("INTEGER");
b.Property<string>("MacAddress")
.HasColumnType("TEXT");
b.Property<string>("Mid")
.HasColumnType("TEXT");
b.Property<string>("MihoyoSDK")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.ToTable("game_accounts");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.HardChallengeEntry", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("HardChallengeData")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("ScheduleId")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("hard_challenges");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryItem", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("Count")
.HasColumnType("INTEGER");
b.Property<uint>("ItemId")
.HasColumnType("INTEGER");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("ProjectId");
b.ToTable("inventory_items");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.ObjectCacheEntry", b =>
{
b.Property<string>("Key")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("ExpireTime")
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("Key");
b.ToTable("object_cache");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.RoleCombatEntry", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("RoleCombatData")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("ScheduleId")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("role_combats");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.SettingEntry", b =>
{
b.Property<string>("Key")
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("Key");
b.ToTable("settings");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.SpiralAbyssEntry", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("ScheduleId")
.HasColumnType("INTEGER");
b.Property<string>("SpiralAbyss")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("spiral_abysses");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.UidProfilePicture", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("AvatarId")
.HasColumnType("INTEGER");
b.Property<uint>("CostumeId")
.HasColumnType("INTEGER");
b.Property<uint>("ProfilePictureId")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("RefreshTime")
.HasColumnType("TEXT");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("uid_profile_pictures");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.User", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Aid")
.HasColumnType("TEXT");
b.Property<string>("CookieToken")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("CookieTokenLastUpdateTime")
.HasColumnType("TEXT");
b.Property<string>("Fingerprint")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("FingerprintLastUpdateTime")
.HasColumnType("TEXT");
b.Property<int>("Index")
.HasColumnType("INTEGER");
b.Property<bool>("IsOversea")
.HasColumnType("INTEGER");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("LToken")
.HasColumnType("TEXT")
.HasColumnName("Ltoken");
b.Property<string>("Mid")
.HasColumnType("TEXT");
b.Property<string>("PreferredUid")
.HasColumnType("TEXT");
b.Property<string>("SToken")
.HasColumnType("TEXT")
.HasColumnName("Stoken");
b.HasKey("InnerId");
b.ToTable("users");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.AchievementArchive", "Archive")
.WithMany()
.HasForeignKey("ArchiveId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Archive");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntry", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateProject", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Snap.Hutao.Model.Entity.CultivateEntry", "RelatedEntry")
.WithMany()
.HasForeignKey("RelatedEntryId")
.OnDelete(DeleteBehavior.SetNull);
b.Navigation("Project");
b.Navigation("RelatedEntry");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntryLevelInformation", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateEntry", "Entry")
.WithOne("LevelInformation")
.HasForeignKey("Snap.Hutao.Model.Entity.CultivateEntryLevelInformation", "EntryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Entry");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateItem", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateEntry", "Entry")
.WithMany()
.HasForeignKey("EntryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Entry");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.DailyNoteEntry", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GachaItem", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.GachaArchive", "Archive")
.WithMany()
.HasForeignKey("ArchiveId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Archive");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryItem", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateProject", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntry", b =>
{
b.Navigation("LevelInformation");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,50 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Snap.Hutao.Migrations
{
/// <inheritdoc />
public partial class AddCultivateEntryRelatedEntryId : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "RelatedEntryId",
table: "cultivate_entries",
type: "TEXT",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_cultivate_entries_RelatedEntryId",
table: "cultivate_entries",
column: "RelatedEntryId");
migrationBuilder.AddForeignKey(
name: "FK_cultivate_entries_cultivate_entries_RelatedEntryId",
table: "cultivate_entries",
column: "RelatedEntryId",
principalTable: "cultivate_entries",
principalColumn: "InnerId",
onDelete: ReferentialAction.SetNull);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_cultivate_entries_cultivate_entries_RelatedEntryId",
table: "cultivate_entries");
migrationBuilder.DropIndex(
name: "IX_cultivate_entries_RelatedEntryId",
table: "cultivate_entries");
migrationBuilder.DropColumn(
name: "RelatedEntryId",
table: "cultivate_entries");
}
}
}
@@ -15,7 +15,7 @@ namespace Snap.Hutao.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.9");
modelBuilder.HasAnnotation("ProductVersion", "10.0.0");
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
@@ -113,6 +113,9 @@ namespace Snap.Hutao.Migrations
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.Property<Guid?>("RelatedEntryId")
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
@@ -120,6 +123,8 @@ namespace Snap.Hutao.Migrations
b.HasIndex("ProjectId");
b.HasIndex("RelatedEntryId");
b.ToTable("cultivate_entries");
});
@@ -585,7 +590,14 @@ namespace Snap.Hutao.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Snap.Hutao.Model.Entity.CultivateEntry", "RelatedEntry")
.WithMany()
.HasForeignKey("RelatedEntryId")
.OnDelete(DeleteBehavior.SetNull);
b.Navigation("Project");
b.Navigation("RelatedEntry");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntryLevelInformation", b =>
@@ -26,6 +26,11 @@ internal sealed class CultivateEntry : IAppDbEntity
public uint Id { get; set; }
public Guid? RelatedEntryId { get; set; }
[ForeignKey(nameof(RelatedEntryId))]
public CultivateEntry? RelatedEntry { get; set; }
public static CultivateEntry From(Guid projectId, CultivateType type, uint id)
{
return new()
@@ -1880,6 +1880,9 @@ Space Available: {2}</value>
<data name="ViewModelCultivationEntryViewPromoteOnlyHint" xml:space="preserve">
<value>Ascending only</value>
</data>
<data name="ViewModelCultivationEntryRelatedAvatar" xml:space="preserve">
<value>Linked character: {0}</value>
</data>
<data name="ViewModelCultivationProjectAdded" xml:space="preserve">
<value>Added successfully</value>
</data>
@@ -1931,6 +1931,9 @@
<data name="ViewModelCultivationEntryViewPromoteOnlyHint" xml:space="preserve">
<value>仅突破</value>
</data>
<data name="ViewModelCultivationEntryRelatedAvatar" xml:space="preserve">
<value>关联角色:{0}</value>
</data>
<data name="ViewModelCultivationProjectAdded" xml:space="preserve">
<value>添加成功</value>
</data>
@@ -0,0 +1,8 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Service.Cultivation.Consumption;
internal readonly record struct ConsumptionSaveResult(
ConsumptionSaveResultKind Kind,
Guid? CreatedEntryInnerId = null);
@@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection;
using Snap.Hutao.Core.Database;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Model.Entity.Database;
using Snap.Hutao.Model.Entity.Primitive;
using Snap.Hutao.Service.Abstraction;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
@@ -51,6 +52,26 @@ internal sealed partial class CultivationRepository : ICultivationRepository
return this.ImmutableArray<CultivateEntry>(e => e.ProjectId == projectId && e.Id == itemId);
}
public Guid? TryGetAvatarCultivateEntryInnerId(Guid projectId, uint avatarId)
{
ImmutableArray<CultivateEntry> entries = GetCultivateEntryImmutableArrayByProjectIdAndItemId(projectId, avatarId);
Guid? last = null;
foreach (ref readonly CultivateEntry entry in entries.AsSpan())
{
if (entry.Type != CultivateType.AvatarAndSkill)
{
continue;
}
if (last is null || entry.InnerId.CompareTo(last.Value) > 0)
{
last = entry.InnerId;
}
}
return last;
}
public void AddCultivateEntry(CultivateEntry entry)
{
this.Add(entry);
@@ -67,6 +67,12 @@ internal sealed partial class CultivationService : ICultivationService
{
ImmutableArray<CultivateEntry> entries = cultivationRepository.GetCultivateEntryImmutableArrayIncludingLevelInformationByProjectId(cultivateProject.InnerId);
Dictionary<Guid, CultivateEntry> entryByInnerId = new(entries.Length);
foreach (ref readonly CultivateEntry entry in entries.AsSpan())
{
entryByInnerId[entry.InnerId] = entry;
}
List<CultivateEntryView> resultEntries = new(entries.Length);
foreach (ref readonly CultivateEntry entry in entries.AsSpan())
{
@@ -87,7 +93,13 @@ internal sealed partial class CultivationService : ICultivationService
_ => default!,
};
resultEntries.Add(CultivateEntryView.Create(entry, item, entryItems.ToImmutable()));
string? relatedAvatarName = null;
if (entry.Type is CultivateType.Weapon && entry.RelatedEntryId is Guid relatedId && entryByInnerId.TryGetValue(relatedId, out CultivateEntry? relatedEntry) && relatedEntry.Type is CultivateType.AvatarAndSkill)
{
relatedAvatarName = context.GetAvatarItem(relatedEntry.Id).Name;
}
resultEntries.Add(CultivateEntryView.Create(entry, item, entryItems.ToImmutable(), relatedAvatarName));
}
ObservableCollection<CultivateEntryView> result = resultEntries.SortByDescending(e => e.IsToday).ToObservableCollection();
@@ -156,13 +168,13 @@ internal sealed partial class CultivationService : ICultivationService
cultivationRepository.UpdateCultivateItem(item.Entity);
}
public async ValueTask<ConsumptionSaveResultKind> SaveConsumptionAsync(InputConsumption inputConsumption)
public async ValueTask<ConsumptionSaveResult> SaveConsumptionAsync(InputConsumption inputConsumption)
{
// No selected project
IAdvancedDbCollectionView<CultivateProject> projects = await GetProjectCollectionAsync().ConfigureAwait(false);
if (!await EnsureCurrentProjectAsync(projects).ConfigureAwait(false))
{
return ConsumptionSaveResultKind.NoProject;
return new(ConsumptionSaveResultKind.NoProject);
}
ArgumentNullException.ThrowIfNull(projects.CurrentItem);
@@ -172,7 +184,7 @@ internal sealed partial class CultivationService : ICultivationService
// PreserveExisting or CreateNewEntry, but no item
if (inputConsumption is { Strategy: not ConsumptionSaveStrategyKind.OverwriteExisting, Items: [] })
{
return ConsumptionSaveResultKind.NoItem;
return new(ConsumptionSaveResultKind.NoItem);
}
// PreserveExisting or OverwriteExisting
@@ -185,7 +197,7 @@ internal sealed partial class CultivationService : ICultivationService
{
if (inputConsumption.Strategy is ConsumptionSaveStrategyKind.PreserveExisting)
{
return ConsumptionSaveResultKind.Skipped;
return new(ConsumptionSaveResultKind.Skipped);
}
if (inputConsumption.Strategy is ConsumptionSaveStrategyKind.OverwriteExisting)
@@ -199,7 +211,7 @@ internal sealed partial class CultivationService : ICultivationService
if (inputConsumption.Items is [])
{
return ConsumptionSaveResultKind.Removed;
return new(ConsumptionSaveResultKind.Removed);
}
}
}
@@ -207,13 +219,14 @@ internal sealed partial class CultivationService : ICultivationService
{
if (inputConsumption.Items is [])
{
return ConsumptionSaveResultKind.NoItem;
return new(ConsumptionSaveResultKind.NoItem);
}
}
}
{
CultivateEntry entry = CultivateEntry.From(projects.CurrentItem.InnerId, inputConsumption.Type, inputConsumption.ItemId);
entry.RelatedEntryId = inputConsumption.RelatedEntryId;
cultivationRepository.AddCultivateEntry(entry);
CultivateEntryLevelInformation entryLevelInformation = CultivateEntryLevelInformation.From(entry.InnerId, inputConsumption.Type, inputConsumption.LevelInformation);
@@ -225,9 +238,23 @@ internal sealed partial class CultivationService : ICultivationService
// The consumption save operation is always performed outside cultivation page
// and without touching the cache. So we have to invalidate the cache manually.
entryCollectionCache.TryRemove(projects.CurrentItem.InnerId, out _);
return new(ConsumptionSaveResultKind.Added, entry.InnerId);
}
}
public async ValueTask<Guid?> TryGetAvatarCultivateEntryInnerIdAsync(uint avatarId)
{
IAdvancedDbCollectionView<CultivateProject> projects = await GetProjectCollectionAsync().ConfigureAwait(false);
if (!await EnsureCurrentProjectAsync(projects).ConfigureAwait(false))
{
return null;
}
return ConsumptionSaveResultKind.Added;
ArgumentNullException.ThrowIfNull(projects.CurrentItem);
await taskContext.SwitchToBackgroundAsync();
return cultivationRepository.TryGetAvatarCultivateEntryInnerId(projects.CurrentItem.InnerId, avatarId);
}
public async ValueTask<ProjectAddResultKind> TryAddProjectAsync(CultivateProject project)
@@ -43,6 +43,12 @@ internal interface ICultivationRepository : IRepository<CultivateEntryLevelInfor
ImmutableArray<CultivateEntry> GetCultivateEntryImmutableArrayByProjectIdAndItemId(Guid projectId, uint itemId);
/// <summary>
/// 解析当前计划中指定角色的养成条目(类型为 CultivateType.AvatarAndSkill)。
/// 若存在多条历史记录,取条目主键 InnerId(Guid)较大的一条。
/// </summary>
Guid? TryGetAvatarCultivateEntryInnerId(Guid projectId, uint avatarId);
Guid GetCultivateProjectIdByEntryId(Guid entryId);
/// <summary>
@@ -25,7 +25,9 @@ internal interface ICultivationService
ValueTask RemoveProjectAsync(CultivateProject project);
ValueTask<ConsumptionSaveResultKind> SaveConsumptionAsync(InputConsumption inputConsumption);
ValueTask<ConsumptionSaveResult> SaveConsumptionAsync(InputConsumption inputConsumption);
ValueTask<Guid?> TryGetAvatarCultivateEntryInnerIdAsync(uint avatarId);
void SaveCultivateItem(CultivateItemView item);
@@ -19,4 +19,9 @@ internal sealed class InputConsumption
public required LevelInformation LevelInformation { get; init; }
public required ConsumptionSaveStrategyKind Strategy { get; init; }
/// <summary>
/// 武器条目关联的养成角色条目的主键(自引用外键,可为空)。
/// </summary>
public Guid? RelatedEntryId { get; init; }
}
@@ -198,6 +198,11 @@
Opacity="0.7"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{Binding Description}"/>
<TextBlock
Opacity="0.7"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{Binding RelatedAvatarLine}"
Visibility="{Binding RelatedAvatarLine, Converter={StaticResource EmptyObjectToVisibilityConverter}}"/>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal">
@@ -335,9 +335,9 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
Strategy = options.Strategy,
};
ConsumptionSaveResultKind avatarSaveKind = await scopeContext.CultivationService.SaveConsumptionAsync(avatarInput).ConfigureAwait(false);
ConsumptionSaveResult avatarSave = await scopeContext.CultivationService.SaveConsumptionAsync(avatarInput).ConfigureAwait(false);
InfoBarMessage? avatarMessage = avatarSaveKind switch
InfoBarMessage? avatarMessage = avatarSave.Kind switch
{
ConsumptionSaveResultKind.NoProject => InfoBarMessage.Warning(SH.ViewModelCultivationEntryAddWarning),
ConsumptionSaveResultKind.Skipped => isBatch ? default : InfoBarMessage.Information(SH.ViewModelCultivationConsumptionSaveSkippedHint),
@@ -351,13 +351,19 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
scopeContext.Messenger.Send(avatarMessage);
}
if (avatarSaveKind is ConsumptionSaveResultKind.NoProject)
if (avatarSave.Kind is ConsumptionSaveResultKind.NoProject)
{
return false;
}
ArgumentNullException.ThrowIfNull(options.Delta.Weapon);
Guid? relatedAvatarEntryId = avatarSave.CreatedEntryInnerId;
if (relatedAvatarEntryId is null && avatarSave.Kind is ConsumptionSaveResultKind.Skipped)
{
relatedAvatarEntryId = await scopeContext.CultivationService.TryGetAvatarCultivateEntryInnerIdAsync(options.Delta.AvatarId).ConfigureAwait(false);
}
InputConsumption weaponInput = new()
{
Type = CultivateType.Weapon,
@@ -365,10 +371,11 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
Items = consumption.WeaponConsume,
LevelInformation = levelInformation,
Strategy = options.Strategy,
RelatedEntryId = relatedAvatarEntryId,
};
ConsumptionSaveResultKind weaponSaveKind = await scopeContext.CultivationService.SaveConsumptionAsync(weaponInput).ConfigureAwait(false);
InfoBarMessage? weaponMessage = weaponSaveKind switch
ConsumptionSaveResult weaponSave = await scopeContext.CultivationService.SaveConsumptionAsync(weaponInput).ConfigureAwait(false);
InfoBarMessage? weaponMessage = weaponSave.Kind switch
{
ConsumptionSaveResultKind.NoProject => InfoBarMessage.Warning(SH.ViewModelCultivationEntryAddWarning),
ConsumptionSaveResultKind.Skipped => isBatch ? default : InfoBarMessage.Information(SH.ViewModelCultivationConsumptionSaveSkippedHint),
@@ -382,7 +389,7 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
scopeContext.Messenger.Send(weaponMessage);
}
return weaponSaveKind is not ConsumptionSaveResultKind.NoProject;
return weaponSave.Kind is not ConsumptionSaveResultKind.NoProject;
}
[Command("ExportToTextCommand")]
@@ -14,7 +14,7 @@ namespace Snap.Hutao.ViewModel.Cultivation;
internal sealed partial class CultivateEntryView : Item, IPropertyValuesProvider
{
private CultivateEntryView(CultivateEntry entry, Item item, ImmutableArray<CultivateItemView> items)
private CultivateEntryView(CultivateEntry entry, Item item, ImmutableArray<CultivateItemView> items, string? relatedAvatarName)
{
Id = entry.Id;
EntryId = entry.InnerId;
@@ -25,6 +25,8 @@ internal sealed partial class CultivateEntryView : Item, IPropertyValuesProvider
Items = items;
Type = entry.Type;
RelatedAvatarLine = relatedAvatarName is { } name ? SH.FormatViewModelCultivationEntryRelatedAvatar(name) : null;
Description = ParseDescription(entry);
IsToday = items.Any(i => i.IsToday);
RotationalItemIds = [.. items.Where(i => i.DaysOfWeek is not DaysOfWeek.Any).Select(i => i.Inner.Id)];
@@ -110,12 +112,17 @@ internal sealed partial class CultivateEntryView : Item, IPropertyValuesProvider
public string Description { get; }
/// <summary>
/// 武器条目在养成计算中与角色条目关联时的展示文案(含本地化前缀)。
/// </summary>
public string? RelatedAvatarLine { get; }
internal Guid EntryId { get; }
internal CultivateType Type { get; }
public static CultivateEntryView Create(CultivateEntry entry, Item item, ImmutableArray<CultivateItemView> items)
public static CultivateEntryView Create(CultivateEntry entry, Item item, ImmutableArray<CultivateItemView> items, string? relatedAvatarName = null)
{
return new(entry, item, items);
return new(entry, item, items, relatedAvatarName);
}
}
@@ -155,7 +155,7 @@ internal sealed partial class WikiAvatarViewModel : Abstraction.ViewModel
Strategy = deltaOptions.Strategy,
};
InfoBarMessage? message = await cultivationService.SaveConsumptionAsync(input).ConfigureAwait(false) switch
InfoBarMessage? message = (await cultivationService.SaveConsumptionAsync(input).ConfigureAwait(false)).Kind switch
{
ConsumptionSaveResultKind.NoProject => InfoBarMessage.Warning(SH.ViewModelCultivationEntryAddWarning),
ConsumptionSaveResultKind.Skipped => InfoBarMessage.Information(SH.ViewModelCultivationConsumptionSaveSkippedHint),
@@ -146,7 +146,7 @@ internal sealed partial class WikiWeaponViewModel : Abstraction.ViewModel
Strategy = deltaOptions.Strategy,
};
InfoBarMessage? message = await cultivationService.SaveConsumptionAsync(input).ConfigureAwait(false) switch
InfoBarMessage? message = (await cultivationService.SaveConsumptionAsync(input).ConfigureAwait(false)).Kind switch
{
ConsumptionSaveResultKind.NoProject => InfoBarMessage.Warning(SH.ViewModelCultivationEntryAddWarning),
ConsumptionSaveResultKind.Skipped => InfoBarMessage.Information(SH.ViewModelCultivationConsumptionSaveSkippedHint),