Skip to content

Commit

Permalink
inventory combine
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Nov 29, 2024
1 parent 65700e8 commit 387a4ed
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ internal static class IntrinsicFrozen
SH.ModelMetadataMaterialWeaponAscensionMaterial,
];

public static FrozenSet<string> ResinMaterialTypeDescriptions { get; } =
[
SH.ModelMetadataMaterialCharacterTalentMaterial,
SH.ModelMetadataMaterialCharacterLevelUpMaterial,
SH.ModelMetadataMaterialWeaponAscensionMaterial,
];

private static FrozenSet<string> NamesFromEnum<TEnum>(Func<TEnum, string?> selector)
where TEnum : struct, Enum
{
Expand Down
2 changes: 2 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Model/Metadata/Item/DisplayItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ internal class DisplayItem
public required string Icon { get; init; }

public required string Name { get; init; }

Check warning on line 20 in src/Snap.Hutao/Snap.Hutao/Model/Metadata/Item/DisplayItem.cs

View workflow job for this annotation

GitHub Actions / build

Check warning on line 20 in src/Snap.Hutao/Snap.Hutao/Model/Metadata/Item/DisplayItem.cs

View workflow job for this annotation

GitHub Actions / build

public required uint Rank { get; init; }

public string? Description { get; init; }

Expand Down
18 changes: 18 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Model/Metadata/Item/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal sealed class Material : DisplayItem
RankLevel = default,
ItemType = default,
Icon = default!,
Rank = default,
Description = "???",
TypeDescription = "???",
};
Expand Down Expand Up @@ -59,6 +60,23 @@ public bool IsInventoryItem()
return IntrinsicFrozen.MaterialTypeDescriptions.Contains(TypeDescription);
}

public bool IsResinItem()
{
// 摩拉 大英雄的经验
if (Id == 202U || Id == 104003U)
{
return true;
}

// 智识之冕
if (TypeDescription is null || Id == 104319U)
{
return false;
}

return IntrinsicFrozen.ResinMaterialTypeDescriptions.Contains(TypeDescription);
}

