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))]
11 protected SCR_ResourceComponent m_ResourceComponent;
13 protected SCR_ResourceConsumer m_ResourceConsumer;
15 protected RplId m_ResourceInventoryPlayerComponentRplId;
16 protected SCR_CatalogEntitySpawnerComponent m_EntitySpawner;
18 protected SCR_EntitySpawnerSlotComponent m_PreviewSlot;
21 protected bool m_bIsSelected;
29 m_EntitySpawnerData =
null;
37 m_EntityData = entityData;
38 m_EntitySpawnerData = spawnerData;
42 override bool HasLocalEffectOnlyScript()
48 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
50 IEntity parent = pOwnerEntity;
51 SCR_CatalogEntitySpawnerComponent comp;
54 comp = SCR_CatalogEntitySpawnerComponent.Cast(parent.FindComponent(SCR_CatalogEntitySpawnerComponent));
57 m_EntitySpawner = comp;
61 parent = parent.GetParent();
76 override void OnActionSelected()
83 if (IsAnySlotAvailable())
84 m_EntitySpawner.CreatePreviewEntity(m_EntityData, m_PreviewSlot, m_iRequestStatus);
88 override void OnActionDeselected()
90 m_bIsSelected =
false;
91 m_EntitySpawner.DeletePreviewEntity();
95 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
100 int playerId =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
101 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
103 if (!playerController)
106 SCR_SpawnerRequestComponent playerReqComponent = SCR_SpawnerRequestComponent.Cast(playerController.FindComponent(SCR_SpawnerRequestComponent));
107 if (!playerReqComponent)
110 SCR_EntitySpawnerSlotComponent usedPreviewSlot = m_PreviewSlot;
111 playerReqComponent.RequestCatalogEntitySpawn(GetActionIndex(), m_EntitySpawner, pUserEntity, usedPreviewSlot);
113 m_EntitySpawner.DeletePreviewEntity();
114 m_EntitySpawner.ClearKnownSlots();
115 m_EntitySpawner.AddKnownOccupiedSlot(usedPreviewSlot);
117 if (IsAnySlotAvailable())
118 m_EntitySpawner.CreatePreviewEntity(m_EntityData, m_PreviewSlot, m_iRequestStatus);
122 override bool GetActionNameScript(out
string outName)
124 if (!m_EntitySpawner || !m_EntitySpawnerData || !m_EntitySpawner.GetSpawnerResourceComponent())
127 ActionNameParams[0] = m_EntitySpawnerData.GetOverwriteName();
128 if (ActionNameParams[0] ==
string.Empty)
129 ActionNameParams[0] = m_EntityData.GetEntityName();
131 if (m_EntitySpawner.IsSuppliesConsumptionEnabled())
133 ActionNameParams[1] = m_EntitySpawnerData.GetSupplyCost().ToString();
134 ActionNameParams[2] = m_EntitySpawner.GetSpawnerResourceValue().ToString();
137 outName =
"#AR-EntitySpawner_Request";
142 protected void SetPreviewSlot(SCR_EntitySpawnerSlotComponent previewSlot)
144 if (m_PreviewSlot == previewSlot)
147 m_PreviewSlot = previewSlot;
148 if (m_PreviewSlot && m_bIsSelected)
149 m_EntitySpawner.CreatePreviewEntity(m_EntityData, m_PreviewSlot, m_iRequestStatus);
154 protected bool IsAnySlotAvailable()
161 SetPreviewSlot(m_EntitySpawner.GetFreeSlot(
data));
163 return m_PreviewSlot !=
null;
167 override bool CanBePerformedScript(IEntity user)
169 if (!m_EntitySpawner)
175 if (!m_ResourceInventoryPlayerComponentRplId || !m_ResourceInventoryPlayerComponentRplId.IsValid())
179 || !m_ResourceInventoryPlayerComponentRplId.IsValid()
183 SetCannotPerformReason(
"#AR-Supplies_CannotPerform_Generic");
193 if (m_ResourceSubscriptionHandleGenerator)
194 m_ResourceSubscriptionHandleGenerator.Poke();
196 m_ResourceSubscriptionHandleGenerator =
GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceGenerator, m_ResourceInventoryPlayerComponentRplId);
199 switch (m_iRequestStatus)
203 SetCannotPerformReason(
"#AR-Campaign_Action_BuildBlocked-UC");
209 SetCannotPerformReason(
"#AR-EntitySpawner_RequestDenied_GroupFull-UC");
215 SetCannotPerformReason(
"#AR-EntitySpawner_RequestDenied_NotGroupLeader-UC");
221 SetCannotPerformReason(
"#AR-Supplies_CannotPerform_Generic");
228 FactionAffiliationComponent factionAffiliationComp = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
229 if (!factionAffiliationComp)
234 rankName = faction.GetRankName(m_EntitySpawnerData.GetMinimumRequiredRank());
236 SetCannotPerformReason(rankName);
242 SetCannotPerformReason(
"#AR-Campaign_Action_Cooldown-UC");
248 if (IsAnySlotAvailable())
251 SetCannotPerformReason(
"#AR-Campaign_Action_BuildBlocked-UC");
260 override bool CanBeShownScript(IEntity user)
262 if (!m_EntitySpawner || !m_EntityData || !m_EntitySpawnerData)
265 SCR_ChimeraCharacter chimeraCharacter = SCR_ChimeraCharacter.Cast(user);
266 if (!chimeraCharacter || chimeraCharacter.GetFaction() != m_EntitySpawner.GetFaction())
269 m_iRequestStatus = m_EntitySpawner.GetRequestState(m_EntityData, user);
277 protected int GetActionIndex()
279 return GetActionID();