Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CatalogSpawnerUserAction.c
Go to the documentation of this file.
1
5{
6 [Attribute(defvalue: EResourceType.SUPPLIES.ToString(), uiwidget: UIWidgets.ComboBox, desc: "Sets the type of Resource to be used.\nOnly a transaction matching Resource types can be successfully concluded.", enums: ParamEnumArray.FromEnum(EResourceType))]
8
11 protected SCR_ResourceComponent m_ResourceComponent;
13 protected SCR_ResourceConsumer m_ResourceConsumer;
14
16 protected SCR_CatalogEntitySpawnerComponent m_EntitySpawner;
18 protected SCR_EntitySpawnerSlotComponent m_PreviewSlot;
19 protected SCR_EntityCatalogEntry m_EntityData
21 protected bool m_bIsSelected;
22
23 //------------------------------------------------------------------------------------------------
25 {
26 if (!entityData)
27 {
28 m_EntityData = null;
30 return;
31 }
32
34 if (!spawnerData)
35 return;
36
37 m_EntityData = entityData;
38 m_EntitySpawnerData = spawnerData;
39 }
40
41 //------------------------------------------------------------------------------------------------
43 {
44 return true;
45 }
46
47 //------------------------------------------------------------------------------------------------
48 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
49 {
50 IEntity parent = pOwnerEntity;
51 SCR_CatalogEntitySpawnerComponent comp;
52 while (parent)
53 {
54 comp = SCR_CatalogEntitySpawnerComponent.Cast(parent.FindComponent(SCR_CatalogEntitySpawnerComponent));
55 if (comp)
56 {
57 m_EntitySpawner = comp;
58 return;
59 }
60
61 parent = parent.GetParent();
62 }
63
64 if (!m_EntitySpawner)
65 return;
66
67 m_ResourceComponent = m_EntitySpawner.GetSpawnerResourceComponent();
68
70 return;
71
74 }
75 //------------------------------------------------------------------------------------------------
76 override void OnActionSelected()
77 {
78 m_bIsSelected = true;
79
80 if (!m_EntitySpawner)
81 return;
82
84 m_EntitySpawner.CreatePreviewEntity(m_EntityData, m_PreviewSlot, m_iRequestStatus);
85 }
86
87 //------------------------------------------------------------------------------------------------
88 override void OnActionDeselected()
89 {
90 m_bIsSelected = false;
91 m_EntitySpawner.DeletePreviewEntity();
92 }
93
94 //------------------------------------------------------------------------------------------------
95 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
96 {
97 if (!m_EntitySpawner)
98 return;
99
100 int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
101 PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
102
103 if (!playerController)
104 return;
105
106 SCR_SpawnerRequestComponent playerReqComponent = SCR_SpawnerRequestComponent.Cast(playerController.FindComponent(SCR_SpawnerRequestComponent));
107 if (!playerReqComponent)
108 return;
109
110 SCR_EntitySpawnerSlotComponent usedPreviewSlot = m_PreviewSlot;
111 playerReqComponent.RequestCatalogEntitySpawn(GetActionIndex(), m_EntitySpawner, pUserEntity, usedPreviewSlot);
112
113 m_EntitySpawner.DeletePreviewEntity();
114 m_EntitySpawner.ClearKnownSlots();
115 m_EntitySpawner.AddKnownOccupiedSlot(usedPreviewSlot);
116
117 if (IsAnySlotAvailable())
118 m_EntitySpawner.CreatePreviewEntity(m_EntityData, m_PreviewSlot, m_iRequestStatus);
119 }
120
121 //------------------------------------------------------------------------------------------------
122 override bool GetActionNameScript(out string outName)
123 {
124 if (!m_EntitySpawner || !m_EntitySpawnerData || !m_EntitySpawner.GetSpawnerResourceComponent())
125 return false;
126
127 ActionNameParams[0] = m_EntitySpawnerData.GetOverwriteName();
128 if (ActionNameParams[0] == string.Empty)
129 ActionNameParams[0] = m_EntityData.GetEntityName();
130
131 if (m_EntitySpawner.IsSuppliesConsumptionEnabled())
132 {
133 ActionNameParams[1] = m_EntitySpawnerData.GetSupplyCost().ToString();
134 ActionNameParams[2] = m_EntitySpawner.GetSpawnerResourceValue().ToString();
135 }
136
137 outName = "#AR-EntitySpawner_Request";
138 return true;
139 }
140
141 //------------------------------------------------------------------------------------------------
142 protected void SetPreviewSlot(SCR_EntitySpawnerSlotComponent previewSlot)
143 {
144 if (m_PreviewSlot == previewSlot)
145 return;
146
147 m_PreviewSlot = previewSlot;
149 m_EntitySpawner.CreatePreviewEntity(m_EntityData, m_PreviewSlot, m_iRequestStatus);
150
151 }
152
153 //------------------------------------------------------------------------------------------------
154 protected bool IsAnySlotAvailable()
155 {
156 if (!m_EntityData)
157 return false;
158
160
161 SetPreviewSlot(m_EntitySpawner.GetFreeSlot(data));
162
163 return m_PreviewSlot != null;
164 }
165
166 //------------------------------------------------------------------------------------------------
167 override bool CanBePerformedScript(IEntity user)
168 {
169 if (!m_EntitySpawner)
170 return false;
171
173 m_ResourceComponent = m_EntitySpawner.GetSpawnerResourceComponent();
174
177
182 {
183 SetCannotPerformReason("#AR-Supplies_CannotPerform_Generic");
184
185 return false;
186 }
187
190 else
191 m_ResourceSubscriptionHandleConsumer = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceConsumer, m_ResourceInventoryPlayerComponentRplId);
192
195 else
196 m_ResourceSubscriptionHandleGenerator = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceGenerator, m_ResourceInventoryPlayerComponentRplId);
197
198
199 switch (m_iRequestStatus)
200 {
201 case SCR_EEntityRequestStatus.AI_LIMIT_REACHED:
202 {
203 SetCannotPerformReason("#AR-Campaign_Action_BuildBlocked-UC");
204 break;
205 }
206
207 case SCR_EEntityRequestStatus.GROUP_FULL:
208 {
209 SetCannotPerformReason("#AR-EntitySpawner_RequestDenied_GroupFull-UC");
210 break;
211 }
212
213 case SCR_EEntityRequestStatus.REQUESTER_NOT_GROUPLEADER:
214 {
215 SetCannotPerformReason("#AR-EntitySpawner_RequestDenied_NotGroupLeader-UC");
216 break;
217 }
218
219 case SCR_EEntityRequestStatus.NOT_ENOUGH_SUPPLIES:
220 {
221 SetCannotPerformReason("#AR-Supplies_CannotPerform_Generic");
222 break;
223 }
224
225 case SCR_EEntityRequestStatus.RANK_LOW:
226 {
227 string rankName;
228 FactionAffiliationComponent factionAffiliationComp = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
229 if (!factionAffiliationComp)
230 break;
231
232 SCR_Faction faction = SCR_Faction.Cast(factionAffiliationComp.GetAffiliatedFaction());
233 if (faction)
234 rankName = faction.GetRanks().GetRankName(m_EntitySpawnerData.GetMinimumRequiredRank());
235
236 SetCannotPerformReason(rankName);
237 break;
238 }
239
240 case SCR_EEntityRequestStatus.COOLDOWN:
241 {
242 SetCannotPerformReason("#AR-Campaign_Action_Cooldown-UC");
243 break;
244 }
245
246 case SCR_EEntityRequestStatus.CAN_SPAWN:
247 {
248 if (IsAnySlotAvailable())
249 return true;
250
251 SetCannotPerformReason("#AR-Campaign_Action_BuildBlocked-UC");
252 break;
253 }
254 }
255
256 return false;
257 }
258
259 //------------------------------------------------------------------------------------------------
260 override bool CanBeShownScript(IEntity user)
261 {
262 if (!m_EntitySpawner || !m_EntityData || !m_EntitySpawnerData)
263 return false;
264
265 SCR_ChimeraCharacter chimeraCharacter = SCR_ChimeraCharacter.Cast(user);
266 if (!chimeraCharacter || chimeraCharacter.GetFaction() != m_EntitySpawner.GetFaction())
267 return false;
268
269 m_iRequestStatus = m_EntitySpawner.GetRequestState(m_EntityData, user);
270 if (m_iRequestStatus != SCR_EEntityRequestStatus.NOT_AVAILABLE)
271 return true;
272
273 return false;
274 }
275
276 //------------------------------------------------------------------------------------------------
277 protected int GetActionIndex()
278 {
279 return GetActionID();
280 }
281}
ArmaReforgerScripted GetGame()
Definition game.c:1398
Get all prefabs that have the spawner data
EResourceGeneratorID
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external int GetActionID()
Returns the ID with which this action is registered in its parent ActionsManagerComponent.
void SetCannotPerformReason(string reason)
string ActionNameParams[9]
Can be filled in scripts to be used as params when name is being formatted when displayed in UI.
proto external Managed FindComponent(typename typeName)
proto external IEntity GetParent()
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
void SetPreviewSlot(SCR_EntitySpawnerSlotComponent previewSlot)
override bool CanBeShownScript(IEntity user)
void SetSpawnerData(SCR_EntityCatalogEntry entityData)
SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleGenerator
override bool GetActionNameScript(out string outName)
SCR_CatalogEntitySpawnerComponent m_EntitySpawner
SCR_EntityCatalogSpawnerData m_EntitySpawnerData
SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer
SCR_EntitySpawnerSlotComponent m_PreviewSlot
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
override bool CanBePerformedScript(IEntity user)
Get prefab entity Data of type Ignores disabled Data s param dataType class of Data type you with to obtain return Entity Data of given type Null if not found *SCR_BaseEntityCatalogData GetEntityDataOfType(typename dataType)
SCR_RankContainer GetRanks()
string GetRankName(SCR_ECharacterRank rankID)
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()