21 int m_NumberOfResults;
22 float m_AnimationLength = 1;
23 float m_Specialty = 0;
26 bool m_AnywhereInInventory;
60 m_IngredientsSorted[i] = NULL;
68 m_NumberOfResults = 0;
71 m_Name =
"RecipeBase default name";
77 float GetLengthInSecs()
87 bool IsRecipeAnywhere()
89 return m_AnywhereInInventory;
94 if( item1 == NULL || item2 == NULL )
return false;
104 for(
int x = 0;
x < tempArray.Count();
x++)
108 if( m_Items[z] != NULL )
111 if( tempArray.Get(
x) == item.GetType() ||
GetGame().IsKindOf(item.GetType(),tempArray.Get(
x)))
115 m_IngredientsSorted[i] = item;
123 if(!found)
return false;
135 void InsertIngredient(
int index,
string ingredient)
137 InsertIngredientEx(index, ingredient,
"");
140 void InsertIngredientEx(
int index,
string ingredient,
string soundCategory)
143 ptr.Insert(ingredient);
144 m_SoundCategories[index].Insert(soundCategory);
147 void RemoveIngredient(
int index,
string ingredient)
150 for(
int i = 0; i < ptr.Count(); i++)
152 if(ptr[i] == ingredient)
155 m_SoundCategories[index].Remove(i);
162 void AddResult(
string item)
164 m_ItemsToCreate[m_NumberOfResults] = item;
175 return m_IsInstaRecipe;
185 spawned_objects.Clear();
188 for(
int i = 0; i < m_NumberOfResults; i++)
190 string item_to_spawn = m_ItemsToCreate[i];
192 if( m_ResultInheritsColor[i] != -1 )
194 ItemBase item = ingredients[m_ResultInheritsColor[i]];
196 string color = item.ConfigGetString(
"color");
197 string new_class_name = m_ItemsToCreate[i] + color;
198 item_to_spawn = new_class_name;
201 if( m_ResultToInventory[i] == -1 )
203 Debug.Log(
" = "+m_ResultToInventory[i].
ToString(),
"recipes");
211 object = player.GetInventory().CreateInInventory(item_to_spawn);
213 else if (m_ResultToInventory[i] >= 0)
222 else if ( m_ResultToInventory[i] == -2 )
224 object = player.GetInventory().CreateEntityInCargo(item_to_spawn);
229 object = player.SpawnEntityOnGroundOnCursorDir(item_to_spawn, m_ResultSpawnDistance[i]);
232 Error(
"failed to spawn entity "+item_to_spawn+
" , make sure the classname exists and item can be spawned");
235 spawned_objects.Insert(
ItemBase.Cast(
object));
245 float all_ingredients_health = 0;
246 float all_ingredients_health01 = 0;
251 all_ingredients_health += ingrd.GetHealth(
"",
"");
252 all_ingredients_health01 += ingrd.GetHealth01(
"",
"");
255 for(i = 0; i < m_NumberOfResults; i++)
263 bool use_soft_skills = m_ResultUseSoftSkills[i];
265 if( res.IsItemBase() )
267 value_delta = m_ResultSetQuantity[i];
271 if( use_soft_skills )
273 value_delta = player.GetSoftSkillsManager().AddSpecialtyBonus(value_delta, m_Specialty);
276 if( !resIb.IsMagazine() )
278 if( m_ResultSetFullQuantity[i] == 1 )
280 resIb.SetQuantityMax();
282 else if( value_delta != -1 )
284 resIb.SetQuantity( value_delta );
289 Magazine mgzn = Magazine.Cast(resIb);
290 if( m_ResultSetFullQuantity[i] == 1 )
292 mgzn.ServerSetAmmoMax();
294 else if( value_delta != -1 )
296 mgzn.ServerSetAmmoCount( value_delta );
300 if( m_ResultSetHealth[i] != -1 )
302 value_delta = m_ResultSetHealth[i];
303 if( use_soft_skills )
305 value_delta = player.GetSoftSkillsManager().AddSpecialtyBonus(value_delta, m_Specialty);
307 res.SetHealth(
"",
"",value_delta);
309 if( m_ResultInheritsHealth[i] != -1 )
311 if( m_ResultInheritsHealth[i] >= 0 )
313 int ing_number = m_ResultInheritsHealth[i];
319 float ing_health01 = ing.GetHealth01(
"",
"");
320 res.SetHealth(
"",
"", ing_health01 * res.GetMaxHealth(
"",
""));
321 Debug.Log(
"Inheriting health from ingredient:"+m_ResultInheritsHealth[i].
ToString(),
"recipes");
324 else if( m_ResultInheritsHealth[i] == -2 )
328 res.SetHealth(
"",
"", average_health01 * res.GetMaxHealth(
"",
""));
332 if( m_ResultReplacesIngredient[i] != -1 )
334 if( m_ResultReplacesIngredient[i] > -1 )
336 int ing_num = m_ResultReplacesIngredient[i];
341 MiscGameplayFunctions.TransferItemProperties(ingr, res);
342 MiscGameplayFunctions.TransferInventory(ingr, res, player);
350 void DeleleIngredientsPass()
352 for(
int i = 0; i < m_IngredientsToBeDeleted.Count(); i++)
354 ItemBase ingredient = m_IngredientsToBeDeleted.Get(i);
357 m_IngredientsToBeDeleted.Clear();
368 if( m_IngredientDestroy[i] == 1 )
370 if( ingredient ) m_IngredientsToBeDeleted.Insert(ingredient);
376 bool use_soft_skills = m_IngredientUseSoftSkills[i];
378 if( m_IngredientAddHealth[i] != 0 )
380 float health_delta = m_IngredientAddHealth[i];
381 if( use_soft_skills )
383 if(health_delta <0) health_delta = player.GetSoftSkillsManager().SubtractSpecialtyBonus(health_delta, m_Specialty);
384 else health_delta = player.GetSoftSkillsManager().AddSpecialtyBonus(health_delta, m_Specialty);
386 ingredient.AddHealth(
"",
"",health_delta);
388 else if(m_IngredientSetHealth[i] != -1)
390 float new_health = m_IngredientSetHealth[i];
391 ingredient.SetHealth(
"",
"",new_health);
393 if( m_IngredientAddQuantity[i] != 0 )
395 float quantity_delta = m_IngredientAddQuantity[i];
397 if( use_soft_skills )
399 if(quantity_delta <0) quantity_delta = player.GetSoftSkillsManager().SubtractSpecialtyBonus(quantity_delta, m_Specialty);
400 else quantity_delta = player.GetSoftSkillsManager().AddSpecialtyBonus(quantity_delta, m_Specialty);
403 if( !ingredient.IsMagazine() )
406 bool isDestroyed = obj.AddQuantity(quantity_delta,
true);
415 Magazine mag = Magazine.Cast(ingredient);
416 int newQuantity = mag.GetAmmoCount() + quantity_delta;
417 if( newQuantity <= 0 )
419 if(mag) m_IngredientsToBeDeleted.Insert(mag);
424 mag.ServerSetAmmoCount( newQuantity );
433 bool CheckConditions(
ItemBase sorted[])
438 if( !ingredient.IsMagazine() )
440 if( ingredient.GetQuantityMax() !=0 && m_MinQuantityIngredient[i] >= 0 && ingredient.GetQuantity() < m_MinQuantityIngredient[i] )
445 if( m_MaxQuantityIngredient[i] >= 0 && ingredient.GetQuantity() > m_MaxQuantityIngredient[i] )
453 Magazine mag1 = Magazine.Cast(ingredient);
454 if( m_MinQuantityIngredient[i] >= 0 && mag1.GetAmmoCount() < m_MinQuantityIngredient[i] )
459 if( m_MaxQuantityIngredient[i] >= 0 && mag1.GetAmmoCount() > m_MaxQuantityIngredient[i] )
465 int dmg3 = ingredient.GetHealthLevel();
466 if( m_MinDamageIngredient[i] >= 0 && ingredient.GetHealthLevel() < m_MinDamageIngredient[i] )
468 int dmg = ingredient.GetHealthLevel();
472 if( m_MaxDamageIngredient[i] >= 0 && ingredient.GetHealthLevel() > m_MaxDamageIngredient[i] )
474 int dmg2 = ingredient.GetHealthLevel();
485 if( item1 == NULL || item2 == NULL )
487 Error(
"recipe invalid, at least one of the ingredients is NULL");
491 ItemBase item_in_hand = player.GetItemInHands();
493 if( !IsRecipeAnywhere() && (item1 != item_in_hand && item2 != item_in_hand) )
498 m_IngredientsSorted[0] = item1;
499 m_IngredientsSorted[1] = item2;
501 if( CanDo( m_IngredientsSorted, player ) && CheckConditions( m_IngredientsSorted ) )
510 if( item1 == NULL || item2 == NULL )
512 Error(
"CheckRecipe: recipe invalid, at least one of the ingredients is NULL");
516 OnSelected(item1,item2,player);
527 if( item1 == NULL || item2 == NULL )
529 Error(
"PerformRecipe: recipe invalid, at least one of the ingredients is NULL");
530 Debug.Log(
"PerformRecipe: at least one of the ingredients is NULL",
"recipes");
541 if( CheckRecipe(item1,item2,player) )
544 SpawnItems(m_IngredientsSorted, player,spawned_objects );
546 ApplyModificationsResults(m_IngredientsSorted, spawned_objects, NULL, player);
547 ApplyModificationsIngredients(m_IngredientsSorted, player);
549 ApplySoftSkillsSpecialty(player);
551 Do( m_IngredientsSorted, player, spawned_objects, m_Specialty );
554 DeleleIngredientsPass();
558 Debug.Log(
"CheckRecipe failed on server",
"recipes");
562 void ApplySoftSkillsSpecialty(
PlayerBase player)
564 player.GetSoftSkillsManager().AddSpecialty(m_Specialty);
572 if (ingredients[i].GetInventory() && ingredients[i].GetInventory().AttachmentCount() > 0)
601 for(
int x = 0;
x < ptr.Count();
x++)
603 items.Insert( ptr.Get(
x) );
608 string GetSoundCategory(
int ingredientIndex,
ItemBase item)
610 string itemType = item.GetType();
613 for (
int x = 0;
x < ptr.Count();
x++)
615 if (
GetGame().IsKindOf(itemType, ptr.Get(
x)))
617 return m_SoundCategories[ingredientIndex].Get(
x);
626 bool IsItemInRecipe(
string item)
632 for(
int x = 0;
x < ptr.Count();
x++)
634 if( ptr.Get(
x) == item )
return true;
640 int GetIngredientMaskForItem(
string item)
648 for(
int x = 0;
x < ptr.Count();
x++)
650 if( ptr.Get(
x) == item )
652 mask = ((
int)
Math.Pow(2, i)) | mask;