Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
barrel_colorbase.c
Go to the documentation of this file.
2 {
3  private bool m_IsLocked = false;
4  private ref Timer m_BarrelOpener;
5 
6  protected ref RainProcurementComponentBarrel m_RainProcComponent;
7  protected ref OpenableBehaviour m_Openable;
8 
9  void Barrel_ColorBase()
10  {
11  m_BarrelOpener = new Timer();
12 
13  m_Openable = new OpenableBehaviour(false);
14  m_RainProcurement = new RainProcurementManager(this); //legacy reasons
15  m_RainProcComponent = new RainProcurementComponentBarrel(this);
16 
17  m_HalfExtents = Vector(0.30,0.85,0.30);
18 
19  RegisterNetSyncVariableBool("m_Openable.m_IsOpened");
20  RegisterNetSyncVariableBool("m_IsSoundSynchRemote");
21  RegisterNetSyncVariableBool("m_IsPlaceSound");
22  }
23 
24  override int GetDamageSystemVersionChange()
25  {
26  return 110;
27  }
28 
29  override void EECargoIn(EntityAI item)
30  {
31  super.EECargoIn(item);
32 
33  MiscGameplayFunctions.SoakItemInsideParentContainingLiquidAboveThreshold(ItemBase.Cast(item), this);
34  }
35 
36  override void OnStoreSave( ParamsWriteContext ctx )
37  {
38  super.OnStoreSave( ctx );
39 
40  ctx.Write( m_Openable.IsOpened() );
41  }
42 
43  override bool OnStoreLoad( ParamsReadContext ctx, int version )
44  {
45  if ( !super.OnStoreLoad( ctx, version ) )
46  return false;
47 
48  bool opened;
49  if ( version >= 110 && !ctx.Read( opened ) )
50  {
51  return false;
52  }
53 
54  if ( opened )
55  {
56  OpenLoad();
57  }
58  else
59  {
60  CloseLoad();
61  }
62 
63  return true;
64  }
65 
66  bool IsLocked()
67  {
68  return m_IsLocked;
69  }
70 
71  override void Open()
72  {
73  m_Openable.Open();
74  m_RainProcComponent.StartRainProcurement();
76  SetTakeable(false);
77 
78  UpdateVisualState();
79  }
80 
81  void OpenLoad()
82  {
83  m_Openable.Open();
84  m_RainProcComponent.StartRainProcurement();
85  SetSynchDirty();
86  SetTakeable(false);
87 
88  UpdateVisualState();
89  }
90 
91  override void Close()
92  {
93  m_Openable.Close();
94  m_RainProcComponent.StopRainProcurement();
96  SetTakeable(true);
97 
98  UpdateVisualState();
99  }
100 
101  void CloseLoad()
102  {
103  m_Openable.Close();
104  m_RainProcComponent.StopRainProcurement();
105  SetSynchDirty();
106  SetTakeable(true);
107 
108  UpdateVisualState();
109  }
110 
111  override bool IsOpen()
112  {
113  return m_Openable.IsOpened();
114  }
115 
116  override void OnWasAttached( EntityAI parent, int slot_id)
117  {
118  super.OnWasAttached(parent, slot_id);
119 
120  Open();
121  }
122 
123  override void OnWasDetached(EntityAI parent, int slot_id)
124  {
125  super.OnWasDetached(parent, slot_id);
126 
127  Close();
128  }
129 
130  protected void UpdateVisualState()
131  {
132  if ( IsOpen() )
133  {
134  SetAnimationPhase("Lid",1);
135  SetAnimationPhase("Lid2",0);
136  }
137  else
138  {
139  SetAnimationPhase("Lid",0);
140  SetAnimationPhase("Lid2",1);
141  }
142  }
143 
144  override void OnVariablesSynchronized()
145  {
146  super.OnVariablesSynchronized();
147 
148  if ( IsPlaceSound() )
149  {
150  PlayPlaceSound();
151  }
152  else if ( IsSoundSynchRemote() && !IsBeingPlaced() && m_Initialized )
153  {
154  if ( IsOpen() )
155  {
156  SoundBarrelOpenPlay();
157  }
158  else if ( !IsOpen() )
159  {
160  SoundBarrelClosePlay();
161  }
162  }
163  UpdateVisualState();
164  }
165 
166  void SoundBarrelOpenPlay()
167  {
168  EffectSound sound = SEffectManager.PlaySound( "barrel_open_SoundSet", GetPosition() );
169  sound.SetAutodestroy( true );
170  }
171 
172  void SoundBarrelClosePlay()
173  {
174  EffectSound sound = SEffectManager.PlaySound( "barrel_close_SoundSet", GetPosition() );
175  sound.SetAutodestroy( true );
176  }
177 
178  void Lock(float actiontime)
179  {
180  m_IsLocked = true;
181  m_BarrelOpener.Run(actiontime, this, "Unlock", NULL,false);
182  }
183 
184  void Unlock()
185  {
186  m_IsLocked = false;
187  Open();
188  }
189 
190  void DetermineAction ( PlayerBase player )
191  {
192  int slot_id;
193  ItemBase ingredient;
194  slot_id = InventorySlots.GetSlotIdFromString("Lime");
195  ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
196  if ( ingredient && GetQuantity() > 10000 )
197  {
198  TanPelts(ingredient, player);
199  }
200  else
201  {
202  slot_id = InventorySlots.GetSlotIdFromString("Material_Nails");
203  ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
204  if ( ingredient && GetQuantity() > 10000 )
205  {
206  ColourLeatherClothes(ingredient, player, "Black");
207  }
208  else
209  {
210  slot_id = InventorySlots.GetSlotIdFromString("BirchBark");
211  ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
212  if ( ingredient && GetQuantity() > 10000 )
213  {
214  ColourLeatherClothes(ingredient, player, "Beige");
215  }
216  else
217  {
218  slot_id = InventorySlots.GetSlotIdFromString("OakBark");
219  ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
220  if ( ingredient && GetQuantity() > 10000 )
221  {
222  ColourLeatherClothes(ingredient, player, "Brown");
223  }
224  else
225  {
226 
227  slot_id = InventorySlots.GetSlotIdFromString("Disinfectant");
228  ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
229  if ( ingredient && GetQuantity() > 10000 )
230  {
231  BleachClothes(ingredient, player);
232  }
233  else
234  {
235  slot_id = InventorySlots.GetSlotIdFromString("Plant");
236  ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
237  slot_id = InventorySlots.GetSlotIdFromString("Guts");
238  ItemBase reactant = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
239  if ( ingredient && reactant && GetQuantity() > 5000 )
240  {
241  ProduceFertilizer(ingredient,reactant,player);
242  }
243  else
244  {
245  slot_id = InventorySlots.GetSlotIdFromString("BerryR");
246  ItemBase ingredientR = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
247  slot_id = InventorySlots.GetSlotIdFromString("Plant");
248  ItemBase ingredientG = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
249  slot_id = InventorySlots.GetSlotIdFromString("BerryB");
250  ItemBase ingredientB = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
251  if ( (ingredientR || ingredientG || ingredientB) && GetQuantity() > 10000)
252  {
253  ColourClothes(ingredientR,ingredientG,ingredientB,player);
254  }
255  }
256  }
257  }
258  }
259  }
260  }
261  Close();
262  }
263 
264  void ProduceFertilizer( ItemBase guts, ItemBase plant, PlayerBase player )
265  {
266  float lime_quantity = plant.GetQuantity()*GameConstants.BAREL_LIME_PER_PLANT;
267 
268  guts.Delete();
269  plant.Delete();
270 
271  ItemBase lime = ItemBase.Cast( GetInventory().CreateInInventory("GardenLime") );
272 
273  lime.SetQuantity(lime_quantity);
274  Lock(50);
275  }
276 
277  void TanPelts( ItemBase lime, PlayerBase player )
278  {
279  EntityAI item;
280  int item_count = GetInventory().GetCargo().GetItemCount();
281  int pelt_count = 0;
282  int lime_amount = Math.Floor(lime.GetQuantity()/GameConstants.BAREL_LIME_PER_PELT);
283 
284 
285  for (int i = 0; i < item_count; i++)
286  {
287  item = GetInventory().GetCargo().GetItem(i);
288  if ( item.IsPeltBase() )
289  {
290  pelt_count = g_Game.ConfigGetInt("cfgVehicles " + item.GetType() + " peltGain");
291  if ( pelt_count <= lime_amount )
292  {
293  TanLeatherLambda lambda = new TanLeatherLambda(item, "TannedLeather", player, pelt_count);
294  lambda.SetTransferParams(true, true, true);
295  player.ServerReplaceItemWithNew(lambda);
296 
297  lime_amount -= pelt_count;
298  if ( lime_amount <= 0 )
299  {
300  lime.Delete();
301  break;
302  }
303  }
304  }
305  }
306  if ( lime )
307  {
308  lime.SetQuantity(lime_amount*GameConstants.BAREL_LIME_PER_PELT);
309  }
310  if ( pelt_count > 0 )
311  {
312  Lock(30);
313  }
314  }
315 
316  void ColourLeatherClothes( ItemBase color_source, PlayerBase player, string color )
317  {
318  EntityAI item;
319  int item_count = GetInventory().GetCargo().GetItemCount();
320  string item_name = "";
321 
322 
323  for (int i = 0; i < item_count; i++)
324  {
325  item = GetInventory().GetCargo().GetItem(i);
326  if ( item.IsClothing() )
327  {
328  if ( GetGame().ObjectIsKindOf (item, "LeatherSack_Natural") )
329  {
330  item_name = "Bag_LeatherSack_"+color;
331  }
332  else if ( GetGame().ObjectIsKindOf (item, "LeatherStorageVest_Natural") )
333  {
334  item_name = "Vest_LeatherStorage_"+color;
335  }
336  else if ( GetGame().ObjectIsKindOf (item, "LeatherJacket_Natural") )
337  {
338  item_name = "Top_LeatherJacket_"+color;
339  }
340  else if ( GetGame().ObjectIsKindOf (item, "LeatherPants_Natural") )
341  {
342  item_name = "Pants_LeatherPants_"+color;
343  }
344  else if ( GetGame().ObjectIsKindOf (item, "LeatherMoccasinsShoes_Natural") )
345  {
346  item_name = "Shoes_LeatherMoccasins_"+color;
347  }
348  else if ( GetGame().ObjectIsKindOf (item, "LeatherHat_Natural") )
349  {
350  item_name = "Hat_Leather_"+color;
351  }
352  if ( item_name != "" )
353  {
354  TurnItemIntoItemLambda lambda = new TurnItemIntoItemLambda(item, item_name, player);
355  lambda.SetTransferParams(true, true, true);
356  player.ServerReplaceItemWithNew(lambda);
357  }
358  }
359  }
360  if ( item_name != "" )
361  {
362  Lock(20);
363  }
364  }
365 
366 
367  void BleachClothes( ItemBase bleach, PlayerBase player )
368  {
369  EntityAI item;
370  int bleach_amount = bleach.GetQuantity();
371  int item_count = GetInventory().GetCargo().GetItemCount();
372  string item_name = "";
373 
374  for (int i = 0; i < item_count; i++)
375  {
376  item = GetInventory().GetCargo().GetItem(i);
377  if ( item.IsClothing() )
378  {
379  if ( bleach_amount >= GameConstants.BAREL_BLEACH_PER_CLOTH )
380  {
381  if ( ( GetGame().ObjectIsKindOf (item, "TShirt_ColorBase") && !GetGame().ObjectIsKindOf (item, "TShirt_White") ) || ( GetGame().ObjectIsKindOf (item, "Armband_ColorBase") && !GetGame().ObjectIsKindOf (item, "Armband_White") ) ) //cannot bleach white items...?
382  {
383  int index = item.GetType().IndexOf("_");
384  string itemtype = item.GetType().Substring( 0, index + 1 );
385  ItemBase itemIB = ItemBase.Cast(item);
386  MiscGameplayFunctions.TurnItemIntoItem(itemIB,itemtype+"White",player);
387 
388  bleach_amount -= GameConstants.BAREL_BLEACH_PER_CLOTH;
389  }
390  if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherSack_ColorBase") )
391  {
392  item_name = "LeatherSack_Natural";
393  }
394  else if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherStorageVest_ColorBase") )
395  {
396  item_name = "LeatherStorageVest_Natural";
397  }
398  else if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherJacket_ColorBase") )
399  {
400  item_name = "LeatherJacket_Natural";
401  }
402  else if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherPants_ColorBase") )
403  {
404  item_name = "LeatherPants_Natural";
405  }
406  else if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherMoccasinsShoes_ColorBase") )
407  {
408  item_name = "LeatherMoccasinsShoes_Natural";
409  }
410  else if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherHat_ColorBase") )
411  {
412  item_name = "LeatherHat_Natural";
413  }
414  if ( item_name != "" )
415  {
416  TurnItemIntoItemLambda lambda = new TurnItemIntoItemLambda(item, item_name, player);
417  lambda.SetTransferParams(true, true, true);
418  player.ServerReplaceItemWithNew(lambda);
419  bleach_amount -= GameConstants.BAREL_BLEACH_PER_CLOTH;
420  }
421  }
422  else
423  {
424  bleach.Delete();
425  break;
426  }
427  }
428  }
429  if ( bleach )
430  {
431  bleach.SetQuantity(bleach_amount);
432  }
433  if ( item_name != "" )
434  {
435  Lock(10);
436  }
437  }
438 
439  void ColourClothes( ItemBase rci, ItemBase gci, ItemBase bci, PlayerBase player )
440  {
441  EntityAI item;
442  float r = 0;
443  float g = 0;
444  float b = 0;
445  float a = 1; //alpha
446  int item_count = GetInventory().GetCargo().GetItemCount();
447  bool was_colored = false;
448  if ( rci )
449  {
450  r = rci.GetQuantity()/10;
451  r = Math.Clamp(r, 0, 0.78); //TODO adjust clamp as needed, full RGB would result in a white item
452  }
453  if ( gci )
454  {
455  g = gci.GetQuantity()/10;
456  g = Math.Clamp(g, 0, 0.78);
457  }
458  if ( bci )
459  {
460  b = bci.GetQuantity()/10;
461  b = Math.Clamp(b, 0, 0.78);
462  }
463  for (int i = 0; i < item_count; i++)
464  {
465  item = GetInventory().GetCargo().GetItem(i);
466  if ( item.IsClothing() )
467  {
468  if ( GetGame().ObjectIsKindOf (item, "TShirt_White") || GetGame().ObjectIsKindOf (item, "Armband_White") )
469  {
470  ItemBase itemIB = ItemBase.Cast(item);
471  int index = itemIB.GetType().IndexOf("_");
472  string itemtype = itemIB.GetType().Substring( 0, index + 1 );
473 
474  ColourClothesLambda clambda = new ColourClothesLambda(itemIB, itemtype + "Dyed", player, r, g, b, a);
475  clambda.SetTransferParams(true, true, true);
476  MiscGameplayFunctions.TurnItemIntoItemEx(player, clambda);
477  was_colored = true;
478  }
479  }
480  }
481 
482  if ( was_colored )
483  {
484  if ( rci )
485  {
486  //rci.AddQuantity(-r*10,true,false);
487  rci.Delete();
488  }
489  if ( gci )
490  {
491  //gci.AddQuantity(-g*10,true,false);
492  gci.Delete();
493  }
494  if ( bci )
495  {
496  //bci.AddQuantity(-b*10,true,false);
497  bci.Delete();
498  }
499  Lock(30);
500  }
501  }
502 
503  override bool CanPutInCargo( EntityAI parent )
504  {
505  if ( !super.CanPutInCargo( parent ))
506  return false;
507 
508  if ( GetNumberOfItems() == 0 && !IsOpen() )
509  return true;
510 
511  return false;
512  }
513 
514  override bool CanPutIntoHands( EntityAI parent )
515  {
516  if ( !super.CanPutIntoHands( parent ))
517  return false;
518 
519  if ( GetNumberOfItems() == 0 && (GetInventory().IsAttachment() || !IsOpen()) )
520  return true;
521 
522  return false;
523  }
524 
525  override bool CanReceiveItemIntoCargo( EntityAI item )
526  {
527  if ( IsOpen() )
528  return super.CanReceiveItemIntoCargo( item );
529 
530  return false;
531  }
532 
533  override bool CanReleaseCargo( EntityAI attachment )
534  {
535  return IsOpen();
536  }
537 
538  override bool CanDetachAttachment( EntityAI parent )
539  {
540  if ( GetNumberOfItems() == 0)
541  return true;
542  return false;
543  }
544 
545  //================================================================
546  // ADVANCED PLACEMENT
547  //================================================================
548  override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
549  {
550  super.OnPlacementComplete( player, position, orientation );
551 
552  SetIsPlaceSound( true );
553  }
554 
555  override string GetPlaceSoundset()
556  {
557  return "placeBarrel_SoundSet";
558  }
559  //================================================================
560 
561  override float GetLiquidThroughputCoef()
562  {
564  }
565 
566  override void SetActions()
567  {
569  super.SetActions();
570 
573 
574  }
575 
576  override void OnDebugSpawn()
577  {
578  SetQuantityMax();
579  }
580 
582  //OUBLIETTE OF THE DEPRECATED CODE//
584  ref RainProcurementManager m_RainProcurement; //DEPRECATED
585 };
586 
591 
593 {
594  int r, g, b, a;
595  void ColourClothesLambda(EntityAI old_item, string new_item_type, PlayerBase player, int rr, int gg, int bb, int aa)
596  { r = rr; g = gg; b = bb; a = aa; }
597 
598  override void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
599  {
600  super.CopyOldPropertiesToNew(old_item, new_item);
601 
602  //Print("ColourClothesLambda::OnCreated object=" + new_item);
603  ItemBase ib = ItemBase.Cast(new_item);
604  if ( new_item )
605  {
606  new_item.SetObjectTexture(new_item.GetHiddenSelectionsData().GetHiddenSelectionIndex( "personality" ), MiscGameplayFunctions.GetColorString(r, g, b, a));
607 
608  //nitem.SetItemVariableString("varColor", color); //SYNCFAIL
609  ib.SetColor(r*255, g*255, b*255, a*255);
610  }
611  }
612 };
613 
615 {
616  int m_PeltCount;
617 
618  void TanLeatherLambda (EntityAI old_item, string new_item_type, PlayerBase player, int pelt_count) { m_PeltCount = pelt_count; }
619 
620  override void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
621  {
622  super.CopyOldPropertiesToNew(old_item, new_item);
623 
624  if (new_item)
625  {
626  ItemBase tanned_pelt = ItemBase.Cast( new_item );
627  tanned_pelt.SetQuantity(m_PeltCount);
628  }
629  else
630  {
631  Debug.LogError("TanLeatherLambda: failed to create new item","static");
632  }
633  }
634 };
ItemBase
Definition: inventoryitem.c:730
RainProcurementComponentBarrel
Definition: rainprocurementcomponent.c:89
GetGame
proto native CGame GetGame()
Barrel_Yellow
Definition: barrel_colorbase.c:590
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
Barrel_Red
Definition: barrel_colorbase.c:589
ActionAttachOnSelection
Definition: actionattachonselection.c:1
m_HalfExtents
Container_Base m_HalfExtents
LIQUID_THROUGHPUT_BARREL
const float LIQUID_THROUGHPUT_BARREL
Definition: constants.c:531
ActionOpenBarrel
Definition: actionopenbarrel.c:1
Barrel_Blue
Definition: barrel_colorbase.c:588
GetQuantity
override float GetQuantity()
Definition: itembase.c:3316
Barrel_Green
Definition: barrel_colorbase.c:587
IsPlaceSound
bool IsPlaceSound()
Definition: itembase.c:4288
m_IsLocked
bool m_IsLocked
Definition: modifierbase.c:27
SetTakeable
override void SetTakeable(bool pState)
Definition: itembase.c:4226
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
DeployableContainer_Base
void DeployableContainer_Base()
Definition: container_base.c:36
TanLeatherLambda
Definition: barrel_colorbase.c:614
RainProcurementManager
DEPRECATED, done through the RainProcurementHandler / component instead.
Definition: rainprocurementmanager.c:2
PlayPlaceSound
void PlayPlaceSound()
Definition: itembase.c:4348
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
SetIsPlaceSound
void SetIsPlaceSound(bool is_place_sound)
Definition: itembase.c:4283
OpenableBehaviour
Definition: openablebehaviour.c:1
ActionCloseBarrel
Definition: actionclosebarrel.c:1
IsBeingPlaced
override bool IsBeingPlaced()
Definition: itembase.c:946
GameConstants
Definition: constants.c:612
Debug
Definition: debug.c:13
GetNumberOfItems
int GetNumberOfItems()
Returns the number of items in cargo, otherwise returns 0(non-cargo objects). Recursive.
Definition: itembase.c:3380
Barrel_ColorBase
Definition: barrel_colorbase.c:1
m_Initialized
protected bool m_Initialized
Definition: uihintpanel.c:23
Timer
Definition: dayzplayerimplement.c:62
SetQuantityMax
void SetQuantityMax()
Definition: itembase.c:3226
Math
Definition: enmath.c:6
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
TurnItemIntoItemLambda
Definition: miscgameplayfunctions.c:91
EntityAI
Definition: building.c:5
IsSoundSynchRemote
bool IsSoundSynchRemote()
Definition: itembase.c:4273
ColourClothesLambda
Definition: barrel_colorbase.c:592
SoundSynchRemote
void SoundSynchRemote()
Definition: itembase.c:4266