1 [
EntityEditorProps(
category:
"GameScripted/GameMode", description:
"Area that provides events and API when an enemy enters it.")]
9 typedef ScriptInvokerBase<SpawnAreaCharacterEventDelegate>
SpawnAreaEvent;
26 [
Attribute(
"", UIWidgets.EditBox,
"The key specifying which faction this area belongs to.")]
27 protected FactionKey m_sFactionKey;
34 protected ref set<SCR_ChimeraCharacter>> m_sOccupants =
new set<SCR_ChimeraCharacter>();
40 protected ref array<IEntity> m_aEnemies = {};
46 return m_pOnCharacterEnter;
56 return m_pOnCharacterExit;
73 return GetGame().GetFactionManager().GetFactionByKey(GetAffiliatedFactionKey());
78 FactionKey GetAffiliatedFactionKey()
88 bool IsInside(SCR_ChimeraCharacter character)
93 return m_sOccupants.Contains(character);
101 bool IsFriendly(notnull SCR_ChimeraCharacter character)
103 Faction faction = character.GetFaction();
112 Faction areaFaction = GetAffiliatedFaction();
113 if (areaFaction && areaFaction.IsFactionFriendly(faction))
127 int GetFriendlyCharactersInside(out notnull array<SCR_ChimeraCharacter> outCharacters)
129 outCharacters.Clear();
131 foreach (SCR_ChimeraCharacter character : m_sOccupants)
136 if (IsFriendly(character))
138 outCharacters.Insert(character);
153 int GetEnemyCharactersInside(out notnull array<SCR_ChimeraCharacter> outCharacters)
155 outCharacters.Clear();
157 foreach (SCR_ChimeraCharacter character : m_sOccupants)
162 if (!IsFriendly(character))
164 outCharacters.Insert(character);
179 int GetCharactersInside(out notnull array<SCR_ChimeraCharacter> outCharacters)
181 outCharacters.Clear();
183 foreach (SCR_ChimeraCharacter character : m_sOccupants)
185 outCharacters.Insert(character);
194 override bool ScriptedEntityFilterForQuery(IEntity ent)
196 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(ent);
200 return !character.GetCharacterController().IsDead();
204 protected bool IsLocalEntity(notnull IEntity ent)
206 PlayerController playerController =
GetGame().GetPlayerController();
207 if (playerController && playerController.GetControlledEntity() == ent)
215 protected override void OnActivate(IEntity ent)
217 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(ent);
222 if (!m_sOccupants.Contains(character))
224 m_sOccupants.Insert(character);
227 OnCharacterEnter(character, IsFriendly(character));
232 protected event void OnCharacterEnter(IEntity character,
bool isFriendly)
234 m_pOnCharacterEnter.Invoke(
this, character, isFriendly)
239 protected override void OnDeactivate(IEntity ent)
241 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(ent);
245 if (m_sOccupants.Contains(character))
247 int index = m_sOccupants.Find(character);
248 m_sOccupants.Remove(
index);
250 OnCharacterExit(character, IsFriendly(character));
255 protected event void OnCharacterExit(IEntity character,
bool isFriendly)
257 m_pOnCharacterExit.Invoke(
this, character, isFriendly)
262 protected override void OnInit(IEntity owner)
265 SetEventMask(EntityEvent.FRAME);
269 protected override void OnFrame(IEntity owner,
float timeSlice)
271 super.OnFrame(owner, timeSlice);
275 foreach (SCR_ChimeraCharacter character : m_sOccupants)
277 if (character.GetCharacterController().IsDead())
280 if (!IsFriendly(character))
281 m_aEnemies.Insert(character);
285 if (!m_aEnemies.IsEmpty())
290 protected event void OnAlert(array<IEntity> enemies)
292 m_pOnAlert.Invoke(
this, enemies);