Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
crafttannedleather.c
Go to the documentation of this file.
1 class CraftTannedLeather extends RecipeBase
2 {
3  float m_PercentageUsed = 0.05; //Variable used to define relative quantity of Lime used when crafting tanned leather
4 
5  //Init Leather crafting recipe
6  override void Init()
7  {
8  m_Name = "#STR_CraftTannedLeather0";
9  m_IsInstaRecipe = false; //should this recipe be performed instantly without animation
10  m_AnimationLength = 1; //animation length in relative time units
11  m_Specialty = 0.02; // value > 0 for roughness, value < 0 for precision
12 
13  m_AnywhereInInventory = true;
14  //conditions
15  m_MinDamageIngredient[0] = -1; //-1 = disable check
16  m_MaxDamageIngredient[0] = 3; //-1 = disable check
17 
18  m_MinQuantityIngredient[0] = -1; //-1 = disable check
19  m_MaxQuantityIngredient[0] = -1; //-1 = disable check
20 
21  m_MinDamageIngredient[1] = -1; //-1 = disable check
22  m_MaxDamageIngredient[1] = 3; //-1 = disable check
23 
24  m_MinQuantityIngredient[1] = -1; //-1 = disable check
25  m_MaxQuantityIngredient[1] = -1; //-1 = disable check
26 
27  //INGREDIENTS
28  //ingredient 1
29  InsertIngredient(0, "Pelt_Base"); //you can insert multiple ingredients this way
30 
31  m_IngredientAddHealth[0] = 0; // 0 = do nothing
32  m_IngredientSetHealth[0] = -1; // -1 = do nothing
33  m_IngredientAddQuantity[0] = -1; // 0 = do nothing
34  m_IngredientDestroy[0] = true; //true = destroy, false = do nothing
35  m_IngredientUseSoftSkills[0] = false; // set 'true' to allow modification of the values by softskills on this ingredient
36 
37  //ingredient 2
38  InsertIngredient(1, "GardenLime"); //you can insert multiple ingredients this way
39 
40  m_IngredientAddHealth[1] = 0; // 0 = do nothing
41  m_IngredientSetHealth[1] = -1; // -1 = do nothing
42  m_IngredientAddQuantity[1] = 0; // 0 = do nothing
43  m_IngredientDestroy[1] = false; //true = destroy, false = do nothing
44  m_IngredientUseSoftSkills[1] = false; // set 'true' to allow modification of the values by softskills on this ingredient
45 
46  //----------------------------------------------------------------------------------------------------------------------
47 
48  //result1
49  AddResult("TannedLeather"); //add results here
50 
51  m_ResultSetFullQuantity[0] = false; //true = set full quantity, false = do nothing
52  m_ResultSetQuantity[0] = -1; //-1 = do nothing
53  m_ResultSetHealth[0] = -1; //-1 = do nothing
54  m_ResultInheritsHealth[0] = -2; // (value) == -1 means do nothing; a (value) >= 0 means this result will inherit health from ingredient number (value);(value) == -2 means this result will inherit health from all ingredients averaged(result_health = combined_health_of_ingredients / number_of_ingredients)
55  m_ResultInheritsColor[0] = -1; // (value) == -1 means do nothing; a (value) >= 0 means this result classname will be a composite of the name provided in AddResult method and config value "color" of ingredient (value)
56  m_ResultToInventory[0] = -2; //(value) == -2 spawn result on the ground;(value) == -1 place anywhere in the players inventory, (value) >= 0 means switch position with ingredient number(value)
57  m_ResultUseSoftSkills[0] = false; // set 'true' to allow modification of the values by softskills on this result
58  m_ResultReplacesIngredient[0] = -1; // value == -1 means do nothing; a value >= 0 means this result will transfer item propertiesvariables, attachments etc.. from an ingredient value
59  }
60 
61  override bool CanDo(ItemBase ingredients[], PlayerBase player)//final check for recipe's validity
62  {
63 
64  //return true;
65  Pelt_Base ingredient1 = Pelt_Base.Cast(ingredients[0]);
66  ItemBase ingredient2 = ingredients[1]; //The garden lime
67 
68  //Evaluate the amount of Lime required to craft leather from Pelt (percentage based)
69  float yieldQuantity = ingredient1.ConfigGetFloat("leatherYield");
70  float qtyModifier = (4 - ingredient1.GetHealthLevel(""))/4; // Normalize the health level so Pristine is 1 and Ruined is 0
71  yieldQuantity = yieldQuantity * qtyModifier;
72 
73  float m_NeededQuantity = (ingredient2.GetQuantityMax() * m_PercentageUsed) * yieldQuantity;
74  if( ingredient1.ConfigGetFloat("leatherYield") >= 0 && ingredient2.GetQuantity() >= m_NeededQuantity)
75  {
76  return true;
77  }
78  else
79  {
80  return false;
81  }
82 
83  }
84 
85 
86  override void Do( ItemBase ingredients[], PlayerBase player, array<ItemBase> results, float specialty_weight )//gets called upon recipe's completion
87  {
88  Debug.Log("Craft Tanned Leather","recipes");
89 
90  ItemBase result;
91  Class.CastTo(result, results.Get(0));
92  ItemBase ingredient1 = ingredients[0];
93 
94  //Set tanned leather output quantity
95  int quantity = ingredient1.ConfigGetFloat("leatherYield");
96  float qtyModifier = (4 - ingredient1.GetHealthLevel(""))/4; // Normalize the health level so Pristine is 1 and Ruined is 0
97  quantity = quantity * qtyModifier;
98 
99  result.SetQuantity(quantity);
100 
101  //Use X% of GardenLime for each tanned leather item crafted
102  ItemBase gardenLime = ingredients[1];
103  float usedLime = (gardenLime.GetQuantityMax() * m_PercentageUsed) * quantity;
104  gardenLime.SetQuantity(gardenLime.GetQuantity() - usedLime);
105 
106  result.SetHealthMax("","");
107 
108  //Split stack if returned quantity over Max stack
109  if (quantity > result.GetQuantityMax())
110  {
111  //Allow spawn of a second stack of tanned leather
112  MiscGameplayFunctions.CreateItemBasePiles("TannedLeather", player.GetPosition(), (quantity - 8), result.GetMaxHealth() ,false);
113  }
114  }
115 }
ItemBase
Definition: inventoryitem.c:730
Do
override protected void Do(PlayerBase player)
Definition: spookyareamisc.c:13
Pelt_Base
class Pelt_Base extends ItemBase Pelt_Base
m_Name
string m_Name
Definition: bioslobbyservice.c:35
RecipeBase
Definition: recipebase.c:4
PlayerBase
Definition: playerbaseclient.c:1
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
CanDo
override protected bool CanDo(PlayerBase player, TStringVectorMap surfaceTypes)
Definition: spookyareamisc.c:8
array< ItemBase >
Debug
Definition: debug.c:13
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10