Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
AonaSuzutsuki committed Jun 4, 2024
2 parents fbd3db4 + 334fb78 commit d096160
Show file tree
Hide file tree
Showing 32 changed files with 2,636 additions and 97 deletions.
4 changes: 2 additions & 2 deletions CookInformationViewer/CookInformationViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Copyright>Copyright (C) Aona Suzutsuki 2022 - 2024</Copyright>
<Configurations>Debug;Release;Debug Log</Configurations>
<AssemblyName>MabinogiRecipesViewer</AssemblyName>
<Version>1.0.6.6</Version>
<Version>1.0.7.7</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down Expand Up @@ -48,7 +48,7 @@
<PackageReference Include="CommonCoreLib" Version="1.0.6" />
<PackageReference Include="CommonStyleLib" Version="1.0.24" />
<PackageReference Include="KimamaSqlExecutorLib" Version="1.0.5" />
<PackageReference Include="KimamaSqliteExecutorLib" Version="1.0.6" />
<PackageReference Include="KimamaSqliteExecutorLib" Version="1.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.15" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SavannahXmlLib" Version="1.0.5" />
Expand Down
251 changes: 251 additions & 0 deletions CookInformationViewer/Models/CalcMaterialsModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media.Media3D;
using CommonStyleLib.Models;
using CookInformationViewer.Models.DataValue;
using CookInformationViewer.Models.Db.Context;
using CookInformationViewer.Models.Db.Manager;
using Newtonsoft.Json.Bson;
using Reactive.Bindings;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;

namespace CookInformationViewer.Models
{
public class CalcMaterialInfo
{
public int Id { get; set; }

public string Name { get; set; } = string.Empty;

public bool IsRecipe { get; set; }

public bool CanPurchasable { get; set; }

public CalcMaterialInfo? Parent { get; set; }

public List<CalcMaterialInfo> Children { get; set; } = new();

public List<LocationItemInfo> LocationItems { get; set; } = new();

public override string ToString()
{
var sb = new StringBuilder();
sb.Append($"{Name}, {CanPurchasable}");
return sb.ToString();
}
}

public class CalcMaterialFlatInfo
{
public string Name { get; set; } = string.Empty;
public int Count { get; set; }
public ObservableCollection<CalcMaterialInfo> UsedRecipes { get; set; } = new();
public ObservableCollection<LocationItemInfo> LocationItems { get; set; } = new();
}

public class CalcMaterialsModel : ModelBase
{
public ObservableCollection<CalcMaterialFlatInfo> Materials { get; set; } = new();

private readonly ContextManager _contextManager = new();

private CalcMaterialInfo? _root;

private bool _ignoreCanPurchasableChecked;

public bool IgnoreCanPurchasableChecked
{
get => _ignoreCanPurchasableChecked;
set => SetProperty(ref _ignoreCanPurchasableChecked, value);
}

public async Task Create(RecipeInfo recipe)
{
_root = new CalcMaterialInfo()
{
Id = recipe.Id,
Name = recipe.Name,
IsRecipe = true
};

await Task.Run(() =>
{
Open(_root, recipe);
Analyze(1);
});
}

public void Open(CalcMaterialInfo parent, RecipeInfo recipe)
{
var material1Id = recipe.Item1Id;
var material2Id = recipe.Item2Id;
var material3Id = recipe.Item3Id;
var recipe1Id = recipe.Item1RecipeId;
var recipe2Id = recipe.Item2RecipeId;
var recipe3Id = recipe.Item3RecipeId;

ParseRecipe(parent, material1Id, recipe1Id);
ParseRecipe(parent, material2Id, recipe2Id);
ParseRecipe(parent, material3Id, recipe3Id);
}

public void Analyze(int recipeCount)
{
var recipes = new List<CalcMaterialInfo>();
if (_root != null)
InternalAnalyze(_root, recipes, IgnoreCanPurchasableChecked);

var test = recipes.GroupBy(x => x.Name)
.ToDictionary(x => x.Key, x => x.ToList());

Materials.Clear();

foreach (var keyValue in test)
{
var name = keyValue.Key;

if (recipeCount > 1)
{
name += $"({keyValue.Value.Count}) x {recipeCount}";
}

Materials.Add(new CalcMaterialFlatInfo
{
Name = name,
Count = keyValue.Value.Count * recipeCount,
UsedRecipes = new ObservableCollection<CalcMaterialInfo>(keyValue.Value.Select(x => x.Parent ?? new CalcMaterialInfo())),
LocationItems = new ObservableCollection<LocationItemInfo>(keyValue.Value.First().LocationItems)
});
}
}

public RecipeHeader? ToRecipeHeader(CalcMaterialInfo materialInfo)
{
var recipe = _contextManager.GetItem(c => (
from x in c.CookRecipes
join category in c.CookCategories on x.CategoryId equals category.Id
where x.Id == materialInfo.Id
select new
{
recipe = x,
category
}
).ToList().FirstOrDefault());

if (recipe == null)
return null;

var header = new RecipeHeader(new RecipeInfo(recipe.recipe)
{
Category = new CategoryInfo(recipe.category)
});

return header;
}

private void InternalAnalyze(CalcMaterialInfo parent, List<CalcMaterialInfo> recipes, bool onlyCanPurchasable)
{
foreach (var child in parent.Children)
{
if (child.IsRecipe)
{
if (onlyCanPurchasable && child.CanPurchasable)
recipes.Add(child);
else
InternalAnalyze(child, recipes, onlyCanPurchasable);
}
else
{
recipes.Add(child);
}
}
}

private void ParseRecipe(CalcMaterialInfo parent, int? materialId, int? recipeId)
{
if (recipeId != null)
{
var dbRecipe = _contextManager.GetItem(c => c.CookRecipes.FirstOrDefault(x => x.Id == recipeId));

if (dbRecipe != null)
{
var recipeInfo = new RecipeInfo(dbRecipe);
var canPurchasable = _contextManager.GetItem(c => c.CookMaterials.Any(x => x.Name == recipeInfo.Name));

var info = new CalcMaterialInfo
{
Id = recipeInfo.Id,
Name = recipeInfo.Name,
Parent = parent,
IsRecipe = true,
CanPurchasable = canPurchasable,
LocationItems = new List<LocationItemInfo>
{
LocationItemInfo.CookItem
}
};

parent.Children.Add(info);

Open(info, recipeInfo);
}
}
else
{
var material = _contextManager.GetItem(c => c.CookMaterials.FirstOrDefault(x => x.Id == materialId));
var sellers = _contextManager.GetItem(c => (
from x in c.CookMaterialSellers
join seller in c.CookSellers on x.SellerId equals seller.Id
join location in c.CookLocations on seller.LocationId equals location.Id
where x.MaterialId == materialId
select new
{
seller,
location
}
).ToList());
var drops = _contextManager.GetItem(c => (
from x in c.CookMaterialDrops
join location in c.CookLocations on x.LocationId equals location.Id
where x.MaterialId == materialId
select new
{
drop = x,
location
}
).ToList());

if (material != null)
{
var info = new CalcMaterialInfo
{
Id = material.Id,
Name = material.Name,
Parent = parent
};
info.LocationItems.AddRange(sellers.Select(x => new LocationItemInfo
{
Name = x.seller.Name,
Location = x.location.Name,
Type = LocationItemInfo.TypeNpc
}));
info.LocationItems.AddRange(drops.Select(x => new LocationItemInfo
{
Name = x.drop.DropName,
Location = x.location.Name,
Type = LocationItemInfo.TypeNpc
}));

parent.Children.Add(info);
}
}
}
}
}
13 changes: 13 additions & 0 deletions CookInformationViewer/Models/DataValue/CategoryInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System.Windows.Media;
using CookInformationViewer.Models.Db.Context;
using Prism.Mvvm;