public bool IsTodaysItem(bool treatSundayAsTrue = false)
{
// TODO: support different time zone
Expand Down
185 changes: 142 additions & 43 deletions src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async ValueTask<ObservableCollection<StatisticsCultivateItem>> GetStatist

if (resultItems.SingleOrDefault(i => i.Inner.Id == item.ItemId) is { } existedItem)
{
existedItem.Count += item.Count;
existedItem.Count += (int)item.Count;
}
else
{
Expand All @@ -107,7 +107,7 @@ public async ValueTask<ObservableCollection<StatisticsCultivateItem>> GetStatist
{
if (resultItems.SingleOrDefault(i => i.Inner.Id == inventoryItem.ItemId) is { } existedItem)
{
existedItem.TotalCount += inventoryItem.Count;
existedItem.TotalCount += (int)inventoryItem.Count;
}
}

Expand All @@ -119,78 +119,177 @@ public async ValueTask<ResinStatistics> GetResinStatisticsAsync(ObservableCollec
await taskContext.SwitchToBackgroundAsync();
ResinStatistics statistics = new();

foreach (StatisticsCultivateItem statisticsCultivateItem in statisticsCultivateItems)
{
if (statisticsCultivateItem.IsFinished)
{
continue;
}
IEnumerable<IGrouping<uint, StatisticsCultivateItem>> groupedItems = statisticsCultivateItems
.Where(i => i.Inner.IsResinItem())
.GroupBy(i => i.Inner.Rank);

Material material = statisticsCultivateItem.Inner;
if (material.TypeDescription is null || material.Id == 104319U)
foreach ((uint rank, IEnumerable<StatisticsCultivateItem> items) in groupedItems)
{
// 摩拉
if (rank is 10U)
{
continue;
}
StatisticsCultivateItem item = items.Single();
if (item.IsFinished)
{
continue;
}

if (material.Id == 202U)
{
double times = statisticsCultivateItem.Count - statisticsCultivateItem.TotalCount;
double times = item.Count - item.TotalCount;
statistics.BlossomOfWealth.RawItemCount += times;
continue;
}

if (material.Id == 104003U)
if (rank is 100U)
{
double times = (statisticsCultivateItem.Count - statisticsCultivateItem.TotalCount) * 20000D;
StatisticsCultivateItem item = items.Single();
if (item.IsFinished)
{
continue;
}

double times = (item.Count - item.TotalCount) * 20000D;
statistics.BlossomOfRevelation.RawItemCount += times;
continue;
}

if (material.TypeDescription.Equals(SH.ModelMetadataMaterialCharacterTalentMaterial, StringComparison.CurrentCulture))
if (rank is 11101U)
{
int pieces = material.RankLevel switch
foreach (StatisticsCultivateItem item in items)
{
QualityType.QUALITY_GREEN => 1,
QualityType.QUALITY_BLUE => 3,
QualityType.QUALITY_PURPLE => 9,
_ => throw HutaoException.NotSupported(),
};
double times = item.Count - item.TotalCount;
switch (item.Inner.RankLevel)
{
case QualityType.QUALITY_PURPLE:
statistics.NormalBoss.RawItemCount += times;
continue;
case QualityType.QUALITY_ORANGE:
statistics.WeeklyBoss.RawItemCount += times;
continue;
default:
throw HutaoException.NotSupported();
}
}

double times = (statisticsCultivateItem.Count - statisticsCultivateItem.TotalCount) * pieces;
statistics.TalentBooks.RawItemCount += times;
continue;
}

if (material.TypeDescription.Equals(SH.ModelMetadataMaterialCharacterLevelUpMaterial, StringComparison.CurrentCulture))
// 天赋书,武器突破材料。一次循环最多为4个
double greenItems = 0D;
double blueItems = 0D;
double purpleItems = 0D;
double orangeItems = 0D;

ResinStatisticsItem targetStatisticsItem = ((rank / 1000) % 10) switch
{
double times = statisticsCultivateItem.Count - statisticsCultivateItem.TotalCount;
switch (material.RankLevel)
3 => statistics.TalentBooks,
5 => statistics.WeaponAscension,
_ => throw HutaoException.NotSupported(),
};

foreach (StatisticsCultivateItem item in items)
{
switch (item.Inner.RankLevel)
{
case QualityType.QUALITY_GREEN:
greenItems += item.Count - item.TotalCount;
continue;
case QualityType.QUALITY_BLUE:
blueItems += item.Count - item.TotalCount;
continue;
case QualityType.QUALITY_PURPLE:
statistics.NormalBoss.RawItemCount += times;
purpleItems += item.Count - item.TotalCount;
continue;
case QualityType.QUALITY_ORANGE:
statistics.WeeklyBoss.RawItemCount += times;
orangeItems += item.Count - item.TotalCount;
continue;
default:
throw HutaoException.NotSupported();
}
}

if (material.TypeDescription.Equals(SH.ModelMetadataMaterialWeaponAscensionMaterial, StringComparison.CurrentCulture))
blueItems *= 3D;
purpleItems *= 9D;
orangeItems *= 27D;

// TODO: Refactor this
if (orangeItems > 0)
{
int pieces = material.RankLevel switch
if (purpleItems > 0)
{
QualityType.QUALITY_GREEN => 1,
QualityType.QUALITY_BLUE => 3,
QualityType.QUALITY_PURPLE => 9,
QualityType.QUALITY_ORANGE => 27,
_ => throw HutaoException.NotSupported(),
};

double times = (statisticsCultivateItem.Count - statisticsCultivateItem.TotalCount) * pieces;
statistics.WeaponAscension.RawItemCount += times;
continue;
if (blueItems > 0)
{
targetStatisticsItem.RawItemCount += orangeItems + purpleItems + blueItems + greenItems;
}
else
{
if (greenItems > 0)
{
double orangeAndPurpleNeed = orangeItems + purpleItems;
double blue = -blueItems > orangeAndPurpleNeed ? orangeAndPurpleNeed : -blueItems;
targetStatisticsItem.RawItemCount += orangeAndPurpleNeed + greenItems - blue;
}
else
{
targetStatisticsItem.RawItemCount += orangeItems + purpleItems + blueItems + greenItems;
}
}
}
else
{
if (blueItems > 0)
{
double purple = -purpleItems > orangeItems ? orangeItems : -purpleItems;
targetStatisticsItem.RawItemCount += orangeItems - purple + blueItems + greenItems;
}
else
{
if (greenItems > 0)
{
double purpleAndBlue = -(purpleItems + blueItems) > orangeItems ? orangeItems : -(purpleItems + blueItems);
targetStatisticsItem.RawItemCount += orangeItems - purpleAndBlue + greenItems;
}
else
{
targetStatisticsItem.RawItemCount += orangeItems + purpleItems + blueItems + greenItems;
}
}
}
}
else
{
if (purpleItems > 0)
{
if (blueItems > 0)
{
targetStatisticsItem.RawItemCount += purpleItems + blueItems + greenItems;
}
else
{
if (greenItems > 0)
{
double blue = -blueItems > purpleItems ? purpleItems : -blueItems;
targetStatisticsItem.RawItemCount += purpleItems - blue + greenItems;
}
else
{
targetStatisticsItem.RawItemCount += purpleItems + blueItems + greenItems;
}
}
}
else
{
if (blueItems > 0)
{
targetStatisticsItem.RawItemCount += blueItems + greenItems;
}
else
{
if (greenItems > 0)
{
targetStatisticsItem.RawItemCount += greenItems;
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public WorldDropProability SelectedWorldDropProability

public bool HasData
{
get => RawItemCount is not 0D;
get => RawItemCount > 0D;
}

public int TotalResin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ internal sealed class StatisticsCultivateItem
public StatisticsCultivateItem(Material inner, Model.Entity.CultivateItem entity)
{
Inner = inner;
Count = entity.Count;
Count = (int)entity.Count;
}

public Material Inner { get; }

public uint Count { get; set; }
public int Count { get; set; }

public uint TotalCount { get; set; }
public int TotalCount { get; set; }

public bool IsFinished { get => TotalCount >= Count; }

Expand Down

0 comments on commit 387a4ed

Please sign in to comment.