Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PerceivedFactionManagerComponent.c
Go to the documentation of this file.
5
7{
8 [Attribute(SCR_EPerceivedFactionOutfitType.DISABLED.ToString(), desc: "Decides what the faction outfit calculation is.\n\DISABLED: Perceived faction is never set by outfit\nHIGHEST_VALUE: The perveived faction is what ever the highest combined value is\nFULL_OUTFIT: Perceived faction will be unknown unless all clothing is of the same faction (Needs at least a torso and pants to be seens as a faction)", category: "Settings", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(SCR_EPerceivedFactionOutfitType)), RplProp(onRplName: "OnPerceivedFactionOutfitTypeChanged")]
9 protected SCR_EPerceivedFactionOutfitType m_eCharacterPerceivedFactionOutfitType;
10
11 [Attribute("0", desc: "The punishment when killing a hostile character while the player is perceived as an unknown or other faction then their own.\n\nNote that warcrime will result as each kill counting as if they killed a friendly which will eventually cause a player to be kicked", uiwidget: UIWidgets.Flags, enumType: SCR_EDisguisedKillingPunishment, category: "Settings"), RplProp(onRplName: "OnPunishKillingWhileDisguisedChanged")]
12 protected SCR_EDisguisedKillingPunishment m_ePunishmentKillingWhileDisguised;
13
14 [Attribute(desc: "If character has no outfit faction it will set default faction. Otherwise it will set outfit faction to null\n\nIf Type is FULL_OUTFIT it will always set it to null regardless of this value", category: "Settings")]
15 protected bool m_bNoOutfitFactionSetsDefaultFaction;
16
17 [Attribute(desc: "Hints for on perceived faction changed. To inform the player about the system and what it means to not be of the perceived faction", category: "Hints")]
18 protected ref SCR_GeneralHintStorage m_PerceivedFactionHints;
19
20 [Attribute("0", desc: "If AI should perceive the Perceived faction of a player character when their outfit changes their perceived faction.\n\nThis is an experimental feature!", category: "AI Settings"), RplProp(onRplName: "OnPerceivedFactionChangesAffectsAIChanged")]
21 protected bool m_bPerceivedFactionChangesAffectsAI;
22
23 [Attribute("CIV", desc: "For AI only when m_bPerceivedFactionChangesAffectsAI is true. FactionKey of a faction which will be set if the player's faction can not be determined. Such as when the player is naked. Keep this empty if you want the faction to be NULL.\n\nThis setting is only used when m_bNoOutfitFactionSetsDefaultFaction is set to false and if that faction exists", category: "AI Settings")]
24 protected FactionKey m_sAIFallbackFaction;
25
26 protected Faction m_FallbackFaction;
27
28 protected ref ScriptInvokerInt m_OnPerceivedFactionOutfitTypeChanged;
29 protected ref ScriptInvokerInt m_OnPunishKillingWhileDisguisedChanged;
30 protected ref ScriptInvokerBool m_OnPerceivedFactionChangesAffectsAI;
31
32 protected static SCR_PerceivedFactionManagerComponent s_Instance;
33
34 //------------------------------------------------------------------------------------------------
35 static SCR_PerceivedFactionManagerComponent GetInstance()
36 {
37 return s_Instance;
38 }
39
40 //------------------------------------------------------------------------------------------------
42 {
43 return m_FallbackFaction;
44 }
45
46 //------------------------------------------------------------------------------------------------
48 void ShowPerceivedFactionChangedHint(Faction playerPerceivedFaction)
49 {
50 ShowHint();
51 }
52
53 //------------------------------------------------------------------------------------------------
54 protected void ShowHint()
55 {
57 if (!m_PerceivedFactionHints)
58 return;
59
61 if (m_eCharacterPerceivedFactionOutfitType == SCR_EPerceivedFactionOutfitType.DISABLED)
62 return;
63
65 SCR_HintManagerComponent hintManager = SCR_HintManagerComponent.GetInstance();
66 if (!hintManager)
67 return;
68
69 //~ Team killing is not punished so do not set hint
71 if (addtionGameModeSettings && !addtionGameModeSettings.IsTeamKillingPunished())
72 return;
73
74 SCR_HintUIInfo hint;
75
76 SCR_EDisguisedKillingPunishment flags = GetPunishmentKillingWhileDisguisedFlags();
77
79 if (flags == 0)
80 hint = m_PerceivedFactionHints.GetHintByType(EHint.GAMEPLAY_PERCEIVED_FACTION_CHANGED);
81 else if (SCR_Enum.HasFlag(flags, SCR_EDisguisedKillingPunishment.WARCRIME))
82 hint = m_PerceivedFactionHints.GetHintByType(EHint.GAMEPLAY_PERCEIVED_FACTION_CHANGED_PUNISH_WARCRIME);
83 else if (SCR_Enum.HasFlag(flags, SCR_EDisguisedKillingPunishment.XP_LOSS))
84 hint = m_PerceivedFactionHints.GetHintByType(EHint.GAMEPLAY_PERCEIVED_FACTION_CHANGED_PUNISH_XP);
85
86 if (!hint)
87 return;
88
90 hintManager.Show(hint);
91 }
92
93 //------------------------------------------------------------------------------------------------
96 {
97 return m_eCharacterPerceivedFactionOutfitType;
98 }
99
100 //------------------------------------------------------------------------------------------------
105 {
106 if (m_eCharacterPerceivedFactionOutfitType == type || !GetGameMode().IsMaster())
107 return;
108
109 m_eCharacterPerceivedFactionOutfitType = type;
110
111 if (playerID > 0)
112 {
114 SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_PERCEIVED_FACTION_TYPE_DISABLED, playerID);
115 else if (type == SCR_EPerceivedFactionOutfitType.HIGHEST_VALUE)
116 SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_PERCEIVED_FACTION_TYPE_HIGHEST_VALUE, playerID);
117 else if (type == SCR_EPerceivedFactionOutfitType.FULL_OUTFIT)
118 SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_PERCEIVED_FACTION_TYPE_FULL_OUTFIT, playerID);
119 }
120
121 Replication.BumpMe();
122
124 }
125
126 //------------------------------------------------------------------------------------------------
128 {
129 if (m_OnPerceivedFactionOutfitTypeChanged)
130 m_OnPerceivedFactionOutfitTypeChanged.Invoke(m_eCharacterPerceivedFactionOutfitType);
131 }
132
133 //------------------------------------------------------------------------------------------------
136 {
137 if (!m_OnPerceivedFactionOutfitTypeChanged)
138 m_OnPerceivedFactionOutfitTypeChanged = new ScriptInvokerInt();
139
140 return m_OnPerceivedFactionOutfitTypeChanged;
141 }
142
143 //------------------------------------------------------------------------------------------------
146 {
147 return m_bNoOutfitFactionSetsDefaultFaction;
148 }
149
150 //------------------------------------------------------------------------------------------------
152 SCR_EDisguisedKillingPunishment GetPunishmentKillingWhileDisguisedFlags()
153 {
154 return m_ePunishmentKillingWhileDisguised;
155 }
156
157 //------------------------------------------------------------------------------------------------
161 void SetPunishmentKillingWhileDisguisedFlags_S(SCR_EDisguisedKillingPunishment punishmentFlags, int playerID = -1)
162 {
163 if (GetPunishmentKillingWhileDisguisedFlags() == punishmentFlags || !GetGameMode().IsMaster())
164 return;
165
166 m_ePunishmentKillingWhileDisguised = punishmentFlags;
167
168 if (playerID > 0)
169 SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_PERCEIVED_FACTION_PUNISHMENT_KILLING_SET, playerID, m_ePunishmentKillingWhileDisguised);
170
171 Replication.BumpMe();
172
174 }
175
176 //------------------------------------------------------------------------------------------------
178 {
179 if (m_OnPunishKillingWhileDisguisedChanged)
180 m_OnPunishKillingWhileDisguisedChanged.Invoke(m_ePunishmentKillingWhileDisguised);
181 }
182
183 //------------------------------------------------------------------------------------------------
186 {
187 if (!m_OnPunishKillingWhileDisguisedChanged)
188 m_OnPunishKillingWhileDisguisedChanged = new ScriptInvokerInt();
189
190 return m_OnPunishKillingWhileDisguisedChanged;
191 }
192
193 //------------------------------------------------------------------------------------------------
194 override void OnPlayerSpawnFinalize_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
195 {
196 SCR_CharacterFactionAffiliationComponent affiliationComponent = SCR_CharacterFactionAffiliationComponent.Cast(entity.FindComponent(SCR_CharacterFactionAffiliationComponent));
197 if (!affiliationComponent)
198 return;
199
200 //~ Init only for players. Will go over player outfit and set the faction values in one go with calling replication only once for all items
201 affiliationComponent.InitPlayerOutfitFaction_S();
202 }
203
204 //------------------------------------------------------------------------------------------------
205 override void OnPlayerKilled(notnull SCR_InstigatorContextData instigatorContextData)
206 {
207 SCR_CharacterFactionAffiliationComponent affiliationComponent = SCR_CharacterFactionAffiliationComponent.Cast(instigatorContextData.GetVictimEntity().FindComponent(SCR_CharacterFactionAffiliationComponent));
208 if (!affiliationComponent)
209 return;
210
211 //~ Init only for players. Will go over player outfit and set the faction values in one go with calling replication only once for all items
212 affiliationComponent.DisableUpdatingPerceivedFaction_S();
213 }
214
215 //------------------------------------------------------------------------------------------------
217 {
218 return m_bPerceivedFactionChangesAffectsAI;
219 }
220
221 //------------------------------------------------------------------------------------------------
222 void SetPerceivedFactionChangesAffectsAI(bool affectsAI, int PlayerID = -1)
223 {
224 if (affectsAI == m_bPerceivedFactionChangesAffectsAI || !GetGameMode().IsMaster())
225 return;
226
227 m_bPerceivedFactionChangesAffectsAI = affectsAI;
228
230 Replication.BumpMe();
231
232 //~ TODO: Notification
233 //if (playerID > 0)
234 // SCR_NotificationsComponent.SendToEveryone(ENotification., playerID);
235 }
236
237 //------------------------------------------------------------------------------------------------
239 {
240 if (m_OnPerceivedFactionChangesAffectsAI)
241 m_OnPerceivedFactionChangesAffectsAI.Invoke(m_bPerceivedFactionChangesAffectsAI);
242 }
243
244 //------------------------------------------------------------------------------------------------
246 {
247 if (!m_OnPerceivedFactionChangesAffectsAI)
248 m_OnPerceivedFactionChangesAffectsAI = new ScriptInvokerBool();
249
250 return m_OnPerceivedFactionChangesAffectsAI;
251 }
252
253 //------------------------------------------------------------------------------------------------
254 //~ Inventory is updated before this is called so it will call an extra replication if this is added. Meaning it has no use
255 /*override void OnPlayerDeleted(int playerId, IEntity player)
256 {
257 if (!player)
258 return;
259
260 SCR_CharacterFactionAffiliationComponent affiliationComponent = SCR_CharacterFactionAffiliationComponent.Cast(player.FindComponent(SCR_CharacterFactionAffiliationComponent));
261 if (!affiliationComponent)
262 return;
263
264 //~ Init only for players. Will go over player outfit and set the faction values in one go with calling replication only once for all items
265 affiliationComponent.DisableUpdatingPerceivedFaction_S();
266 }*/
267
268 //------------------------------------------------------------------------------------------------
270 {
271 if (s_Instance)
272 {
273 Print("'SCR_PerceivedFactionManagerComponent' exists twice in the world!", LogLevel.WARNING);
274 return;
275 }
276
277 s_Instance = this;
278 }
279
280 #ifdef ENABLE_DIAG
281 //------------------------------------------------------------------------------------------------
282 override void EOnFrame(IEntity owner, float timeSlice)
283 {
284 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_CHARACTER_SHOW_FACTION_OUTFIT))
285 CharacterOutfitDebug();
286 }
287 #endif
288
289 //------------------------------------------------------------------------------------------------
290 override void OnPostInit(IEntity owner)
291 {
292 super.OnPostInit(owner);
293
294 #ifdef ENABLE_DIAG
295 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_CHARACTER_SHOW_FACTION_OUTFIT, "", "Show Perceived Faction", "Character");
296 SetEventMask(owner, EntityEvent.FRAME);
297 #endif
298
299 SetEventMask(owner, EntityEvent.INIT);
300 }
301
302 //------------------------------------------------------------------------------------------------
303 override void EOnInit(IEntity owner)
304 {
305 if (!GetGame().InPlayMode())
306 return;
307
308 if (m_sAIFallbackFaction.IsEmpty())
309 return;
310
311 FactionManager factionManager = GetGame().GetFactionManager();
312 if (!factionManager)
313 return;
314
315 m_FallbackFaction = factionManager.GetFactionByKey(m_sAIFallbackFaction);
316 if (!m_FallbackFaction)
317 Print("SCR_PerceivedFactionManagerComponent trying to set fall back faction '" + m_sAIFallbackFaction + "' but this faction could not be found so it is null instead.", LogLevel.WARNING);
318 }
319
320 #ifdef ENABLE_DIAG
321 //------------------------------------------------------------------------------------------------
322 protected void CharacterOutfitDebug()
323 {
324 DbgUI.Begin("Player Perceived Faction", 0, 0);
325
326 IEntity player = SCR_PlayerController.GetLocalControlledEntity();
327 if (!player)
328 {
329 DbgUI.Text("No Player");
330 DbgUI.End();
331
332 return;
333 }
334
335 DbgUI.Text("Faction Outfit setting: " + typename.EnumToString(SCR_EPerceivedFactionOutfitType, GetCharacterPerceivedFactionOutfitType()));
336 DbgUI.Text("");
337 DbgUI.Text("");
338 DbgUI.Text("");
339 DbgUI.Text("--------");
340 DbgUI.Text("");
341
343 {
344 DbgUI.End();
345 return;
346 }
347
348 SCR_CharacterFactionAffiliationComponent charFactionAffiliation = SCR_CharacterFactionAffiliationComponent.Cast(player.FindComponent(SCR_CharacterFactionAffiliationComponent));
349 if (!charFactionAffiliation)
350 {
351 DbgUI.Text("Player is missing SCR_CharacterFactionAffiliationComponent");
352 DbgUI.End();
353
354 return;
355 }
356
357 if (!charFactionAffiliation.HasPerceivedFaction())
358 {
359 DbgUI.Text("Unable to get Perceived faction:");
360
361 SCR_PossessingManagerComponent possessingManager = SCR_PossessingManagerComponent.GetInstance();
362
363 if (!possessingManager || possessingManager.IsPossessing(SCR_PlayerController.GetLocalPlayerId()))
364 DbgUI.Text(" - Player is possessing an AI");
365 else
366 DbgUI.Text(" - Player spawned was not called: Was player spawned on play in workbench?");
367
368 DbgUI.End();
369
370 return;
371 }
372
373 Faction currentOutfitFaction = charFactionAffiliation.GetPerceivedFaction();
374
375 if (!currentOutfitFaction)
376 DbgUI.Text("Perceived Faction: UNKNOWN");
377 else
378 DbgUI.Text("Perceived Faction: " + currentOutfitFaction.GetFactionKey());
379
380
381 DbgUI.Text("Disguise Type: " + typename.EnumToString(SCR_ECharacterDisguiseType, charFactionAffiliation.GetCharacterDisguiseType()));
382
383 map<Faction, int> outfitFactionValues = new map<Faction, int>();
384 int count = charFactionAffiliation.GetCharacterOutfitValues(outfitFactionValues);
385
386 DbgUI.Text("");
387 DbgUI.Text("Outfit values:");
388
389 if (count <= 0)
390 {
391 DbgUI.Text(" - None");
392 }
393 else
394 {
395 foreach(Faction outfitFaction, int outfitvalue : outfitFactionValues)
396 {
397 DbgUI.Text(" - " + outfitFaction.GetFactionKey() + ": " + outfitvalue);
398 }
399 }
400
401 if (GetCharacterPerceivedFactionOutfitType() == SCR_EPerceivedFactionOutfitType.FULL_OUTFIT && !charFactionAffiliation.IsCharacterWearingFullOutfit())
402 {
403 DbgUI.Text("");
404 DbgUI.Text("Missing:");
405
406 //~ Check if both torso and pants on
407 EquipedLoadoutStorageComponent characterStorage = EquipedLoadoutStorageComponent.Cast(player.FindComponent(EquipedLoadoutStorageComponent));
408
409 if (!characterStorage.GetClothFromArea(LoadoutJacketArea))
410 DbgUI.Text(" - Jacket");
411
412 if (!characterStorage.GetClothFromArea(LoadoutPantsArea))
413 DbgUI.Text(" - Pants");
414
415 //if (!characterStorage.GetClothFromArea(LoadoutBootsArea))
416 // DbgUI.Text(" - Shoes");
417 }
418
419 DbgUI.Text("");
420 DbgUI.Text("");
421 DbgUI.Text("");
422 DbgUI.Text("--------");
423
424 DbgUI.Text("");
425 DbgUI.Text("Killing while disguised punishment: " + SCR_Enum.FlagsToString(SCR_EDisguisedKillingPunishment, GetPunishmentKillingWhileDisguisedFlags(), noValue: "NONE"));
426
427 DbgUI.Text("");
428 DbgUI.Text("AI reacts to perceived faction: " + DoesPerceivedFactionChangesAffectsAI().ToString() + " ");
429 DbgUI.Text("");
430
432 {
433 if (m_FallbackFaction && !DoesNoOutfitSetFactionToDefault())
434 DbgUI.Text("Faction AI perceives if no outfit values: " + m_sAIFallbackFaction + " ");
435 else
436 DbgUI.Text("Faction AI perceives if no outfit values: DEFAULT FACTION");
437 }
438
439 DbgUI.End();
440 }
441 #endif
442}
443
450
451enum SCR_EDisguisedKillingPunishment
452{
453 WARCRIME = 1 << 0,
454 XP_LOSS = 1 << 1,
455}
456
SCR_EAIThreatSectorFlags flags
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
EHint
Definition EHint.c:11
ENotification
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
void SCR_AdditionalGameModeSettingsComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_BaseGameMode GetGameMode()
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
void OnPlayerKilled(notnull SCR_InstigatorContextData instigatorContextData)
EDamageType type
Get all prefabs that have the spawner data
Get all prefabs that have the spawner the given labels and are valid in the editor mode param catalogType Type to catalog to get prefabs from param editorMode Editor mode to get valid entries from param faction Faction(Optional)
bool DoesPerceivedFactionChangesAffectsAI()
@ HIGHEST_VALUE
The faction is set to the highest value of all combined clothing.
@ FULL_OUTFIT
The faction is unknown until all clothing items are of the same faction and at least a pants and tors...
ScriptInvokerInt GetPerceivedFactionOutfitTypeChanged()
enum SCR_EPerceivedFactionOutfitType XP_LOSS
Killing players while disguised will case a lose in XP.
void OnPerceivedFactionChangesAffectsAIChanged()
SCR_EPerceivedFactionOutfitType GetCharacterPerceivedFactionOutfitType()
Get the current Perceived faction outfit type. Which determintes how the perceived faction is calcula...
SCR_EDisguisedKillingPunishment GetPunishmentKillingWhileDisguisedFlags()
bool DoesNoOutfitSetFactionToDefault()
void SetPunishmentKillingWhileDisguisedFlags_S(SCR_EDisguisedKillingPunishment punishmentFlags, int playerID=-1)
void OnPerceivedFactionOutfitTypeChanged()
ScriptInvokerInt GetOnPunishKillingWhileDisguisedChanged()
void SetCharacterPerceivedFactionOutfitType_S(SCR_EPerceivedFactionOutfitType type, int playerID=-1)
void OnPunishKillingWhileDisguisedChanged()
void ShowPerceivedFactionChangedHint(Faction playerPerceivedFaction)
Called by SCR_CharacterFactionAffiliationComponent On Perceived faction changed. To show hint to play...
void SetPerceivedFactionChangesAffectsAI(bool affectsAI, int PlayerID=-1)
void SCR_PerceivedFactionManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
ScriptInvokerBool GetOnPerceivedFactionChangesAffectsAIChanged()
override void EOnFrame(IEntity owner, float timeSlice)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerBoolMethod > ScriptInvokerBool
ScriptInvokerBase< ScriptInvokerIntMethod > ScriptInvokerInt
override void OnPlayerSpawnFinalize_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
enum EVehicleType IEntity
Diagnostic and developer menu system.
Definition DiagMenu.c:18
proto external Managed FindComponent(typename typeName)
Main replication API.
Definition Replication.c:14
override void EOnInit(IEntity owner)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
@ DISABLED
General event switch.
Definition EntityEvent.c:35
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.