1
This commit is contained in:
57
Src/Crafting/ICrating.cs
Normal file
57
Src/Crafting/ICrating.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user