Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
craftingmanager.c
Go to the documentation of this file.
1 class CraftingManager
3 {
4  const int CM_MODE_NONE = 0;
5  const int CM_MODE_WORLD = 1;
6  const int CM_MODE_INVENTORY = 2;
7 
8  PlayerBase m_player;
9  PluginRecipesManager m_recipesManager;
10  ActionVariantManager m_actionVariantManager;
11  int m_recipeID;
12  int m_contextualRecipeID;
13  int m_recipeCount;
14  int m_craftingMode;
15  ItemBase m_item1;
16  ItemBase m_item2;
17 
18  ref array<int> m_recipes;
19 
20  void CraftingManager(PlayerBase player, PluginRecipesManager recipesManager)
21  {
22  m_recipesManager = recipesManager;
23  m_player = player;
24  m_craftingMode = CM_MODE_NONE;
25  m_actionVariantManager = ActionManagerClient.GetVariantManager( ActionWorldCraft );
26  m_actionVariantManager.GetOnUpdateInvoker().Clear();
27  m_actionVariantManager.GetOnUpdateInvoker().Insert(OnUpdate);
28  m_recipes = new array<int>;
29  }
30 
31  void SetRecipeID(int recipeID)
32  {
33  m_recipeID = recipeID;
34  }
35 
36  int GetRecipeID()
37  {
38  return m_recipeID;
39  }
40 
41  bool IsInventoryCraft()
42  {
43  return m_craftingMode == CM_MODE_INVENTORY;
44  }
45 
46  bool IsWorldCraft()
47  {
48  return m_craftingMode == CM_MODE_WORLD;
49  }
50 
51  int GetRecipesCount()
52  {
53  return m_recipeCount;
54  }
55  // deprecated
56  void SetNextRecipe()
57  {
58 
59  }
60 
61  void OnUpdate( Object item, Object target, int component_index )
62  {
63  ItemBase item1 = ItemBase.Cast( item );
64  ItemBase item2 = ItemBase.Cast( target );
65 
66  if ( m_player.GetActionManager().GetRunningAction() )
67  return;
68 
69  ItemBase item_in_hands = m_player.GetItemInHands();
70 
71  if (!item1 || !item2)
72  {
73  m_recipeCount = 0;
74  m_craftingMode = CM_MODE_NONE;
75  m_actionVariantManager.Clear();
76  return;
77  }
78  else
79  {
80 
81  if ( item1 != item_in_hands && item2 != item_in_hands )
82  {
85 
86  item1.GetInventory().GetCurrentInventoryLocation(il1);
87  item2.GetInventory().GetCurrentInventoryLocation(il2);
88 
89  Error("Crafting manager - both of items are out of hands - item1: " + il1.DumpToString() + " item2: " + il2.DumpToString() + " / item in hands: - " + item_in_hands);
90  }
91  }
92 
93  int recipeCount = 0;
94 
95  if (m_craftingMode == CM_MODE_INVENTORY)
96  {
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);
100  return;
101  }
102 
103  recipeCount = m_recipesManager.GetValidRecipes(item1, item2, m_recipes, m_player);
104 
105  if (recipeCount == 0)
106  {
107  m_recipeCount = 0;
108  m_craftingMode = CM_MODE_NONE;
109  m_actionVariantManager.Clear();
110  }
111  else
112  {
113  if ( m_craftingMode == CM_MODE_NONE || m_recipeCount != recipeCount || m_item1 != item1 || m_item2 != item2 )
114  {
115  m_craftingMode = CM_MODE_WORLD;
116  m_recipeCount = recipeCount;
117  m_contextualRecipeID = 0;
118  m_item1 = item1;
119  m_item2 = item2;
120 
121  m_actionVariantManager.SetActionVariantCount(m_recipeCount);
122  }
123  m_recipeID = m_recipes.Get(m_contextualRecipeID);
124  }
125 
126  }
127 
128  bool SetInventoryCraft(int recipeID, ItemBase item1, ItemBase item2)
129  {
130  int recipeCount = m_recipesManager.GetValidRecipes(item1,item2,m_recipes, m_player);
131 
132  for ( int i = 0; i < recipeCount; i++ )
133  {
134  if (recipeID == -1 || m_recipes.Get(i) == recipeID)
135  {
136  if ( m_recipesManager.GetIsInstaRecipe(m_recipes.Get(i)) || m_recipesManager.IsEnableDebugCrafting() )
137  {
138  Param craftParam = new Param3<int, ItemBase, ItemBase>(m_recipes.Get(i), item1, item2);
139  m_player.RPCSingleParam(ERPCs.RPC_CRAFTING_INVENTORY_INSTANT, craftParam, true, m_player.GetIdentity());
140  return true;
141  }
142  else
143  {
144  m_craftingMode = CM_MODE_INVENTORY;
145  m_recipeCount = recipeCount;
146  m_contextualRecipeID = i;
147  m_item1 = item1;
148  m_item2 = item2;
149  m_recipeID = m_recipes.Get(i);
150 
151  ActionManagerClient am = ActionManagerClient.Cast(m_player.GetActionManager());
152 
153  if ( m_player.GetItemInHands() == item1) am.SetInventoryAction( am.GetAction(ActionWorldCraft), item2, item1);
154  else am.SetInventoryAction( am.GetAction(ActionWorldCraft), item1, item2);
155 
156  return true;
157  }
158  }
159 
160  }
161  return false;
162  }
163 
164  void ResetInventoryCraft()
165  {
166  m_recipeCount = 0;
167  m_craftingMode = CM_MODE_NONE;
168  }
169 
170  bool IsEnableDebugCrafting()
171  {
172  return true;
173  }
174 
175  int GetRecipeID( int action_index )
176  {
177  return m_recipes[action_index];
178  }
179 }
ItemBase
Definition: inventoryitem.c:730
m_player
DayZPlayer m_player
Definition: randomgeneratorsyncmanager.c:15
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
ActionVariantManager
Definition: actionvariantsmanager.c:1
m_item1
DeferredSwapEntities m_item1
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
Param3
Definition: entityai.c:95
ActionWorldCraft
Definition: actionworldcraft.c:32
PlayerBase
Definition: playerbaseclient.c:1
m_item2
EntityAI m_item2
Definition: dayzplayerinventory.c:77
Object
Definition: objecttyped.c:1
CraftingManager
Client only - manage set up crafting on client.
Definition: craftingmanager.c:2
ActionManagerClient
Definition: actionmanagerclient.c:4
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
ERPCs
ERPCs
Definition: erpcs.c:1