Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ResupplySupportStationComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/SupportStation", description: "")]
5
6class SCR_ResupplySupportStationComponent : SCR_BaseItemSupportStationComponent
7{
8 //------------------------------------------------------------------------------------------------
9 protected override bool InitValidSetup()
10 {
11 //~ Resupply ammo does not support range as only players can resupply themselves or others at the moment
12 if (UsesRange())
13 {
14 Print("'SCR_ResupplySupportStationComponent' does not support range. Make sure m_fRange is set to -1", LogLevel.ERROR);
15 return false;
16 }
17
18 return super.InitValidSetup();
19 }
20
21 //------------------------------------------------------------------------------------------------
23 {
24 return ESupportStationType.RESUPPLY_AMMO;
25 }
26
27 //------------------------------------------------------------------------------------------------
28 override bool IsValid(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action, vector actionPosition, out ESupportStationReasonInvalid reasonInvalid, out int supplyAmount)
29 {
31 {
32 Debug.Error2("SCR_ResupplySupportStationComponent", "'IsValid' fails as the resupply support station is executed with a non SCR_BaseResupplySupportStationAction action! This is will break the support station!");
33 return false;
34 }
35
36 return super.IsValid(actionOwner, actionUser, action, actionPosition, reasonInvalid, supplyAmount);
37 }
38
39 //------------------------------------------------------------------------------------------------
40 override void OnExecutedServer(notnull IEntity actionOwner, notnull IEntity actionUser, notnull SCR_BaseUseSupportStationAction action)
41 {
43
44 SCR_InventoryStorageManagerComponent inventoryManager = resupplyAction.GetTargetInventory();
45 if (!inventoryManager)
46 return;
47
48 //~ Consume supplies
50 {
51 if (!OnConsumeSuppliesServer(GetSupplyAmountAction(actionOwner, actionUser, action)))
52 return;
53 }
54
55 //~ Consume Military Supply Allocation if enabled
56 if (SCR_ArsenalManagerComponent.IsMilitarySupplyAllocationEnabled())
58
60 itemsToResupply.Insert(resupplyAction.GetItemPrefab(), 1);
61 inventoryManager.ResupplyMagazines(itemsToResupply);
62
63 super.OnExecutedServer(actionOwner, actionUser, action);
64 }
65
66 //------------------------------------------------------------------------------------------------
67 //~ Called by OnExecuteBroadcast and is executed both on server and on client
68 //~ playerId can be -1 if the user was not a player
69 protected override void OnExecute(IEntity actionOwner, IEntity actionUser, int playerId, SCR_BaseUseSupportStationAction action)
70 {
71 //~ On succesfully executed
72 OnSuccessfullyExecuted(actionOwner, actionUser, action);
73
74 if (!actionUser || !actionOwner)
75 return;
76
78
79 SCR_InventoryStorageManagerComponent targetInventory = resupplyAction.GetTargetInventory();
80 if (!targetInventory)
81 return;
82
83 //~ Player resupplied themselves
84 if (targetInventory.GetOwner() == actionUser)
85 {
86 //~ Play sound on use
87 PlaySoundEffect(GetOnUseAudioConfig(), actionOwner, action);
88
89 //~ Play full done voice event (if any)
90 PlayCharacterVoiceEvent(actionOwner);
91
92 if (GetSendNotificationOnUse() && resupplyAction.GetNotificationOnUse() != ENotification.UNKNOWN)
93 {
94 //~ ID is not the local player so do not send notification
95 playerId = SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(actionUser);
96 if (SCR_PlayerController.GetLocalPlayerId() == playerId)
97 SCR_NotificationsComponent.SendLocal(resupplyAction.GetNotificationOnUse());
98 }
99 }
100 //~ Player resupplied other
101 else
102 {
103 //~ Play sound on use
104 PlaySoundEffect(GetOnUseAudioConfig(), actionUser, action);
105
106 //~ Play full done voice event (if any)
107 PlayCharacterVoiceEvent(actionUser);
108
109 if (GetSendNotificationOnUse() && resupplyAction.GetNotificationOnUse() != ENotification.UNKNOWN)
110 {
111 //~ ID is not the local player so do not send notification
112 playerId = SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(actionOwner);
113 if (SCR_PlayerController.GetLocalPlayerId() == playerId)
114 {
115 RplId ownerId;
116 RplId userId;
117 FindEntityIds(actionOwner, actionUser, ownerId, userId, playerId);
118 SCR_NotificationsComponent.SendLocal(resupplyAction.GetNotificationOnUse(), userId);
119 }
120 }
121 }
122 }
123
124 //------------------------------------------------------------------------------------------------
127 protected void OnConsumeMilitarySupplyAllocationServer(IEntity actionUser, int amount)
128 {
129 if (amount == 0)
130 return;
131
132 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
133 if (!factionManager)
134 return;
135
136 PlayerManager playerManager = GetGame().GetPlayerManager();
137 int playerId = playerManager.GetPlayerIdFromControlledEntity(actionUser);
138
139 // Do not consume Military Supply Allocation if resupplying on enemy support station
140 SCR_Faction playerFaction = SCR_Faction.Cast(factionManager.GetPlayerFaction(playerId));
141 if (playerFaction && playerFaction != GetFaction())
142 return;
143
144 SCR_PlayerController playerController = SCR_PlayerController.Cast(playerManager.GetPlayerController(playerId));
145 if (!playerController)
146 return;
147
148 SCR_PlayerSupplyAllocationComponent playerSupplyAllocationComponent = SCR_PlayerSupplyAllocationComponent.Cast(playerController.FindComponent(SCR_PlayerSupplyAllocationComponent));
149 if (!playerSupplyAllocationComponent)
150 return;
151
152 playerSupplyAllocationComponent.AddPlayerAvailableAllocatedSupplies(-1 * amount);
153 }
154
155 //------------------------------------------------------------------------------------------------
159 {
160 if (!SCR_ArsenalManagerComponent.IsMilitarySupplyAllocationEnabled())
161 return 0;
162
164 if (!itemHolder)
165 return 0;
166
167 SCR_EntityCatalogEntry catalogEntry = m_EntityCatalogManager.GetEntryWithPrefabFromAnyCatalog(EEntityCatalogType.ITEM, itemHolder.GetItemPrefab(), GetFaction());
168 if (!catalogEntry)
169 return 0;
170
171 SCR_ArsenalItem arsenalData = SCR_ArsenalItem.Cast(catalogEntry.GetEntityDataOfType(SCR_ArsenalItem));
172 if (!arsenalData)
173 return 0;
174
175 if (arsenalData.GetUseMilitarySupplyAllocation())
176 return Math.ClampInt(arsenalData.GetSupplyCost(m_eSupplyCostType) + m_iBaseSupplyCostOnUse, 0, int.MAX);
177
178 return 0;
179 }
180}
EEntityCatalogType
ENotification
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)
SCR_EntityCatalogManagerComponent m_EntityCatalogManager
override bool InitValidSetup()
bool GetSendNotificationOnUse()
void PlayCharacterVoiceEvent(IEntity character)
ESupportStationType GetSupportStationType()
bool OnConsumeSuppliesServer(int amount)
void FindEntityIds(IEntity owner, IEntity user, out RplId ownerId, out RplId userId, out int playerId)
void OnSuccessfullyExecuted(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action)
void PlaySoundEffect(SCR_AudioSourceConfiguration audioConfig, notnull IEntity soundOwner, SCR_BaseUseSupportStationAction action)
SCR_AudioSourceConfiguration GetOnUseAudioConfig()
SCR_CampaignFaction GetFaction()
void SCR_FactionManager(IEntitySource src, IEntity parent)
void OnConsumeMilitarySupplyAllocationServer(IEntity actionUser, int amount)
int GetMilitarySupplyAllocationCostOfAction(SCR_BaseUseSupportStationAction action)
Definition Debug.c:13
Definition Math.c:13
Replication item identifier.
Definition RplId.c:14
bool GetUseMilitarySupplyAllocation()
int GetSupplyCost(SCR_EArsenalSupplyCostType supplyCostType, bool addAdditionalCosts=true)
SCR_InventoryStorageManagerComponent GetTargetInventory()
Get prefab entity Data of type Ignores disabled Data s param dataType class of Data type you with to obtain return Entity Data of given type Null if not found *SCR_BaseEntityCatalogData GetEntityDataOfType(typename dataType)
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
Definition Types.c:486
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