Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignRepairEntityUserAction.c
Go to the documentation of this file.
1#define ENABLE_BASE_DESTRUCTION
2//------------------------------------------------------------------------------------------------
4{
5#ifdef ENABLE_BASE_DESTRUCTION
6 SCR_CampaignServiceEntityComponent m_ServiceEntityComp;
7 SCR_DestructionMultiPhaseComponent m_DestructionMultiphaseComp;
8
12 protected const int SLOT_SEARCH_DISTANCE = 5;
13
14 //------------------------------------------------------------------------------------------------
16 {/*
17 IEntity owner = GetOwner();
18 m_ServiceEntityComp = SCR_CampaignServiceEntityComponent.Cast(owner.FindComponent(SCR_CampaignServiceEntityComponent));
19 m_DestructionMultiphaseComp = SCR_DestructionMultiPhaseComponent.Cast(owner.FindComponent(SCR_DestructionMultiPhaseComponent));
20
21 GetGame().GetWorld().QueryEntitiesBySphere(m_Owner.GetOrigin(), SLOT_SEARCH_DISTANCE, GetNearestSlot, null, EQueryEntitiesFlags.ALL);
22 if (!m_Slot)
23 {
24 IEntity parent = owner.GetParent();
25 if (!parent)
26 return;
27
28 SCR_CampaignServiceCompositionComponent serviceCompositionComp = SCR_CampaignServiceCompositionComponent.Cast(parent.FindComponent(SCR_CampaignServiceCompositionComponent));
29 if (serviceCompositionComp)
30 {
31 m_CompType = serviceCompositionComp.GetCompositionType();
32 SCR_ServicePointComponent service = serviceCompositionComp.GetService();
33 if (service)
34 {
35 array<SCR_MilitaryBaseComponent> bases = {};
36 service.GetBases(bases);
37
38 if (!bases.IsEmpty())
39 m_CampaignBase = SCR_CampaignMilitaryBaseComponent.Cast(bases[0]);
40 }
41 }
42 }
43
44 SCR_GameModeCampaign gameModeMP = SCR_GameModeCampaign.GetInstance();
45 if (!gameModeMP)
46 return;
47
48 if (!m_CampaignBase)
49 m_CampaignBase = gameModeMP.GetSlotPresetBase(m_Slot);*/
50 }
51
52 //------------------------------------------------------------------------------------------------
53 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
54 {
55 if (!m_CampaignBase)
56 return;
57
58 if (!m_ServiceEntityComp)
59 return;
60
62 if (!destructionManager)
63 return;
64
65 IEntity compositionParent = SCR_EntityHelper.GetMainParent(pOwnerEntity);
66 if (!compositionParent)
67 return;
68
69 RplComponent rplComp = RplComponent.Cast(compositionParent.FindComponent(RplComponent));
70 if (!rplComp)
71 return;
72
73 RplId destructibleID = rplComp.Id();
74 if (!destructibleID.IsValid())
75 return;
76
77 PlayerController playerController = GetGame().GetPlayerController();
78 if (!playerController)
79 return;
80
81 SCR_CampaignNetworkComponent campaignNetworkComponent = SCR_CampaignNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignNetworkComponent));
82 if (!campaignNetworkComponent)
83 return;
84
85 //m_Slot can be a null. If so, composition type is used.
86 campaignNetworkComponent.RepairComposition(destructionManager.FindDynamicallySpawnedDestructibleIndex(destructibleID, m_DestructionMultiphaseComp), m_ServiceEntityComp.GetRepairCost(), destructibleID, m_Slot, m_CampaignBase);
87 }
88
89 //------------------------------------------------------------------------------------------------
91 {
92 return true;
93 }
94
95 //------------------------------------------------------------------------------------------------
96 override bool CanBePerformedScript(IEntity user)
97 {
98 if (m_ServiceEntityComp.GetRepairCost() > m_CampaignBase.GetSupplies())
99 {
100 SetCannotPerformReason("#AR-Campaign_Repair_Composition-UC");
101 return false;
102 }
103 return true;
104 }
105
106 //------------------------------------------------------------------------------------------------
107 override bool CanBeShownScript(IEntity user)
108 {
109 if (!m_DestructionMultiphaseComp)
110 return false;
111
112 if (!m_ServiceEntityComp)
113 {
115 return false;
116 }
117
118 if (!m_CampaignBase)
119 return false;
120
121 // Composition is in initial state don't need to be repair...
122 if (m_DestructionMultiphaseComp && m_DestructionMultiphaseComp.GetDamagePhase() == 0)
123 return false;
124
125 return true;
126 }
127
128 //------------------------------------------------------------------------------------------------
129 // Get the nearest slot to this composition
130 protected bool GetNearestSlot(IEntity ent)
131 {
132 SCR_SiteSlotEntity slotEnt = SCR_SiteSlotEntity.Cast(ent);
133 if (!slotEnt)
134 return true;
135
136 m_Slot = slotEnt;
137 return false;
138 }
139
140 //------------------------------------------------------------------------------------------------
141 override bool GetActionNameScript(out string outName)
142 {
143 if (!m_CampaignBase)
144 return false;
145 // get composition value
146 int availableSupplies = m_CampaignBase.GetSupplies();
147
148 ActionNameParams[0] = m_ServiceEntityComp.GetRepairCost().ToString();
149 ActionNameParams[1] = availableSupplies.ToString();
150
151 outName = ("#AR-Campaign_Action_ServiceRepair-UC");
152 return true;
153
154 }
155#endif
156};
EEditableEntityLabel
ArmaReforgerScripted GetGame()
Definition game.c:1398
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)
Replication item identifier.
Definition RplId.c:14
Takes care of Campaign-specific server <> client communication and requests.
void RepairComposition(int index, int repairCost, int destructibleID, SCR_SiteSlotEntity slotEnt, notnull SCR_CampaignMilitaryBaseComponent base)
Repair destroyed mandatory part of composition.
override bool GetActionNameScript(out string outName)
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
SCR_CampaignMilitaryBaseComponent m_CampaignBase
static IEntity GetMainParent(IEntity entity, bool self=false)
static SCR_MPDestructionManager GetInstance()
Returns the instance of the destruction manager.
int FindDynamicallySpawnedDestructibleIndex(RplId rplId, SCR_DestructionDamageManagerComponent destructible)