Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_ClearTaskEntity.c
Go to the documentation of this file.
1
class
SCR_ClearTaskEntityClass
:
SCR_TaskClass
2
{
3
}
4
5
class
SCR_ClearTaskEntity :
SCR_Task
6
{
7
protected
const
int
PERIODICAL_CHECK_INTERVAL
= 5000;
// ms
8
9
[
Attribute
(
"50"
,
UIWidgets
.EditBox,
"Area radius [m]"
,
"0 inf"
)]
10
protected
float
m_fAreaRadius
;
11
12
protected
ref array<IEntity>
m_aObstacleEntities
= {};
13
protected
ref array<int>
m_aAssigneesInArea
= {};
14
15
protected
RplComponent
m_RplComponent
;
16
protected
bool
m_bWasActivated
;
17
18
//------------------------------------------------------------------------------------------------
19
protected
void
PeriodicalCheck
()
20
{
21
array<int> assigneePlayerIDs =
GetTaskAssigneePlayerIDs
();
22
if
(!assigneePlayerIDs || assigneePlayerIDs.IsEmpty())
23
return
;
24
25
SCR_ChimeraCharacter character;
26
CharacterControllerComponent charControl;
27
PlayerManager
playerManager =
GetGame
().GetPlayerManager();
28
vector
taskPosition =
GetTaskPosition
();
29
m_aAssigneesInArea
.Clear();
30
31
foreach
(
int
playerId : assigneePlayerIDs)
32
{
33
character = SCR_ChimeraCharacter.Cast(playerManager.GetPlayerControlledEntity(playerId));
34
if
(!character)
35
continue
;
36
37
charControl = character.GetCharacterController();
38
if
(!charControl || charControl.IsDead())
39
continue
;
40
41
if
(
vector
.DistanceSqXZ(character.GetOrigin(), taskPosition) >
m_fAreaRadius
*
m_fAreaRadius
)
42
continue
;
43
44
m_aAssigneesInArea
.Insert(playerId);
45
}
46
47
if
(
m_aAssigneesInArea
.IsEmpty())
48
return
;
49
50
int
obstacleCount =
m_aObstacleEntities
.Count();
51
m_aObstacleEntities
.Clear();
52
GetGame
().GetWorld().QueryEntitiesBySphere(taskPosition,
m_fAreaRadius
,
QueryCallback
);
53
54
if
(
m_bWasActivated
&& obstacleCount >
m_aObstacleEntities
.Count())
55
{
56
// Obstacle was removed, objective successful
57
SetTaskState
(
SCR_ETaskState
.COMPLETED);
58
m_TaskSystem
.DeleteTask(
this
);
59
return
;
60
}
61
62
if
(!
m_bWasActivated
)
63
{
64
m_bWasActivated
=
true
;
65
66
// Fail objective if nothing to be cleared found on first activation
67
if
(
m_aObstacleEntities
.IsEmpty())
68
{
69
SetTaskState
(
SCR_ETaskState
.FAILED);
70
m_TaskSystem
.DeleteTask(
this
);
71
return
;
72
}
73
74
SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(
GetGame
().
GetGameMode
().FindComponent(SCR_CampaignBuildingManagerComponent));
75
if
(buildingManagerComponent)
76
buildingManagerComponent.GetOnCompositionUnregistered().Insert(
OnCompositionUnregistered
);
77
}
78
}
79
80
//------------------------------------------------------------------------------------------------
82
protected
bool
QueryCallback
(
IEntity
e)
83
{
84
SCR_CampaignBuildingCompositionComponent buildingComp = SCR_CampaignBuildingCompositionComponent.Cast(e.
FindComponent
(SCR_CampaignBuildingCompositionComponent));
85
if
(buildingComp && buildingComp.IsCompositionSpawned())
86
m_aObstacleEntities
.Insert(e);
87
88
SCR_BaseTriggerComponent
triggerComp =
SCR_BaseTriggerComponent
.Cast(e.
FindComponent
(
SCR_BaseTriggerComponent
));
89
if
(triggerComp && triggerComp.IsActivated())
90
m_aObstacleEntities
.Insert(e);
91
92
return
true
;
93
}
94
95
//------------------------------------------------------------------------------------------------
96
protected
void
OnCompositionUnregistered
(SCR_CampaignBuildingCompositionComponent composition)
97
{
98
if
(
m_aObstacleEntities
.IsEmpty())
99
return
;
100
101
IEntity
owner = composition.GetOwner();
102
if
(!owner || !
m_aObstacleEntities
.Contains(owner))
103
return
;
104
105
// Obstacle cleared, objective successful
106
SetTaskState
(
SCR_ETaskState
.COMPLETED);
107
m_TaskSystem
.DeleteTask(
this
);
108
}
109
110
//------------------------------------------------------------------------------------------------
111
protected
void
AddXPReward
()
112
{
113
if
(
m_RplComponent
.IsProxy())
114
return
;
115
116
SCR_XPHandlerComponent xpHandler = SCR_XPHandlerComponent.Cast(
GetGame
().
GetGameMode
().FindComponent(SCR_XPHandlerComponent));
117
if
(!xpHandler)
118
return
;
119
120
foreach
(
int
playerId :
m_aAssigneesInArea
)
121
{
122
xpHandler.AwardXP(playerId,
SCR_EXPRewards
.CLEAR_TASK_COMPLETED);
123
}
124
}
125
126
//------------------------------------------------------------------------------------------------
127
override
void
SetTaskState
(
SCR_ETaskState
state)
128
{
129
if
(state ==
SCR_ETaskState
.COMPLETED)
130
{
131
AddXPReward
();
132
GetGame
().GetCallqueue().Remove(
PeriodicalCheck
);
133
}
134
else
if
(state ==
SCR_ETaskState
.FAILED || state ==
SCR_ETaskState
.CANCELLED)
135
{
136
GetGame
().GetCallqueue().Remove(
PeriodicalCheck
);
137
}
138
139
super.SetTaskState(state);
140
}
141
142
//------------------------------------------------------------------------------------------------
143
override
void
EOnInit
(
IEntity
owner)
144
{
145
super.EOnInit(owner);
146
147
if
(
SCR_Global
.
IsEditMode
(
this
))
148
return
;
149
150
m_RplComponent
= RplComponent.Cast(owner.
FindComponent
(RplComponent));
151
if
(!
m_RplComponent
||
m_RplComponent
.IsProxy())
152
return
;
153
154
GetGame
().GetCallqueue().CallLater(
PeriodicalCheck
,
PERIODICAL_CHECK_INTERVAL
,
true
);
155
}
156
157
//------------------------------------------------------------------------------------------------
158
void
~SCR_ClearTaskEntity
()
159
{
160
if
(
SCR_Global
.
IsEditMode
(
this
))
161
return
;
162
163
GetGame
().GetCallqueue().Remove(
PeriodicalCheck
);
164
165
BaseGameMode gameMode =
GetGame
().GetGameMode();
166
if
(!gameMode)
167
return
;
168
169
SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
170
if
(buildingManagerComponent)
171
buildingManagerComponent.GetOnCompositionUnregistered().Remove(
OnCompositionUnregistered
);
172
}
173
}
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
PeriodicalCheck
void PeriodicalCheck()
Definition
SCR_AttackTaskEntity.c:35
m_bWasActivated
bool m_bWasActivated
array of playerIDs
Definition
SCR_AttackTaskEntity.c:31
SetTaskState
override void SetTaskState(SCR_ETaskState state)
Definition
SCR_AttackTaskEntity.c:290
m_fAreaRadius
float m_fAreaRadius
Definition
SCR_AttackTaskEntity.c:9
PERIODICAL_CHECK_INTERVAL
SCR_AttackTaskEntityClass PERIODICAL_CHECK_INTERVAL
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition
SCR_BaseGameModeComponent.c:15
SCR_BaseTriggerComponent
void SCR_BaseTriggerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition
SCR_BaseTriggerComponent.c:117
OnCompositionUnregistered
void OnCompositionUnregistered(SCR_CampaignBuildingCompositionComponent composition)
Definition
SCR_BuildingCampaignMilitaryBaseTaskEntity.c:10
m_RplComponent
RplComponent m_RplComponent
Definition
SCR_CampaignBuildingManagerComponent.c:64
AddXPReward
void AddXPReward()
Definition
SCR_ClearTaskEntity.c:111
m_aAssigneesInArea
ref array< int > m_aAssigneesInArea
Definition
SCR_ClearTaskEntity.c:13
QueryCallback
bool QueryCallback(IEntity e)
Inserts compositions and active mines to list of obstacles.
Definition
SCR_ClearTaskEntity.c:82
m_aObstacleEntities
ref array< IEntity > m_aObstacleEntities
Definition
SCR_ClearTaskEntity.c:12
~SCR_ClearTaskEntity
void ~SCR_ClearTaskEntity()
Definition
SCR_ClearTaskEntity.c:158
GetTaskAssigneePlayerIDs
array< int > GetTaskAssigneePlayerIDs()
Definition
SCR_Task.c:458
GetTaskPosition
vector GetTaskPosition()
Definition
SCR_Task.c:1282
SCR_Task
void SCR_Task(IEntitySource src, IEntity parent)
Definition
SCR_Task.c:1938
SCR_ETaskState
SCR_ETaskState
Definition
SCR_Task.c:3
m_TaskSystem
SCR_TaskSystem m_TaskSystem
Definition
SCR_TaskNotificationComponent.c:11
SCR_EXPRewards
SCR_EXPRewards
Definition
SCR_XPHandlerComponent.c:826
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
PlayerManager
Definition
PlayerManager.c:13
SCR_ClearTaskEntityClass
Definition
SCR_ClearTaskEntity.c:2
SCR_Global
Definition
Functions.c:7
SCR_Global::IsEditMode
static bool IsEditMode()
Definition
Functions.c:1566
SCR_TaskClass
Definition
SCR_Task.c:75
UIWidgets
Definition
attributes.c:40
vector
Definition
vector.c:13
EOnInit
override void EOnInit(IEntity owner)
Definition
SCR_AIConfigComponent.c:87
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
scripts
Game
Tasks
Campaign
SCR_ClearTaskEntity.c
Generated by
1.17.0