Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AmbientPatrolSpawnPointComponentSerializer.c
Go to the documentation of this file.
2{
3 //------------------------------------------------------------------------------------------------
4 override static typename GetTargetType()
5 {
6 return SCR_AmbientPatrolSpawnPointComponent;
7 }
8
9 //------------------------------------------------------------------------------------------------
10 override protected ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
11 {
12 auto ambientPatrol = SCR_AmbientPatrolSpawnPointComponent.Cast(component);
13 auto world = ChimeraWorld.CastFrom(owner.GetWorld());
14 const WorldTimestamp currentTime = world.GetServerTimestamp();
15
16 const bool spawned = ambientPatrol.GetIsSpawned();
17 const bool paused = ambientPatrol.GetIsPaused();
18 const int membersAlive = ambientPatrol.GetMembersAlive();
19
20 if (!spawned && !paused && (membersAlive == -1))
21 return ESerializeResult.DEFAULT;
22
23 const UUID groupId = GetSystem().GetId(ambientPatrol.GetSpawnedGroup());
24 const bool groupActive = ambientPatrol.IsGroupActive();
25 const UUID waypointId = GetSystem().GetId(ambientPatrol.GetWaypoint());
26
27 const WorldTimestamp despawnTimestamp = ambientPatrol.GetDespawnTimestamp();
28 float despawnTime = 0;
29 if (despawnTimestamp)
30 despawnTime = currentTime.DiffSeconds(despawnTimestamp);
31
32 const WorldTimestamp respawnTimestamp = ambientPatrol.GetRespawnTimestamp();
33 float respawnTime = 0;
34 if (respawnTimestamp)
35 respawnTime = currentTime.DiffSeconds(respawnTimestamp);
36
37 context.WriteValue("version", 1);
38 context.WriteDefault(spawned, false);
39 context.WriteDefault(paused, false);
40 context.WriteDefault(groupId, UUID.NULL_UUID);
41 context.WriteDefault(groupActive, false);
42 context.WriteDefault(membersAlive, -1);
43 context.WriteDefault(waypointId, UUID.NULL_UUID);
44 context.WriteDefault(despawnTime, 0.0);
45 context.WriteDefault(respawnTime, 0.0);
46 return ESerializeResult.OK;
47 }
48
49 //------------------------------------------------------------------------------------------------
50 override protected bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
51 {
52 auto ambientPatrol = SCR_AmbientPatrolSpawnPointComponent.Cast(component);
53 auto world = ChimeraWorld.CastFrom(owner.GetWorld());
54 const WorldTimestamp currentTime = world.GetServerTimestamp();
55
56 int version;
57 context.Read(version);
58
59 bool spawned;
60 if (context.Read(spawned))
61 ambientPatrol.SetIsSpawned(spawned);
62
63 bool paused;
64 if (context.Read(paused))
65 ambientPatrol.SetIsPaused(paused);
66
67 UUID groupId;
68 if (context.Read(groupId) && !groupId.IsNull())
69 {
72 GetSystem().WhenAvailable(groupId, task);
73 }
74
75 bool groupActive;
76 if (context.Read(groupActive))
77 {
78 if (groupActive)
79 {
80 ambientPatrol.ActivateGroup();
81 }
82 else
83 {
84 ambientPatrol.DeactivateGroup();
85 }
86 }
87
88 int membersAlive;
89 if (context.Read(membersAlive))
90 ambientPatrol.SetMembersAlive(membersAlive);
91
92 UUID waypointId;
93 if (context.Read(waypointId) && !waypointId.IsNull())
94 {
97 GetSystem().WhenAvailable(waypointId, task);
98 }
99
100 float despawnTime;
101 if (context.Read(despawnTime))
102 ambientPatrol.SetDespawnTimestamp(currentTime.PlusSeconds(despawnTime));
103
104 float respawnTime;
105 if (context.Read(respawnTime))
106 ambientPatrol.SetRespawnTimestamp(currentTime.PlusSeconds(respawnTime));
107
108 return true;
109 }
110
111 //------------------------------------------------------------------------------------------------
112 protected static void OnGroupAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
113 {
114 auto group = SCR_AIGroup.Cast(instance);
115 if (!group)
116 return;
117
118 auto ctx = Tuple1<SCR_AmbientPatrolSpawnPointComponent>.Cast(context);
119 if (ctx.param1)
120 ctx.param1.SetspawnedGroup(group);
121 }
122
123 //------------------------------------------------------------------------------------------------
124 protected static void OnWaypointAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
125 {
126 auto wp = SCR_AIWaypoint.Cast(instance);
127 if (!wp)
128 return;
129
130 auto ctx = Tuple1<SCR_AmbientPatrolSpawnPointComponent>.Cast(context);
131 if (ctx.param1)
132 ctx.param1.SetWaypoint(wp);
133 }
134}
class SCR_PersistentThreatSector GetTargetType()
ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
static void OnGroupAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
static void OnWaypointAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
Definition UUID.c:28
ESerializeResult
void Tuple1(T1 p1)
Definition tuple.c:37