This commit is contained in:
CortexCore
2025-08-03 02:28:22 +08:00
parent 87007c9c24
commit 519c93d651
26 changed files with 427 additions and 5 deletions

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using BITKit.WorldNode;
namespace Net.Project.B.Craft
{
// 合成环境,例如工作台(制造),篝火(烹饪或温度)
public interface ICraftEnvironment
{
}
[Serializable]
public class CraftingWorkbench:ICraftEnvironment,IWorldNode
{
public override bool Equals(object obj) => obj is CraftingWorkbench;
public override int GetHashCode() => GetType().GetHashCode();
}
[Serializable]
public class CraftingTemperatureSource:ICraftEnvironment,IWorldNode
{
public override bool Equals(object obj) => obj is CraftingTemperatureSource;
public override int GetHashCode() => GetType().GetHashCode();
}
[Serializable]
public class CraftingWaterSource:ICraftEnvironment,IWorldNode
{
public override bool Equals(object obj) => obj is CraftingWaterSource;
public override int GetHashCode() => GetType().GetHashCode();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e73646397d685e24ea49a0c4d45353fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

57
Src/Crafting/ICrating.cs Normal file
View 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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5bb537c45fe82d5499d8ac656a415c6e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
{
"name": "Net.Project.B.Crafting",
"rootNamespace": "",
"references": [
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:d750d221812bb1d48baff92e6ef73e28"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": true
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 564e9f22877ff6544a2f3c9b209a7752
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: