DayZ 1.24
Loading...
Searching...
No Matches
RecipeBase.c
Go to the documentation of this file.
2const int MAXIMUM_RESULTS = 10;
3const float DEFAULT_SPAWN_DISTANCE = 0.5;
5{
9
11
12 ItemBase m_IngredientsSorted[MAX_NUMBER_OF_INGREDIENTS]; //if the recipe is valid, this array will contain all ingredients sorted against the recipe ingredients
13
14 //ref array<string> m_ItemsToCreate;
15
16 //string m_Result;
18 string m_Name;
19
20 int m_ID;
22 float m_AnimationLength = 1;//animation length in relative time units
23 float m_Specialty = 0;// value > 0 for roughness, value < 0 for precision
24 bool m_IsInstaRecipe;//should this recipe be performed instantly without animation
25 //bool m_IsActionType;//will this recipe be also a user action(only set true if you know what you are doing)
26 bool m_AnywhereInInventory;//is this recipe valid even when neither of the items is in hands
27 //array<string> ptr;
28
33
39
40
50
51
53 {
54
55 for (int i = 0; i < MAX_NUMBER_OF_INGREDIENTS; i++)
56 {
60 }
61
62 for (i = 0; i < MAXIMUM_RESULTS; i++)
64
66 //m_IsActionType = false;
67
68 m_Name = "RecipeBase default name";
69 Init();
70 }
71
72 void Init();
73
78
80 {
81 return m_Specialty;
82 }
83
85 {
87 }
88
90 {
91 if (item1 == NULL || item2 == NULL) return false;
92
93 m_Items[0] = item1;
94 m_Items[1] = item2;
95
96 bool found = false;
97 for (int i = 0; i < MAX_NUMBER_OF_INGREDIENTS; i++) //all ingredients
98 {
99 found = false;
101 for (int x = 0; x < tempArray.Count(); x++) //particular ingredient array
102 {
103 for (int z = 0; z < MAX_NUMBER_OF_INGREDIENTS; z++)
104 {
105 if (m_Items[z] != NULL)
106 {
107 ItemBase item = m_Items[z];
108 if (tempArray.Get(x) == item.GetType() || GetGame().IsKindOf(item.GetType(), tempArray.Get(x)))
109 {
110 found = true;//we found a match
111 //m_IngredientsSorted.Insert(item);
113 m_Items[z] = NULL;
114 }
115 }
116 if (found) break; //we found a match, no need to check the remaining ingredients
117 }
118 if (found) break; //we found a match, no need to check this m_Ingredient array
119 }
120 if (!found) return false; // no match within an m_Ingredient array, no reason to continue the search, recipe is invalid
121 }
122 if (found)
123 return true;
124 else
125 return false;
126 }
127
129 {
131 }
132
139
141 {
143 for (int i = 0; i < ptr.Count(); i++)
144 {
145 if (ptr[i] == ingredient)
146 {
147 ptr.Remove(i);
148 m_SoundCategories[index].Remove(i);
149 return;
150 }
151 }
152 }
153
154
155 void AddResult(string item)
156 {
159 }
160
161 string GetName()
162 {
163 return m_Name;
164 }
165
167 {
168 return m_IsInstaRecipe;
169 }
170
171
172 //spawns results in the world
174 {
175 //vector item_position = player.GetPosition() + ( player.GetDirection() * 1 );
176 //Debug.Log("SpawnItems called","recipes");
177 spawned_objects.Clear();//just to make sure
178 EntityAI object = NULL;
179
180 for (int i = 0; i < m_NumberOfResults; i++)
181 {
183
184 if (m_ResultInheritsColor[i] != -1)
185 {
187 //string class_name = item.GetType();
188 string color = item.ConfigGetString("color");
191 }
192
193 if (m_ResultToInventory[i] == -1)
194 {
195 Debug.Log(" = " + m_ResultToInventory[i].ToString(), "recipes");
196 /*
197 InventoryLocation inv_loc = new InventoryLocation;
198 if (player.GetInventory().FindFirstFreeLocationForNewEntity(item_to_spawn, FindInventoryLocationType.ANY, inv_loc))
199 {
200 object = SpawnItemOnLocation(item_to_spawn, inv_loc, false);
201 }
202 */
203 object = player.GetInventory().CreateInInventory(item_to_spawn);
204 }
205 else if (m_ResultToInventory[i] >= 0)
206 {
207 /*
208 object = player.SpawnEntityOnGroundOnCursorDir(item_to_spawn, 0.5);
209
210 ItemBase item_swap_with = ingredients[m_ResultToInventory[i]];
211 player.SwapEntities(true, item_swap_with, EntityAI.Cast(object));
212 */
213 }
214 else if (m_ResultToInventory[i] == -2)
215 object = player.GetInventory().CreateEntityInCargo(item_to_spawn);
216 if (!object)
217 {
218 //spawning in inventory failed, spawning on the ground instead.....
219 object = player.SpawnEntityOnGroundOnCursorDir(item_to_spawn, m_ResultSpawnDistance[i]);
220 if (!object)
221 Error("failed to spawn entity " + item_to_spawn + " , make sure the classname exists and item can be spawned");
222 }
223 spawned_objects.Insert(ItemBase.Cast(object));
224 //Debug.Log("spawning item "+item_to_spawn,"recipes");
225 object = null;
226 }
227
228 }
229
230 //applies final modifications to results
232 {
233 float all_ingredients_health = 0;//this is used later in results
234 float all_ingredients_health01 = 0;//combined damage % of ingredients
235 int value_delta;
236 for (int i = 0; i < MAX_NUMBER_OF_INGREDIENTS; i++)
237 {
238 ItemBase ingrd = ItemBase.Cast(sorted[i]);
239 all_ingredients_health += ingrd.GetHealth("", "");//accumulate health of all ingredients, used in results
240 all_ingredients_health01 += ingrd.GetHealth01("", "");
241 }
242 //------------------- results ----------------------
243 for (i = 0; i < m_NumberOfResults; i++)
244 {
245 ItemBase res = results.Get(i);
246 if (!res)
247 continue;
248
250
251 if (res.IsItemBase())
252 {
254
255 ItemBase resIb = ItemBase.Cast(res);
256
257 if (use_soft_skills)
258 value_delta = player.GetSoftSkillsManager().AddSpecialtyBonus(value_delta, m_Specialty);
259
260 if (!resIb.IsMagazine()) //is not a magazine
261 {
262 if (m_ResultSetFullQuantity[i] == 1) //<------m_ResultSetFullQuantity
263 resIb.SetQuantityMax();
264 else if (value_delta != -1) //<------m_ResultSetQuantity
265 resIb.SetQuantity(value_delta);
266 }
267 else//is magazine
268 {
269 Magazine mgzn = Magazine.Cast(resIb);
270 if (m_ResultSetFullQuantity[i] == 1) //<------m_ResultSetFullQuantity
271 mgzn.ServerSetAmmoMax();
272 else if (value_delta != -1) //<------m_ResultSetQuantity
273 mgzn.ServerSetAmmoCount(value_delta);
274 }
275 }
276 if (m_ResultSetHealth[i] != -1) //<------m_ResultSetHealth
277 {
279 if (use_soft_skills)
280 value_delta = player.GetSoftSkillsManager().AddSpecialtyBonus(value_delta, m_Specialty);
281 res.SetHealth("", "", value_delta);
282 }
283 if (m_ResultInheritsHealth[i] != -1) //<------m_ResultInheritsHealth
284 {
285 if (m_ResultInheritsHealth[i] >= 0)
286 {
288 ItemBase ing = sorted[ing_number];
289
290 if (ing)
291 {
292 //float ing_health = ing.GetHealth("","");
293 float ing_health01 = ing.GetHealth01("", "");
294 res.SetHealth("", "", ing_health01 * res.GetMaxHealth("", ""));
295 Debug.Log("Inheriting health from ingredient:" + m_ResultInheritsHealth[i].ToString(), "recipes");
296 }
297 }
298 else if (m_ResultInheritsHealth[i] == -2)
299 {
300 //float average_health = all_ingredients_health / MAX_NUMBER_OF_INGREDIENTS;
302 res.SetHealth("", "", average_health01 * res.GetMaxHealth("", ""));
303 }
304 }
305
306 if (m_ResultReplacesIngredient[i] != -1) //<------ResultReplacesIngredient
307 {
309 {
311 ItemBase ingr = sorted[ing_num];
312
313 if (ingr)
314 {
315 MiscGameplayFunctions.TransferItemProperties(ingr, res);
316 MiscGameplayFunctions.TransferInventory(ingr, res, player);
317 }
318 }
319 }
320 }
321 }
322
323
325 {
326 for (int i = 0; i < m_IngredientsToBeDeleted.Count(); i++)
327 {
329 ingredient.Delete();
330 }
332 }
333
334 //applies final modifications to ingredients
336 {
337 //---------------------- ingredients ----------------------
338 for (int i = 0; i < MAX_NUMBER_OF_INGREDIENTS; i++)
339 {
340 ItemBase ingredient = sorted[i];
341
342 if (m_IngredientDestroy[i] == 1) //<------m_IngredientDestroy
343 {
345 //ingredient.Delete();
346 //sorted[i] = NULL;
347 }
348 else
349 {
351
352 if (m_IngredientAddHealth[i] != 0) //<------m_IngredientAddHealth
353 {
355 if (use_soft_skills)
356 {
357 if (health_delta < 0) health_delta = player.GetSoftSkillsManager().SubtractSpecialtyBonus(health_delta, m_Specialty);
358 else health_delta = player.GetSoftSkillsManager().AddSpecialtyBonus(health_delta, m_Specialty);
359 }
360 ingredient.AddHealth("", "", health_delta);
361 }
362 else if (m_IngredientSetHealth[i] != -1) //<------m_IngredientSetHealth
363 {
365 ingredient.SetHealth("", "", new_health);
366 }
367 if (m_IngredientAddQuantity[i] != 0) //<------m_IngredientAddQuantity
368 {
370
371 if (use_soft_skills)
372 {
373 if (quantity_delta < 0) quantity_delta = player.GetSoftSkillsManager().SubtractSpecialtyBonus(quantity_delta, m_Specialty);
374 else quantity_delta = player.GetSoftSkillsManager().AddSpecialtyBonus(quantity_delta, m_Specialty);
375 }
376
377 if (!ingredient.IsMagazine())
378 {
379 ItemBase obj = ingredient;
380 bool isDestroyed = obj.AddQuantity(quantity_delta, true);
381 if (isDestroyed)
382 {
383 //if (obj) m_IngredientsToBeDeleted.Insert(obj);
384 continue;
385 }
386 }
387 else
388 {
390 int newQuantity = mag.GetAmmoCount() + quantity_delta;
391 if (newQuantity <= 0)
392 {
393 if (mag) m_IngredientsToBeDeleted.Insert(mag);
394 continue;
395 }
396 else
397 mag.ServerSetAmmoCount(newQuantity);
398 }
399 }
400 }
401 }
402 }
403
404 //checks the recipe conditions
406 {
407 for (int i = 0; i < MAX_NUMBER_OF_INGREDIENTS; i++)
408 {
409 ItemBase ingredient = sorted[i];
410 if (!ingredient.IsMagazine())
411 {
412 if (ingredient.GetQuantityMax() != 0 && m_MinQuantityIngredient[i] >= 0 && ingredient.GetQuantity() < m_MinQuantityIngredient[i])
413 {
414 //Debug.Log("Recipe condition check failing1: m_MinQuantityIngredient","recipes");
415 return false;
416 }
417 if (m_MaxQuantityIngredient[i] >= 0 && ingredient.GetQuantity() > m_MaxQuantityIngredient[i])
418 {
419 //Debug.Log("Recipe condition check failing1: m_MaxQuantityIngredient","recipes");
420 return false;
421 }
422 }
423 else
424 {
426 if (m_MinQuantityIngredient[i] >= 0 && mag1.GetAmmoCount() < m_MinQuantityIngredient[i])
427 {
428 //Debug.Log("Recipe condition check failing1: m_MinQuantityIngredient[0]","recipes");
429 return false;
430 }
431 if (m_MaxQuantityIngredient[i] >= 0 && mag1.GetAmmoCount() > m_MaxQuantityIngredient[i])
432 {
433 //Debug.Log("Recipe condition check failing1: m_MaxQuantityIngredient[0]","recipes");
434 return false;
435 }
436 }
437 int dmg3 = ingredient.GetHealthLevel();
438 if (m_MinDamageIngredient[i] >= 0 && ingredient.GetHealthLevel() < m_MinDamageIngredient[i])
439 {
440 int dmg = ingredient.GetHealthLevel();
441 //Debug.Log("Recipe condition check failing1: m_MinDamageIngredient[0]","recipes");
442 return false;
443 }
444 if (m_MaxDamageIngredient[i] >= 0 && ingredient.GetHealthLevel() > m_MaxDamageIngredient[i])
445 {
446 int dmg2 = ingredient.GetHealthLevel();
447 //Debug.Log("Recipe condition check failing1: m_MaxDamageIngredient[0]","recipes");
448 return false;
449 }
450 }
451 return true;
452 }
453
454 //checks overall validity of this recipe
456 {
457 if (item1 == NULL || item2 == NULL)
458 {
459 Error("recipe invalid, at least one of the ingredients is NULL");
460 return false;
461 }
462
463 ItemBase item_in_hand = player.GetItemInHands();
464
466 return false;
467
470
472 return true;
473 return false;
474 }
475
477 {
478 if (item1 == NULL || item2 == NULL)
479 {
480 Error("CheckRecipe: recipe invalid, at least one of the ingredients is NULL");
481 //Debug.Log("recipe invalid, at least one of the ingredients is NULL","recipes");
482 return;
483 }
485 }
486
491
492 //performs this recipe
494 {
495 if (item1 == NULL || item2 == NULL)
496 {
497 Error("PerformRecipe: recipe invalid, at least one of the ingredients is NULL");
498 Debug.Log("PerformRecipe: at least one of the ingredients is NULL", "recipes");
499 }
500 /*
501 m_IngredientsSorted[0] = item1;
502 m_IngredientsSorted[1] = item2;
503 */
504
505 /*
506 Debug.Log("PerformRecipe Ingredient 1: "+ToString(item1.Ptr().GetType()),"recipes");
507 Debug.Log("PerformRecipe Ingredient 2: "+ToString(item2.Ptr().GetType()),"recipes");
508 */
510 {
513
516
518
520
521
523 }
524 else
525 Debug.Log("CheckRecipe failed on server", "recipes");
526 }
527
529 {
530 player.GetSoftSkillsManager().AddSpecialty(m_Specialty);
531 }
532
534 {
535 //Debug.Log("Called Can Do on a recipe id:" + m_ID.ToString(),"recipes");
536 for (int i = 0; i < MAX_NUMBER_OF_INGREDIENTS; i++)
537 {
538 if (ingredients[i].GetInventory() && ingredients[i].GetInventory().AttachmentCount() > 0)
539 return false;
540 }
541
542 return true;
543 }
544
546 {
547 //Debug.Log("Called Do on a recipe id:" + m_ID.ToString(),"recipes");
548 }
549
550 int GetID()
551 {
552 return m_ID;
553 }
554
555
556 void SetID(int id)
557 {
558 m_ID = id;
559 }
560
562 {
563 for (int i = 0; i < MAX_NUMBER_OF_INGREDIENTS; i++)
564 {
566
567 for (int x = 0; x < ptr.Count(); x++)
568 items.Insert(ptr.Get(x));
569 }
570 }
571
573 {
574 string itemType = item.GetType();
576
577 for (int x = 0; x < ptr.Count(); x++)
578 {
579 if (GetGame().IsKindOf(itemType, ptr.Get(x)))
581 }
582 return "";
583 }
584
585
586 bool IsItemInRecipe(string item)
587 {
588 for (int i = 0; i < MAX_NUMBER_OF_INGREDIENTS; i++)
589 {
591
592 for (int x = 0; x < ptr.Count(); x++)
593 {
594 if (ptr.Get(x) == item) return true;
595 }
596 }
597 return false;
598 }
601 {
602 int mask = 0;
603
604 for (int i = 0; i < MAX_NUMBER_OF_INGREDIENTS; i++)
605 {
607
608 for (int x = 0; x < ptr.Count(); x++)
609 {
610 if (ptr.Get(x) == item)
611 mask = ((int)Math.Pow(2, i)) | mask;
612 }
613 }
614 return mask;
615 }
616}
Param3 int
proto string ToString()
Icon x
const float DEFAULT_SPAWN_DISTANCE
Definition RecipeBase.c:3
const int MAXIMUM_RESULTS
Definition RecipeBase.c:2
const int MAX_NUMBER_OF_INGREDIENTS
Definition RecipeBase.c:1
ScriptConsoleEnfScriptTab ScriptConsoleTabBase OnSelected()
Definition Debug.c:14
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:133
Definition EnMath.c:7
int GetID()
Definition RecipeBase.c:550
void SetID(int id)
Definition RecipeBase.c:556
string m_ItemsToCreate[MAXIMUM_RESULTS]
Definition RecipeBase.c:6
bool m_IngredientDestroy[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:38
void InsertIngredientEx(int index, string ingredient, string soundCategory)
Definition RecipeBase.c:133
float GetSpecialty()
Definition RecipeBase.c:79
bool IsInstaRecipe()
Definition RecipeBase.c:166
bool IsRecipeAnywhere()
Definition RecipeBase.c:84
void SpawnItems(ItemBase ingredients[], PlayerBase player, array< ItemBase > spawned_objects)
Definition RecipeBase.c:173
int m_ResultToInventory[MAXIMUM_RESULTS]
Definition RecipeBase.c:45
float GetLengthInSecs()
Definition RecipeBase.c:74
bool CheckIngredientMatch(ItemBase item1, ItemBase item2)
Definition RecipeBase.c:89
bool m_IngredientUseSoftSkills[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:34
string m_Name
Definition RecipeBase.c:18
float m_ResultSetHealth[MAXIMUM_RESULTS]
Definition RecipeBase.c:43
void DeleleIngredientsPass()
Definition RecipeBase.c:324
float m_ResultSetQuantity[MAXIMUM_RESULTS]
Definition RecipeBase.c:42
void Do(ItemBase ingredients[], PlayerBase player, array< ItemBase > results, float specialty_weight)
Definition RecipeBase.c:545
bool m_ResultSetFullQuantity[MAXIMUM_RESULTS]
Definition RecipeBase.c:41
bool CanDo(ItemBase ingredients[], PlayerBase player)
Definition RecipeBase.c:533
bool IsItemInRecipe(string item)
Definition RecipeBase.c:586
ref array< string > m_SoundCategories[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:8
void Init()
void OnSelected(ItemBase item1, ItemBase item2, PlayerBase player)
Definition RecipeBase.c:487
bool m_IsInstaRecipe
Definition RecipeBase.c:24
string GetSoundCategory(int ingredientIndex, ItemBase item)
Definition RecipeBase.c:572
ref array< string > m_Ingredients[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:7
void RecipeBase()
Definition RecipeBase.c:52
int GetIngredientMaskForItem(string item)
returns a mask which marks ingredient positions for a given item in this recipe(for example mask of v...
Definition RecipeBase.c:600
float m_ResultSpawnDistance[MAXIMUM_RESULTS]
Definition RecipeBase.c:44
void AddResult(string item)
Definition RecipeBase.c:155
bool m_ResultUseSoftSkills[MAXIMUM_RESULTS]
Definition RecipeBase.c:49
ItemBase m_Items[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:10
ItemBase m_IngredientsSorted[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:12
void ApplyModificationsIngredients(ItemBase sorted[], PlayerBase player)
Definition RecipeBase.c:335
int m_ResultReplacesIngredient[MAXIMUM_RESULTS]
Definition RecipeBase.c:48
void ApplySoftSkillsSpecialty(PlayerBase player)
Definition RecipeBase.c:528
void OnSelectedRecipe(ItemBase item1, ItemBase item2, PlayerBase player)
Definition RecipeBase.c:476
float m_IngredientAddHealth[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:35
bool CheckConditions(ItemBase sorted[])
Definition RecipeBase.c:405
float m_Specialty
Definition RecipeBase.c:23
float m_IngredientSetHealth[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:37
int m_ResultInheritsHealth[MAXIMUM_RESULTS]
Definition RecipeBase.c:46
void PerformRecipe(ItemBase item1, ItemBase item2, PlayerBase player)
Definition RecipeBase.c:493
float m_MinQuantityIngredient[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:29
void InsertIngredient(int index, string ingredient)
Definition RecipeBase.c:128
float m_AnimationLength
Definition RecipeBase.c:22
void ApplyModificationsResults(ItemBase sorted[], array< ItemBase > results, ItemBase result, PlayerBase player)
Definition RecipeBase.c:231
int m_ResultInheritsColor[MAXIMUM_RESULTS]
Definition RecipeBase.c:47
float m_MaxQuantityIngredient[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:30
float m_IngredientAddQuantity[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:36
float m_MinDamageIngredient[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:31
string GetName()
Definition RecipeBase.c:161
void RemoveIngredient(int index, string ingredient)
Definition RecipeBase.c:140
void GetAllItems(array< string > items)
Definition RecipeBase.c:561
float m_MaxDamageIngredient[MAX_NUMBER_OF_INGREDIENTS]
Definition RecipeBase.c:32
bool m_AnywhereInInventory
Definition RecipeBase.c:26
int m_NumberOfResults
Definition RecipeBase.c:21
bool CheckRecipe(ItemBase item1, ItemBase item2, PlayerBase player)
Definition RecipeBase.c:455
ref array< ItemBase > m_IngredientsToBeDeleted
Definition RecipeBase.c:17
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
const float CRAFTING_TIME_UNIT_SIZE
Definition constants.c:589
static proto float Pow(float v, float power)
Return power of v ^ power.