4 const int CM_MODE_NONE = 0;
5 const int CM_MODE_WORLD = 1;
6 const int CM_MODE_INVENTORY = 2;
9 PluginRecipesManager m_recipesManager;
12 int m_contextualRecipeID;
22 m_recipesManager = recipesManager;
24 m_craftingMode = CM_MODE_NONE;
26 m_actionVariantManager.GetOnUpdateInvoker().Clear();
27 m_actionVariantManager.GetOnUpdateInvoker().Insert(OnUpdate);
31 void SetRecipeID(
int recipeID)
33 m_recipeID = recipeID;
41 bool IsInventoryCraft()
43 return m_craftingMode == CM_MODE_INVENTORY;
48 return m_craftingMode == CM_MODE_WORLD;
61 void OnUpdate(
Object item,
Object target,
int component_index )
66 if (
m_player.GetActionManager().GetRunningAction() )
74 m_craftingMode = CM_MODE_NONE;
75 m_actionVariantManager.Clear();
81 if ( item1 != item_in_hands && item2 != item_in_hands )
86 item1.GetInventory().GetCurrentInventoryLocation(il1);
87 item2.GetInventory().GetCurrentInventoryLocation(il2);
89 Error(
"Crafting manager - both of items are out of hands - item1: " + il1.DumpToString() +
" item2: " + il2.DumpToString() +
" / item in hands: - " + item_in_hands);
95 if (m_craftingMode == CM_MODE_INVENTORY)
97 recipeCount = m_recipesManager.GetValidRecipes(m_item1, m_item2, m_recipes, m_player);
98 m_recipeCount = recipeCount;
99 m_recipeID = m_recipes.Get(m_contextualRecipeID);
103 recipeCount = m_recipesManager.GetValidRecipes(item1, item2, m_recipes, m_player);
105 if (recipeCount == 0)
108 m_craftingMode = CM_MODE_NONE;
109 m_actionVariantManager.Clear();
113 if ( m_craftingMode == CM_MODE_NONE || m_recipeCount != recipeCount || m_item1 != item1 || m_item2 != item2 )
115 m_craftingMode = CM_MODE_WORLD;
116 m_recipeCount = recipeCount;
117 m_contextualRecipeID = 0;
121 m_actionVariantManager.SetActionVariantCount(m_recipeCount);
123 m_recipeID = m_recipes.Get(m_contextualRecipeID);
130 int recipeCount = m_recipesManager.GetValidRecipes(item1,item2,m_recipes, m_player);
132 for (
int i = 0; i < recipeCount; i++ )
134 if (recipeID == -1 || m_recipes.Get(i) == recipeID)
136 if ( m_recipesManager.GetIsInstaRecipe(m_recipes.Get(i)) || m_recipesManager.IsEnableDebugCrafting() )
139 m_player.RPCSingleParam(
ERPCs.RPC_CRAFTING_INVENTORY_INSTANT, craftParam,
true,
m_player.GetIdentity());
144 m_craftingMode = CM_MODE_INVENTORY;
145 m_recipeCount = recipeCount;
146 m_contextualRecipeID = i;
149 m_recipeID = m_recipes.Get(i);
164 void ResetInventoryCraft()
167 m_craftingMode = CM_MODE_NONE;
170 bool IsEnableDebugCrafting()
175 int GetRecipeID(
int action_index )
177 return m_recipes[action_index];