DayZ 1.24
Loading...
Searching...
No Matches
Barrel_ColorBase.c
Go to the documentation of this file.
1class Barrel_ColorBase : DeployableContainer_Base
2{
3 private bool m_IsLocked = false;
5
8
10 {
11 m_BarrelOpener = new Timer();
12
13 m_Openable = new OpenableBehaviour(false);
14 m_RainProcurement = new RainProcurementManager(this); //legacy reasons
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
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
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 return false;
51
52 if (opened)
53 OpenLoad();
54 else
55 CloseLoad();
56
57 return true;
58 }
59
60 bool IsLocked()
61 {
62 return m_IsLocked;
63 }
64
65 override void Open()
66 {
67 m_Openable.Open();
68 m_RainProcComponent.StartRainProcurement();
70 SetTakeable(false);
71
73 }
74
75 void OpenLoad()
76 {
77 m_Openable.Open();
78 m_RainProcComponent.StartRainProcurement();
79 SetSynchDirty();
80 SetTakeable(false);
81
83 }
84
85 override void Close()
86 {
87 m_Openable.Close();
88 m_RainProcComponent.StopRainProcurement();
90 SetTakeable(true);
91
93 }
94
95 void CloseLoad()
96 {
97 m_Openable.Close();
98 m_RainProcComponent.StopRainProcurement();
99 SetSynchDirty();
100 SetTakeable(true);
101
103 }
104
105 override bool IsOpen()
106 {
107 return m_Openable.IsOpened();
108 }
109
110 override void OnWasAttached(EntityAI parent, int slot_id)
111 {
112 super.OnWasAttached(parent, slot_id);
113
114 Open();
115 }
116
117 override void OnWasDetached(EntityAI parent, int slot_id)
118 {
119 super.OnWasDetached(parent, slot_id);
120
121 Close();
122 }
123
124 protected void UpdateVisualState()
125 {
126 if (IsOpen())
127 {
128 SetAnimationPhase("Lid", 1);
129 SetAnimationPhase("Lid2", 0);
130 }
131 else
132 {
133 SetAnimationPhase("Lid", 0);
134 SetAnimationPhase("Lid2", 1);
135 }
136 }
137
139 {
140 super.OnVariablesSynchronized();
141
142 if (IsPlaceSound())
145 {
146 if (IsOpen())
148 else if (!IsOpen())
150 }
152 }
153
155 {
156 EffectSound sound = SEffectManager.PlaySound("barrel_open_SoundSet", GetPosition());
157 sound.SetAutodestroy(true);
158 }
159
161 {
162 EffectSound sound = SEffectManager.PlaySound("barrel_close_SoundSet", GetPosition());
163 sound.SetAutodestroy(true);
164 }
165
166 void Lock(float actiontime)
167 {
168 m_IsLocked = true;
169 m_BarrelOpener.Run(actiontime, this, "Unlock", NULL, false);
170 }
171
172 void Unlock()
173 {
174 m_IsLocked = false;
175 Open();
176 }
177
179 {
180 int slot_id;
183 ingredient = ItemBase.Cast(GetInventory().FindAttachment(slot_id));
184 if (ingredient && GetQuantity() > 10000)
186 else
187 {
188 slot_id = InventorySlots.GetSlotIdFromString("Material_Nails");
189 ingredient = ItemBase.Cast(GetInventory().FindAttachment(slot_id));
190 if (ingredient && GetQuantity() > 10000)
192 else
193 {
195 ingredient = ItemBase.Cast(GetInventory().FindAttachment(slot_id));
196 if (ingredient && GetQuantity() > 10000)
198 else
199 {
201 ingredient = ItemBase.Cast(GetInventory().FindAttachment(slot_id));
202 if (ingredient && GetQuantity() > 10000)
204 else
205 {
206
208 ingredient = ItemBase.Cast(GetInventory().FindAttachment(slot_id));
209 if (ingredient && GetQuantity() > 10000)
211 else
212 {
214 ingredient = ItemBase.Cast(GetInventory().FindAttachment(slot_id));
216 ItemBase reactant = ItemBase.Cast(GetInventory().FindAttachment(slot_id));
217 if (ingredient && reactant && GetQuantity() > 5000)
219 else
220 {
222 ItemBase ingredientR = ItemBase.Cast(GetInventory().FindAttachment(slot_id));
224 ItemBase ingredientG = ItemBase.Cast(GetInventory().FindAttachment(slot_id));
226 ItemBase ingredientB = ItemBase.Cast(GetInventory().FindAttachment(slot_id));
227 if ((ingredientR || ingredientG || ingredientB) && GetQuantity() > 10000)
229 }
230 }
231 }
232 }
233 }
234 }
235 Close();
236 }
237
239 {
241
242 guts.Delete();
243 plant.Delete();
244
245 ItemBase lime = ItemBase.Cast(GetInventory().CreateInInventory("GardenLime"));
246
247 lime.SetQuantity(lime_quantity);
248 Lock(50);
249 }
250
252 {
254 int item_count = GetInventory().GetCargo().GetItemCount();
255 int pelt_count = 0;
257
258
259 for (int i = 0; i < item_count; i++)
260 {
261 item = GetInventory().GetCargo().GetItem(i);
262 if (item.IsPeltBase())
263 {
264 pelt_count = g_Game.ConfigGetInt("cfgVehicles " + item.GetType() + " peltGain");
265 if (pelt_count <= lime_amount)
266 {
268 lambda.SetTransferParams(true, true, true);
269 player.ServerReplaceItemWithNew(lambda);
270
272 if (lime_amount <= 0)
273 {
274 lime.Delete();
275 break;
276 }
277 }
278 }
279 }
280 if (lime)
282 if (pelt_count > 0)
283 Lock(30);
284 }
285
287 {
289 int item_count = GetInventory().GetCargo().GetItemCount();
290 string item_name = "";
291
292
293 for (int i = 0; i < item_count; i++)
294 {
295 item = GetInventory().GetCargo().GetItem(i);
296 if (item.IsClothing())
297 {
298 if (GetGame().ObjectIsKindOf(item, "LeatherSack_Natural"))
299 item_name = "Bag_LeatherSack_" + color;
300 else if (GetGame().ObjectIsKindOf(item, "LeatherStorageVest_Natural"))
301 item_name = "Vest_LeatherStorage_" + color;
302 else if (GetGame().ObjectIsKindOf(item, "LeatherJacket_Natural"))
303 item_name = "Top_LeatherJacket_" + color;
304 else if (GetGame().ObjectIsKindOf(item, "LeatherPants_Natural"))
305 item_name = "Pants_LeatherPants_" + color;
306 else if (GetGame().ObjectIsKindOf(item, "LeatherMoccasinsShoes_Natural"))
307 item_name = "Shoes_LeatherMoccasins_" + color;
308 else if (GetGame().ObjectIsKindOf(item, "LeatherHat_Natural"))
309 item_name = "Hat_Leather_" + color;
310 if (item_name != "")
311 {
313 lambda.SetTransferParams(true, true, true);
314 player.ServerReplaceItemWithNew(lambda);
315 }
316 }
317 }
318 if (item_name != "")
319 Lock(20);
320 }
321
322
324 {
326 int bleach_amount = bleach.GetQuantity();
327 int item_count = GetInventory().GetCargo().GetItemCount();
328 string item_name = "";
329
330 for (int i = 0; i < item_count; i++)
331 {
332 item = GetInventory().GetCargo().GetItem(i);
333 if (item.IsClothing())
334 {
336 {
337 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...?
338 {
339 int index = item.GetType().IndexOf("_");
340 string itemtype = item.GetType().Substring(0, index + 1);
342 MiscGameplayFunctions.TurnItemIntoItem(itemIB, itemtype + "White", player);
343
345 }
346 if (GetGame().IsKindOf(item.GetDisplayName(), "LeatherSack_ColorBase"))
347 item_name = "LeatherSack_Natural";
348 else if (GetGame().IsKindOf(item.GetDisplayName(), "LeatherStorageVest_ColorBase"))
349 item_name = "LeatherStorageVest_Natural";
350 else if (GetGame().IsKindOf(item.GetDisplayName(), "LeatherJacket_ColorBase"))
351 item_name = "LeatherJacket_Natural";
352 else if (GetGame().IsKindOf(item.GetDisplayName(), "LeatherPants_ColorBase"))
353 item_name = "LeatherPants_Natural";
354 else if (GetGame().IsKindOf(item.GetDisplayName(), "LeatherMoccasinsShoes_ColorBase"))
355 item_name = "LeatherMoccasinsShoes_Natural";
356 else if (GetGame().IsKindOf(item.GetDisplayName(), "LeatherHat_ColorBase"))
357 item_name = "LeatherHat_Natural";
358 if (item_name != "")
359 {
361 lambda.SetTransferParams(true, true, true);
362 player.ServerReplaceItemWithNew(lambda);
364 }
365 }
366 else
367 {
368 bleach.Delete();
369 break;
370 }
371 }
372 }
373 if (bleach)
374 bleach.SetQuantity(bleach_amount);
375 if (item_name != "")
376 Lock(10);
377 }
378
380 {
382 float r = 0;
383 float g = 0;
384 float b = 0;
385 float a = 1; //alpha
386 int item_count = GetInventory().GetCargo().GetItemCount();
387 bool was_colored = false;
388 if (rci)
389 {
390 r = rci.GetQuantity() / 10;
391 r = Math.Clamp(r, 0, 0.78); //TODO adjust clamp as needed, full RGB would result in a white item
392 }
393 if (gci)
394 {
395 g = gci.GetQuantity() / 10;
396 g = Math.Clamp(g, 0, 0.78);
397 }
398 if (bci)
399 {
400 b = bci.GetQuantity() / 10;
401 b = Math.Clamp(b, 0, 0.78);
402 }
403 for (int i = 0; i < item_count; i++)
404 {
405 item = GetInventory().GetCargo().GetItem(i);
406 if (item.IsClothing())
407 {
408 if (GetGame().ObjectIsKindOf(item, "TShirt_White") || GetGame().ObjectIsKindOf(item, "Armband_White"))
409 {
411 int index = itemIB.GetType().IndexOf("_");
412 string itemtype = itemIB.GetType().Substring(0, index + 1);
413
415 clambda.SetTransferParams(true, true, true);
416 MiscGameplayFunctions.TurnItemIntoItemEx(player, clambda);
417 was_colored = true;
418 }
419 }
420 }
421
422 if (was_colored)
423 {
424 if (rci)
425 {
426 //rci.AddQuantity(-r*10,true,false);
427 rci.Delete();
428 }
429 if (gci)
430 {
431 //gci.AddQuantity(-g*10,true,false);
432 gci.Delete();
433 }
434 if (bci)
435 {
436 //bci.AddQuantity(-b*10,true,false);
437 bci.Delete();
438 }
439 Lock(30);
440 }
441 }
442
443 override bool CanPutInCargo(EntityAI parent)
444 {
445 if (!super.CanPutInCargo(parent))
446 return false;
447
448 if (GetNumberOfItems() == 0 && !IsOpen())
449 return true;
450
451 return false;
452 }
453
454 override bool CanPutIntoHands(EntityAI parent)
455 {
456 if (!super.CanPutIntoHands(parent))
457 return false;
458
459 if (GetNumberOfItems() == 0 && (GetInventory().IsAttachment() || !IsOpen()))
460 return true;
461
462 return false;
463 }
464
466 {
467 if (IsOpen())
468 return super.CanReceiveItemIntoCargo(item);
469
470 return false;
471 }
472
474 {
475 return IsOpen();
476 }
477
478 override bool CanDetachAttachment(EntityAI parent)
479 {
480 if (GetNumberOfItems() == 0)
481 return true;
482 return false;
483 }
484
485 //================================================================
486 // ADVANCED PLACEMENT
487 //================================================================
488 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
489 {
490 super.OnPlacementComplete(player, position, orientation);
491
492 SetIsPlaceSound(true);
493 }
494
495 override string GetPlaceSoundset()
496 {
497 return "placeBarrel_SoundSet";
498 }
499 //================================================================
500
501 override float GetLiquidThroughputCoef()
502 {
504 }
505
506 override void SetActions()
507 {
509 super.SetActions();
510
513
514 }
515
516 override void OnDebugSpawn()
517 {
519 }
520
522 //OUBLIETTE OF THE DEPRECATED CODE//
525};
526
531
533{
534 int r, g, b, a;
536 { r = rr; g = gg; b = bb; a = aa; }
537
539 {
540 super.CopyOldPropertiesToNew(old_item, new_item);
541
542 //Print("ColourClothesLambda::OnCreated object=" + new_item);
544 if (new_item)
545 {
546 new_item.SetObjectTexture(new_item.GetHiddenSelectionsData().GetHiddenSelectionIndex("personality"), MiscGameplayFunctions.GetColorString(r, g, b, a));
547
548 //nitem.SetItemVariableString("varColor", color); //SYNCFAIL
549 ib.SetColor(r * 255, g * 255, b * 255, a * 255);
550 }
551 }
552};
553
555{
557
559
561 {
562 super.CopyOldPropertiesToNew(old_item, new_item);
563
564 if (new_item)
565 {
567 tanned_pelt.SetQuantity(m_PeltCount);
568 }
569 else
570 Debug.LogError("TanLeatherLambda: failed to create new item", "static");
571 }
572};
void AddAction(typename actionName)
Container_Base m_HalfExtents
DayZGame g_Game
Definition DayZGame.c:3528
int GetNumberOfItems()
Returns the number of items in cargo, otherwise returns 0(non-cargo objects). Recursive.
Definition ItemBase.c:8059
void SetQuantityMax()
Definition ItemBase.c:7905
override float GetQuantity()
Definition ItemBase.c:7995
void PlayPlaceSound()
Definition ItemBase.c:9027
override void SetTakeable(bool pState)
Definition ItemBase.c:8905
void SetIsPlaceSound(bool is_place_sound)
Definition ItemBase.c:8962
void SoundSynchRemote()
Definition ItemBase.c:8945
bool IsPlaceSound()
Definition ItemBase.c:8967
override bool IsBeingPlaced()
Definition ItemBase.c:5625
bool IsSoundSynchRemote()
Definition ItemBase.c:8952
bool m_Initialized
class JsonUndergroundAreaTriggerData GetPosition
override void Close()
override bool CanDetachAttachment(EntityAI parent)
override bool CanPutInCargo(EntityAI parent)
override void Open()
override bool CanReleaseCargo(EntityAI attachment)
override void OnVariablesSynchronized()
override void OnDebugSpawn()
override bool OnStoreLoad(ParamsReadContext ctx, int version)
ref RainProcurementManager m_RainProcurement
override bool CanReceiveItemIntoCargo(EntityAI item)
void ColourLeatherClothes(ItemBase color_source, PlayerBase player, string color)
ref Timer m_BarrelOpener
override void EECargoIn(EntityAI item)
void BleachClothes(ItemBase bleach, PlayerBase player)
void ProduceFertilizer(ItemBase guts, ItemBase plant, PlayerBase player)
override string GetPlaceSoundset()
void DetermineAction(PlayerBase player)
override void OnWasDetached(EntityAI parent, int slot_id)
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
void ColourClothes(ItemBase rci, ItemBase gci, ItemBase bci, PlayerBase player)
override void SetActions()
void Lock(float actiontime)
override bool IsOpen()
override float GetLiquidThroughputCoef()
override int GetDamageSystemVersionChange()
override void OnStoreSave(ParamsWriteContext ctx)
override bool CanPutIntoHands(EntityAI parent)
override void OnWasAttached(EntityAI parent, int slot_id)
ref OpenableBehaviour m_Openable
ref RainProcurementComponentBarrel m_RainProcComponent
void TanPelts(ItemBase lime, PlayerBase player)
void ColourClothesLambda(EntityAI old_item, string new_item_type, PlayerBase player, int rr, int gg, int bb, int aa)
override void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
Definition Debug.c:14
static void LogError(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message as error message.
Definition Debug.c:341
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
Definition EnMath.c:7
DEPRECATED, done through the RainProcurementHandler / component instead.
Manager class for managing Effect (EffectParticle, EffectSound)
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
override void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
void TanLeatherLambda(EntityAI old_item, string new_item_type, PlayerBase player, int pelt_count)
proto native CGame GetGame()
const int BAREL_BLEACH_PER_CLOTH
Definition constants.c:824
const int BAREL_LIME_PER_PELT
Definition constants.c:823
const float BAREL_LIME_PER_PLANT
Definition constants.c:825
const float LIQUID_THROUGHPUT_BARREL
Definition constants.c:530
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Floor(float f)
Returns floor of value.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.