Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlayerFactionAffiliationComponentSerializer.c
Go to the documentation of this file.
2{
3 //------------------------------------------------------------------------------------------------
4 override static typename GetTargetType()
5 {
7 }
8
9 //------------------------------------------------------------------------------------------------
10 override protected ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
11 {
12 const SCR_PlayerController playerController = SCR_PlayerController.Cast(owner);
13 auto playerFactionAffiliation = SCR_PlayerFactionAffiliationComponent.Cast(component);
14
15 FactionKey factionKey = playerFactionAffiliation.GetAffiliatedFactionKey();
16 const FactionKey defaultFactionKey = playerFactionAffiliation.GetDefaultFactionKey();
17
18 const Faction faction = SCR_FactionManager.SGetPlayerFaction(playerController.GetPlayerId());
19 if (faction)
20 factionKey = faction.GetFactionKey();
21
22 if (factionKey == defaultFactionKey)
23 return ESerializeResult.DEFAULT;
24
25 context.WriteValue("version", 1);
26 context.Write(factionKey);
27 return ESerializeResult.OK;
28 }
29
30 //------------------------------------------------------------------------------------------------
31 override protected bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
32 {
33 auto playerController = SCR_PlayerController.Cast(owner);
34 auto playerFactionAffiliation = SCR_PlayerFactionAffiliationComponent.Cast(component);
35
36 int version;
37 context.Read(version);
38
39 FactionKey factionKey;
40 context.Read(factionKey);
41
42 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
43 const Faction faction = factionManager.GetFactionByKey(factionKey);
44 const Faction currentFaction = SCR_FactionManager.SGetPlayerFaction(playerController.GetPlayerId());
45 if (faction != currentFaction)
46 playerFactionAffiliation.SetFaction_S(faction);
47
48 return true;
49 }
50}
class SCR_PersistentThreatSector GetTargetType()
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_FactionManager(IEntitySource src, IEntity parent)
ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
ESerializeResult