Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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))]
7  protected EResourceType m_eResourceType;
8 
9  protected SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer;
10  protected SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleGenerator;
11  protected SCR_ResourceComponent m_ResourceComponent;
12  protected SCR_ResourceGenerator m_ResourceGenerator;
13  protected SCR_ResourceConsumer m_ResourceConsumer;
14 
15  protected RplId m_ResourceInventoryPlayerComponentRplId;
16  protected SCR_CatalogEntitySpawnerComponent m_EntitySpawner;
17  protected SCR_EEntityRequestStatus m_iRequestStatus;
18  protected SCR_EntitySpawnerSlotComponent m_PreviewSlot;
19  protected SCR_EntityCatalogEntry m_EntityData
20  protected SCR_EntityCatalogSpawnerData m_EntitySpawnerData;
21  protected bool m_bIsSelected;
22 
23  //------------------------------------------------------------------------------------------------
24  void SetSpawnerData(SCR_EntityCatalogEntry entityData)
25  {
26  if (!entityData)
27  {
28  m_EntityData = null;
29  m_EntitySpawnerData = null;
30  return;
31  }
32 
33  SCR_EntityCatalogSpawnerData spawnerData = SCR_EntityCatalogSpawnerData.Cast(entityData.GetEntityDataOfType(SCR_EntityCatalogSpawnerData));
34  if (!spawnerData)
35  return;
36 
37  m_EntityData = entityData;
38  m_EntitySpawnerData = spawnerData;
39  }
40 
41  //------------------------------------------------------------------------------------------------
42  override bool HasLocalEffectOnlyScript()
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 
72  m_ResourceGenerator = m_ResourceComponent.GetGenerator(EResourceGeneratorID.DEFAULT, m_eResourceType);
73  m_ResourceConsumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, m_eResourceType);
74  }
75  //------------------------------------------------------------------------------------------------
76  override void OnActionSelected()
77  {
78  m_bIsSelected = true;
79 
80  if (!m_EntitySpawner)
81  return;
82 
83  if (IsAnySlotAvailable())
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;
148  if (m_PreviewSlot && m_bIsSelected)
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 
172  if (!m_ResourceComponent)
173  m_ResourceComponent = m_EntitySpawner.GetSpawnerResourceComponent();
174 
175  if (!m_ResourceInventoryPlayerComponentRplId || !m_ResourceInventoryPlayerComponentRplId.IsValid())
176  m_ResourceInventoryPlayerComponentRplId = Replication.FindId(SCR_ResourcePlayerControllerInventoryComponent.Cast(GetGame().GetPlayerController().FindComponent(SCR_ResourcePlayerControllerInventoryComponent)));
177 
178  if (!m_ResourceComponent
179  || !m_ResourceInventoryPlayerComponentRplId.IsValid()
180  || !m_ResourceGenerator && !m_ResourceComponent.GetGenerator(EResourceGeneratorID.DEFAULT, m_eResourceType, m_ResourceGenerator)
181  || !m_ResourceConsumer && !m_ResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, m_eResourceType, m_ResourceConsumer))
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 
193  if (m_ResourceSubscriptionHandleGenerator)
194  m_ResourceSubscriptionHandleGenerator.Poke();
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.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 }
SCR_EEntityRequestStatus
SCR_EEntityRequestStatus
Definition: SCR_CatalogEntitySpawnerComponent.c:1428
SCR_CatalogSpawnerUserAction
Definition: SCR_CatalogSpawnerUserAction.c:4
m_ResourceConsumer
protected SCR_ResourceConsumer m_ResourceConsumer
Definition: SCR_BaseSupportStationComponent.c:114
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ScriptedUserAction
Definition: ScriptedUserAction.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
m_ResourceSubscriptionHandleConsumer
protected SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer
Definition: SCR_BaseSupportStationComponent.c:125
Attribute
typedef Attribute
Post-process effect of scripted camera.
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
m_ResourceComponent
protected SCR_ResourceComponent m_ResourceComponent
Definition: SCR_CampaignBuildingProviderComponent.c:51
SCR_EntityCatalogSpawnerData
Definition: SCR_EntityCatalogSpawnerData.c:5
SCR_ResourcePlayerControllerInventoryComponent
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:20
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
SCR_ResourceSystemSubscriptionHandleBase
Definition: SCR_ResourceSystemSubscriptionHandleBase.c:1
SCR_Faction
Definition: SCR_Faction.c:6
SCR_EntityCatalogEntry
Definition: SCR_EntityCatalogEntry.c:5
SCR_ResourceGenerator
Definition: SCR_ResourceGenerator.c:79
EResourceGeneratorID
EResourceGeneratorID
Definition: SCR_ResourceGenerator.c:1