Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ExtendedCharacterIdentityComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Character", description: "Holds flavour information of character")]
6{
7 [Attribute("1", desc: "Gender of character. Never overwrite in runtime.", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_EIdentityGender))]
9
10 [Attribute("0.25", desc: "The chance of the identity documentation in the characters inventory being valuable meaning the player can hand them in for a bonus", params: "0 1")]
12
13 //~ Set on entity spawned. Will be 0 if not a player character
14 protected int m_iPlayerId;
15
16 //~ If identity item was added to the character at least once
17 protected bool m_bIdentityItemAdded;
18
19 //======================================== GENDER ========================================\\
20 //------------------------------------------------------------------------------------------------
24 {
25 return m_eGender;
26 }
27
28 //------------------------------------------------------------------------------------------------
29 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
30 protected override void RandomizeIdentity(int combinedBioIndex)
31 {
32 super.RandomizeIdentity(combinedBioIndex);
33
35 {
36 Print("'SCR_ExtendedCharacterIdentityComponent' could not find 'SCR_ExtendedCharacterIdentity' it is either missing or does not use (or inherent from) SCR_ExtendedCharacterIdentity class! Identity is not set for character!", LogLevel.ERROR);
37 return;
38 }
39
41
42 //~ Assign bloodtype if not yet assigned
43 if (charExtendedIdentity.GetBloodType() == SCR_EBloodType.AUTO)
44 {
46 if (!identityManager)
47 return;
48
49 charExtendedIdentity.SetBloodType(identityManager.GetRandomBloodTypeIndex(m_Randomizer));
50 }
51 }
52
53 //======================================== OVERWRITE ========================================\\
54 //------------------------------------------------------------------------------------------------
55 //~ When Bio (or other system) overwrites the current Identity
56 override void OverwriteExtendedIdentity(SCR_ExtendedIdentity newExtendedIdentity)
57 {
58 super.OverwriteExtendedIdentity(newExtendedIdentity);
59
60 SCR_ExtendedCharacterIdentity newCharacterExtendedIdentity = SCR_ExtendedCharacterIdentity.Cast(newExtendedIdentity);
62
63 if (!newCharacterExtendedIdentity || !characterExtendedIdentity)
64 return;
65
66 if (newCharacterExtendedIdentity.GetBloodType() != SCR_EBloodType.AUTO)
67 characterExtendedIdentity.SetBloodType(newCharacterExtendedIdentity.GetBloodType());
68 }
69
70 //------------------------------------------------------------------------------------------------
76 protected void OverwriteCharacterName(string overwriteName, string overwriteAlias, string overwriteSurname)
77 {
78 IEntity owner = GetOwner();
79
80 if (!owner)
81 return;
82
83 CharacterIdentityComponent characterIdentityComponent = CharacterIdentityComponent.Cast(owner.FindComponent(CharacterIdentityComponent));
84 if (!characterIdentityComponent)
85 return;
86
87 Identity identity = characterIdentityComponent.GetIdentity();
88 if (!identity)
89 return;
90
91 if (!SCR_StringHelper.IsEmptyOrWhiteSpace(overwriteName))
92 identity.SetName(overwriteName);
93
94 if (!SCR_StringHelper.IsEmptyOrWhiteSpace(overwriteAlias))
95 identity.SetAlias(overwriteAlias);
96
97 if (!SCR_StringHelper.IsEmptyOrWhiteSpace(overwriteSurname))
98 identity.SetSurname(overwriteSurname);
99 }
100
101 //~ TODO: Overwrite identity does not work with Identity Class and Identity class is fully code so no access to it
102 /*
103 protected void OverwriteCharacterIdentity(notnull Identity overwriteIdentity)
104 {
105 IEntity owner = GetOwner();
106
107 if (!owner)
108 return;
109
110 CharacterIdentityComponent characterIdentityComponent = CharacterIdentityComponent.Cast(owner.FindComponent(CharacterIdentityComponent));
111 if (!characterIdentityComponent)
112 return;
113
114 Identity identity = characterIdentityComponent.GetIdentity();
115 if (!identity)
116 return;
117
118 //~ This should overwrite the identity and set any vars that are assigned and ignore the ones that aren't
119 characterIdentityComponent.SetIdentity(overwriteIdentity);
120 }*/
121
124 {
126 }
127
128 //------------------------------------------------------------------------------------------------
134 int OnIdentityItemAdded_S(SCR_IdentityInventoryItemComponent item, bool generateValuableIntel)
135 {
136 //~ Item was already added once so no need to generate valuable intel
138 return -1;
139
140 //~ Make sure that checking if the item is valuable intel is always only done once
142
143 //~ Does not generate intel so no need to continue
144 if (!generateValuableIntel)
145 return -1;
146
147 //~ Chance of identity documentation being valuable
148 if (m_fChanceOfIdentityDocumentBeingValuable <= 0) //m_iPlayerId > 0 -> Might want to turn it off for players
149 return -1;
150
151 //~ Randomize if identity is valuable
152 if (m_fChanceOfIdentityDocumentBeingValuable <= Math.RandomFloatInclusive(0, 1))
153 return -1;
154
155 IEntity owner = GetOwner();
156 if (!owner)
157 return -1;
158
159 FactionAffiliationComponent affiliationComp = FactionAffiliationComponent.Cast(owner.FindComponent(FactionAffiliationComponent));
160 if (!affiliationComp)
161 return -1;
162
163 //~ Set intel faction to character faction index
164 return GetGame().GetFactionManager().GetFactionIndex(affiliationComp.GetAffiliatedFaction());
165 }
166
167 //======================================== DEATH DATE ========================================\\
168 //------------------------------------------------------------------------------------------------
171 {
173 if (!characterIdentity)
174 return;
175
176 BaseGameMode gameMode = GetGame().GetGameMode();
177 if (!gameMode)
178 return;
179
180 ChimeraWorld world = ChimeraWorld.CastFrom(gameMode.GetWorld());
181 if (!world)
182 return;
183
184 TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
185 if (!timeManager)
186 return;
187
188 int day, month, year, hour, minute, seconds;
189
190 timeManager.GetDate(year, month, day);
191 timeManager.GetHoursMinutesSeconds(hour, minute, seconds);
192
193 int totalDeathDateMinutes = SCR_DateTimeHelper.ConvertDateIntoMinutes(year, month, day, hour, minute);
194
195 OnCharacterDeathBroadCast(totalDeathDateMinutes);
196 Rpc(OnCharacterDeathBroadCast, totalDeathDateMinutes);
197 }
198
199 //------------------------------------------------------------------------------------------------
200 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
201 protected void OnCharacterDeathBroadCast(int totalDeathDateMinutes)
202 {
204 if (!characterIdentity)
205 return;
206
207 //~ No death value set
208 if (totalDeathDateMinutes <= 0)
209 return;
210
211 //~ Death date is set, abstract each value from total minutes
212 int deathYear, deathMonth, deathDay, deathHour, deathMinute;
213 SCR_DateTimeHelper.ConvertMinutesIntoDate(totalDeathDateMinutes, deathYear, deathMonth, deathDay, deathHour, deathMinute);
214
215 characterIdentity.SetDeathDateAndTime(deathDay, deathMonth, deathYear, deathHour, deathMinute);
216 }
217
218 //======================================== BIO ========================================\\
219 //------------------------------------------------------------------------------------------------
220 //~ Bio assigned locally
221 protected override void AssignBio(SCR_IdentityBio identityBio)
222 {
223 super.AssignBio(identityBio);
224
225 if (!m_IdentityBio)
226 return;
227
229 if (!advanceCharacterOverwrite)
230 return;
231
232 //~ TODO: Overwrite identity does not work with Identity Class and Identity class is fully code so no access to it
233 /*Identity identity = advanceCharacterOverwrite.GetOverwriteIdentity();
234 if (identity)
235 GetGame().GetCallqueue().CallLater(OverwriteCharacterIdentity, 0, false, identity);*/
236
237 string overwriteName, overwriteAlias, overwriteSurname;
238 //~ Get is overwriting names, if true overwrite after 1 frame (Else they get overwritten by default naming system)
239 if (advanceCharacterOverwrite.GetOverwriteNames(overwriteName, overwriteAlias, overwriteSurname))
240 GetGame().GetCallqueue().CallLater(OverwriteCharacterName, 0, false, overwriteName, overwriteAlias, overwriteSurname);
241 }
242
243 //======================================== BIRTH PLACE ========================================\\
244 //------------------------------------------------------------------------------------------------
245 //~ Overwrite to set place of birth similar to group leader if any
246 //~ Server Only
247 protected override void RandomizePlaceOfOrigin()
248 {
250 if (!gamemode || !gamemode.IsMaster())
251 return;
252
254 return;
255
256 //~ No faction so no origin
257 int FactionOfOrigin = m_ExtendedIdentity.GetFactionOfOriginIndex();
258 if (FactionOfOrigin <= -1)
259 return;
260
261 IEntity owner = GetOwner();
262 if (!owner)
263 return;
264
265 AIControlComponent aiControlComp = AIControlComponent.Cast(owner.FindComponent(AIControlComponent));
266 if (!aiControlComp)
267 return;
268
269 AIAgent aIAgent = aiControlComp.GetAIAgent();
270 if (!aIAgent)
271 return;
272
273 SCR_Faction scrFaction;
274 SCR_FactionHomeTerritoryConfig placeOfBirthConfig;
275
276 //~ Has AI group
277 SCR_AIGroup aiGroup = SCR_AIGroup.Cast(aIAgent.GetParentGroup());
278 if (aiGroup)
279 {
280 scrFaction = SCR_Faction.Cast(aiGroup.GetFaction());
281 if (!scrFaction)
282 return;
283
284 //~ Faction was changed by Bio
285 if (m_ExtendedIdentity.GetFactionOfOriginKey() != scrFaction.GetFactionKey())
286 {
287 FactionManager factionManager = GetGame().GetFactionManager();
288 if (factionManager)
289 scrFaction = SCR_Faction.Cast(factionManager.GetFactionByIndex(m_ExtendedIdentity.GetFactionOfOriginIndex()));
290
291 if (scrFaction)
292 {
293 placeOfBirthConfig = scrFaction.GetFactionHomeTerritoryConfig();
294 if (placeOfBirthConfig)
295 {
297 return;
298 }
299 }
300 }
301
302 placeOfBirthConfig = scrFaction.GetFactionHomeTerritoryConfig();
303 if (placeOfBirthConfig)
304 {
305 //~ If leader (Or no leader) set place of birth random
306 if (aiGroup.GetLeaderAgent() == null || aiGroup.GetLeaderAgent() == aIAgent)
307 {
308 if (placeOfBirthConfig)
309 {
311 return;
312 }
313 }
314 //~ If not leader set place of birth to leader or random
315 else
316 {
317 IEntity leaderEntity = aiGroup.GetLeaderEntity();
318
319 if (!leaderEntity)
320 {
322 return;
323 }
324
326 if (!leaderExtendedIdentityComponent)
327 {
329 return;
330 }
331
332 SCR_ExtendedIdentity leaderExtendedIdentity = leaderExtendedIdentityComponent.GetExtendedIdentity();
333 if (!leaderExtendedIdentity)
334 {
336 return;
337 }
338
339
340 //~ Not the same initial faction
341 if (leaderExtendedIdentity.GetFactionOfOriginIndex() < 0 || leaderExtendedIdentity.GetFactionOfOriginIndex() != m_ExtendedIdentity.GetFactionOfOriginIndex())
342 {
344 return;
345 }
346
347 //~ Check if should have same birth index as leader or have seperate one
348 float randomPercentage = m_Randomizer.RandIntInclusive(0, 100);
349
350 //~ Grab same place of birth as leader
351 if (randomPercentage / 100 <= placeOfBirthConfig.GetSharedPlaceOfBirthWeight())
352 {
353 SetPlaceOfOriginIndex(leaderExtendedIdentity.GetPlaceOfOriginIndex());
354 return;
355 }
356 //~ Set random place of birth
357 else
358 {
360 return;
361 }
362 }
363 }
364 }
365
366 //~ Did not successfully set place of birth so try using initial faction index (Not in AI group)
367 FactionManager factionManager = GetGame().GetFactionManager();
368 if (factionManager)
369 scrFaction = SCR_Faction.Cast(factionManager.GetFactionByIndex(m_ExtendedIdentity.GetFactionOfOriginIndex()));
370
371 if (!scrFaction)
372 return;
373
374 placeOfBirthConfig = scrFaction.GetFactionHomeTerritoryConfig();
375 if (!placeOfBirthConfig)
376 return;
377
379 }
380
381 //------------------------------------------------------------------------------------------------
382 //~ Server only
388
389 //------------------------------------------------------------------------------------------------
390 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
392 {
393 m_ExtendedIdentity.SetPlaceOfOriginIndex(index);
394 }
395
396 //------------------------------------------------------------------------------------------------
398 void SetPlayerID(int playerId)
399 {
400 m_iPlayerId = playerId;
401 }
402
403 //------------------------------------------------------------------------------------------------
406 {
407 return m_iPlayerId;
408 }
409
410 //======================================== LIFE STATE CHANGED ========================================\\
411 //------------------------------------------------------------------------------------------------
412 protected void OnCharacterLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
413 {
414 if (newLifeState != ECharacterLifeState.INCAPACITATED)
415 return;
416
418 if (!identityManager)
419 return;
420
421 identityManager.OnCharacterBecomeUnconscious(GetOwner());
422 }
423
424 //======================================== INIT/DESTROY ========================================\\
425 //------------------------------------------------------------------------------------------------
426 override void DelayedInit(IEntity owner)
427 {
428 super.DelayedInit(owner);
429
430 //~ No need to inform the identity manager on state changed if not server
432 if ((gameMode && !gameMode.IsMaster()) || (!gameMode && Replication.IsClient()))
433 return;
434
435 ChimeraCharacter character = ChimeraCharacter.Cast(owner);
436 if (!character)
437 return;
438
439 SCR_CharacterControllerComponent controllerComponent = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
440 if (!controllerComponent)
441 return;
442
443 controllerComponent.m_OnLifeStateChanged.Insert(OnCharacterLifeStateChanged);
444 }
445
446 //------------------------------------------------------------------------------------------------
447 override void OnDelete(IEntity owner)
448 {
450 return;
451
452 ChimeraCharacter character = ChimeraCharacter.Cast(owner);
453 if (!character)
454 return;
455
456 SCR_CharacterControllerComponent controllerComponent = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
457 if (!controllerComponent)
458 return;
459
460 controllerComponent.m_OnLifeStateChanged.Remove(OnCharacterLifeStateChanged);
461 }
462
463 //======================================== RPL ========================================\\
464 //------------------------------------------------------------------------------------------------
465 override bool RplSave(ScriptBitWriter writer)
466 {
467 super.RplSave(writer);
468
470 if (!charExtendedIdentity)
471 return false;
472
473 int deathYear, deathMonth, deathDay, deathHour, deathMinute;
474 charExtendedIdentity.GetDeathDateAndTime(deathDay, deathMonth, deathYear, deathHour, deathMinute);
475
476 int totalDeathDateMinutes;
477
478 //~ Check if a death value is set
479 if (deathYear <= 0)
480 totalDeathDateMinutes = 0;
481 //~ Death date is set. Combine it into total minutes
482 else
483 totalDeathDateMinutes = SCR_DateTimeHelper.ConvertDateIntoMinutes(deathYear, deathMonth, deathDay, deathHour, deathMinute);
484
485 writer.WriteInt(totalDeathDateMinutes);
486 writer.WriteInt(charExtendedIdentity.GetPlaceOfOriginIndex());
487
488 return true;
489 }
490
491 //------------------------------------------------------------------------------------------------
492 override bool RplLoad(ScriptBitReader reader)
493 {
494 super.RplLoad(reader);
495
497 return false;
498
499 int totalDeathDateMinutes, placeOfOrginIndex;
500 reader.ReadInt(totalDeathDateMinutes);
501 reader.ReadInt(placeOfOrginIndex);
502
503 OnCharacterDeathBroadCast(totalDeathDateMinutes);
504 SetCharacterPlaceOfOriginBroadcast(placeOfOrginIndex);
505
506 return true;
507 }
508}
509
510
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_BaseGameMode GetGameMode()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
SCR_EBloodType
SCR_EIdentityGender
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
Main replication API.
Definition Replication.c:14
Faction GetFaction()
sealed bool IsMaster()
ref OnLifeStateChangedInvoker m_OnLifeStateChanged
override void AssignBio(SCR_IdentityBio identityBio)
void OnCharacterDeath()
Called by SCR_CharacterIdentityManagerComponent when character dies (Server Only).
void OverwriteCharacterName(string overwriteName, string overwriteAlias, string overwriteSurname)
override void OverwriteExtendedIdentity(SCR_ExtendedIdentity newExtendedIdentity)
void SetPlayerID(int playerId)
Set this character player ID. Handled in the preparing of this character by the SCR_IdentityManagerCo...
int OnIdentityItemAdded_S(SCR_IdentityInventoryItemComponent item, bool generateValuableIntel)
void OnCharacterLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
bool GetDeathDateAndTime(out int deathDay, out int deathMonth, out int deathYear, out int deathHour, out int deathMinute)
void SetBloodType(SCR_EBloodType bloodType)
void SetDeathDateAndTime(int deathDay, int deathMonth, int deathYear, int deathHour, int deathMinute)
int GetRandomHomeTerritoryIndex(RandomGenerator randomizer=null, bool useWeightedRandom=true)
SCR_FactionHomeTerritoryConfig GetFactionHomeTerritoryConfig()
bool GetOverwriteNames(out string name, out string alias, out string surname)
void OnCharacterBecomeUnconscious(IEntity character)
static SCR_IdentityManagerComponent GetInstance()
int GetRandomBloodTypeIndex(RandomGenerator randomizer=null, bool useWeightedRandom=true)
static bool IsEmptyOrWhiteSpace(string input)
proto external GenericEntity GetOwner()
Get owner entity.
ECharacterLifeState
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
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