namespace CookInformationViewer.Models.DataValue;

public class CategoryInfo : BindableBase
{
public static CategoryInfo Empty { get; } = new();

public static CategoryInfo Favorite => new()
{
Id = 0,
Expand All @@ -26,6 +29,16 @@ public bool IsSelected

public Brush Foreground => SameFavorite() ? Constants.FavoriteForeground : new SolidColorBrush(Colors.White);

public CategoryInfo()
{
}

public CategoryInfo(DbCookCategories category)
{
Id = category.Id;
Name = category.Name;
}

public bool SameFavorite()
{
return Name == FavoriteContent;
Expand Down
62 changes: 62 additions & 0 deletions CookInformationViewer/Models/DataValue/EffectInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CookInformationViewer.Models.Db.Context;

namespace CookInformationViewer.Models.DataValue
{
public class EffectInfo
{
public int RecipeId { get; set; }

public int Number { get; set; }

public int Star { get; set; }

public int Hp { get; set; }
public int Mana { get; set; }
public int Stamina { get; set; }
public int Str { get; set; }
public int Int { get; set; }
public int Dex { get; set; }
public int Will { get; set; }
public int Luck { get; set; }
public int Damage { get; set; }
public int MagicDamage { get; set; }
public int MinDamage { get; set; }
public int Protection { get; set; }
public int Defense { get; set; }
public int MagicProtection { get; set; }
public int MagicDefense { get; set; }

public EffectInfo(DbCookEffects effect)
{
RecipeId = effect.RecipeId;
Number = effect.Number;
Star = effect.Star;
Hp = effect.Hp;
Mana = effect.Mana;
Stamina = effect.Stamina;
Str = effect.Str;
Int = effect.Int;
Dex = effect.Dex;
Will = effect.Will;
Luck = effect.Luck;
MinDamage = effect.MinDamage;
Damage = effect.Damage;
MagicDamage = effect.MagicDamage;
Defense = effect.Defense;
Protection = effect.Protection;
MagicDefense = effect.MagicDefense;
MagicProtection = effect.MagicProtection;
}

public EffectInfo()
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace CookInformationViewer.Models.DataValue
{
public class FestivalFoodQualityComboItem
{
public int Star { get; set; }
public string Name { get; set; } = string.Empty;
public Brush StarBrush
{
get
{
return Star switch
{
6 => Constants.StarSixForeground,
_ => new SolidColorBrush(Colors.White)
};
}
}
public List<EffectInfo> Effects { get; set; } = new();
}
}
Loading

0 comments on commit d096160

Please sign in to comment.