Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SupplyContainerValueAttribute.c
Go to the documentation of this file.
3 {
4  override SCR_BaseEditorAttributeVar ReadVariable(Managed item, SCR_AttributesManagerEditorComponent manager)
5  {
7  if (!editableEntity)
8  return null;
9 
10  GenericEntity entity = editableEntity.GetOwnerScripted();
11  if (!entity)
12  return null;
13 
14  SCR_ResourceComponent resourceComponent;
15  SCR_ResourceContainer supplyContainer = GetContainer(entity, resourceComponent);
16  if (!supplyContainer)
17  return null;
18 
19  float currentValue = supplyContainer.GetResourceValue();
20  float maxValue = supplyContainer.GetMaxResourceValue();
21 
22  if (maxValue == 0)
23  return null;
24 
25  return SCR_BaseEditorAttributeVar.CreateFloat((currentValue / maxValue) * 100);
26  }
27 
28  override void WriteVariable(Managed item, SCR_BaseEditorAttributeVar var, SCR_AttributesManagerEditorComponent manager, int playerID)
29  {
30  SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(item);
31  if (!editableEntity)
32  return;
33 
34  GenericEntity entity = editableEntity.GetOwnerScripted();
35  if (!entity)
36  return;
37 
38  SCR_ResourceComponent resourceComponent;
39  SCR_ResourceContainer supplyContainer = GetContainer(entity, resourceComponent);
40  if (!supplyContainer)
41  return;
42 
43  float percentage = var.GetFloat();
44  float currentValue = supplyContainer.GetResourceValue();
45  float maxValue = supplyContainer.GetMaxResourceValue();
46  float newValue = (maxValue * percentage) / 100;
47 
48  supplyContainer.SetResourceValue(newValue);
49  }
50 
51  SCR_ResourceContainer GetContainer(notnull IEntity entity, out SCR_ResourceComponent component)
52  {
53  component = SCR_ResourceComponent.Cast(entity.FindComponent(SCR_ResourceComponent));
54  SCR_ResourceContainer container;
55 
56  if (component)
57  {
58  container = component.GetContainer(EResourceType.SUPPLIES);
59  if (container)
60  return container;
61  }
62 
63  IEntity iteratedEntity = entity.GetChildren();
64  while (iteratedEntity)
65  {
66  component = SCR_ResourceComponent.Cast(iteratedEntity.FindComponent(SCR_ResourceComponent));
67  if (component)
68  {
69  container = component.GetContainer(EResourceType.SUPPLIES);
70  if (container)
71  return container;
72  }
73 
74  iteratedEntity = iteratedEntity.GetSibling();
75  }
76 
77  return null;
78  }
79 }
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_BaseEditorAttributeCustomTitle
Definition: SCR_BaseEditorAttribute.c:868
SCR_BaseEditorAttributeVar
Definition: SCR_BaseEditorAttributeVar.c:1
SCR_BaseValueListEditorAttribute
Definition: SCR_BaseValueListEditorAttribute.c:5
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
SCR_SupplyContainerValueAttribute
Definition: SCR_SupplyContainerValueAttribute.c:2
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_ResourceContainer
Definition: SCR_ResourceContainer.c:34
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468