Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VehicleWeaponSupportStationComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/SupportStation", description: "")]
5
6class SCR_VehicleWeaponSupportStationComponent : SCR_BaseItemSupportStationComponent
7{
9
10 //------------------------------------------------------------------------------------------------
11 protected override void DelayedInit(IEntity owner)
12 {
13 if (!owner)
14 return;
15
17 super.DelayedInit(owner);
18 }
19
20 //------------------------------------------------------------------------------------------------
21 protected override bool InitValidSetup()
22 {
23 //~ Resupply ammo does not support range as only players can resupply themselves or others at the moment
24 if (!UsesRange())
25 {
26 Print("'SCR_VehicleWeaponSupportStationComponent' requires range. Make sure it is greater than 0", LogLevel.ERROR);
27 return false;
28 }
29
30 return super.InitValidSetup();
31 }
32
33 //------------------------------------------------------------------------------------------------
34 override bool IsValid(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action, vector actionPosition, out ESupportStationReasonInvalid reasonInvalid, out int supplyAmount)
35 {
36 if (!super.IsValid(actionOwner, actionUser, action, actionPosition, reasonInvalid, supplyAmount))
37 return false;
38
40 if (baseItemHolderAction)
41 {
42 //~ Item is not in the inventory
43 if (m_InventoryStorage && !SCR_InventoryStorageManagerComponent.IsItemInStorage(m_InventoryStorage, baseItemHolderAction.GetItemPrefab(), actionUser))
44 {
45 reasonInvalid = ESupportStationReasonInvalid.RESUPPLY_NOT_IN_STORAGE;
46 return false;
47 }
48 }
49
50 return true;
51 }
52
53 //------------------------------------------------------------------------------------------------
55 {
56 //~ If refund action it is gain instead of cost
58 }
59
60 //------------------------------------------------------------------------------------------------
63 {
65 return 1;
66
67 return m_ResourceGenerator.GetResourceMultiplier();
68 }
69
70 //------------------------------------------------------------------------------------------------
72 {
73 return ESupportStationType.VEHICLE_WEAPON;
74 }
75
76 //------------------------------------------------------------------------------------------------
77 protected override int GetSupplyAmountAction(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action)
78 {
79 //~ Uses item logic
81 if (itemHolder)
82 return super.GetSupplyAmountAction(actionOwner, actionUser, action);
83
84 //~ Supplies are disabled
85 if (!AreSuppliesEnabled())
86 return 0;
87
88 //~ If Pylon refund action: Get pylon cost to calculate pylon refund
90 if (refundPylonAction)
91 return SCR_ResourceSystemHelper.RoundRefundSupplyAmount(refundPylonAction.GetSupplyRefundAmount() * GetGeneratorSupplyMultiplier());
92
93 //~ If ammo refund action: Get Ammo cost to calculate ammo refund
95 if (refundAmmoAction)
96 return SCR_ResourceSystemHelper.RoundRefundSupplyAmount(refundAmmoAction.GetSupplyRefundAmount() * GetGeneratorSupplyMultiplier());
97
98 //~ Invalid action
99 Print("SCR_VehicleWeaponSupportStationComponent is called by an invalid action not supported by the GetSupplyAmountAction", LogLevel.ERROR);
100
101 return 0;
102 }
103
104 //------------------------------------------------------------------------------------------------
105 override void OnExecutedServer(notnull IEntity actionOwner, notnull IEntity actionUser, notnull SCR_BaseUseSupportStationAction action)
106 {
107 //~ Add ammo in vehicle
109 if (resupplyRocketAction)
110 {
111 RocketEjectorMuzzleComponent rocketMuzzleComp = resupplyRocketAction.GetRocketMuzzle();
112 if (!rocketMuzzleComp || !rocketMuzzleComp.CanReloadNextBarrel())
113 return;
114
115 Resource resource = Resource.Load(resupplyRocketAction.GetItemPrefab());
116 if (!resource.IsValid())
117 return;
118
119 //~ Consume Supplies
120 if (!OnConsumeSuppliesServer(GetSupplyAmountAction(actionOwner, actionUser, action)))
121 return;
122
123 IEntity spawnedRocket = GetGame().SpawnEntityPrefab(resource);
124 if (!spawnedRocket)
125 return;
126
127 rocketMuzzleComp.ReloadNextBarrel(spawnedRocket);
128 super.OnExecutedServer(actionOwner, actionUser, action);
129
130 return;
131 }
132
133 //~ Add ammo in vehicle
135 if (resupplyMagazineAction)
136 {
137 BaseMagazineComponent currentMagazine = resupplyMagazineAction.GetCurrentMagazine();
138 if (!currentMagazine)
139 return;
140
141 int count = currentMagazine.GetAmmoCount();
142 int maxCount = currentMagazine.GetMaxAmmoCount();
143 int added = resupplyMagazineAction.GetAddedBulletsAmount();
144
145 //~ Consume Supplies
146 if (!OnConsumeSuppliesServer(GetSupplyAmountAction(actionOwner, actionUser, action)))
147 return;
148
149 if (count + added < maxCount)
150 currentMagazine.SetAmmoCount(count + added);
151 else
152 currentMagazine.SetAmmoCount(maxCount);
153
154 super.OnExecutedServer(actionOwner, actionUser, action);
155
156 return;
157 }
158
159 //~ Refund the ammo in vehicle
161 if (refundAmmoAction)
162 {
163 RocketEjectorMuzzleComponent rocketMuzzleComp = refundAmmoAction.GetRocketMuzzle();
164 if (!rocketMuzzleComp)
165 return;
166
167 //~ Get rockets in reverse order
168 int count = rocketMuzzleComp.GetBarrelsCount();
169 for (int i = count - 1; i >= 0; i--)
170 {
171 if (!rocketMuzzleComp.CanReloadBarrel(i))
172 {
173 IEntity projectile = rocketMuzzleComp.GetBarrelProjectile(i);
174 if (!projectile)
175 return;
176
177 rocketMuzzleComp.UnloadBarrel(i);
178
179 //~ Generate supplies
180 if (!OnGenerateSuppliesServer(GetSupplyAmountAction(actionOwner, actionUser, action)))
181 return;
182
183 super.OnExecutedServer(actionOwner, actionUser, action);
184 break;
185 }
186 }
187
188 return;
189 }
190
191 //~ Attach Pylon action
193 if (attachPylonAction)
194 {
195 TurretControllerComponent turrentController = TurretControllerComponent.Cast(actionOwner.FindComponent(TurretControllerComponent));
196 if (turrentController)
197 {
198 WeaponSlotComponent weaponSlot = attachPylonAction.GetLinkedWeaponSlot();
199 if (!weaponSlot || weaponSlot.GetWeaponEntity())
200 return;
201
202 Resource resource = Resource.Load(attachPylonAction.GetItemPrefab());
203 if (!resource.IsValid())
204 return;
205
206 //~ Consume supplies
207 if (!OnConsumeSuppliesServer(GetSupplyAmountAction(actionOwner, actionUser, action)))
208 return;
209
211 weaponSlot.GetSlotInfo().GetWorldTransform(params.Transform);
212
213 IEntity spawnedWeapon = GetGame().SpawnEntityPrefab(resource, actionOwner.GetWorld(), params);
214 if (!spawnedWeapon)
215 return;
216
217 turrentController.AddWeapon(actionUser, weaponSlot.GetWeaponSlotIndex(), spawnedWeapon);
218 super.OnExecutedServer(actionOwner, actionUser, action);
219 }
220
221 return;
222 }
223
224 //~ Refund Pylon Action
226 if (refundPylonAction)
227 {
228 TurretControllerComponent turrentController = TurretControllerComponent.Cast(actionOwner.FindComponent(TurretControllerComponent));
229 if (!turrentController)
230 return;
231
232 const WeaponSlotComponent weaponSlot = refundPylonAction.GetManagedWeaponSlot();
233 if (!weaponSlot)
234 return;
235
236 const IEntity attachedWeapon = weaponSlot.GetWeaponEntity();
237 if (!attachedWeapon)
238 return;
239
240 const int weaponId = refundPylonAction.GetPylonIndex();
241 turrentController.RemoveWeapon(null, weaponId, null);
242
243 //~ Generate supplies
244 if (!OnGenerateSuppliesServer(GetSupplyAmountAction(actionOwner, actionUser, action)))
245 return;
246
247 super.OnExecutedServer(actionOwner, actionUser, action);
248
249 RplComponent.DeleteRplEntity(attachedWeapon, false);
250
251 return;
252 }
253 }
254
255 //------------------------------------------------------------------------------------------------
256 //~ Called by OnExecuteBroadcast and is executed both on server and on client
257 //~ playerId can be -1 if the user was not a player
258 protected override void OnExecute(IEntity actionOwner, IEntity actionUser, int playerId, SCR_BaseUseSupportStationAction action)
259 {
260 super.OnExecute(actionOwner, actionUser, playerId, action);
261
262 ResourceName soundProject;
263 string soundEffectName;
264
266 if (!baseAudioAction || !baseAudioAction.GetSoundEffectProjectAndEvent(soundProject, soundEffectName))
267 return;
268
269 SCR_AudioSourceConfiguration audioConfig = CreateOnUseAudioConfig(soundProject, soundEffectName);
270 if (audioConfig)
271 PlaySoundEffect(audioConfig, baseAudioAction.GetSoundSource(), action);
272 }
273}
ESupportStationType
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
override int GetSupplyAmountAction(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action)
override void OnExecute(IEntity actionOwner, IEntity actionUser, int playerId, SCR_BaseUseSupportStationAction action)
override void OnExecutedServer(notnull IEntity actionOwner, notnull IEntity actionUser, notnull SCR_BaseUseSupportStationAction action)
override bool InitValidSetup()
bool HasSupplyGainInsteadOfCost(SCR_BaseUseSupportStationAction action)
ESupportStationType GetSupportStationType()
bool OnConsumeSuppliesServer(int amount)
bool OnGenerateSuppliesServer(int amount)
SCR_AudioSourceConfiguration CreateOnUseAudioConfig(ResourceName soundFile, string soundEvent)
void PlaySoundEffect(SCR_AudioSourceConfiguration audioConfig, notnull IEntity soundOwner, SCR_BaseUseSupportStationAction action)
override void DelayedInit()
SCR_ResourceGenerator m_ResourceGenerator
SCR_VehicleWeaponSupportStationComponentClass m_InventoryStorage
proto external Managed FindComponent(typename typeName)
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
bool GetSoundEffectProjectAndEvent(out ResourceName soundProject, out string soundEffectName)
void EntitySpawnParams()
Definition gameLib.c:130
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14