-
Notifications
You must be signed in to change notification settings - Fork 38
/
CustomRecipe.cs
81 lines (72 loc) · 3.08 KB
/
CustomRecipe.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System.Reflection;
using Jotunn.Configs;
using Jotunn.Managers;
namespace Jotunn.Entities
{
/// <summary>
/// Main interface for adding custom recipes to the game.<br />
/// All custom recipes have to be wrapped inside this class to add it to Jötunns <see cref="ItemManager"/>.
/// </summary>
public class CustomRecipe : CustomEntity
{
/// <summary>
/// The <see cref="global::Recipe"/> for this custom recipe.
/// </summary>
public Recipe Recipe { get; }
/// <summary>
/// Indicator if references from <see cref="Entities.Mock{T}"/>s will be replaced at runtime.
/// </summary>
public bool FixReference { get; set; }
/// <summary>
/// Indicator if references from <see cref="MockRequirement"/>s will be replaced at runtime.
/// </summary>
public bool FixRequirementReferences { get; set; }
/// <summary>
/// Custom recipe from a <see cref="global::Recipe"/>.<br />
/// Can fix references for <see cref="Entities.Mock{T}"/>s and <see cref="MockRequirement"/>s or not.
/// </summary>
/// <param name="recipe">The <see cref="global::Recipe"/> for a custom item.</param>
/// <param name="fixReference">If true references for <see cref="Entities.Mock{T}"/> objects get resolved at runtime by Jötunn.</param>
/// <param name="fixRequirementReferences">If true references for <see cref="MockRequirement"/>s get resolved at runtime by Jötunn.</param>
public CustomRecipe(Recipe recipe, bool fixReference, bool fixRequirementReferences) : base(Assembly.GetCallingAssembly())
{
Recipe = recipe;
FixReference = fixReference;
FixRequirementReferences = fixRequirementReferences;
}
/// <summary>
/// Custom recipe from a <see cref="RecipeConfig"/>.<br />
/// The <see cref="global::Recipe"/> is created automatically by Jötunn at runtime.
/// </summary>
/// <param name="recipeConfig">The <see cref="RecipeConfig"/> for a custom recipe.</param>
public CustomRecipe(RecipeConfig recipeConfig) : base(Assembly.GetCallingAssembly())
{
Recipe = recipeConfig.GetRecipe();
FixReference = true;
FixRequirementReferences = true;
}
/// <summary>
/// Checks if a custom status effect is valid (i.e. has a <see cref="global::Recipe"/>).
/// </summary>
/// <returns>true if all criteria is met</returns>
public bool IsValid()
{
return Recipe != null && Recipe.IsValid() && Recipe.m_item != null;
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
return obj.GetHashCode() == GetHashCode();
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Recipe.name.GetStableHashCode();
}
/// <inheritdoc/>
public override string ToString()
{
return Recipe.name;
}
}
}