Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_HoldCampaignMilitaryBaseTaskEntity.c
Go to the documentation of this file.
4
5class SCR_HoldCampaignMilitaryBaseTaskEntity : SCR_CampaignMilitaryBaseTaskEntity
6{
7 protected const int PERIODICAL_CHECK_INTERVAL = 5000; // ms
8
9 [Attribute("200", UIWidgets.EditBox, "Area radius [m] around base", "0 inf")]
10 protected float m_fAreaRadiusAroundBase;
11
12 [Attribute("300", UIWidgets.EditBox, "The time [s] it takes to finish a task when no combat is going on in the zone and at least one enemy character was killed", "0 inf")]
13 protected float m_fNoCombatFinishTime;
14
15 [Attribute("600", UIWidgets.EditBox, "The time [s] it takes to automatically cancel a task when no enemy has been killed in the zone", "0 inf")]
16 protected float m_fAutoCancelTime;
17
18 protected RplComponent m_RplComponent;
21 protected WorldTimestamp m_LastCombatTimestamp; // is used for autocancel and win condition
22 protected WorldTimestamp m_TaskStartedTimestamp; // is used for autocancel
23
24 //------------------------------------------------------------------------------------------------
25 protected void OnControllableDestroyed(notnull SCR_InstigatorContextData instigatorContextData)
26 {
27 // check if was killed by enemy
28 if (!instigatorContextData.HasAnyVictimKillerRelation(SCR_ECharacterDeathStatusRelations.KILLED_BY_ENEMY_PLAYER | SCR_ECharacterDeathStatusRelations.KILLED_BY_ENEMY_AI))
29 return;
30
31 IEntity victimEntity = instigatorContextData.GetVictimEntity();
32 if (!victimEntity)
33 return;
34
35 vector basePositon = GetMilitaryBase().GetOwner().GetOrigin();
36
37 // check distance from base
38 if (vector.DistanceSq(basePositon, victimEntity.GetOrigin()) > m_fAreaRadiusAroundBaseSq)
39 return;
40
41 // somebody was killed(player, AI) in the zone => reset combat timer
42 ChimeraWorld world = GetGame().GetWorld();
43 if (world)
44 m_LastCombatTimestamp = world.GetServerTimestamp();
45
46 #ifdef HOLD_TASK_DEBUG
47 Print("Hold task, somebody was killed in the zone - reset combat timer");
48 #endif
49
50 // if an enemy has been killed by someone in the assigned group, we do not need to check again.
52 return;
53
54 IEntity killerEntity = instigatorContextData.GetKillerEntity();
55 if (!killerEntity)
56 return;
57
58 // get faction from entity(player, AI)
59 Faction killerFaction = SCR_Faction.GetEntityFaction(killerEntity);
60 array<string> ownerFactionKeys = GetOwnerFactionKeys();
61 if (!ownerFactionKeys || !ownerFactionKeys.Contains(killerFaction.GetFactionKey()))
62 return;
63
64 SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
65 if (!groupManager)
66 return;
67
68 SCR_AIGroup group;
69 int killerId = instigatorContextData.GetKillerPlayerID();
70 if (killerId <= 0)
71 {
72 // killer is AI
73 AIControlComponent aiControlComponent = AIControlComponent.Cast(killerEntity.FindComponent(AIControlComponent));
74 if (!aiControlComponent)
75 return;
76
77 AIAgent agent = aiControlComponent.GetAIAgent();
78 if (!agent)
79 return;
80
81 group = SCR_AIGroup.Cast(agent);
82 if (!group)
83 group = SCR_AIGroup.Cast(agent.GetParentGroup());
84
85 if (!group || !group.IsSlave() || !group.GetMaster())
86 return;
87
88 group = group.GetMaster();
89 }
90 else
91 {
92 // killer is player
93 group = groupManager.GetPlayerGroup(killerId);
94 }
95
96 if (!group)
97 return;
98
99 // check if killer's group(could be master) is assigned in the task
100 if (!IsTaskAssignedTo(SCR_TaskExecutor.FromGroup(group.GetGroupID())))
101 return;
102
104
105 #ifdef HOLD_TASK_DEBUG
106 Print("Hold task, enemy was killed in the zone");
107 #endif
108 }
109
110 //------------------------------------------------------------------------------------------------
111 override protected void OnTargetBaseCaptured(SCR_MilitaryBaseComponent base, Faction faction)
112 {
114 return;
115
116 #ifdef HOLD_TASK_DEBUG
117 PrintFormat("Hold task, base captured, task canceled");
118 #endif
119
120 SetTaskState(SCR_ETaskState.CANCELLED);
121 DeleteTask();
122 }
123
124 //------------------------------------------------------------------------------------------------
125 protected void PeriodicalCheck()
126 {
127 ChimeraWorld world = GetGame().GetWorld();
128 if (!world)
129 return;
130
131 WorldTimestamp currentTime = world.GetServerTimestamp();
132
134 {
135 // check finish
136 WorldTimestamp finishTimestamp = m_LastCombatTimestamp.PlusSeconds(m_fNoCombatFinishTime);
137
138 #ifdef HOLD_TASK_DEBUG
139 PrintFormat("Hold task, finish remaining time %1", finishTimestamp.DiffSeconds(currentTime));
140 #endif
141
142 if (currentTime.Less(finishTimestamp))
143 return;
144
145 #ifdef HOLD_TASK_DEBUG
146 PrintFormat("Hold task, completed");
147 #endif
148
149 m_TaskSystem.SetTaskState(this, SCR_ETaskState.COMPLETED);
150 DeleteTask();
151 }
152 else
153 {
154 // check auto cancel
155 WorldTimestamp cancelTimestamp = m_TaskStartedTimestamp.PlusSeconds(m_fAutoCancelTime);
156
157 #ifdef HOLD_TASK_DEBUG
158 PrintFormat("Hold task, cancel remaining time %1", cancelTimestamp.DiffSeconds(currentTime));
159 #endif
160
161 if (currentTime.Less(cancelTimestamp))
162 return;
163
164 #ifdef HOLD_TASK_DEBUG
165 PrintFormat("Hold task, auto cancel");
166 #endif
167
168 m_TaskSystem.SetTaskState(this, SCR_ETaskState.CANCELLED);
169 DeleteTask();
170 }
171 }
172
173 //------------------------------------------------------------------------------------------------
174 protected void AddXPReward()
175 {
176 SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
177 if (!comp || !m_RplComponent || m_RplComponent.IsProxy())
178 return;
179
180 // add XP to all players in the assigned group
181 array<int> assigneePlayerIDs = GetTaskAssigneePlayerIDs();
182 if (!assigneePlayerIDs)
183 return;
184
185 foreach (int playerID : assigneePlayerIDs)
186 {
187 comp.AwardXP(playerID, SCR_EXPRewards.HOLD_TASK_COMPLETED, 1.0, false);
188 }
189 }
190
191 //------------------------------------------------------------------------------------------------
192 override void SetTaskState(SCR_ETaskState state)
193 {
194 if (state == SCR_ETaskState.COMPLETED)
195 AddXPReward();
196
197 super.SetTaskState(state);
198 }
199
200 //------------------------------------------------------------------------------------------------
201 override void EOnInit(IEntity owner)
202 {
203 super.EOnInit(owner);
204
205 if (SCR_Global.IsEditMode(this) || !GetGame().GetGameMode())
206 return;
207
209
210 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
211 if (!m_RplComponent || m_RplComponent.IsProxy())
212 return;
213
214 GetGame().GetCallqueue().CallLater(PeriodicalCheck, PERIODICAL_CHECK_INTERVAL, true);
215
217 if (!gameMode)
218 return;
219
221
222 ChimeraWorld world = GetGame().GetWorld();
223 if (!world)
224 return;
225
226 m_TaskStartedTimestamp = world.GetServerTimestamp();
227 }
228
229 //------------------------------------------------------------------------------------------------
231 {
232 GetGame().GetCallqueue().Remove(PeriodicalCheck);
233
235 if (!gameMode)
236 return;
237
239 }
240}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void DeleteTask()
void PeriodicalCheck()
override void SetTaskState(SCR_ETaskState state)
SCR_AttackTaskEntityClass PERIODICAL_CHECK_INTERVAL
SCR_BaseGameMode GetGameMode()
void OnTargetBaseCaptured(SCR_MilitaryBaseComponent base, Faction faction)
RplComponent m_RplComponent
SCR_CampaignMilitaryBaseComponent m_MilitaryBase
SCR_CampaignMilitaryBaseComponent GetMilitaryBase()
void AddXPReward()
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
WorldTimestamp m_TaskStartedTimestamp
WorldTimestamp m_LastCombatTimestamp
void ~SCR_HoldCampaignMilitaryBaseTaskEntity()
void OnControllableDestroyed(IEntity entity, IEntity killerEntity, Instigator instigator, notnull SCR_InstigatorContextData instigatorContextData)
array< int > GetTaskAssigneePlayerIDs()
Definition SCR_Task.c:458
array< string > GetOwnerFactionKeys()
Definition SCR_Task.c:951
SCR_ETaskState
Definition SCR_Task.c:3
bool IsTaskAssignedTo(SCR_TaskExecutor executor, out SCR_TaskExecutor match=null)
Definition SCR_Task.c:493
SCR_TaskSystem m_TaskSystem
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
SCR_AIGroup GetMaster()
int GetGroupID()
bool IsSlave()
ScriptInvokerBase< SCR_BaseGameMode_OnControllableDestroyed > GetOnControllableDestroyed()
static Faction GetEntityFaction(notnull IEntity entity)
static bool IsEditMode()
Definition Functions.c:1566
override void EOnInit(IEntity owner)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute