Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_GameModeCampaignSerializer.c
Go to the documentation of this file.
2{
3 [Attribute("120.0", desc: "Maximum time a faction commander can reconnect at and automatically get his role back.")]
5
6 [Attribute("60.0", desc: "How much time, if any, is added to victory countdown to account for players needing time to reconnect after loading a save.")]
7 protected float m_fVictoryGracePeriod;
8
9 //------------------------------------------------------------------------------------------------
10 override static typename GetTargetType()
11 {
13 }
14
15 //------------------------------------------------------------------------------------------------
16 override protected ESerializeResult Serialize(notnull IEntity entity, notnull SaveContext context)
17 {
18 const SCR_GameModeCampaign conflict = SCR_GameModeCampaign.Cast(entity);
19
20 const int callsignOffset = conflict.GetCallsignOffset();
21
22 const WorldTimestamp currentTime = entity.GetWorld().GetTimestamp();
23
24 map<FactionKey, UUID> factionCommanders();
25 map<FactionKey, int> factionVictoryTimestamps();
26 const FactionManager factionManager = GetGame().GetFactionManager();
27 array<Faction> factions();
28 factionManager.GetFactionsList(factions);
29 foreach (auto faction : factions)
30 {
31 const SCR_CampaignFaction campaignFaction = SCR_CampaignFaction.Cast(faction);
32 if (!campaignFaction)
33 continue;
34
35 if (!campaignFaction.IsAICommander())
36 {
37 const UUID playerIdentity = GetSystem().GetId(GetGame().GetPlayerManager().GetPlayerController(campaignFaction.GetCommanderId()));
38 if (!playerIdentity.IsNull())
39 factionCommanders.Set(campaignFaction.GetFactionKey(), playerIdentity);
40 }
41
42 const float victoryTime = Math.Max(campaignFaction.GetVictoryTimestamp().DiffSeconds(currentTime), 0.0);
43 if (victoryTime)
44 factionVictoryTimestamps.Set(campaignFaction.GetFactionKey(), victoryTime);
45 }
46
47 context.StartObject("base");
48 const ESerializeResult baseResult = super.Serialize(entity, context);
49 context.EndObject();
50 if (baseResult == ESerializeResult.ERROR)
51 return baseResult;
52
53 context.WriteValue("version", 1);
54 context.Write(callsignOffset);
55
56 if (!factionCommanders.IsEmpty() || !context.CanSeekMembers())
57 context.Write(factionCommanders);
58
59 if (!factionVictoryTimestamps.IsEmpty() || !context.CanSeekMembers())
60 context.Write(factionVictoryTimestamps);
61
62 return ESerializeResult.OK;
63 }
64
65 //------------------------------------------------------------------------------------------------
66 override protected bool Deserialize(notnull IEntity entity, notnull LoadContext context)
67 {
68 auto conflict = SCR_GameModeCampaign.Cast(entity);
69
70 if (context.DoesObjectExist("base"))
71 {
72 if (!context.StartObject("base") ||
73 !super.Deserialize(entity, context) ||
74 !context.EndObject())
75 {
76 return false;
77 }
78 }
79
80 int version;
81 context.Read(version);
82
83 int callsignOffset;
84 context.Read(callsignOffset);
85 conflict.SetCallsignOffset(callsignOffset);
86
87 map<FactionKey, UUID> factionCommanders;
88 if (context.Read(factionCommanders))
89 {
90 foreach (FactionKey factionKey, UUID commanderId : factionCommanders)
91 {
92 Tuple1<FactionKey> ctx(factionKey);
94 GetSystem().WhenAvailable(commanderId, task, m_fMaxCommanderReconnectTime);
95 }
96 }
97
98 map<FactionKey, int> factionVictoryTimestamps;
99 if (context.Read(factionVictoryTimestamps))
100 {
101 const FactionManager factionManager = GetGame().GetFactionManager();
102 const WorldTimestamp currentTime = entity.GetWorld().GetTimestamp();
103 foreach (FactionKey factionKey, int timestamp : factionVictoryTimestamps)
104 {
105 auto campaignFaction = SCR_CampaignFaction.Cast(factionManager.GetFactionByKey(factionKey));
106 if (campaignFaction && timestamp > 0)
107 campaignFaction.SetVictoryTimestamp(currentTime.PlusSeconds(timestamp + m_fVictoryGracePeriod));
108 }
109 }
110
111 return true;
112 }
113
114 //------------------------------------------------------------------------------------------------
115 protected static void OnPlayerAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
116 {
117 auto playerController = PlayerController.Cast(instance);
118 if (!playerController)
119 return;
120
121 SCR_FactionCommanderHandlerComponent component = SCR_FactionCommanderHandlerComponent.GetInstance();
122 if (!component)
123 return;
124
125 auto factionManager = GetGame().GetFactionManager();
126 if (!factionManager)
127 return;
128
129 auto ctx = Tuple1<FactionKey>.Cast(context);
130 auto faction = SCR_Faction.Cast(factionManager.GetFactionByKey(ctx.param1));
131 if (faction && faction.IsAICommander())
132 component.SetFactionCommander(faction, playerController.GetPlayerId());
133 }
134}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Math.c:13
void SetVictoryTimestamp(WorldTimestamp timestamp)
WorldTimestamp GetVictoryTimestamp()
static void OnPlayerAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
ESerializeResult Serialize(notnull IEntity entity, notnull SaveContext context)
bool Deserialize(notnull IEntity entity, notnull LoadContext context)
Definition UUID.c:28
Definition Types.c:486
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()
ESerializeResult
void Tuple1(T1 p1)
Definition tuple.c:37