Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ScenarioFrameworkActionOnResourceConsumerChange.c
Go to the documentation of this file.
3{
4 [Attribute(desc: "Target entity to manipulate supply (Optional if action is attached on Slot that spawns target entity)")]
5 ref SCR_ScenarioFrameworkGet m_Getter;
6
7 [Attribute(desc: "Actions that will be executed on compartment entered", UIWidgets.Auto)]
8 ref array<ref SCR_ScenarioFrameworkActionBase> m_aActions;
9
10 [Attribute(defvalue: "0", desc: "Activation amount", params: "0 inf 0.01")]
11 int m_iActivationAmount;
12
13 [Attribute(defvalue: "0", desc: "Operator", uiwidget: UIWidgets.ComboBox, enumType: SCR_EScenarioFrameworkComparisonOperator)]
14 SCR_EScenarioFrameworkComparisonOperator m_eComparisonOperator;
15
16 IEntity m_SupplyHolderEntity;
18
19 //------------------------------------------------------------------------------------------------
20 override void OnActivate(IEntity object)
21 {
22 if (!CanActivate())
23 return;
24
25 if (!ValidateInputEntity(object, m_Getter, m_SupplyHolderEntity))
26 return;
27
28 SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.Cast(m_SupplyHolderEntity.FindComponent(SCR_ResourceComponent));
29 if (!resourceComponent)
30 return;
31
32 SCR_ResourceConsumer consumer = resourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, EResourceType.SUPPLIES);
33 if (!consumer)
34 {
35 if (object)
36 Print(string.Format("ScenarioFramework Action: No resource consumer found for Action %1 attached on %2.", this, object.GetName()), LogLevel.ERROR);
37 else
38 Print(string.Format("ScenarioFramework Action: No resource consumer Managers found for Action %1.", this), LogLevel.ERROR);
39
40 return;
41 }
42
43 consumer.GetOnResourcesChanged().Insert(OnResourceChanged);
44 m_Handle = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandle(consumer, Replication.FindItemId(GetGame().GetPlayerController().FindComponent(SCR_ResourcePlayerControllerInventoryComponent)));
45 }
46
47 //------------------------------------------------------------------------------------------------
48 void OnResourceChanged(SCR_ResourceInteractor interactor, float previousValue)
49 {
50 SCR_ResourceConsumer consumer = SCR_ResourceConsumer.Cast(interactor);
51 if (!consumer)
52 return;
53
54 float current = consumer.GetAggregatedResourceValue();
55
56 if (((m_eComparisonOperator == SCR_EScenarioFrameworkComparisonOperator.LESS_THAN) && (current < m_iActivationAmount)) || ((m_eComparisonOperator == SCR_EScenarioFrameworkComparisonOperator.LESS_OR_EQUAL) && (current <= m_iActivationAmount)) || ((m_eComparisonOperator == SCR_EScenarioFrameworkComparisonOperator.EQUAL) && (current == m_iActivationAmount)) || ((m_eComparisonOperator == SCR_EScenarioFrameworkComparisonOperator.GREATER_OR_EQUAL) && (current >= m_iActivationAmount)) ||((m_eComparisonOperator == SCR_EScenarioFrameworkComparisonOperator.GREATER_THEN) && (current > m_iActivationAmount)))
57 {
58 foreach (SCR_ScenarioFrameworkActionBase action : m_aActions)
59 {
60 action.Init(m_SupplyHolderEntity);
61 }
62 }
63 }
64
65 //------------------------------------------------------------------------------------------------
70 SCR_ResourceConsumer GetContainer(notnull IEntity entity, out SCR_ResourceComponent component)
71 {
72 component = SCR_ResourceComponent.Cast(entity.FindComponent(SCR_ResourceComponent));
73 SCR_ResourceConsumer consumer;
74
75 if (component)
76 {
77 consumer = component.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
78 if (consumer)
79 return consumer;
80 }
81
82 IEntity iteratedEntity = entity.GetChildren();
83 while (iteratedEntity)
84 {
85 component = SCR_ResourceComponent.Cast(iteratedEntity.FindComponent(SCR_ResourceComponent));
86 if (component)
87 {
88 consumer = component.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
89 if (consumer)
90 return consumer;
91 }
92
93 iteratedEntity = iteratedEntity.GetSibling();
94 }
95
96 return null;
97 }
98
99 //------------------------------------------------------------------------------------------------
100 override array<ref SCR_ScenarioFrameworkActionBase> GetSubActions()
101 {
102 return m_aActions;
103 }
104}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
override void OnActivate()
EResourceGeneratorID
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
proto external IEntity GetChildren()
proto external IEntity GetSibling()
Main replication API.
Definition Replication.c:14
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()