Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CharacterFactionAffiliationComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Faction", description: "")]
5
6class SCR_CharacterFactionAffiliationComponent : FactionAffiliationComponent
7{
9
10 [RplProp(onRplName: "OnPerceivedFactionChanged")]
11 protected int m_iOutfitFactionIndex = -1;
12
14
15 protected ref set<SCR_OutfitFactionDataHolder> m_CurrentOutfitData = new set<SCR_OutfitFactionDataHolder>();
16
19
21
22 //~ What is the relationship between character faction and the perceived faction
24
25 //~ Set by SCR_PerceivedFactionManagerComponent. Only for players to avoid unneccessary replication calls
26 protected bool m_bHasPerceivedFaction;
27
29
30 //------------------------------------------------------------------------------------------------
33 {
35 }
36
37 //------------------------------------------------------------------------------------------------
46
47 //------------------------------------------------------------------------------------------------
56
57 //------------------------------------------------------------------------------------------------
60 int GetCharacterOutfitValues(out notnull map<Faction, int> outfitFactionValues)
61 {
62 outfitFactionValues.Copy(m_mOutfitFactionValues);
63
64 return outfitFactionValues.Count();
65 }
66
67 //------------------------------------------------------------------------------------------------
69 int GetCharacterOutfitData(out notnull set<SCR_OutfitFactionDataHolder> outfitFactionData)
70 {
71 outfitFactionData.Copy(m_CurrentOutfitData);
72
73 return outfitFactionData.Count();
74 }
75
76 //------------------------------------------------------------------------------------------------
81 void AddFactionOutfitValue(notnull Faction faction, int value, bool updateFaction = true)
82 {
83 if (value <= 0)
84 return;
85
86 ChangeFactionOutfitValue(faction, value, updateFaction);
87 }
88
89 //------------------------------------------------------------------------------------------------
93 void AddFactionOutfitValue(SCR_OutfitFactionDataHolder outfitFactionHolder, bool updateFaction = true)
94 {
95 //~ Null is given (If not set up) or the outfit is already registered
96 if (!outfitFactionHolder || m_CurrentOutfitData.Contains(outfitFactionHolder))
97 return;
98
99 m_CurrentOutfitData.Insert(outfitFactionHolder);
100
101 if (!m_PerceivedManager || m_PerceivedManager.GetCharacterPerceivedFactionOutfitType() == SCR_EPerceivedFactionOutfitType.DISABLED)
102 return;
103
104 if (m_PerceivedManager.GetCharacterPerceivedFactionOutfitType() == SCR_EPerceivedFactionOutfitType.FULL_OUTFIT)
105 {
106 //~ If Full outfit and the outfit has the default faction then ignore all other outfit factions
107 SCR_OutfitFactionData data = outfitFactionHolder.GetOutfitFactionData(GetAffiliatedFaction());
108 if (data)
109 {
110 AddFactionOutfitValue(data.GetAffiliatedFaction(), data.GetOutfitFactionValue());
111 return;
112 }
113 }
114
115 array<SCR_OutfitFactionData> outfitDataArray = {};
116 outfitFactionHolder.GetOutfitFactionDataArray(outfitDataArray);
117
118 //~ Update faction values
119 foreach (SCR_OutfitFactionData data : outfitDataArray)
120 {
121 if (!data || !data.GetAffiliatedFaction())
122 continue;
123
124 AddFactionOutfitValue(data.GetAffiliatedFaction(), data.GetOutfitFactionValue(), updateFaction);
125 }
126 }
127
128 //------------------------------------------------------------------------------------------------
133 void RemoveFactionOutfitValue(notnull Faction faction, int value, bool updateFaction = true)
134 {
135 if (value <= 0)
136 return;
137
138 ChangeFactionOutfitValue(faction, -value, updateFaction);
139 }
140
141 //------------------------------------------------------------------------------------------------
145 void RemoveFactionOutfitValue(SCR_OutfitFactionDataHolder outfitFactionHolder, bool updateFaction = true)
146 {
147 //~ Did not find the correct data so recalculate
148 if (!outfitFactionHolder || !m_CurrentOutfitData.Contains(outfitFactionHolder))
149 {
152 return;
153 }
154
155 m_CurrentOutfitData.RemoveItem(outfitFactionHolder);
156
157 if (!HasPerceivedFaction() || !m_PerceivedManager || m_PerceivedManager.GetCharacterPerceivedFactionOutfitType() == SCR_EPerceivedFactionOutfitType.DISABLED)
158 return;
159
160 if (m_PerceivedManager.GetCharacterPerceivedFactionOutfitType() == SCR_EPerceivedFactionOutfitType.FULL_OUTFIT)
161 {
162 //~ If Full outfit and the outfit has the default faction then ignore all other outfit factions
163 SCR_OutfitFactionData data = outfitFactionHolder.GetOutfitFactionData(GetAffiliatedFaction());
164 if (data)
165 {
166 RemoveFactionOutfitValue(data.GetAffiliatedFaction(), data.GetOutfitFactionValue());
167 return;
168 }
169 }
170
171 array<SCR_OutfitFactionData> outfitDataArray = {};
172 outfitFactionHolder.GetOutfitFactionDataArray(outfitDataArray);
173
174 //~ Update faction values
175 foreach (SCR_OutfitFactionData data : outfitDataArray)
176 {
177 if (!data || !data.GetAffiliatedFaction())
178 continue;
179
180 RemoveFactionOutfitValue(data.GetAffiliatedFaction(), data.GetOutfitFactionValue(), updateFaction);
181 }
182 }
183
184 //------------------------------------------------------------------------------------------------
189 void OnNoFactionSlottedItemChanged(bool addedToSlot, IEntity item, bool updateFaction = true)
190 {
191 if (!updateFaction || !m_PerceivedManager || m_PerceivedManager.GetCharacterPerceivedFactionOutfitType() != SCR_EPerceivedFactionOutfitType.FULL_OUTFIT)
192 return;
193
194 //~ Makes sure that if a clothing piece with no faction is added it checks if the uniform is full or not
196 }
197
198 //------------------------------------------------------------------------------------------------
203
204 //------------------------------------------------------------------------------------------------
207 {
208 FactionManager factionManager = GetGame().GetFactionManager();
209 if (!factionManager)
210 return;
211
212 if (!m_PerceivedManager || m_PerceivedManager.GetCharacterPerceivedFactionOutfitType() == SCR_EPerceivedFactionOutfitType.DISABLED)
213 {
214 SetPerceivedFaction_S(factionManager.GetFactionIndex(GetAffiliatedFaction()));
215 return;
216 }
217
219 array<SCR_OutfitFactionData> outfitDataArray = {};
220
221 for (int i = m_CurrentOutfitData.Count() - 1; i >= 0; i--)
222 {
223 //~ Clear any null data
224 if (!m_CurrentOutfitData[i])
225 {
226 m_CurrentOutfitData.Remove(i);
227 continue;
228 }
229
230 if (m_PerceivedManager.GetCharacterPerceivedFactionOutfitType() == SCR_EPerceivedFactionOutfitType.FULL_OUTFIT)
231 {
232 //~ If Full outfit and the outfit has the default faction then ignore all other outfit factions
233 SCR_OutfitFactionData data = m_CurrentOutfitData[i].GetOutfitFactionData(GetAffiliatedFaction());
234 if (data)
235 {
236 AddFactionOutfitValue(data.GetAffiliatedFaction(), data.GetOutfitFactionValue(), false);
237 continue;
238 }
239 }
240
241 m_CurrentOutfitData[i].GetOutfitFactionDataArray(outfitDataArray);
242
243 //~ Update faction values
244 foreach (SCR_OutfitFactionData data : outfitDataArray)
245 {
246 if (!data || !data.GetAffiliatedFaction())
247 continue;
248
249 AddFactionOutfitValue(data.GetAffiliatedFaction(), data.GetOutfitFactionValue(), false);
250 }
251 }
252
253 //~ Update faction
255 }
256
257 //------------------------------------------------------------------------------------------------
258 //~ Update the given faction outfit value to calculate perceived faction with
259 protected void ChangeFactionOutfitValue(Faction faction, int value, bool updateFaction = true)
260 {
261 int foundValue;
262
263 if (!m_mOutfitFactionValues.Find(faction, foundValue))
264 {
265 if (value < 0)
266 {
267 Debug.Error2("SCR_CharacterFactionAffiliationComponent", "ChangeFactionOutfitValue trying to add a new faction unform value for '" + faction + "' but the given value is less than 0!");
268 return;
269 }
270
271 m_mOutfitFactionValues.Insert(faction, value);
272 }
273 else
274 {
275 //~ Update the value
276 foundValue += value;
277 if (foundValue < 0)
278 Debug.Error2("SCR_CharacterFactionAffiliationComponent", "ChangeFactionOutfitValue trying to set a new Outfit value for '" + faction + "' but the total value became less than 0!");
279
280 //~ Remove the entry from the map as no need to keep unneccessary data
281 if (foundValue <= 0)
282 m_mOutfitFactionValues.Remove(faction);
283 //~ Set the new value
284 else
285 m_mOutfitFactionValues[faction] = foundValue;
286 }
287
288 //~ Update the percieved faction
289 if (updateFaction)
291 }
292
293 //------------------------------------------------------------------------------------------------
296 {
298 if (!characterStorage)
299 return true;
300
301 //~ Get blocked slots
302 array<typename> blockedSlots = {};
303 characterStorage.GetBlockedSlots(blockedSlots);
304
305 //~ No jacket
306 if (!characterStorage.GetClothFromArea(LoadoutJacketArea) && !blockedSlots.Contains(LoadoutJacketArea))
307 return false;
308
309 //~ No pants
310 if (!characterStorage.GetClothFromArea(LoadoutPantsArea) && !blockedSlots.Contains(LoadoutPantsArea))
311 return false;
312
313 //~ No shoes
314 //if (!characterStorage.GetClothFromArea(LoadoutBootsArea) && !blockedSlots.Contains(LoadoutBootsArea))
315 // return false;
316
317 return true;
318 }
319
320 //------------------------------------------------------------------------------------------------
324 {
325 if (m_mOutfitFactionValues.IsEmpty())
326 return -1;
327
328 if (m_PerceivedManager && m_PerceivedManager.GetCharacterPerceivedFactionOutfitType() == SCR_EPerceivedFactionOutfitType.FULL_OUTFIT)
329 {
330 //~ Cannot have mixed outfit
331 if (m_mOutfitFactionValues.Count() > 1)
332 return -1;
333
334 //~ Check if both torso and pants on
336 return -1;
337 }
338
339 array<Faction> highestFactionValues = {};
340 int highestValue = -1;
341
342 //~ Get highest faction(s)
343 foreach(Faction faction, int value : m_mOutfitFactionValues)
344 {
345 //~ No highest is set so set first found entry
346 if (highestValue < 0)
347 {
348 highestFactionValues.Insert(faction);
349 highestValue = value;
350 continue;
351 }
352
353 //~ New faction has the highest Outfit value
354 if (value > highestValue)
355 {
356 highestFactionValues.Clear();
357 highestFactionValues.Insert(faction);
358 highestValue = value;
359 continue;
360 }
361
362 //~ Multiple factions have the same Outfit value
363 if (value == highestValue)
364 {
365 highestFactionValues.Insert(faction);
366 continue;
367 }
368 }
369
370 if (highestFactionValues.IsEmpty())
371 return -1;
372
373 FactionManager factionManager = GetGame().GetFactionManager();
374 if (!factionManager)
375 return -1;
376
377 //~ Only one entry
378 if (highestFactionValues.Count() == 1)
379 return factionManager.GetFactionIndex(highestFactionValues[0]);
380
381 Faction defaultFaction = GetDefaultAffiliatedFaction();
382
383 //~ One of the highest contains it's own default faction so set that as faction
384 if (defaultFaction && highestFactionValues.Contains(defaultFaction))
385 return factionManager.GetFactionIndex(defaultFaction);
386
387 SCR_Faction scrDefaultFaction = SCR_Faction.Cast(defaultFaction);
388 Faction factionCandidate;
389 SCR_Faction scrfactionCandidate;
390 SCR_Faction scrFaction;
391
392 //~ Loop through the highest factions and choose the correct one
393 foreach (Faction faction : highestFactionValues)
394 {
395 if (!factionCandidate)
396 {
397 factionCandidate = faction;
398 scrfactionCandidate = SCR_Faction.Cast(factionCandidate);
399 continue;
400 }
401
402 //~ Always give priority to hostile factions
403 if (scrDefaultFaction)
404 {
405 //~ If current candiate is not hostile to player but another one is a hostile. Set that faction
406 if (scrDefaultFaction.IsFactionFriendly(factionCandidate) && scrDefaultFaction.IsFactionEnemy(faction))
407 {
408 factionCandidate = faction;
409 continue;
410 }
411 }
412
413 //~ If candidate is scripted check if new candidate is military
414 if (scrfactionCandidate)
415 {
416 //~ Get scripted versions of the factions
417 scrFaction = SCR_Faction.Cast(faction);
418
419 //~ Always give priority to military factions
420 if (scrFaction && !scrfactionCandidate.IsMilitary() && scrFaction.IsMilitary())
421 {
422 factionCandidate = faction;
423 continue;
424 }
425 }
426 }
427
428 //~ Set the Outfit faction
429 return factionManager.GetFactionIndex(factionCandidate);
430 }
431
432 //------------------------------------------------------------------------------------------------
433 protected void SetPerceivedFaction_S(int OutfitFaction)
434 {
435 //~ Server only
436 if (Replication.IsClient())
437 return;
438
439 if (m_iOutfitFactionIndex == OutfitFaction)
440 return;
441
442
443 m_iOutfitFactionIndex = OutfitFaction;
444
446
447 //~ Set the perceived Faction on the m_PerceivableComponent
448 if (m_PerceivableComponent && m_PerceivedManager && m_PerceivedManager.DoesPerceivedFactionChangesAffectsAI())
450
451 Replication.BumpMe();
452 }
453
454 //------------------------------------------------------------------------------------------------
455 protected void SetPerceivedFactionForAI(bool resetToNull = false)
456 {
458 return;
459
460 //~ Note that currently having no perceived faction is not supported and it will instead reset the perceived faction to default
461 if (!resetToNull)
462 {
463 Faction faction = GetPerceivedFaction();
464
465 //~ Set AI faction to perceived faction
466 if (faction)
467 {
468 m_PerceivableComponent.SetPerceivedFactionOverride(faction);
469 }
470 //~ Set AI faction to fallback faction if faction is null so AI do not perceive the player as their default faction
471 else if (m_PerceivedManager)
472 {
473 m_PerceivableComponent.SetPerceivedFactionOverride(m_PerceivedManager.GetFallbackFaction());
474 }
475 //~ Sets perceived faction of AI to default faction
476 else
477 {
478 m_PerceivableComponent.SetPerceivedFactionOverride(null);
479 }
480 }
481
482 else
483 {
484 m_PerceivableComponent.SetPerceivedFactionOverride(null);
485 }
486 }
487
488 //------------------------------------------------------------------------------------------------
489 protected void OnPerceivedFactionChangesAffectsAIChanged(bool affectsAI)
490 {
491 SetPerceivedFactionForAI(!affectsAI);
492 }
493
494 //------------------------------------------------------------------------------------------------
496 {
497 //~ Faction is unknown
498 if (m_iOutfitFactionIndex < 0)
499 {
501 {
502 //~ Set faction to default depending on setting
503 if (m_PerceivedManager.DoesNoOutfitSetFactionToDefault() && m_PerceivedManager.GetCharacterPerceivedFactionOutfitType() != SCR_EPerceivedFactionOutfitType.FULL_OUTFIT)
505 else
506 m_PerceivedFaction = null;
507 }
508 else
509 {
510 m_PerceivedFaction = null;
511 }
512 }
513 //~ Set Faction
514 else
515 {
516 m_PerceivedFaction = GetGame().GetFactionManager().GetFactionByIndex(m_iOutfitFactionIndex);
517 }
518
520
523
524 Faction affiliatedFaction = GetAffiliatedFaction();
525
526 //~ Local player changed perceived faction
528 m_PerceivedManager.ShowPerceivedFactionChangedHint(m_PerceivedFaction);
529
530 //~ Set Disguise type which is the relationship between the affiliated faction and perceived faction
532 {
533 if (!affiliatedFaction || affiliatedFaction == m_PerceivedFaction)
535 else
536 {
537 SCR_Faction scrAffiliatedFaction = SCR_Faction.Cast(affiliatedFaction);
538
539 //~ Is SCR_Faction
540 if (scrAffiliatedFaction)
541 {
542 //~ Check if friendly
543 if (scrAffiliatedFaction.DoCheckIfFactionFriendly(m_PerceivedFaction))
545 else
547 }
548 //~ Not an SCR_Faction
549 else
550 {
551 //~ Check if friendly
552 if (m_PerceivedFaction.IsFactionFriendly(affiliatedFaction))
554 else
556 }
557 }
558 }
559 //~ Has no perceived faction so disguise is UNKNOWN type
560 else
561 {
563 }
564 }
565
566 //------------------------------------------------------------------------------------------------
575
576 //------------------------------------------------------------------------------------------------
577 override protected void OnFactionChanged(Faction previous, Faction current)
578 {
580 m_OnFactionChangedInvoker.Invoke(this, previous, current);
581 }
582
583 //------------------------------------------------------------------------------------------------
592
593 //------------------------------------------------------------------------------------------------
596 {
599
601
603 m_PerceivedManager.GetOnPerceivedFactionChangesAffectsAIChanged().Insert(OnPerceivedFactionChangesAffectsAIChanged);
604 }
605
606 //------------------------------------------------------------------------------------------------
607 //~ Go over all inventory items and set the uniform faction
608 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
609 protected void InitPlayerOutfitFaction()
610 {
612
614
616 {
617 Print("SCR_CharacterFactionAffiliationComponent: InitPlayerOutfitFaction, Could not find SCR_PerceivedFactionManagerComponent!", LogLevel.WARNING);
618 return;
619 }
620
621 //~ Listen to Type changed
622 m_PerceivedManager.GetPerceivedFactionOutfitTypeChanged().Insert(OnPerceivedFactionOutfitTypeChanged);
623
624 //~ Clear any data that was there
625 m_CurrentOutfitData.Clear();
626
628 if (!characterInventoryComponent)
629 {
630 Print("SCR_CharacterFactionAffiliationComponent: InitPlayerOutfitFaction, Could not find SCR_CharacterInventoryStorageComponent!", LogLevel.ERROR);
631 return;
632 }
633
634 //~ Init the character inventory comp
635 characterInventoryComponent.InitCharacterPerceivedOutfitData(this);
636
637 //~ Recalculate the character's faction and replicate this value if Server
639 }
640
641 //------------------------------------------------------------------------------------------------
651
652 //------------------------------------------------------------------------------------------------
653 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
655 {
657
659 return;
660
661 m_PerceivedManager.GetPerceivedFactionOutfitTypeChanged().Remove(OnPerceivedFactionOutfitTypeChanged);
662 m_PerceivedManager = null;
663 }
664
665 //------------------------------------------------------------------------------------------------
667 {
669 return;
670
671 if (Replication.IsServer())
672 m_PerceivedManager.GetOnPerceivedFactionChangesAffectsAIChanged().Remove(OnPerceivedFactionChangesAffectsAIChanged);
673
674 m_PerceivedManager.GetPerceivedFactionOutfitTypeChanged().Remove(OnPerceivedFactionOutfitTypeChanged);
675 }
676}
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
int GetCharacterOutfitValues(out notnull map< Faction, int > outfitFactionValues)
int GetCharacterOutfitData(out notnull set< SCR_OutfitFactionDataHolder > outfitFactionData)
paramp[out] Get Set of all outfit data. This data
ref OnFactionChangedInvoker m_OnFactionChangedInvoker
void SetPerceivedFaction_S(int OutfitFaction)
void DisableUpdatingPerceivedFaction_S()
Disables perceived faction from updating after the character is destroyed or dead.
void AddFactionOutfitValue(notnull Faction faction, int value, bool updateFaction=true)
OnFactionChangedInvoker GetOnFactionChanged()
SCR_PerceivedFactionManagerComponent m_PerceivedManager
void OnPerceivedFactionOutfitTypeChanged(SCR_EPerceivedFactionOutfitType newType)
SCR_ECharacterDisguiseType m_eDisguiseType
ScriptInvokerFaction GetOnOnPerceivedFactionChanged()
void OnPerceivedFactionChangesAffectsAIChanged(bool affectsAI)
void InitPlayerOutfitFaction_S()
Called by SCR_PerceivedFactionManagerComponent when player is spawned. Is not called for Non-Players.
ref set< SCR_OutfitFactionDataHolder > m_CurrentOutfitData
void RecalculateOutfitFaction()
Recalculates the perceived faction. Called when the Pervceived faction type is changed and after init...
PerceivableComponent m_PerceivableComponent
void OnNoFactionSlottedItemChanged(bool addedToSlot, IEntity item, bool updateFaction=true)
void SetPerceivedFactionForAI(bool resetToNull=false)
SCR_ECharacterDisguiseType GetCharacterDisguiseType()
ref map< Faction, int > m_mOutfitFactionValues
SCR_CharacterFactionAffiliationComponentClass m_PerceivedFaction
void ~SCR_CharacterFactionAffiliationComponent()
void ChangeFactionOutfitValue(Faction faction, int value, bool updateFaction=true)
ref ScriptInvokerFaction m_OnPerceivedFactionChanged
void RemoveFactionOutfitValue(notnull Faction faction, int value, bool updateFaction=true)
Get all prefabs that have the spawner data
ScriptInvokerBase< OnFactionChangeDelegate > OnFactionChangedInvoker
void OnPerceivedFactionChangesAffectsAIChanged()
void OnPerceivedFactionOutfitTypeChanged()
void SCR_PerceivedFactionManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
ScriptInvokerBase< ScriptInvokerFactionMethod > ScriptInvokerFaction
Definition Debug.c:13
Main replication API.
Definition Replication.c:14
void GetBlockedSlots(out notnull array< typename > blockedSlots)
void InitCharacterPerceivedOutfitData(notnull SCR_CharacterFactionAffiliationComponent characterAffiliationComponent)
override bool DoCheckIfFactionFriendly(Faction faction)
bool IsMilitary()
SCR_OutfitFactionData GetOutfitFactionData(FactionKey faction)
int GetOutfitFactionDataArray(out notnull array< SCR_OutfitFactionData > outfitDataArray)
static IEntity GetLocalMainEntity()
Definition Types.c:486
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_CampaignFaction GetAffiliatedFaction()
Returns the affiliated faction or null if none.
proto external Faction GetDefaultAffiliatedFaction()
Returns the default affiliated faction or null if none.
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
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14