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")]
8 enum ECampaignClientNotificationID
35 static const float FULL_SUPPLY_TRUCK_AMOUNT = 600.0;
36 static const int SUPPLY_DELIVERY_THRESHOLD_SQ = 200 * 200;
42 [
RplProp(condition: RplCondition.OwnerOnly)]
45 [
RplProp(condition: RplCondition.OwnerOnly)]
51 static SCR_CampaignNetworkComponent GetCampaignNetworkComponent(
int playerID)
53 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerID);
55 if (!playerController)
58 SCR_CampaignNetworkComponent networkComponent = SCR_CampaignNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignNetworkComponent));
60 return networkComponent;
89 if (!s_OnSuppliesDelivered)
92 return s_OnSuppliesDelivered;
106 #ifdef ENABLE_BASE_DESTRUCTION
119 if (!player || !base)
122 RplId baseID = Replication.FindId(base);
139 if (!player || !depot)
142 RplId depotID = Replication.FindId(depot);
156 void StartLoading(RplId suppliesID,
int supplies,
bool IsUnloading =
false)
179 if (!player || !base)
182 RplId baseID = Replication.FindId(base);
199 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
207 SCR_ChimeraCharacter player = SCR_ChimeraCharacter.Cast(pMan.GetPlayerControlledEntity(playerID));
212 EntitySpawnParams spawnParams = EntitySpawnParams();
213 spawnParams.TransformMode = ETransformMode.WORLD;
214 player.GetWorldTransform(spawnParams.Transform);
221 Resource res = Resource.Load(faction.GetRadioPrefab());
226 IEntity radio =
GetGame().SpawnEntityPrefab(res,
GetGame().GetWorld(),spawnParams);
231 RplComponent rplC = RplComponent.Cast(radio.FindComponent(RplComponent));
240 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
249 RplComponent rplC = RplComponent.Cast(Replication.FindItem(ID));
260 IEntity radio = rplC.GetEntity();
265 SCR_InventoryStorageManagerComponent inventory = SCR_InventoryStorageManagerComponent.Cast(player.FindComponent(SCR_InventoryStorageManagerComponent));
270 inventory.InsertItem(radio);
283 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
286 SCR_CampaignMobileAssemblyComponent comp = SCR_CampaignMobileAssemblyComponent.Cast(Replication.FindItem(assemblyComponentID));
293 if (
SCR_WorldTools.IsObjectUnderwater(comp.GetOwner(), vector.Zero, -1, depth) && depth > SCR_CampaignMobileAssemblyComponent.MAX_WATER_DEPTH)
296 if (comp.IsDeployed() == deploy)
314 int factionID = SCR_CampaignFactionManager.Cast(
GetGame().GetFactionManager()).GetFactionIndex(faction);
321 CharacterControllerComponent comp = CharacterControllerComponent.Cast(player.FindComponent(CharacterControllerComponent));
351 int factionID = SCR_CampaignFactionManager.Cast(
GetGame().GetFactionManager()).GetFactionIndex(faction);
364 #ifdef ENABLE_BASE_DESTRUCTION
367 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
370 if (
index == -1 || repairCost == -1 || destructibleID == -1)
374 if (!destructionManager)
377 SCR_DestructionMultiPhaseComponent destructibleComp = SCR_DestructionMultiPhaseComponent.Cast(destructionManager.FindDynamicallySpawnedDestructibleByIndex(destructibleID,
index));
378 if (!destructibleComp)
389 IEntity composition = IEntity.Cast(
SCR_EntityHelper.GetMainParent(destructibleComp.GetOwner()));
393 SCR_CampaignServiceEntityComponent serviceEntityComp = SCR_CampaignServiceEntityComponent.Cast(destructibleComp.GetOwner().FindComponent(SCR_CampaignServiceEntityComponent));
394 if (!serviceEntityComp)
397 SCR_CampaignServiceCompositionComponent serviceCompositionComp = SCR_CampaignServiceCompositionComponent.Cast(composition.FindComponent(SCR_CampaignServiceCompositionComponent));
398 if (!serviceCompositionComp)
406 serviceEntityComp.RepairEntity();
409 base.AddSupplies(-repairCost);
412 if (RplSession.Mode() != RplMode.Dedicated)
413 base.GetMapDescriptor().HandleMapInfo();
423 RplId baseID = Replication.FindId(base);
425 if (!baseID.IsValid())
432 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
440 if (base.GetSupplies() >= base.GetSuppliesMax())
443 base.AddSupplies(Math.Min(suppliesCnt, base.GetSuppliesMax() - base.GetSupplies()));
456 IEntity parentVehicle = vehicleEntity.GetParent();
461 SCR_BaseCompartmentManagerComponent comp = SCR_BaseCompartmentManagerComponent.Cast(parentVehicle.FindComponent(SCR_BaseCompartmentManagerComponent));
465 array<IEntity> occupants = {};
466 comp.GetOccupants(occupants);
468 if(occupants.IsEmpty())
471 foreach (IEntity occupant : occupants)
473 int occupantID =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(occupant);
475 SCR_NotificationsComponent.SendToPlayer(occupantID, messageID, playerID, number);
477 SCR_NotificationsComponent.SendToPlayer(occupantID, messageID, playerID);
483 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
487 array<IEntity> occupants = {};
489 if(!suppliesComponent)
493 IEntity vehicleEntity = suppliesComponent.GetOwner();
509 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
514 if(!suppliesComponent)
518 IEntity vehicleEntity = suppliesComponent.GetOwner();
539 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
544 if (!suppliesComponent)
547 IEntity box = suppliesComponent.GetOwner();
557 if (amount > base.GetSupplies())
560 IEntity player =
GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
570 if (!playerFaction || playerFaction != base.GetFaction())
574 if (!baseSuppliesComponent)
605 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
610 if (!suppliesComponent)
618 IEntity player =
GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
623 IEntity box = suppliesComponent.GetOwner();
653 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
658 if (!suppliesComponent)
666 IEntity player =
GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
671 IEntity box = suppliesComponent.GetOwner();
730 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
733 SCR_CampaignFaction faction = SCR_CampaignFactionManager.Cast(
GetGame().GetFactionManager()).GetCampaignFactionByIndex(factionIndex);
743 base.BeginCapture(faction, playerID);
747 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
783 if (!callsignManager)
791 int companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller;
793 if (!callsignManager.GetEntityCallsignIndexes(player, companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller))
801 IEntity radioEnt = gadgetMan.GetGadgetByType(EGadgetType.RADIO);
806 BaseRadioComponent radio = BaseRadioComponent.Cast(radioEnt.FindComponent(BaseRadioComponent));
808 if (!radio || !radio.IsPowered())
816 IEntity called =
GetGame().GetPlayerManager().GetPlayerControlledEntity(calledID);
818 int factionId = fManager.GetFactionIndex(fManager.GetPlayerFaction(
m_PlayerController.GetPlayerId()));
821 msg.SetRadioMsg(msgType);
822 msg.SetFactionId(factionId);
823 msg.SetBaseCallsign(baseCallsign);
824 msg.SetCallerCallsign(companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller);
825 msg.SetIsPublic(
public);
828 msg.SetEncryptionKey(radio.GetEncryptionKey());
830 int companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled;
832 if (called && callsignManager.GetEntityCallsignIndexes(called, companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled))
833 msg.SetCalledCallsign(companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled);
835 Rpc(
RpcDo_PlayRadioMsg, msgType, factionId, baseCallsign,
CompressCallsign(companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller),
CompressCallsign(companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled), param, msg.GetSeed(), 1.0);
838 transmitter.BeginTransmission(msg);
846 Replication.BumpMe();
852 return (company * 10000) + (platoon * 100) + squad;
858 company = Math.Floor(callsign * 0.0001);
859 callsign = callsign - (company * 10000);
861 platoon = Math.Floor(callsign * 0.01);
862 callsign = callsign - (platoon * 100);
872 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
875 SCR_CampaignFaction faction = SCR_CampaignFactionManager.Cast(
GetGame().GetFactionManager()).GetCampaignFactionByIndex(factionIndex);
885 if (base.BeginCapture(faction, playerID))
886 base.SetFaction(faction);
895 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
906 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
917 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
940 SCR_CampaignFeedbackComponent manager = SCR_CampaignFeedbackComponent.GetInstance();
947 case ECampaignClientNotificationID.SUPPLIES_LOADED:
949 msg =
"#AR-Campaign_SuppliesLoaded-UC";
952 msg1param1 = value.ToString();
956 msg2 =
"#AR-Campaign_SuppliesAmountInfo-UC";
957 msg2param1 = base.GetBaseName();
958 msg2param2 = base.GetSupplies().ToString();
965 case ECampaignClientNotificationID.SUPPLIES_UNLOADED:
967 msg =
"#AR-Campaign_SuppliesUnloaded-UC";
970 msg1param1 = value.ToString();
974 msg2 =
"#AR-Campaign_SuppliesAmountInfo-UC";
975 msg2param1 = base.GetBaseName();
976 msg2param2 = base.GetSupplies().ToString();
979 if (!campaign.IsTutorial())
982 manager.ShowHint(
EHint.CONFLICT_BUILDING);
989 case ECampaignClientNotificationID.RESPAWN:
998 msg = base.GetBaseNameUpperCase();
1000 TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
1007 timeManager.GetHoursMinutesSeconds(hours, minutes, seconds);
1008 string strHours = hours.ToString();
1010 if (hours > 0 && hours < 10)
1011 strHours =
"0" + strHours;
1013 string strMinutes = minutes.ToString();
1016 strMinutes =
"0" + strMinutes;
1018 msg =
string.Format(
"%1, %2:%3", msg, strHours, strMinutes);
1041 SCR_PopUpNotification.GetInstance().PopupMsg(msg, duration, msg2, param1: msg1param1, text2param1: msg2param1, text2param2: msg2param2);
1053 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
1056 SCR_CampaignFeedbackComponent feedbackComponent = SCR_CampaignFeedbackComponent.GetInstance();
1058 if (!feedbackComponent)
1061 feedbackComponent.ShowHint(hintID);
1077 SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.Cast(
GetOwner().FindComponent(SCR_CampaignFeedbackComponent));
1087 EventHandlerManagerComponent eventHandlerManagerComponent = EventHandlerManagerComponent.Cast(player.FindComponent(EventHandlerManagerComponent));
1089 if (!eventHandlerManagerComponent)
1094 comp.OnConsciousnessChanged(
true);
1095 eventHandlerManagerComponent.RegisterScriptHandler(
"OnConsciousnessChanged", comp, comp.OnConsciousnessChanged);
1099 eventHandlerManagerComponent.RemoveScriptHandler(
"OnConsciousnessChanged", comp, comp.OnConsciousnessChanged);
1106 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
1110 SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
1111 GetGame().GetCallqueue().CallLater(comp.EnablePlayerSpawnHint, 100,
true, enable);
1114 comp.PauseHintQueue();
1120 SCR_PlayerRadioSpawnPointCampaign spawnpoint = SCR_PlayerRadioSpawnPointCampaign.Cast(
SCR_SpawnPoint.GetSpawnPointByRplId(spawnPointId));
1129 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
1135 SCR_PlayerRadioSpawnPointCampaign spawnpoint = SCR_PlayerRadioSpawnPointCampaign.Cast(
SCR_SpawnPoint.GetSpawnPointByRplId(selectedSpawnPointId));
1140 IEntity
operator =
GetGame().GetPlayerManager().GetPlayerControlledEntity(spawnpoint.GetPlayerID());
1150 SCR_CampaignFactionManager fManager = SCR_CampaignFactionManager.Cast(
GetGame().GetFactionManager());
1155 SCR_TimedSpawnPointComponent timer = SCR_TimedSpawnPointComponent.Cast(campaign.FindComponent(SCR_TimedSpawnPointComponent));
1161 float suicidePenalty;
1166 suicidePenalty =
data.GetRespawnPenalty();
1168 timer.SetRespawnTime(playerId, fManager.GetRankRadioRespawnCooldown(
SCR_CharacterRankComponent.GetCharacterRank(
operator)) + suicidePenalty);
1187 void PlayRadioMsg(
SCR_ERadioMsg msg,
int FactionId,
int baseCallsign,
int callerCallsignCompany,
int callerCallsignPlatoon,
int callerCallsignSquad,
int calledCallsignCompany,
int calledCallsignPlatoon,
int calledCallsignSquad,
bool isPublic,
int param,
float seed,
float quality,
int playerID)
1196 if (!callsignManager)
1199 int playerCallsignCompany, playerCallsignPlatoon, playerCallsignSquad, playerCallsignCharacter;
1200 callsignManager.GetEntityCallsignIndexes(
m_PlayerController.GetMainEntity(), playerCallsignCompany, playerCallsignPlatoon, playerCallsignSquad, playerCallsignCharacter);
1203 Rpc(
RpcDo_PlayRadioMsg, msg, FactionId, baseCallsign,
CompressCallsign(callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad),
CompressCallsign(calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad), param, seed, quality);
1216 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
1221 int callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad;
1222 DecompressCallsign(callerCallsign, callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad);
1223 DecompressCallsign(calledCallsign, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad);
1225 SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
1230 comp.PlayRadioMsg(msg, factionId, baseCallsign, callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad, param, seed, quality);
1254 if (!playerController || !resourceComponentFrom || !resourceComponentTo)
1257 vector pos = resourceComponentFrom.GetOwner().GetOrigin();
1259 switch (interactionType)
1275 Vehicle vehicleFrom = Vehicle.Cast(
SCR_EntityHelper.GetMainParent(resourceComponentFrom.GetOwner(),
true));
1276 Vehicle vehicleTo = Vehicle.Cast(
SCR_EntityHelper.GetMainParent(resourceComponentTo.GetOwner(),
true));
1279 if (vehicleFrom && vehicleTo)
1306 if (s_OnSuppliesDelivered)
1309 SCR_XPHandlerComponent compXP = SCR_XPHandlerComponent.Cast(
GetGame().
GetGameMode().FindComponent(SCR_XPHandlerComponent));
1312 compXP.AwardXP(playerId,
SCR_EXPRewards.SUPPLIES_DELIVERED, amount / FULL_SUPPLY_TRUCK_AMOUNT);
1330 Print(
"SCR_CampaignNetworkComponent must be attached to PlayerController!", LogLevel.ERROR);
1334 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
1351 super.OnPostInit(owner);
1352 SetEventMask(owner, EntityEvent.INIT);