3 [
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))]
9 [
Attribute(
"#AR-Supplies_Refund_Action_Object_NoSupplies",
desc:
"If no supplies are returned or supplies are disabled action name")]
12 [
Attribute(
"#AR-Supplies_Refund_Action_Vehicle_NoDepot",
desc:
"Invalid reason shown when there is no valid refund point")]
15 [
Attribute(
"#AR-Supplies_Refund_Action_Vehicle_Occupied",
desc:
"Invalid reason shown when entity is a vehicle and it is occupied")]
19 protected SCR_EntityCatalogManagerComponent m_EntityCatalogManager;
20 protected SCR_CatalogEntitySpawnerComponent m_CatalogEntitySpawnerComponent;
21 protected RplComponent m_ReplicationComponent;
23 protected float m_fResourceCost = -1;
25 protected bool m_bIsResourceEnabled =
true;
28 protected SCR_BaseCompartmentManagerComponent m_CompartmentManager;
31 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
36 if (!SelectSuitableResourceGenerator(pUserEntity) || !m_CatalogEntitySpawnerComponent)
44 if (m_bIsResourceEnabled)
46 if (m_CatalogEntitySpawnerComponent.IsInGracePeriod(
GetOwner()))
47 m_ResourceGenerator.RequestGeneration(
SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_ResourceGenerator.GetResourceMultiplier()));
49 m_ResourceGenerator.RequestGeneration(
SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_CatalogEntitySpawnerComponent.GetPostGracePeriodRefundMultiplier()));
52 RplComponent.DeleteRplEntity(
GetOwner(),
false);
56 override bool GetActionNameScript(out
string outName)
58 if (!m_CatalogEntitySpawnerComponent)
61 if (m_bIsResourceEnabled)
65 if (m_CatalogEntitySpawnerComponent.IsInGracePeriod(
GetOwner()))
66 resourceCost =
SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_ResourceGenerator.GetResourceMultiplier());
68 resourceCost =
SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_CatalogEntitySpawnerComponent.GetPostGracePeriodRefundMultiplier());
76 outName = m_sNoSuppliesActionName;
82 outName = m_sNoSuppliesActionName;
90 override event bool CanBePerformedScript(IEntity user)
92 if (!SelectSuitableResourceGenerator(user))
94 m_sCannotPerformReason = m_sInvalidNoValidRefundPoint;
101 m_sCannotPerformReason = m_sInvalidIsOccupied;
113 bool SelectSuitableResourceGenerator(IEntity user)
115 SCR_ResourceComponent resourceComponent;
117 m_ResourceGenerator =
null;
118 m_CatalogEntitySpawnerComponent =
null;
119 vector ownerOrigin =
GetOwner().GetOrigin();
120 float distanceSq =
float.MAX;
121 float distanceSqCompare =
float.MAX;
123 foreach (SCR_CatalogEntitySpawnerComponent component : SCR_CatalogEntitySpawnerComponent.INSTANCES)
125 distanceSqCompare = vector.DistanceSq(ownerOrigin, component.GetOwner().GetOrigin());
127 if (distanceSq <= distanceSqCompare && !component.CanRefund(
GetOwner(), user))
130 resourceComponent = SCR_ResourceComponent.Cast(component.GetOwner().FindComponent(SCR_ResourceComponent));
132 if (resourceComponent && resourceComponent.GetGenerator(
EResourceGeneratorID.DEFAULT, m_eResourceType, resourceGeneratorCompare) && distanceSqCompare < resourceGeneratorCompare.GetStorageRange() * resourceGeneratorCompare.GetStorageRange())
134 distanceSq = distanceSqCompare;
135 m_CatalogEntitySpawnerComponent = component;
136 m_ResourceGenerator = resourceGeneratorCompare;
141 resourceGeneratorCompare =
null;
145 if (resourceComponent)
146 m_bIsResourceEnabled = resourceComponent.IsResourceTypeEnabled(m_eResourceType);
150 return m_ResourceGenerator;
154 override event bool CanBeShownScript(IEntity user)
159 return super.CanBeShownScript(user);
163 override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
166 GetGame().GetCallqueue().CallLater(DelayedInit, param1: pOwnerEntity, param2: pManagerComponent);
170 protected void DelayedInit(IEntity pOwnerEntity, GenericComponent pManagerComponent)
172 m_fResourceCost = -1;
181 ResourceName prefabName = pOwnerEntity.GetPrefabData().GetPrefabName();
184 if (factionComponent)
219 m_CompartmentManager = SCR_BaseCompartmentManagerComponent.Cast(pOwnerEntity.FindComponent(SCR_BaseCompartmentManagerComponent));
224 array<ref SCR_EntityBudgetValue> budgets = {};
225 uiInfo.GetEntityAndChildrenBudgetCost(budgets);
231 m_fResourceCost = budget.GetBudgetValue();
242 m_fResourceCost =
data.GetSupplyCost();