Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
openitem.c
Go to the documentation of this file.
1 class OpenItem
2 {
4  static void OpenAndSwitch(ItemBase item_tool, ItemBase item_target, PlayerBase player, float specialty_weight = 0)
5  {
6  array<int> spill_range = new array<int>;
7 
8  if( item_tool.ConfigIsExisting("OpenItemSpillRange") )
9  {
10  item_tool.ConfigGetIntArray("OpenItemSpillRange", spill_range );
11  }
12  else
13  {
14  Debug.LogError("OpenItemSpillRange config parameter missing, default values used ! ");
15  Error("OpenItemSpillRange config parameter missing, default values used !");
16  spill_range.Insert(0);
17  spill_range.Insert(100);
18  }
19  float spill_modificator = Math.RandomIntInclusive( spill_range.Get(0),spill_range.Get(1) ) / 100;
20 
21  OpenItem.SwitchItems(item_target, player, spill_modificator, specialty_weight);
22  }
23 
25  static void SwitchItems (EntityAI old_item, PlayerBase player, float spill_modificator, float specialty_weight)
26  {
27  string old_name = old_item.GetType();
28  string new_name = old_name + "_Opened";
29  OpenAndSwitchLambda l = new OpenAndSwitchLambda(old_item, new_name, player, spill_modificator, specialty_weight);
30  l.SetTransferParams(true, true, true, true);
31  MiscGameplayFunctions.TurnItemIntoItemEx(player, l);
32  }
33 };
34 
35 
37 {
38  float m_SpillModifier;
39  float m_SpecialtyWeight;
40  void OpenAndSwitchLambda (EntityAI old_item, string new_item_type, PlayerBase player, float spill_modificator, float specialty_weight) { m_SpillModifier = spill_modificator; m_SpecialtyWeight = specialty_weight; }
41 
42  override void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
43  {
44  super.CopyOldPropertiesToNew(old_item, new_item);
45  }
46 
47  override void OnSuccess (EntityAI new_item)
48  {
49  super.OnSuccess(new_item);
50 
51  ItemBase ib = ItemBase.Cast(new_item);
52  if ( new_item )
53  {
54  float quantity_old = ib.GetQuantity();
55  float spill_amount = quantity_old * m_SpillModifier;
56  spill_amount = m_Player.GetSoftSkillsManager().SubtractSpecialtyBonus(spill_amount, m_SpecialtyWeight);
57  float quantity_new = quantity_old - spill_amount;
58 
59  Debug.Log("quantity before spill: "+quantity_old.ToString());
60  Debug.Log("spill_amount: "+spill_amount.ToString());
61  Debug.Log("quantity_new: "+quantity_new.ToString());
62 
63  ib.SetQuantity(quantity_new);
64  }
65  }
66 };
67 
ItemBase
Definition: inventoryitem.c:730
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
PlayerBase
Definition: playerbaseclient.c:1
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
OpenItem
Definition: openitem.c:1
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
OpenAndSwitchLambda
Definition: openitem.c:36
Debug
Definition: debug.c:13
Math
Definition: enmath.c:6
m_SpecialtyWeight
protected float m_SpecialtyWeight
Definition: actionbase.c:68
TurnItemIntoItemLambda
Definition: miscgameplayfunctions.c:91
EntityAI
Definition: building.c:5