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