Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
craftingmanager.c
Go to the documentation of this file.
1
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 ~CraftingManager()
32 {
33 if (m_actionVariantManager)
34 {
35 m_actionVariantManager.GetOnUpdateInvoker().Remove(OnUpdate);
36 }
37 }
38
39 void SetRecipeID(int recipeID)
40 {
41 m_recipeID = recipeID;
42 }
43
44 int GetRecipeID()
45 {
46 return m_recipeID;
47 }
48
49 bool IsInventoryCraft()
50 {
51 return m_craftingMode == CM_MODE_INVENTORY;
52 }
53
54 bool IsWorldCraft()
55 {
56 return m_craftingMode == CM_MODE_WORLD;
57 }
58
59 int GetRecipesCount()
60 {
61 return m_recipeCount;
62 }
63 // deprecated
64 void SetNextRecipe()
65 {
66
67 }
68
69 void OnUpdate( Object item, Object target, int component_index )
70 {
71 ItemBase item1 = ItemBase.Cast( item );
72 ItemBase item2 = ItemBase.Cast( target );
73
74 if ( m_player.GetActionManager().GetRunningAction() )
75 return;
76
77 ItemBase item_in_hands = m_player.GetItemInHands();
78
79 if (!item1 || !item2)
80 {
81 m_recipeCount = 0;
82 m_craftingMode = CM_MODE_NONE;
83 m_actionVariantManager.Clear();
84 return;
85 }
86 else
87 {
88
89 if ( item1 != item_in_hands && item2 != item_in_hands )
90 {
93
94 item1.GetInventory().GetCurrentInventoryLocation(il1);
95 item2.GetInventory().GetCurrentInventoryLocation(il2);
96
97 Error("Crafting manager - both of items are out of hands - item1: " + il1.DumpToString() + " item2: " + il2.DumpToString() + " / item in hands: - " + item_in_hands);
98 }
99 }
100
101 int recipeCount = 0;
102
103 if (m_craftingMode == CM_MODE_INVENTORY)
104 {
105 recipeCount = m_recipesManager.GetValidRecipes(m_item1, m_item2, m_recipes, m_player);
106 m_recipeCount = recipeCount;
107 m_recipeID = m_recipes.Get(m_contextualRecipeID);
108 return;
109 }
110
111 recipeCount = m_recipesManager.GetValidRecipes(item1, item2, m_recipes, m_player);
112
113 if (recipeCount == 0)
114 {
115 m_recipeCount = 0;
116 m_craftingMode = CM_MODE_NONE;
117 m_actionVariantManager.Clear();
118 }
119 else
120 {
121 if ( m_craftingMode == CM_MODE_NONE || m_recipeCount != recipeCount || m_item1 != item1 || m_item2 != item2 )
122 {
123 m_craftingMode = CM_MODE_WORLD;
124 m_recipeCount = recipeCount;
125 m_contextualRecipeID = 0;
126 m_item1 = item1;
127 m_item2 = item2;
128
129 m_actionVariantManager.SetActionVariantCount(m_recipeCount);
130 }
131 m_recipeID = m_recipes.Get(m_contextualRecipeID);
132 }
133
134 }
135
136 bool SetInventoryCraft(int recipeID, ItemBase item1, ItemBase item2)
137 {
138 int recipeCount = m_recipesManager.GetValidRecipes(item1,item2,m_recipes, m_player);
139
140 for ( int i = 0; i < recipeCount; i++ )
141 {
142 if (recipeID == -1 || m_recipes.Get(i) == recipeID)
143 {
144 if ( m_recipesManager.GetIsInstaRecipe(m_recipes.Get(i)) || m_recipesManager.IsEnableDebugCrafting() )
145 {
146 Param craftParam = new Param3<int, ItemBase, ItemBase>(m_recipes.Get(i), item1, item2);
147 m_player.RPCSingleParam(ERPCs.RPC_CRAFTING_INVENTORY_INSTANT, craftParam, true, m_player.GetIdentity());
148 return true;
149 }
150 else
151 {
152 m_craftingMode = CM_MODE_INVENTORY;
153 m_recipeCount = recipeCount;
154 m_contextualRecipeID = i;
155 m_item1 = item1;
156 m_item2 = item2;
157 m_recipeID = m_recipes.Get(i);
158
159 ActionManagerClient am = ActionManagerClient.Cast(m_player.GetActionManager());
160
161 if ( m_player.GetItemInHands() == item1) am.SetInventoryAction( am.GetAction(ActionWorldCraft), item2, item1);
162 else am.SetInventoryAction( am.GetAction(ActionWorldCraft), item1, item2);
163
164 return true;
165 }
166 }
167
168 }
169 return false;
170 }
171
172 void ResetInventoryCraft()
173 {
174 m_recipeCount = 0;
175 m_craftingMode = CM_MODE_NONE;
176 }
177
178 bool IsEnableDebugCrafting()
179 {
180 return true;
181 }
182
183 int GetRecipeID( int action_index )
184 {
185 return m_recipes[action_index];
186 }
187}
void SetInventoryAction(ActionBase action_name, ItemBase target_item, ItemBase main_item)
static ActionVariantManager GetVariantManager(typename actionName)
ScriptInvoker GetOnUpdateInvoker()
void SetActionVariantCount(int count)
Client only - manage set up crafting on client.
InventoryLocation.
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DeferredSwapEntities m_item1
EntityAI m_item2
ERPCs
Definition erpcs.c:2
void Error(string err)
Messagebox with error message.
Definition endebug.c:90
DayZPlayer m_player