2 [
EntityEditorProps(
category:
"GameScripted/Tasks", description:
"Campaign defend task support entity.", color:
"0 0 255 255")]
15 [
Attribute(
"300",
desc:
"From how far can an ally request reinforcements. (in m)")]
16 protected float m_fMinAllyDistance;
18 [
Attribute(
"400",
desc:
"How far an ally can be to receive rewards for this task. (in m)")]
19 protected float m_fMaxAllyDistance;
21 [
Attribute(
"300",
desc:
"How far an enemy has to be, for an ally to be able to request reinforcements. (in m)")]
22 protected float m_fMinEnemyDistance;
24 [
Attribute(
"400",
desc:
"How far an enemy has to be, to be outside of the radius of an existing defend task. (in m)")]
25 protected float m_fMaxEnemyDistance;
28 protected ref map<SCR_CampaignFaction, ref array<SCR_ChimeraCharacter>> m_mFactionSortedCharacters =
new map<SCR_CampaignFaction, ref array<SCR_ChimeraCharacter>>();
37 if (!m_OnCharacterDeath)
40 return m_OnCharacterDeath;
44 override bool CanRequest()
47 if (!playerController)
57 override void Request()
59 PlayerController playerController =
GetGame().GetPlayerController();
60 if (!playerController)
67 override void SetRequestButtonText(notnull TextWidget textWidget)
72 textWidget.SetTextFormat(m_sRequestButtonText, m_ClosestBase.GetBaseName());
76 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
77 void RPC_SetTargetBase(
int taskID,
int baseID)
90 task.SetTargetBase(base);
101 taskID = task.GetTaskID();
102 baseID = base.GetCallsign();
104 Rpc(RPC_SetTargetBase, taskID, baseID);
105 RPC_SetTargetBase(taskID, baseID);
118 SetTargetBase(defendTask, targetBase);
119 SetTargetFaction(defendTask, targetFaction);
123 void OnControllableCreated(IEntity controllable)
125 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(controllable);
133 array<SCR_ChimeraCharacter> factionCharacters = GetCharactersByFaction(faction);
134 if (!factionCharacters)
136 factionCharacters =
new array<SCR_ChimeraCharacter>();
137 m_mFactionSortedCharacters.Insert(faction, factionCharacters);
140 factionCharacters.Insert(character);
143 if (!characterControllerComponent)
146 characterControllerComponent.GetOnPlayerDeathWithParam().Insert(
OnCharacterDeath);
152 SCR_ChimeraCharacter character = characterControllerComponent.GetCharacter();
160 array<SCR_ChimeraCharacter> factionCharacters = m_mFactionSortedCharacters.Get(faction);
161 if (!factionCharacters)
164 factionCharacters.RemoveItem(character);
166 if (m_OnCharacterDeath)
167 m_OnCharacterDeath.Invoke(character);
172 void OnControllableDeleted(IEntity controllable)
174 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(controllable);
182 array<SCR_ChimeraCharacter> factionCharacters = m_mFactionSortedCharacters.Get(faction);
183 if (!factionCharacters)
186 if (factionCharacters.Find(character) > -1)
187 factionCharacters.RemoveItem(character);
193 array<SCR_ChimeraCharacter> characters = m_mFactionSortedCharacters.Get(faction);
200 for (
int i = characters.Count() - 1; i >= 0; i--)
203 characters.Remove(i);
210 float GetMinAllyDistance()
212 return m_fMinAllyDistance;
216 float GetMaxAllyDistance()
218 return m_fMaxAllyDistance;
222 float GetMinEnemyDistance()
224 return m_fMinEnemyDistance;
228 float GetMaxEnemyDistance()
230 return m_fMaxEnemyDistance;
242 array<Widget> widgets = uiTaskManagerComponent.GetWidgetsArray();
246 Widget button = CreateButtonAndSetPadding(uiTaskManagerComponent.GetParentWidget(), widgets);
250 TextWidget textWidget = TextWidget.Cast(button.FindAnyWidget(
"Text"));
252 SetRequestButtonText(textWidget);
256 override void Initialize()
262 gameMode.GetOnControllableSpawned().Insert(OnControllableCreated);
263 gameMode.GetOnControllableDeleted().Insert(OnControllableDeleted);
272 gameMode.GetOnControllableSpawned().Remove(OnControllableCreated);
273 gameMode.GetOnControllableDeleted().Remove(OnControllableDeleted);
277 array<SCR_ChimeraCharacter> characters;
278 for (
int i = m_mFactionSortedCharacters.Count() - 1; i >= 0; i--)
280 characters = m_mFactionSortedCharacters.GetElement(i);
284 for (
int j = characters.Count() - 1; j >= 0; j--)
290 if (!characterControllerComponent)
293 characterControllerComponent.GetOnPlayerDeathWithParam().Remove(
OnCharacterDeath);