1 [
EntityEditorProps(
category:
"GameScripted/Building", description:
"Component attached to a provider, responsible for basic provider behaviour.")]
6 class SCR_CampaignBuildingProviderComponent : SCR_MilitaryBaseLogicComponent
8 [
Attribute(
"", UIWidgets.EditBox,
"Name of provider shown in provider interface",
"")]
9 protected string m_sProviderDisplayName;
11 [
Attribute(
"0", UIWidgets.CheckBox,
"Can the building mode at this provider executed only via user action?")]
14 [
Attribute(
"0", UIWidgets.CheckBox,
"Master provider is for example HQ with other service (providers) in vicinity.")]
17 [
Attribute(
"0", UIWidgets.CheckBox,
"When opening a Free Roam Building mode, try to use master provider. Master provider is HQ where the service is registered in.")]
20 [
Attribute(
"0", UIWidgets.CheckBox,
"Register at nearby base, if available.")]
23 [
Attribute(
"0", UIWidgets.CheckBox,
"If set, player can command friendly AI in building radius.")]
26 [
Attribute(
"1", UIWidgets.CheckBox,
"Obstruct view when an enemy is present within the radius of the building.")]
29 [
Attribute(
"50", UIWidgets.EditBox,
"Building radius")]
32 [
Attribute(defvalue:
"1", uiwidget: UIWidgets.ComboBox,
desc:
"Minimal rank that allows player to use the provider to build structures.", enums: ParamEnumArray.FromEnum(
SCR_ECharacterRank))]
35 [
Attribute(
desc:
"Fill in the budgets to be used with this provider")]
38 [
Attribute(
desc:
"Traits this provider will provide. Each trait represents a tab in building interface. The tabs have to be defined in building mode's SCR_ContentBrowserEditorComponent.", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(
EEditableEntityLabel))]
55 protected ref array<SCR_CampaignBuildingBudgetToEvaluateData>
m_aShownBudget = {};
72 return m_sProviderDisplayName;
108 array<SCR_MilitaryBaseComponent> bases = {};
109 array<SCR_CampaignBuildingProviderComponent> providers = {};
113 foreach (SCR_MilitaryBaseComponent base : bases)
115 base.GetBuildingProviders(providers);
117 foreach (SCR_CampaignBuildingProviderComponent provider : providers)
119 if (provider.IsMasterProvider())
120 return provider.GetOwner();
134 IEntity masterProvider;
138 if (budgetData.GetBudget() == budget && budgetData.UseMasterProviderBudget())
144 masterProviderComponent = SCR_CampaignBuildingProviderComponent.Cast(masterProvider.FindComponent(SCR_CampaignBuildingProviderComponent));
155 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
156 if (!playerController)
159 SCR_CampaignBuildingNetworkComponent buildingNetworkComponent = SCR_CampaignBuildingNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignBuildingNetworkComponent));
160 if (!buildingNetworkComponent)
163 buildingNetworkComponent.SetClientLock(lock, provider);
205 cooldownChange =
true;
227 float cooldown = 0.0;
235 if (cooldownEntry.param1 == playerId)
237 cooldown = cooldownEntry.param2.DiffMilliseconds(world.GetServerTimestamp()) * 0.001;
260 super.RegisterBase(base);
274 array<SCR_MilitaryBaseComponent> bases = {};
306 if (maxValueBudgetData)
307 return maxValueBudgetData.GetMaxValue();
325 SCR_CampaignBuildingProviderComponent masterProviderComponent;
328 masterProviderComponent.SetPropValue(value);
330 Replication.BumpMe();
340 SCR_CampaignBuildingProviderComponent masterProviderComponent;
343 masterProviderComponent.AddPropValue(value);
345 Replication.BumpMe();
351 SCR_CampaignBuildingProviderComponent masterProviderComponent;
354 return masterProviderComponent.GetCurrentAIValue();
364 SCR_CampaignBuildingProviderComponent masterProviderComponent;
367 masterProviderComponent.SetAIValue(value);
369 Replication.BumpMe();
377 SCR_CampaignBuildingProviderComponent masterProviderComponent;
380 masterProviderComponent.AddAIValue(value);
382 Replication.BumpMe();
397 SCR_EditableCharacterComponent editableCharacter = SCR_EditableCharacterComponent.Cast(ent.FindComponent(SCR_EditableCharacterComponent));
398 if (!editableCharacter)
401 editableCharacter.GetOnDestroyed().Insert(
OnAIRemoved);
402 editableCharacter.GetOnDeleted().Insert(
OnAIRemoved);
409 SCR_EditableCharacterComponent editableCharacter = SCR_EditableCharacterComponent.Cast(ent.FindComponent(SCR_EditableCharacterComponent));
410 if (!editableCharacter)
413 editableCharacter.GetOnDestroyed().Remove(
OnAIRemoved);
414 editableCharacter.GetOnDeleted().Remove(
OnAIRemoved);
420 array<EEditableEntityLabel> availableTraits = {};
422 return availableTraits;
428 SetEventMask(owner, EntityEvent.INIT);
430 super.OnPostInit(owner);
436 super.EOnInit(owner);
526 if (!networkComponent)
544 PlayerController playerController =
GetGame().GetPlayerController();
545 if (!playerController)
548 SCR_PlayerTeleportedFeedbackComponent playerTeleportComponent = SCR_PlayerTeleportedFeedbackComponent.Cast(playerController.FindComponent(SCR_PlayerTeleportedFeedbackComponent));
549 if (!playerTeleportComponent)
559 ChimeraCharacter player = ChimeraCharacter.Cast(
SCR_PlayerController.GetLocalControlledEntity());
576 if (!networkComponent)
590 if (!networkComponent)
601 ChimeraCharacter player = ChimeraCharacter.Cast(
SCR_PlayerController.GetLocalControlledEntity());
615 if (!factionComponent)
676 if (!placingComponent)
708 if (!networkComponent)
718 return s_OnProviderCreated;
736 PlayerController playerController =
GetGame().GetPlayerController();
737 if (!playerController)
740 SCR_PlayerTeleportedFeedbackComponent playerTeleportComponent = SCR_PlayerTeleportedFeedbackComponent.Cast(playerController.FindComponent(SCR_PlayerTeleportedFeedbackComponent));
741 if (!playerTeleportComponent)
758 PlayerController playerController =
GetGame().GetPlayerController();
759 if (!playerController)
762 return SCR_CampaignBuildingNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignBuildingNetworkComponent));
773 return core.GetEditorManager();
784 return core.GetEditorManager(playerId);
790 IEntity player =
GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
800 if (!characterControllerComponent)
803 IEntity ent = characterControllerComponent.GetOwner();
807 return GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(ent);
829 return playerFaction == owningFaction;
835 FactionAffiliationComponent factionComp = FactionAffiliationComponent.Cast(ent.FindComponent(FactionAffiliationComponent));
838 while (!factionComp && ent)
840 ent = ent.GetParent();
842 factionComp = FactionAffiliationComponent.Cast(ent.FindComponent(FactionAffiliationComponent));
848 Faction faction = factionComp.GetAffiliatedFaction();
850 faction = factionComp.GetDefaultAffiliatedFaction();
878 [
Obsolete(
"SCR_CampaignBuildingProviderComponent.GetResourceComponent() should be used instead.")]
890 if (budgetData.GetBudget() == budget)
903 budgets.Insert(budgetData.GetBudget());
906 return budgets.Count();
919 if (budgetData.GetBudget() == blockingBudget && budgetData.CanBeUsed())
932 if (budgetData.CanShowBudgetInUI() && !
m_aShownBudget.Contains(budgetData))
935 return budgetData.GetBudget();
953 if (!cooldownBudgetData)
956 return cooldownBudgetData.CooldownTimeModifier(playerId, cooldownTime);
967 BaseGameMode gameMode =
GetGame().GetGameMode();
971 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
972 if (!buildingManagerComponent)
978 isActiveUser =
false;
994 buildingManagerComponent.RemoveProvider(playerId,
this, isActiveUser);
1045 FactionAffiliationComponent factionComponent = FactionAffiliationComponent.Cast(
char.FindComponent(FactionAffiliationComponent));
1046 if (!factionComponent)
1049 Faction faction = factionComponent.GetAffiliatedFaction();
1053 SCR_CampaignFactionManager factionManager = SCR_CampaignFactionManager.Cast(
GetGame().GetFactionManager());
1054 if (!factionManager)
1057 Faction playerFaction = factionManager.GetLocalPlayerFaction();
1061 return playerFaction.IsFactionEnemy(faction);
1067 s_OnProviderCreated.Invoke();