Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourcePlayerControllerInventoryComponent.c
Go to the documentation of this file.
2 {
5  STORAGE,
7 }
8 
9 void ScriptInvoker_ResourceOnPlayerInteraction(EResourcePlayerInteractionType interactionType, PlayerController playerController, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue);
11 typedef ScriptInvokerBase<ScriptInvokerActiveWidgetInteractionFunc> ScriptInvokerResourceOnPlayerInteraction;
12 
13 [ComponentEditorProps(category: "GameScripted/Resources", description: "")]
14 class SCR_ResourcePlayerControllerInventoryComponentClass : ScriptComponentClass
15 {
16 }
17 
18 typedef SCR_ResourceSystemSubscriptionHandle<SCR_ResourcePlayerControllerInventoryComponent> SCR_SCR_ResourcePlayerControllerInventoryComponentSubscriptionHandle;
19 
21 {
22  protected ref ScriptInvokerResourceOnPlayerInteraction m_OnPlayerInteractionInvoker;
23 
24  //------------------------------------------------------------------------------------------------
26  ScriptInvokerResourceOnPlayerInteraction GetOnPlayerInteraction()
27  {
28  if (!m_OnPlayerInteractionInvoker)
29  m_OnPlayerInteractionInvoker = new ScriptInvokerResourceOnPlayerInteraction();
30 
31  return m_OnPlayerInteractionInvoker;
32  }
33 
34  //------------------------------------------------------------------------------------------------
35  protected SCR_ResourceActor TryGetGenerationActor(notnull SCR_ResourceComponent resourceComponent, EResourceType resourceType, out float currentResourceValue, out float maxResourceValue)
36  {
37  SCR_ResourceContainer containerFrom = resourceComponent.GetContainer(resourceType);
38 
39  if (containerFrom)
40  {
41  currentResourceValue = containerFrom.GetResourceValue();
42  maxResourceValue = containerFrom.GetMaxResourceValue();
43 
44  return containerFrom;
45  }
46 
47  SCR_ResourceGenerator generator = resourceComponent.GetGenerator(EResourceGeneratorID.DEFAULT_STORAGE, resourceType);
48 
49  if (generator)
50  {
51  currentResourceValue = generator.GetAggregatedResourceValue();
52  maxResourceValue = generator.GetAggregatedMaxResourceValue();
53 
54  return generator;
55  }
56 
57  generator = resourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_UNLOAD, resourceType);
58 
59  if (generator)
60  {
61  currentResourceValue = generator.GetAggregatedResourceValue();
62  maxResourceValue = generator.GetAggregatedMaxResourceValue();
63 
64  return generator;
65  }
66 
67  return null;
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  protected SCR_ResourceActor TryGetConsumptionActor(notnull SCR_ResourceComponent resourceComponent, EResourceType resourceType, out float currentResourceValue, out float maxResourceValue)
72  {
73  SCR_ResourceContainer containerFrom = resourceComponent.GetContainer(resourceType);
74 
75  if (containerFrom)
76  {
77  currentResourceValue = containerFrom.GetResourceValue();
78  maxResourceValue = containerFrom.GetMaxResourceValue();
79 
80  return containerFrom;
81  }
82 
83  SCR_ResourceConsumer consumer = resourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, resourceType);
84 
85  if (consumer)
86  {
87  currentResourceValue = consumer.GetAggregatedResourceValue();
88  maxResourceValue = consumer.GetAggregatedMaxResourceValue();
89 
90  return consumer;
91  }
92 
93  consumer = resourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, resourceType);
94 
95  if (consumer)
96  {
97  currentResourceValue = consumer.GetAggregatedResourceValue();
98  maxResourceValue = consumer.GetAggregatedMaxResourceValue();
99 
100  return consumer;
101  }
102 
103  return null;
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  protected bool TryPerformResourceConsumption(notnull SCR_ResourceActor actor, EResourceType resourceType, float resourceValue, bool ignoreOnEmptyBehavior = false)
108  {
109  SCR_ResourceContainer container = SCR_ResourceContainer.Cast(actor);
110 
111  if (container)
112  {
113  EResourceContainerOnEmptyBehavior emptyBehavior = container.GetOnEmptyBehavior();
114  SCR_ResourceEncapsulator encapsulator = container.GetResourceEncapsulator();
115 
116  if (ignoreOnEmptyBehavior)
117  container.SetOnEmptyBehavior(EResourceContainerOnEmptyBehavior.NONE);
118 
119  if (encapsulator)
120  encapsulator.RequestConsumtion(resourceValue);
121  else
122  container.DecreaseResourceValue(resourceValue);
123 
124  if (ignoreOnEmptyBehavior)
125  container.SetOnEmptyBehavior(emptyBehavior);
126 
127  return true;
128  }
129 
130  SCR_ResourceConsumer consumer = SCR_ResourceConsumer.Cast(actor);
131 
132  if (consumer)
133  {
134  consumer.RequestConsumtion(resourceValue);
135 
136  return true;
137  }
138 
139  return false;
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  protected bool TryPerformResourceGeneration(notnull SCR_ResourceActor actor, EResourceType resourceType, float resourceValue)
144  {
145  SCR_ResourceContainer container = SCR_ResourceContainer.Cast(actor);
146 
147  if (container)
148  {
149  SCR_ResourceEncapsulator encapsulator = container.GetResourceEncapsulator();
150 
151  if (encapsulator)
152  encapsulator.RequestGeneration(resourceValue);
153  else
154  container.IncreaseResourceValue(resourceValue);
155 
156  return true;
157  }
158 
159  SCR_ResourceGenerator generator = SCR_ResourceGenerator.Cast(actor);
160 
161  if (generator)
162  {
163  generator.RequestGeneration(resourceValue);
164 
165  return true;
166  }
167 
168  return false;
169  }
170 
171  //------------------------------------------------------------------------------------------------
177  void RequestSubscription(RplId resourceComponentRplId, typename interactorType, EResourceType resourceType, EResourceGeneratorID resourceIdentifier)
178  {
179  Rpc(RpcAsk_RequestSubscription, resourceComponentRplId, interactorType.ToString(), resourceType, resourceIdentifier);
180  }
181 
182  //------------------------------------------------------------------------------------------------
188  void RequestUnsubscription(RplId resourceComponentRplId, typename interactorType, EResourceType resourceType, EResourceGeneratorID resourceIdentifier)
189  {
190  Rpc(RpcAsk_RequestUnsubscription, resourceComponentRplId, interactorType.ToString(), resourceType, resourceIdentifier);
191  }
192 
193  //------------------------------------------------------------------------------------------------
199  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
200  void RpcAsk_RequestSubscription(RplId resourceComponentRplId, string interactorType, EResourceType resourceType, EResourceGeneratorID resourceIdentifier)
201  {
202  if (!resourceComponentRplId.IsValid())
203  return;
204 
205  SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.Cast(Replication.FindItem(resourceComponentRplId));
206 
207  if (!resourceComponent)
208  return;
209 
210  SCR_ResourceInteractor interactor;
211 
212  if (interactorType == "SCR_ResourceGenerator")
213  interactor = resourceComponent.GetGenerator(resourceIdentifier, resourceType);
214  else if (interactorType == "SCR_ResourceConsumer")
215  interactor = resourceComponent.GetConsumer(resourceIdentifier, resourceType);
216  else
217  return;
218 
219  GetGame().GetResourceSystemSubscriptionManager().SubscribeListener(Replication.FindId(this), interactor);
220  }
221 
222  //------------------------------------------------------------------------------------------------
228  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
229  void RpcAsk_RequestUnsubscription(RplId resourceComponentRplId, string interactorType, EResourceType resourceType, EResourceGeneratorID resourceIdentifier)
230  {
231  if (!resourceComponentRplId.IsValid())
232  return;
233 
234  SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.Cast(Replication.FindItem(resourceComponentRplId));
235 
236  if (!resourceComponent)
237  return;
238 
239  SCR_ResourceInteractor interactor;
240 
241  if (interactorType == "SCR_ResourceGenerator")
242  interactor = resourceComponent.GetGenerator(resourceIdentifier, resourceType);
243  else if (interactorType == "SCR_ResourceConsumer")
244  interactor = resourceComponent.GetConsumer(resourceIdentifier, resourceType);
245  else
246  return;
247 
248  GetGame().GetResourceSystemSubscriptionManager().UnsubscribeListener(Replication.FindId(this), interactor);
249  }
250 
251  //------------------------------------------------------------------------------------------------
258  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
259  void RpcAsk_OnPlayerInteraction(EResourcePlayerInteractionType interactionType, RplId rplIdResourceComponentFrom, RplId rplIdResourceComponentTo, EResourceType resourceType, float resourceValue)
260  {
261  if (!rplIdResourceComponentFrom.IsValid())
262  return;
263 
264  PlayerController playerController = PlayerController.Cast(GetOwner());
265 
266  if (!playerController)
267  return;
268 
269  SCR_ResourceComponent resourceComponentFrom = SCR_ResourceComponent.Cast(Replication.FindItem(rplIdResourceComponentFrom));
270 
271  if (!resourceComponentFrom)
272  return;
273 
274  SCR_ResourceComponent resourceComponentTo = SCR_ResourceComponent.Cast(Replication.FindItem(rplIdResourceComponentTo));
275 
276  OnPlayerInteraction(interactionType, resourceComponentFrom, resourceComponentTo, resourceType, resourceValue);
277  }
278 
279  //------------------------------------------------------------------------------------------------
286  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
287  void RpcAsk_ArsenalRequestItem(RplId rplIdResourceComponent, RplId rplIdInventoryManager, RplId rplIdStorageComponent, ResourceName resourceNameItem, EResourceType resourceType)
288  {
289  if (!rplIdInventoryManager.IsValid())
290  return;
291 
292  SCR_InventoryStorageManagerComponent inventoryManagerComponent = SCR_InventoryStorageManagerComponent.Cast(Replication.FindItem(rplIdInventoryManager));
293 
294  if (!inventoryManagerComponent)
295  return;
296 
297 
298  if (!rplIdStorageComponent.IsValid())
299  return;
300 
301  BaseInventoryStorageComponent storageComponent = BaseInventoryStorageComponent.Cast(Replication.FindItem(rplIdStorageComponent));
302 
303  if (!storageComponent)
304  return;
305 
306  if (!rplIdResourceComponent.IsValid())
307  return;
308 
309  SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.Cast(Replication.FindItem(rplIdResourceComponent));
310  if (!resourceComponent)
311  return;
312 
313  SCR_ResourceConsumer consumer = resourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, resourceType);
314  if (!consumer)
315  return;
316 
317  float resourceCost = 0;
318 
319  //~ Get item cost
320  SCR_EntityCatalogManagerComponent entityCatalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
321  if (entityCatalogManager)
322  {
323  IEntity resourcesOwner = resourceComponent.GetOwner();
324  if (!resourcesOwner)
325  return;
326 
327  //~ Get Supply cost only if arsenal has supplies enabled
328  SCR_ArsenalComponent arsenalComponent = SCR_ArsenalComponent.FindArsenalComponent(resourcesOwner);
329  if ((arsenalComponent && arsenalComponent.IsArsenalUsingSupplies()) || !arsenalComponent)
330  {
331  SCR_Faction faction;
332  if (arsenalComponent)
333  faction = arsenalComponent.GetAssignedFaction();
334 
336 
337  if (faction)
338  entry = entityCatalogManager.GetEntryWithPrefabFromFactionCatalog(EEntityCatalogType.ITEM, resourceNameItem, faction);
339  else
340  entry = entityCatalogManager.GetEntryWithPrefabFromCatalog(EEntityCatalogType.ITEM, resourceNameItem);
341 
342  if (entry)
343  {
344  SCR_ArsenalItem data = SCR_ArsenalItem.Cast(entry.GetEntityDataOfType(SCR_ArsenalItem));
345  if (data)
346  {
347  if (arsenalComponent)
348  resourceCost = data.GetSupplyCost(arsenalComponent.GetSupplyCostType());
349  else
350  resourceCost = data.GetSupplyCost(SCR_EArsenalSupplyCostType.DEFAULT);
351  }
352 
353  }
354  }
355  }
356 
357  SCR_ResourceConsumtionResponse response = consumer.RequestConsumtion(resourceCost * consumer.GetBuyMultiplier());
358 
359  if (response.GetReason() == EResourceReason.SUFFICIENT)
360  inventoryManagerComponent.TrySpawnPrefabToStorage(resourceNameItem, storageComponent);
361  }
362 
363  //------------------------------------------------------------------------------------------------
368  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
369  void RpcAsk_ArsenalRefundItem(RplId rplIdResourceComponent, RplId rplIdInventoryItem, EResourceType resourceType)
370  {
371  if (!rplIdInventoryItem.IsValid())
372  return;
373 
374  InventoryItemComponent inventoryItemComponent = InventoryItemComponent.Cast(Replication.FindItem(rplIdInventoryItem));
375 
376  if (!inventoryItemComponent)
377  return;
378 
379  if (!rplIdResourceComponent.IsValid())
380  return;
381 
382  SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.Cast(Replication.FindItem(rplIdResourceComponent));
383  if (!resourceComponent)
384  return;
385 
386  SCR_ResourceGenerator generator = resourceComponent.GetGenerator(EResourceGeneratorID.DEFAULT, resourceType);
387  if (!generator)
388  return;
389 
390  IEntity inventoryItemEntity = inventoryItemComponent.GetOwner();
391  if (!inventoryItemEntity)
392  return;
393 
394  float resourceCost = 0;
395 
396  //~ Get item cost
397  SCR_EntityCatalogManagerComponent entityCatalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
398  if (entityCatalogManager)
399  {
400  IEntity resourcesOwner = resourceComponent.GetOwner();
401  if (!resourcesOwner)
402  return;
403 
404  //~ Get Supply cost only if arsenal has supplies enabled
405  SCR_ArsenalComponent arsenalComponent = SCR_ArsenalComponent.FindArsenalComponent(resourcesOwner);
406  if ((arsenalComponent && arsenalComponent.IsArsenalUsingSupplies()) || !arsenalComponent)
407  {
408  SCR_Faction faction;
409  if (arsenalComponent)
410  faction = arsenalComponent.GetAssignedFaction();
411 
412  ResourceName resourceNameItem = inventoryItemEntity.GetPrefabData().GetPrefabName();
413 
414  SCR_EntityCatalogEntry entry = entityCatalogManager.GetEntryWithPrefabFromAnyCatalog(EEntityCatalogType.ITEM, resourceNameItem, faction);
415  if (!entry)
416  return;
417 
418  SCR_ArsenalItem data = SCR_ArsenalItem.Cast(entry.GetEntityDataOfType(SCR_ArsenalItem));
419  if (data)
420  {
421  if (arsenalComponent)
422  resourceCost = data.GetSupplyCost(arsenalComponent.GetSupplyCostType());
423  else
424  resourceCost = data.GetSupplyCost(SCR_EArsenalSupplyCostType.DEFAULT);
425  }
426 
427  }
428  }
429 
430  resourceCost = SCR_ResourceSystemHelper.RoundRefundSupplyAmount(resourceCost * generator.GetResourceMultiplier());
431 
432  //~ Check if it can refund if resource cost is greater than 0
433  if (resourceCost > 0)
434  {
435  SCR_ResourceGenerationResponse response = generator.RequestAvailability(resourceCost);
436  if (response.GetReason() != EResourceReason.SUFFICIENT)
437  return;
438  }
439 
440  IEntity parentEntity = inventoryItemEntity.GetParent();
441  SCR_InventoryStorageManagerComponent inventoryManagerComponent;
442 
443  if (parentEntity)
444  inventoryManagerComponent = SCR_InventoryStorageManagerComponent.Cast(parentEntity.FindComponent(SCR_InventoryStorageManagerComponent));
445 
446  if (inventoryManagerComponent && !inventoryManagerComponent.TryDeleteItem(inventoryItemEntity))
447  return;
448  else if (!inventoryManagerComponent)
449  RplComponent.DeleteRplEntity(inventoryItemEntity, false);
450 
451  generator.RequestGeneration(SCR_ResourceSystemHelper.RoundRefundSupplyAmount(resourceCost));
452  }
453 
454  //------------------------------------------------------------------------------------------------
459  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
460  void RpcAsk_MergeContainerWithContainer(RplId rplIdFrom, RplId rplIdTo, EResourceType resourceType)
461  {
462  if (!rplIdFrom.IsValid() || !rplIdTo.IsValid())
463  return;
464 
465  SCR_ResourceComponent componentFrom = SCR_ResourceComponent.Cast(Replication.FindItem(rplIdFrom));
466 
467  if (!componentFrom)
468  return;
469 
470  SCR_ResourceComponent componentTo = SCR_ResourceComponent.Cast(Replication.FindItem(rplIdTo));
471 
472  if (!componentTo)
473  return;
474 
475  float resourceValueCurrentFrom, resourceValueMaxFrom;
476  SCR_ResourceActor actorFrom = TryGetConsumptionActor(componentFrom, resourceType, resourceValueCurrentFrom, resourceValueMaxFrom);
477 
478  float resourceValueCurrentTo, resourceValueMaxTo;
479  SCR_ResourceActor actorTo = TryGetGenerationActor(componentTo, resourceType, resourceValueCurrentTo, resourceValueMaxTo);
480 
481  float resourceUsed = Math.Min(resourceValueCurrentFrom, resourceValueMaxTo - resourceValueCurrentTo);
482 
483  if(TryPerformResourceConsumption(actorFrom, resourceType, resourceUsed) && TryPerformResourceGeneration(actorTo, resourceType, resourceUsed))
484  OnPlayerInteraction(EResourcePlayerInteractionType.INVENTORY_SPLIT, componentFrom, componentTo, resourceType, resourceUsed);
485  }
486 
487  //------------------------------------------------------------------------------------------------
493  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
494  void RpcAsk_MergeContainerWithContainerPartial(RplId rplIdFrom, RplId rplIdTo, EResourceType resourceType, float requestedResources)
495  {
496  if (!rplIdFrom.IsValid() || !rplIdTo.IsValid())
497  return;
498 
499  SCR_ResourceComponent componentFrom = SCR_ResourceComponent.Cast(Replication.FindItem(rplIdFrom));
500 
501  if (!componentFrom)
502  return;
503 
504  SCR_ResourceComponent componentTo = SCR_ResourceComponent.Cast(Replication.FindItem(rplIdTo));
505 
506  if (!componentTo)
507  return;
508 
509  float resourceValueCurrentFrom, resourceValueMaxFrom;
510  SCR_ResourceActor actorFrom = TryGetConsumptionActor(componentFrom, resourceType, resourceValueCurrentFrom, resourceValueMaxFrom);
511 
512  float resourceValueCurrentTo, resourceValueMaxTo;
513  SCR_ResourceActor actorTo = TryGetGenerationActor(componentTo, resourceType, resourceValueCurrentTo, resourceValueMaxTo);
514 
515  float resourceUsed = Math.Min(Math.Min(resourceValueCurrentFrom, resourceValueMaxTo - resourceValueCurrentTo), requestedResources);
516 
517  if(TryPerformResourceConsumption(actorFrom, resourceType, resourceUsed) && TryPerformResourceGeneration(actorTo, resourceType, resourceUsed))
518  OnPlayerInteraction(EResourcePlayerInteractionType.INVENTORY_SPLIT, componentFrom, componentTo, resourceType, resourceUsed);
519  }
520 
521  //------------------------------------------------------------------------------------------------
528  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
529  void RpcAsk_CreatePhysicalContainerWithContainer(RplId rplIdResourceComponent, RplId rplIdInventoryManager, RplId rplIdStorageComponent, EResourceType resourceType, float requestedResources)
530  {
531  if (!rplIdResourceComponent.IsValid())
532  return;
533 
534  SCR_ResourceComponent resourceComponentFrom = SCR_ResourceComponent.Cast(Replication.FindItem(rplIdResourceComponent));
535 
536  if (!resourceComponentFrom)
537  return;
538 
539  float resourceValueCurrentFrom, resourceValueMaxFrom;
540  SCR_ResourceActor actorFrom = TryGetConsumptionActor(resourceComponentFrom, resourceType, resourceValueCurrentFrom, resourceValueMaxFrom);
541 
542  float resourceValueCurrentTo, resourceValueMaxTo;
543  SCR_ResourceActor actorConsumptionTo, actorGenerationTo;
544 
545  if (!rplIdInventoryManager.IsValid())
546  {
547  SCR_EntityCatalog resourceContainerCatalog = SCR_EntityCatalogManagerComponent.GetInstance().GetEntityCatalogOfType(EEntityCatalogType.SUPPLY_CONTAINER_ITEM);
548  array<SCR_EntityCatalogEntry> entries = {};
549  array<SCR_BaseEntityCatalogData> data = {};
551  float resourceUsed;
552  int selectedEntryIdx;
553 
554  resourceContainerCatalog.GetEntityListWithData(SCR_ResourceContainerItemData, entries, data);
555 
556  for (selectedEntryIdx = data.Count() - 1; selectedEntryIdx >= 0; --selectedEntryIdx)
557  {
558  datum = SCR_ResourceContainerItemData.Cast(data[selectedEntryIdx]);
559  resourceUsed = datum.GetMaxResourceValue();
560 
561  if (resourceUsed >= requestedResources)
562  break;
563  }
564 
565  if (selectedEntryIdx < 0)
566  selectedEntryIdx = 0;
567 
568  resourceUsed = Math.Min(resourceUsed, requestedResources);
569 
570  if (!TryPerformResourceConsumption(actorFrom, resourceType, resourceUsed))
571  return;
572 
573  RandomGenerator randGenerator = new RandomGenerator();
574  vector center = resourceComponentFrom.GetOwner().GetOrigin();
575  vector position = vector.Up * center[1] + randGenerator.GenerateRandomPointInRadius(0.0, 2.5, center);
576  TraceParam param = new TraceParam();
577  param.Start = position + "0.0 10.0 0.0";
578  param.End = position;
579  param.Flags = TraceFlags.WORLD | TraceFlags.ENTS;
580  param.LayerMask = EPhysicsLayerDefs.Projectile;
581 
582  float traced = GetGame().GetWorld().TraceMove(param, null);
583 
584  if (traced < 1)
585  position = (param.End - param.Start) * traced + param.Start;
586 
587  EntitySpawnParams spawnParams = new EntitySpawnParams();
588  spawnParams.TransformMode = ETransformMode.WORLD;
589  spawnParams.Transform[3] = position;
590  IEntity newStorageEntity = GetGame().SpawnEntityPrefab(Resource.Load(entries[selectedEntryIdx].GetPrefab()), GetGame().GetWorld(), spawnParams);
591  SCR_ResourceComponent resourceComponentTo = SCR_ResourceComponent.FindResourceComponent(newStorageEntity);
592  actorConsumptionTo = TryGetConsumptionActor(resourceComponentTo, resourceType, resourceValueCurrentTo, resourceValueMaxTo);
593  actorGenerationTo = TryGetGenerationActor(resourceComponentTo, resourceType, resourceValueCurrentTo, resourceValueMaxTo);
594 
595  TryPerformResourceConsumption(actorConsumptionTo, resourceType, resourceValueCurrentTo, true);
596 
597  if (TryPerformResourceGeneration(actorGenerationTo, resourceType, resourceUsed))
598  {
599  OnPlayerInteraction(EResourcePlayerInteractionType.INVENTORY_SPLIT, resourceComponentFrom, resourceComponentTo, resourceType, resourceUsed);
600 
601  return;
602  }
603 
604  delete newStorageEntity;
605 
606  return;
607  }
608 
609  SCR_InventoryStorageManagerComponent inventoryManagerComponent = SCR_InventoryStorageManagerComponent.Cast(Replication.FindItem(rplIdInventoryManager));
610 
611  if (!inventoryManagerComponent)
612  return;
613 
614  if (!rplIdStorageComponent.IsValid())
615  return;
616 
617  BaseInventoryStorageComponent storageComponent = BaseInventoryStorageComponent.Cast(Replication.FindItem(rplIdStorageComponent));
618 
619  if (!storageComponent)
620  return;
621 
622  IEntity resourcesOwner = resourceComponentFrom.GetOwner();
623  SCR_EntityCatalogEntry selectedEntry = null;
624  int selectedEntryIdx = -1;
625  SCR_EntityCatalog resourceContainerCatalog = SCR_EntityCatalogManagerComponent.GetInstance().GetEntityCatalogOfType(EEntityCatalogType.SUPPLY_CONTAINER_ITEM);
626  array<SCR_EntityCatalogEntry> entries = {};
627  array<SCR_BaseEntityCatalogData> data = {};
628  float maxResourceValueTo = 0.0;
629 
630  resourceContainerCatalog.GetEntityListWithData(SCR_ResourceContainerItemData, entries, data);
631 
632  foreach (int idx, SCR_EntityCatalogEntry entry: entries)
633  {
634  if (inventoryManagerComponent.CanInsertResourceInStorage(entry.GetPrefab(), storageComponent))
635  {
636  selectedEntry = entry;
637  selectedEntryIdx = idx;
638 
639  break;
640  }
641  }
642 
643  if (!selectedEntry)
644  return;
645 
646  SCR_ResourceContainerItemData datum = SCR_ResourceContainerItemData.Cast(data[selectedEntryIdx]);
647  float maxStoredResources = Math.Min(resourceValueCurrentFrom, datum.GetMaxResourceValue());
648  float resourceUsed = Math.Min(requestedResources, maxStoredResources);
649 
650  if (!TryPerformResourceConsumption(actorFrom, resourceType, resourceUsed))
651  return;
652 
653  EntitySpawnParams spawnParams = new EntitySpawnParams();
654  spawnParams.TransformMode = ETransformMode.WORLD;
655 
656  inventoryManagerComponent.GetOwner().GetTransform(spawnParams.Transform);
657 
658  IEntity newStorageEntity = GetGame().SpawnEntityPrefab(Resource.Load(selectedEntry.GetPrefab()), GetGame().GetWorld(), spawnParams);
659 
660  if (!newStorageEntity)
661  return;
662 
663  SCR_ResourceComponent resourceComponentTo = SCR_ResourceComponent.FindResourceComponent(newStorageEntity);
664  actorConsumptionTo = TryGetConsumptionActor(resourceComponentTo, resourceType, resourceValueCurrentTo, resourceValueMaxTo);
665  actorGenerationTo = TryGetGenerationActor(resourceComponentTo, resourceType, resourceValueCurrentTo, resourceValueMaxTo);
666 
667  TryPerformResourceConsumption(actorConsumptionTo, resourceType, resourceValueCurrentTo, true);
668 
669  if (!TryPerformResourceGeneration(actorGenerationTo, resourceType, resourceUsed))
670  {
671  delete newStorageEntity;
672 
673  return;
674  }
675 
676  inventoryManagerComponent.TryInsertItemInStorage(newStorageEntity, storageComponent);
677  OnPlayerInteraction(EResourcePlayerInteractionType.INVENTORY_SPLIT, resourceComponentFrom, resourceComponentTo, resourceType, resourceUsed);
678  }
679 
680  //------------------------------------------------------------------------------------------------
686  void OnPlayerInteraction(EResourcePlayerInteractionType interactionType, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue)
687  {
688  IEntity owner = GetOwner();
689  PlayerController playerController = PlayerController.Cast(owner);
690 
691  if (!playerController)
692  return;
693 
694  RplComponent rplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
695 
696  if (!playerController)
697  return;
698 
699  if (rplComponent && !rplComponent.IsProxy() && !rplComponent.IsOwner())
700  Rpc(RpcAsk_OnPlayerInteraction, interactionType, Replication.FindId(resourceComponentFrom), Replication.FindId(resourceComponentTo), resourceType, resourceValue);
701 
702  GetOnPlayerInteraction().Invoke(interactionType, owner, resourceComponentFrom, resourceComponentTo, resourceType, resourceValue);
703  }
704 
705  //------------------------------------------------------------------------------------------------
708  override event protected void OnDelete(IEntity owner)
709  {
710  super.OnDelete(owner);
711 
712  GetGame().GetResourceSystemSubscriptionManager().UnsubscribeListenerCompletely(Replication.FindId(this));
713  }
714 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
SCR_ResourceSystemHelper
Definition: SCR_ResourceSystemHelper.c:1
SCR_ResourceSystemSubscriptionHandle
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:14
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
STORAGE
STORAGE
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:4
EEntityCatalogType
EEntityCatalogType
Definition: EEntityCatalogType.c:4
EResourceReason
EResourceReason
Definition: SCR_ResourceConsumtionResponse.c:1
INVENTORY_SPLIT
INVENTORY_SPLIT
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:6
VEHICLE_UNLOAD
VEHICLE_UNLOAD
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:3
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_ResourceActor
Definition: SCR_ResourceConsumer.c:2
ScriptInvoker_ResourceOnPlayerInteraction
typedef ScriptInvoker_ResourceOnPlayerInteraction
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
SCR_ResourceConsumtionResponse
void SCR_ResourceConsumtionResponse(float availableResource=0, float resourceMultiplier=0, float range=0, EResourceReason reasonCode=EResourceReason.UNAVAILABLE)
Definition: SCR_ResourceConsumtionResponse.c:17
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_ResourceGenerationResponse
Definition: SCR_ResourceGenerator.c:13
SCR_ResourceContainerItemData
Definition: SCR_ResourceContainerItemData.c:2
InventoryItemComponent
Definition: InventoryItemComponent.c:12
ScriptInvokerActiveWidgetInteractionFunc
func ScriptInvokerActiveWidgetInteractionFunc
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:10
ScriptInvokerResourceOnPlayerInteraction
ScriptInvokerBase< ScriptInvokerActiveWidgetInteractionFunc > ScriptInvokerResourceOnPlayerInteraction
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:11
VEHICLE_LOAD
VEHICLE_LOAD
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:2
SCR_EntityCatalog
Definition: SCR_EntityCatalog.c:181
SCR_ResourceContainer
Definition: SCR_ResourceContainer.c:34
SCR_ResourcePlayerControllerInventoryComponent
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:20
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
SCR_ResourceEncapsulator
Definition: SCR_ResourceEncapsulator.c:1
EResourcePlayerInteractionType
EResourcePlayerInteractionType
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:1
SCR_ArsenalComponent
Definition: SCR_ArsenalComponent.c:9
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
SCR_ArsenalItem
Definition: SCR_ArsenalItem.c:2
SCR_Faction
Definition: SCR_Faction.c:6
SCR_EntityCatalogEntry
Definition: SCR_EntityCatalogEntry.c:5
SCR_ResourceGenerator
Definition: SCR_ResourceGenerator.c:79
EResourceContainerOnEmptyBehavior
EResourceContainerOnEmptyBehavior
Definition: SCR_ResourceContainer.c:26
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
EResourceGeneratorID
EResourceGeneratorID
Definition: SCR_ResourceGenerator.c:1