Files
Net.Project.B/Src/Crafting/ICrating.cs
CortexCore 519c93d651 1
2025-08-03 02:28:22 +08:00

57 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
namespace Net.Project.B.Craft
{
// 合成配方
public interface ICraftRecipe
{
int Id { get; }
public int CraftItemId { get; }
IReadOnlyDictionary<int,int> RequiredItems { get; }
IReadOnlyDictionary<string,int> RequiredTags { get; }
IReadOnlyCollection<ICraftEnvironment> RequiredEnvironments { get; }
}
public class CraftRecipe : ICraftRecipe
{
public int Id { get; set; }
public int CraftItemId { get; set; }
public readonly Dictionary<int, int> RequiredItems = new();
public readonly Dictionary<string,int> RequiredTag = new();
public readonly HashSet<ICraftEnvironment> RequiredEnvironments = new();
IReadOnlyDictionary<int, int> ICraftRecipe.RequiredItems => RequiredItems;
IReadOnlyDictionary<string, int> ICraftRecipe.RequiredTags => RequiredTag;
IReadOnlyCollection<ICraftEnvironment> ICraftRecipe.RequiredEnvironments => RequiredEnvironments;
}
// 合成服务
public interface ICraftingService
{
/// <summary>
/// 获取可合成配方(无 GC 分配),写入调用方传入的缓冲区
/// </summary>
/// <param name="buffer">结果缓冲区</param>
/// <returns>写入的个数</returns>
int GetCraftableRecipesNonGc(
ICraftRecipe[] buffer);
/// <summary>
/// 判断是否可以合成(无 GC
/// </summary>
bool CanCraftNonGc(ICraftRecipe recipe,out ICraftRecipe missing);
/// <summary>
/// 执行合成(不会分配新对象)
/// </summary>
bool TryCraftNonGc(ICraftRecipe recipe);
/// <summary>
/// 获取合成环境
/// </summary>
/// <param name="buffer"></param>
/// <returns></returns>
int QueryCraftEnvironments(ICraftEnvironment[] buffer);
}
}