1#define ENABLE_BASE_DESTRUCTION
2[
EntityEditorProps(
category:
"GameScripted/Campaign", description:
"Handles client > server communication in Campaign. Should be attached to PlayerController.", color:
"0 0 255 255")]
8enum ECampaignClientNotificationID
61 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerID);
63 if (!playerController)
68 return networkComponent;
130#ifdef ENABLE_BASE_DESTRUCTION
144#ifdef ENABLE_BASE_DESTRUCTION
145 if (
index == -1 || repairCost == -1 || destructibleID == -1)
149 if (!destructionManager)
153 if (!destructibleComp)
168 SCR_CampaignServiceEntityComponent serviceEntityComp = SCR_CampaignServiceEntityComponent.Cast(destructibleComp.GetOwner().FindComponent(SCR_CampaignServiceEntityComponent));
169 if (!serviceEntityComp)
172 SCR_CampaignServiceCompositionComponent serviceCompositionComp = SCR_CampaignServiceCompositionComponent.Cast(composition.
FindComponent(SCR_CampaignServiceCompositionComponent));
173 if (!serviceCompositionComp)
181 serviceEntityComp.RepairEntity();
184 base.AddSupplies(-repairCost);
188 base.GetMapDescriptor().HandleMapInfo();
217 if (!callsignManager)
225 int companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller;
227 if (!callsignManager.
GetEntityCallsignIndexes(player, companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller))
240 BaseRadioComponent radio = BaseRadioComponent.Cast(radioEnt.
FindComponent(BaseRadioComponent));
242 if (!radio || !radio.IsPowered())
250 IEntity called =
GetGame().GetPlayerManager().GetPlayerControlledEntity(calledID);
252 int factionId = fManager.GetFactionIndex(fManager.GetPlayerFaction(
m_PlayerController.GetPlayerId()));
258 msg.
SetCallerCallsign(companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller);
262 msg.SetEncryptionKey(radio.GetEncryptionKey());
264 int companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled;
266 if (called && callsignManager.
GetEntityCallsignIndexes(called, companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled))
267 msg.
SetCalledCallsign(companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled);
269 Rpc(
RpcDo_PlayRadioMsg, msgType, factionId, baseCallsign,
CompressCallsign(companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller),
CompressCallsign(companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled), param, msg.
GetSeed(), 1.0);
272 transmitter.BeginTransmission(msg);
286 return (company * 1000000) + (platoon * 10000) + (squad * 100) + character;
290 protected void DecompressCallsign(
int callsign, out
int company, out
int platoon, out
int squad, out
int character)
292 company =
Math.Floor(callsign * 0.000001);
293 callsign = callsign - (company * 1000000);
295 platoon =
Math.Floor(callsign * 0.0001);
296 callsign = callsign - (platoon * 10000);
298 squad =
Math.Floor(callsign * 0.01);
299 callsign = callsign - (squad * 100);
301 character = callsign;
352 SCR_CampaignFeedbackComponent manager = SCR_CampaignFeedbackComponent.GetInstance();
359 case ECampaignClientNotificationID.SUPPLIES_LOADED:
361 msg =
"#AR-Campaign_SuppliesLoaded-UC";
364 msg1param1 = value.ToString();
368 msg2 =
"#AR-Campaign_SuppliesAmountInfo-UC";
369 msg2param1 =
base.GetBaseName();
370 msg2param2 =
base.GetSupplies().ToString();
377 case ECampaignClientNotificationID.SUPPLIES_UNLOADED:
379 msg =
"#AR-Campaign_SuppliesUnloaded-UC";
382 msg1param1 = value.ToString();
386 msg2 =
"#AR-Campaign_SuppliesAmountInfo-UC";
387 msg2param1 =
base.GetBaseName();
388 msg2param2 =
base.GetSupplies().ToString();
391 if (!campaign.IsTutorial())
394 manager.ShowHint(
EHint.CONFLICT_BUILDING);
401 case ECampaignClientNotificationID.RESPAWN:
410 msg =
base.GetBaseNameUpperCase();
419 timeManager.GetHoursMinutesSeconds(hours, minutes, seconds);
420 string strHours = hours.ToString();
422 if (hours > 0 && hours < 10)
423 strHours =
"0" + strHours;
425 string strMinutes = minutes.ToString();
428 strMinutes =
"0" + strMinutes;
430 msg =
string.Format(
"%1, %2:%3", msg, strHours, strMinutes);
468 SCR_CampaignFeedbackComponent feedbackComponent = SCR_CampaignFeedbackComponent.GetInstance();
470 if (!feedbackComponent)
473 feedbackComponent.ShowHint(hintID);
501 SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.Cast(
GetOwner().
FindComponent(SCR_CampaignFeedbackComponent));
505 EventHandlerManagerComponent eventHandlerManagerComponent = EventHandlerManagerComponent.Cast(player.
FindComponent(EventHandlerManagerComponent));
506 if (!eventHandlerManagerComponent)
511 comp.OnConsciousnessChanged(
true);
512 eventHandlerManagerComponent.RegisterScriptHandler(
"OnConsciousnessChanged", comp, comp.OnConsciousnessChanged);
516 eventHandlerManagerComponent.RemoveScriptHandler(
"OnConsciousnessChanged", comp, comp.OnConsciousnessChanged);
524 SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
525 comp.UpdatePlayerSpawnHint(show,
position);
551 IEntity operator =
GetGame().GetPlayerManager().GetPlayerControlledEntity(spawnpoint.GetPlayerID());
561 SCR_CampaignFactionManager fManager = SCR_CampaignFactionManager.Cast(
GetGame().GetFactionManager());
566 SCR_TimedSpawnPointComponent timer = SCR_TimedSpawnPointComponent.Cast(campaign.FindComponent(SCR_TimedSpawnPointComponent));
572 float suicidePenalty;
576 suicidePenalty =
data.GetRespawnPenalty();
578 timer.SetRespawnTime(playerId, fManager.GetRankRadioRespawnCooldown(
SCR_CharacterRankComponent.GetCharacterRank(
operator), playerId) + suicidePenalty);
607 if (!taskNotificationManager)
610 taskNotificationManager.PlayTaskNotificationMsg(taskNotification, msg, factionId, baseCallsign, callerGroupId, calledGroupId, grid, quality);
631 void PlayRadioMsg(
SCR_ERadioMsg msg,
int FactionId,
int baseCallsign,
int callerCallsignCompany,
int callerCallsignPlatoon,
int callerCallsignSquad,
int callerCallsignCharacter,
int calledCallsignCompany,
int calledCallsignPlatoon,
int calledCallsignSquad,
int calledCallsignCharacter,
bool isPublic,
int param,
float seed,
float quality,
int playerID)
634 Rpc(
RpcDo_PlayRadioMsg, msg, FactionId, baseCallsign,
CompressCallsign(callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, callerCallsignCharacter),
CompressCallsign(calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad, calledCallsignCharacter), param, seed, quality);
652 int callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, callerCallsignCharacter, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad, calledCallsignCharacter;
653 DecompressCallsign(callerCallsign, callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, callerCallsignCharacter);
654 DecompressCallsign(calledCallsign, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad, calledCallsignCharacter);
656 SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
661 comp.PlayRadioMsg(msg, factionId, baseCallsign, callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, callerCallsignCharacter, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad, calledCallsignCharacter, param, seed, quality);
669 SCR_ResourceConsumer consumer = resourceComponentFrom.GetConsumer(
EResourceGeneratorID.VEHICLE_LOAD, resourceType);
671 if (!consumer && !resourceComponentFrom.GetConsumer(
EResourceGeneratorID.DEFAULT, resourceType, consumer))
674 SCR_ResourceContainerQueue containerQueue = SCR_ResourceContainerQueue.Cast(consumer.GetContainerQueue());
689 if (!playerController || !resourceComponentFrom || !resourceComponentTo)
692 GetOnTransferSupplies().Invoke(interactionType, resourceComponentFrom, resourceComponentTo, resourceType, resourceValue, playerController);
694 vector pos = resourceComponentFrom.GetOwner().GetOrigin();
696 switch (interactionType)
706 OnSuppliesUnloaded(pos, resourceValue, playerController.GetPlayerId(), resourceComponentFrom);
716 if (vehicleFrom && vehicleTo)
720 OnSuppliesUnloaded(pos, resourceValue, playerController.GetPlayerId(), resourceComponentFrom);
745 if (!nearestBase || !nearestBase.
IsInitialized() ||
vector.DistanceXZ(
position, nearestBase.GetOwner().GetOrigin()) > nearestBase.GetRadius())
749 if (!nearestDepot ||
vector.DistanceXZ(
position, nearestDepot.GetOwner().GetOrigin()) > 100)
779 array<int> allPlayerIds = {};
781 pManager.GetPlayers(allPlayerIds);
782 PlayerController loaderController;
785 foreach (
int loaderId : allPlayerIds)
787 loaderController = pManager.GetPlayerController(loaderId);
789 if (!loaderController)
794 if (!networkComponent)
823 if (!nearestBase || !nearestBase.
IsInitialized() ||
vector.DistanceXZ(
position, nearestBase.GetOwner().GetOrigin()) > nearestBase.GetRadius())
836 compXP.AwardXP(playerId,
SCR_EXPRewards.SUPPLIES_DELIVERED, suppliesXPmultiplier);
839 compXP.AwardXP(assistantId,
SCR_EXPRewards.SUPPLIES_DELIVERED, suppliesXPmultiplier * campaign.GetSupplyOffloadAssistanceReward());
860 Print(
"SCR_CampaignNetworkComponent must be attached to PlayerController!",
LogLevel.ERROR);
884 super.OnPostInit(owner);
ArmaReforgerScripted GetGame()
RplMode
Mode of replication.
SCR_BaseGameMode GetGameMode()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
SCR_ECampaignPopupPriority
Popup message priorities sorted from lowest to highest.
func ScriptInvokerTransferSuppliesMethod
SCR_CampaignNetworkComponentClass VEHICLE_SPAWNED
Used to identify various notifications for client.
SCR_CampaignNetworkComponentClass NO_SPACE
SCR_CampaignNetworkComponentClass SUPPLIES_LOADED
SCR_CampaignNetworkComponentClass OUT_OF_STOCK
SCR_CampaignNetworkComponentClass SUPPLIES_UNLOADED
ScriptInvokerBase< ScriptInvokerTransferSuppliesMethod > ScriptInvokerTransferSupplies
void SCR_CampaignSuppliesComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
SCR_ETaskNotification
Objective and request notifications types.
SCR_ETaskNotificationMsg
Various types of task notifications for different events and states.
Get all prefabs that have the spawner data
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
EResourceContainerStorageType
EResourcePlayerInteractionType
ScriptInvokerBase< ScriptInvokerInt3Method > ScriptInvokerInt3
void SCR_TaskNotificationManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_TextsTaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external GenericComponent FindComponent(typename typeName)
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
Replication item identifier.
bool GetEntityCallsignIndexes(IEntity entity, out int companyCallsignIndex, out int platoonCallsignIndex, out int squadCallsignIndex, out int characterCallsignIndex)
Used for storing client data to be reapplied for reconnecting clients.
static const int INVALID_PLAYER_INDEX
Created in SCR_GameModeCampaign.
SCR_CampaignMilitaryBaseComponent FindClosestBase(vector position, SCR_ECampaignBaseType searchedType=-1)
SCR_CampaignSuppliesComponent FindClosestSupplyDepot(vector position)
Takes care of Campaign-specific server <> client communication and requests.
WorldTimestamp m_fLastHQRadioMessageTimestamp
void OnPlayerAliveStateChanged(bool alive)
void SetLastRequestTimestamp(WorldTimestamp timestamp)
void RespawnLocationPopup(int baseID)
float m_fLoadedSupplyAmount
void RpcAsk_RepairComposition(int index, int repairCost, int destructibleID, RplId slotID, RplId baseID)
Repair damaged entity in composition.
void ~SCR_CampaignNetworkComponent()
static const int SUPPLY_DELIVERY_XP_PERCENT
void RpcDo_PlayerFeedbackValueBase(int msgID, float value, int baseID)
static const int SUPPLY_DELIVERY_THRESHOLD_SQ
void SendVehicleSpawnHint(int hintID)
WorldTimestamp GetLastRequestTimestamp()
void OnSuppliesUnloaded(vector position, float amount, int playerId, notnull SCR_ResourceComponent resourceComponentFrom, int assistantId=0)
SCR_PlayerController m_PlayerController
void RpcDo_PlayerFeedback(int msgID)
static SCR_CampaignNetworkComponent GetCampaignNetworkComponent(int playerID)
void EOnInit(IEntity owner)
float m_fNoRewardSupplies
void SendPlayerMessage(SCR_ERadioMsg msgType, int baseCallsign=SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN, int calledID=SCR_CampaignMilitaryBaseComponent.INVALID_PLAYER_INDEX, bool public=true, int param=SCR_CampaignRadioMsg.INVALID_RADIO_MSG_PARAM, bool checkHQReached=false)
void HandleRadioRespawnTimer(RplId spawnPointId)
void DecompressCallsign(int callsign, out int company, out int platoon, out int squad, out int character)
SCR_ResourceComponent GetLastLoadedComponent()
static ScriptInvokerTransferSupplies GetOnTransferSupplies()
int m_iTotalSuppliesDelivered
void RpcDo_UpdatePlayerSpawnHint(bool show, vector position)
void RpcAsk_HandleRadioRespawnTimer(RplId selectedSpawnPointId)
void SetLastHQRadioMessageTimestamp(WorldTimestamp time)
void PlayTaskNotificationMsg(SCR_ETaskNotification taskNotification, SCR_ETaskNotificationMsg msg, int factionId, int baseCallsign, int callerGroupId, int calledGroupId, int grid, float quality, int playerID)
void RpcDo_VehicleSpawnHint(int hintID)
WorldTimestamp m_fLastAssetRequestTimestamp
static ref ScriptInvokerInt3 s_OnSuppliesDelivered
void OnPlayerSuppliesInteraction(EResourcePlayerInteractionType interactionType, PlayerController playerController, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue)
static ScriptInvokerInt3 GetOnSuppliesDelivered()
bool m_bOrphanSuppliesLoaded
void RpcDo_PlayTaskNotificationMsg(SCR_ETaskNotification taskNotification, SCR_ETaskNotificationMsg msg, int factionId, int baseCallsign, int callerGroupId, int calledGroupId, int grid, float quality)
void RpcDo_PlayRadioMsg(SCR_ERadioMsg msg, int factionId, int baseCallsign, int callerCallsign, int calledCallsign, int param, float seed, float quality)
void RepairComposition(int index, int repairCost, int destructibleID, SCR_SiteSlotEntity slotEnt, notnull SCR_CampaignMilitaryBaseComponent base)
Repair destroyed mandatory part of composition.
void OnSuppliesLoaded(vector position, float amount, notnull SCR_ResourceComponent resourceComponentTo)
void RpcDo_PlayerFeedbackBase(int msgID, int baseID)
void OnPostInit(IEntity owner)
int CompressCallsign(int company, int platoon, int squad, int character)
SCR_ResourceComponent m_LastLoadedComponent
static ref ScriptInvokerTransferSupplies s_OnSuppliesTransferred
RplComponent m_RplComponent
void PlayerFeedbackImpl(int msgID, float value=0, int assetID=-1, int baseID=-1)
void OnBeforePlayerInteraction(EResourcePlayerInteractionType interactionType, PlayerController playerController, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue)
Callback.
void PlayRadioMsg(SCR_ERadioMsg msg, int FactionId, int baseCallsign, int callerCallsignCompany, int callerCallsignPlatoon, int callerCallsignSquad, int callerCallsignCharacter, int calledCallsignCompany, int calledCallsignPlatoon, int calledCallsignSquad, int calledCallsignCharacter, bool isPublic, int param, float seed, float quality, int playerID)
void ResetSavedSupplies()
void SetRadioMsg(SCR_ERadioMsg msg)
void SetCallerCallsign(int companyID, int platoonID, int squadID, int characterID)
void SetFactionId(int factionId)
void SetCalledCallsign(int companyID, int platoonID, int squadID, int characterID)
void SetIsPublic(bool public)
void SetPlayerID(int playerID)
void SetBaseCallsign(int callsign)
static IEntity GetMainParent(IEntity entity, bool self=false)
IEntity GetGadgetByType(EGadgetType type)
SCR_DestructionDamageManagerComponent FindDynamicallySpawnedDestructibleByIndex(RplId rplId, int index)
static SCR_MPDestructionManager GetInstance()
Returns the instance of the destruction manager.
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
Takes care of dynamic and static onscreen popups.
void PopupMsg(string text, float duration=DEFAULT_DURATION, string text2="", int prio=-1, string param1="", string param2="", string param3="", string param4="", string text2param1="", string text2param2="", string text2param3="", string text2param4="", string sound="", SCR_EPopupMsgFilter category=SCR_EPopupMsgFilter.ALL, WorldTimestamp progressStart=null, WorldTimestamp progressEnd=null)
static SCR_PopUpNotification GetInstance()
static const string TASKS_KEY_IMAGE_FORMAT
ScriptInvokerResourceOnPlayerInteraction GetOnBeforePlayerInteraction()
ScriptInvokerResourceOnPlayerInteraction GetOnPlayerInteraction()
Spawn point entity defines positions on which players can possibly spawn.
static SCR_SpawnPoint GetSpawnPointByRplId(RplId id)
static ScriptInvoker SGetOnSpawnPointSelected()
proto external GenericEntity GetOwner()
Get owner entity.
enum EPhysicsLayerPresets Vehicle
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
EntityEvent
Various entity events.
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
RplCondition
Conditional replication rule. Fine grained selection of receivers.
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.