Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResupplySupportStationComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/SupportStation", description: "")]
3 {
4 }
5 
6 class SCR_ResupplySupportStationComponent : SCR_BaseSupportStationComponent
7 {
8  [Attribute(SCR_EArsenalSupplyCostType.DEFAULT.ToString(), desc: "Cost type of items. If it is not DEFAULT than it will try to get the diffrent supply cost if the item has it assigned" , uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(SCR_EArsenalSupplyCostType), category: "Resupply Support Station")]
9  protected SCR_EArsenalSupplyCostType m_eSupplyCostType;
10 
11  [Attribute("1", desc: "Fallback item supply cost. If for some reason the item that was supplied had no cost or could not be found then the fallback cost is used", category: "Resupply Support Station", params: "1 inf 1")]
13 
14  protected SCR_EntityCatalogManagerComponent m_EntityCatalogManager;
15 
16  //------------------------------------------------------------------------------------------------
17  protected override void DelayedInit(IEntity owner)
18  {
19  m_EntityCatalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
20  super.DelayedInit(owner);
21  }
22 
23  //------------------------------------------------------------------------------------------------
24  protected override bool InitValidSetup()
25  {
27  {
28  Print("'SCR_ResupplySupportStationComponent' needs a entity catalog manager!", LogLevel.ERROR);
29  return false;
30  }
31 
32  //~ Resupply ammo does not support range as only players can resupply themselves or others at the moment
33  if (UsesRange())
34  {
35  Print("'SCR_ResupplySupportStationComponent' does not support range. Make sure m_fRange is set to -1", LogLevel.ERROR);
36  return false;
37  }
38 
39  return super.InitValidSetup();
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  override bool IsValid(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action, vector actionPosition, out ESupportStationReasonInvalid reasonInvalid, out int supplyCost)
44  {
45  if (!SCR_BaseResupplySupportStationAction.Cast(action))
46  {
47  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!");
48  return false;
49  }
50 
51  return super.IsValid(actionOwner, actionUser, action, actionPosition, reasonInvalid, supplyCost);
52  }
53 
54  //------------------------------------------------------------------------------------------------
56  {
57  return ESupportStationType.RESUPPLY_AMMO;
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  protected override int GetSupplyCostAction(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action)
62  {
63  if (!AreSuppliesEnabled())
64  return 0;
65 
67 
68  SCR_EntityCatalogEntry catalogEntry = m_EntityCatalogManager.GetEntryWithPrefabFromAnyCatalog(EEntityCatalogType.ITEM, resupplyAction.GetItemToResupply(), GetFaction());
69  if (!catalogEntry)
70  {
71  Print("'SCR_ResupplySupportStationComponent' could not find SCR_EntityCatalogEntry for '" + resupplyAction.GetItemToResupply() + "' so will use fallback cost!", LogLevel.WARNING);
72  return Math.ClampInt(m_iFallbackItemSupplyCost + m_iBaseSupplyCostOnUse, 0, int.MAX);
73  }
74 
75  //~ Could not find arsenal data use fallback cost
76  SCR_ArsenalItem arsenalData = SCR_ArsenalItem.Cast(catalogEntry.GetEntityDataOfType(SCR_ArsenalItem));
77  if (!arsenalData)
78  {
79  Print("'SCR_ResupplySupportStationComponent' could not find SCR_ArsenalItem '" + resupplyAction.GetItemToResupply() + "' so will use fallback cost!", LogLevel.WARNING);
80  return Math.ClampInt(m_iFallbackItemSupplyCost + m_iBaseSupplyCostOnUse, 0, int.MAX);
81  }
82 
83  return Math.ClampInt(arsenalData.GetSupplyCost(m_eSupplyCostType) + m_iBaseSupplyCostOnUse, 0, int.MAX);
84  }
85 
86  //------------------------------------------------------------------------------------------------
87  override void OnExecutedServer(notnull IEntity actionOwner, notnull IEntity actionUser, notnull SCR_BaseUseSupportStationAction action)
88  {
90 
91  SCR_InventoryStorageManagerComponent inventoryManager = resupplyAction.GetTargetInventory();
92  if (!inventoryManager)
93  return;
94 
95  //~ Consume supplies
96  if (AreSuppliesEnabled())
97  {
98  if (!OnConsumeSuppliesServer(GetSupplyCostAction(actionOwner, actionUser, action)))
99  return;
100  }
101 
102  map<ResourceName, int> itemsToResupply = new map<ResourceName, int>;
103  itemsToResupply.Insert(resupplyAction.GetItemToResupply(), 1);
104  inventoryManager.ResupplyMagazines(itemsToResupply);
105 
106  super.OnExecutedServer(actionOwner, actionUser, action);
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  //~ Called by OnExecuteBroadcast and is executed both on server and on client
111  //~ playerId can be -1 if the user was not a player
112  protected override void OnExecute(IEntity actionOwner, IEntity actionUser, int playerId, SCR_BaseUseSupportStationAction action)
113  {
114  //~ On succesfully executed
115  OnSuccessfullyExecuted(actionOwner, actionUser, action);
116 
117  if (!actionUser || !actionOwner)
118  return;
119 
121 
122  SCR_InventoryStorageManagerComponent targetInventory = resupplyAction.GetTargetInventory();
123  if (!targetInventory)
124  return;
125 
126  //~ Player resupplied themselves
127  if (targetInventory.GetOwner() == actionUser)
128  {
129  //~ Play sound on use
130  PlaySoundEffect(GetOnUseAudioConfig(), actionOwner, action);
131 
132  //~ Play full done voice event (if any)
133  PlayCharacterVoiceEvent(actionOwner);
134 
135  if (GetSendNotificationOnUse() && resupplyAction.GetNotificationOnUse() != ENotification.UNKNOWN)
136  {
137  //~ ID is not the local player so do not send notification
138  playerId = SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(actionUser);
139  if (SCR_PlayerController.GetLocalPlayerId() == playerId)
140  SCR_NotificationsComponent.SendLocal(resupplyAction.GetNotificationOnUse());
141  }
142  }
143  //~ Player resupplied other
144  else
145  {
146  //~ Play sound on use
147  PlaySoundEffect(GetOnUseAudioConfig(), actionUser, action);
148 
149  //~ Play full done voice event (if any)
150  PlayCharacterVoiceEvent(actionUser);
151 
152  if (GetSendNotificationOnUse() && resupplyAction.GetNotificationOnUse() != ENotification.UNKNOWN)
153  {
154  //~ ID is not the local player so do not send notification
155  playerId = SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(actionOwner);
156  if (SCR_PlayerController.GetLocalPlayerId() == playerId)
157  {
158  RplId ownerId;
159  RplId userId;
160  FindEntityIds(actionOwner, actionUser, ownerId, userId, playerId);
161  SCR_NotificationsComponent.SendLocal(resupplyAction.GetNotificationOnUse(), userId);
162  }
163  }
164  }
165  }
166 }
SCR_BaseSupportStationComponentClass
Definition: SCR_BaseSupportStationComponent.c:2
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
m_EntityCatalogManager
protected SCR_EntityCatalogManagerComponent m_EntityCatalogManager
Definition: SCR_ResupplySupportStationComponent.c:14
SCR_PlayerController
Definition: SCR_PlayerController.c:31
m_iBaseSupplyCostOnUse
protected int m_iBaseSupplyCostOnUse
Definition: SCR_BaseSupportStationComponent.c:100
FindEntityIds
protected void FindEntityIds(IEntity owner, IEntity user, out RplId ownerId, out RplId userId, out int playerId)
Definition: SCR_BaseSupportStationComponent.c:148
EEntityCatalogType
EEntityCatalogType
Definition: EEntityCatalogType.c:4
OnSuccessfullyExecuted
protected void OnSuccessfullyExecuted(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action)
Definition: SCR_BaseSupportStationComponent.c:214
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
IsValid
override bool IsValid(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action, vector actionPosition, out ESupportStationReasonInvalid reasonInvalid, out int supplyCost)
Definition: SCR_ResupplySupportStationComponent.c:43
SCR_ResupplySupportStationComponentClass
Definition: SCR_ResupplySupportStationComponent.c:2
Attribute
SCR_ResupplySupportStationComponentClass SCR_BaseSupportStationComponentClass Attribute(SCR_EArsenalSupplyCostType.DEFAULT.ToString(), desc:"Cost type of items. If it is not DEFAULT than it will try to get the diffrent supply cost if the item has it assigned", uiwidget:UIWidgets.SearchComboBox, enums:ParamEnumArray.FromEnum(SCR_EArsenalSupplyCostType), category:"Resupply Support Station")] protected SCR_EArsenalSupplyCostType m_eSupplyCostType
PlaySoundEffect
protected void PlaySoundEffect(SCR_AudioSourceConfiguration audioConfig, notnull IEntity soundOwner, SCR_BaseUseSupportStationAction action)
Definition: SCR_BaseSupportStationComponent.c:222
PlayCharacterVoiceEvent
protected void PlayCharacterVoiceEvent(IEntity character)
Definition: SCR_BaseSupportStationComponent.c:269
ENotification
ENotification
Definition: ENotification.c:4
ESupportStationReasonInvalid
ESupportStationReasonInvalid
Definition: ESupportStationReasonInvalid.c:3
m_iFallbackItemSupplyCost
protected int m_iFallbackItemSupplyCost
Definition: SCR_ResupplySupportStationComponent.c:12
GetSendNotificationOnUse
bool GetSendNotificationOnUse()
Definition: SCR_BaseSupportStationComponent.c:28
OnConsumeSuppliesServer
protected bool OnConsumeSuppliesServer(int amount)
Definition: SCR_BaseSupportStationComponent.c:630
ESupportStationType
ESupportStationType
Definition: ESupportStationType.c:2
OnExecute
protected override void OnExecute(IEntity actionOwner, IEntity actionUser, int playerId, SCR_BaseUseSupportStationAction action)
Definition: SCR_ResupplySupportStationComponent.c:112
InitValidSetup
protected override bool InitValidSetup()
Definition: SCR_ResupplySupportStationComponent.c:24
GetSupplyCostAction
protected override int GetSupplyCostAction(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action)
Definition: SCR_ResupplySupportStationComponent.c:61
GetSupportStationType
override ESupportStationType GetSupportStationType()
Definition: SCR_ResupplySupportStationComponent.c:55
DelayedInit
protected override void DelayedInit(IEntity owner)
Definition: SCR_ResupplySupportStationComponent.c:17
UsesRange
bool UsesRange()
Definition: SCR_BaseSupportStationComponent.c:681
SCR_BaseResupplySupportStationAction
Definition: SCR_ResupplySupportStationAction.c:3
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
AreSuppliesEnabled
bool AreSuppliesEnabled()
Definition: SCR_BaseSupportStationComponent.c:644
SCR_BaseUseSupportStationAction
Definition: SCR_BaseUseSupportStationAction.c:1
GetFaction
SCR_CampaignFaction GetFaction()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:351
GetOnUseAudioConfig
SCR_AudioSourceConfiguration GetOnUseAudioConfig()
Definition: SCR_BaseSupportStationComponent.c:54
OnExecutedServer
override void OnExecutedServer(notnull IEntity actionOwner, notnull IEntity actionUser, notnull SCR_BaseUseSupportStationAction action)
Definition: SCR_ResupplySupportStationComponent.c:87
SCR_ArsenalItem
Definition: SCR_ArsenalItem.c:2
SCR_EntityCatalogEntry
Definition: SCR_EntityCatalogEntry.c:5
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180