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_TutorialLogic_SW.c
Go to the documentation of this file.
1
[
BaseContainerProps
()]
2
class
SCR_TutorialLogic_SW
:
SCR_BaseTutorialCourseLogic
3
{
4
ref
ScriptInvoker
m_OnAmmoDepletedChanged, m_OnAmmoAddedChanged;
5
ref array <SCR_PlaceableInventoryItemComponent> m_aPlacedCharges;
6
ref array <IEntity> m_aDestructables;
7
8
int
m_iMisses_M72;
9
bool
m_bRPGVoiceLinePlayed;
10
protected
vector
m_vCheckOffset
=
"0 0.5 0"
;
11
12
//------------------------------------------------------------------------------------------------
13
override
void
OnCourseStart
()
14
{
15
SCR_TutorialGamemodeComponent tutorialComponent = SCR_TutorialGamemodeComponent.Cast(
GetGame
().
GetGameMode
().FindComponent(SCR_TutorialGamemodeComponent));
16
if
(!tutorialComponent)
17
return
;
18
19
//respawn TARGETS
20
array <IEntity> targets = {};
21
targets.Insert(tutorialComponent.SpawnAsset(
"TARGET_1"
,
"{94803C603CF5651B}Prefabs/Structures/Military/Training/TargetVehicles/TargetBTR_flank.et"
));
22
targets.Insert(tutorialComponent.SpawnAsset(
"TARGET_2"
,
"{E1EDC3CC5421436F}Prefabs/Structures/Military/Training/TargetVehicles/TargetBMP_flank.et"
));
23
targets.Insert(tutorialComponent.SpawnAsset(
"TARGET_3"
,
"{74EF3F7B90C793AF}Prefabs/Structures/Military/Training/TargetVehicles/TargetUral_flank.et"
));
24
targets.Insert(tutorialComponent.SpawnAsset(
"TARGET_4"
,
"{DFD494A96CA95D0B}Prefabs/Structures/Military/Training/TargetVehicles/TargetBTR_front.et"
));
25
26
SCR_DestructionMultiPhaseComponent destructionComp;
27
foreach
(
IEntity
target : targets)
28
{
29
destructionComp = SCR_DestructionMultiPhaseComponent.Cast(target.GetChildren().FindComponent(SCR_DestructionMultiPhaseComponent));
30
if
(!destructionComp)
31
continue
;
32
33
destructionComp.EnableDamageHandling(
false
);
34
}
35
36
IEntity
playerEnt = tutorialComponent.GetPlayer();
37
if
(playerEnt)
38
{
39
EventHandlerManagerComponent eventHandlerManager = EventHandlerManagerComponent.Cast(playerEnt.
FindComponent
(EventHandlerManagerComponent));
40
if
(eventHandlerManager)
41
{
42
eventHandlerManager.RegisterScriptHandler(
"OnProjectileShot"
, playerEnt,
OnPlayerWeaponFired
);
43
eventHandlerManager.RegisterScriptHandler(
"OnAmmoCountChanged"
, playerEnt,
OnPlayerAmmoChangeCallback
);
44
}
45
}
46
47
if
(!m_OnAmmoDepletedChanged)
48
m_OnAmmoDepletedChanged =
new
ScriptInvoker
;
49
50
if
(!m_OnAmmoAddedChanged)
51
m_OnAmmoAddedChanged =
new
ScriptInvoker
;
52
53
// SETUP Range trigger
54
SCR_BaseTriggerEntity rangeTrigger = SCR_BaseTriggerEntity.Cast(
GetGame
().GetWorld().FindEntityByName(
"SW_TRIGGER"
));
55
if
(rangeTrigger)
56
{
57
rangeTrigger.EnablePeriodicQueries(
true
);
58
rangeTrigger.GetOnActivate().Insert(
OnCharacterInRange
);
59
rangeTrigger.SetUpdateRate(1);
60
}
61
62
// Register destructables for charge setting
63
RegisterDestructables
();
64
}
65
66
//------------------------------------------------------------------------------------------------
67
protected
void
RegisterDestructables
()
68
{
69
IEntity
ent =
GetGame
().
GetWorld
().FindEntityByName(
"DESTRUCTABLE_OBSTACLE"
);
70
if
(!ent)
71
return
;
72
73
SCR_DestructionMultiPhaseComponent destruction;
74
ent = ent.
GetChildren
();
75
while
(ent)
76
{
77
destruction = SCR_DestructionMultiPhaseComponent.Cast(ent.
FindComponent
(SCR_DestructionMultiPhaseComponent));
78
if
(destruction)
79
destruction.EnableDamageHandling(
false
);
80
81
if
(ent.
FindComponent
(DynamicPhysicsObstacleComponent))
82
{
83
if
(!m_aDestructables)
84
m_aDestructables = {};
85
86
m_aDestructables.Insert(ent);
87
}
88
89
ent = ent.
GetSibling
();
90
}
91
}
92
93
//------------------------------------------------------------------------------------------------
94
IEntity
GetAttachedTo
(
SCR_PlaceableInventoryItemComponent
charge)
95
{
96
if
(!m_aDestructables)
97
return
null;
98
99
IEntity
owner = charge.GetOwner();
100
IEntity
parent = owner.
GetParent
();
101
IEntity
mainParent =
SCR_EntityHelper
.
GetMainParent
(owner,
true
);
102
if
(mainParent && mainParent.IsInherited(
ChimeraCharacter
))
103
return
null;
104
105
foreach
(
IEntity
destructable : m_aDestructables)
106
{
107
if
(parent == destructable)
108
return
destructable;
109
110
if
(
vector
.Distance(owner.
GetOrigin
(), destructable.GetOrigin() +
m_vCheckOffset
) <= 1.5)
111
return
destructable;
112
}
113
114
return
null;
115
}
116
117
//------------------------------------------------------------------------------------------------
118
void
CheckPlacedCharges
()
119
{
120
if
(!m_aPlacedCharges)
121
m_aPlacedCharges = {};
122
123
SCR_TutorialGamemodeComponent tutorial = SCR_TutorialGamemodeComponent.GetInstance();
124
if
(!tutorial)
125
return
;
126
127
if
(
IsBarricadeDestroyed
())
128
{
129
SCR_HintManagerComponent.HideHint();
130
SCR_HintManagerComponent.ClearLatestHint();
131
132
tutorial.SetStage(
"SW_END"
);
133
GetGame
().GetCallqueue().Remove(
CheckPlacedCharges
);
134
return
;
135
}
136
137
SCR_BaseTutorialStage
stage = tutorial.GetCurrentStage();
138
139
IEntity
attachedTo;
140
for
(
int
i = m_aPlacedCharges.Count()-1; i >= 0; i--)
141
{
142
if
(!m_aPlacedCharges[i])
143
{
144
m_aPlacedCharges.Remove(i);
145
continue
;
146
}
147
148
attachedTo =
GetAttachedTo
(m_aPlacedCharges[i]);
149
if
(attachedTo)
150
continue
;
151
152
m_aPlacedCharges.Remove(i);
153
}
154
155
if
(m_aPlacedCharges.Count() >= m_aDestructables.Count())
156
{
157
if
(stage && stage.Type() ==
SCR_Tutorial_SW_PLACE_CHARGES
)
158
stage.
FinishStage
();
159
160
return
;
161
}
162
163
if
(stage.IsInherited(
SCR_Tutorial_SW_PLACE_CHARGES
))
164
{
165
foreach
(
IEntity
destructable : m_aDestructables)
166
{
167
if
(!destructable)
168
continue
;
169
170
attachedTo = null;
171
foreach
(
SCR_PlaceableInventoryItemComponent
charge : m_aPlacedCharges)
172
{
173
attachedTo =
GetAttachedTo
(charge);
174
175
if
(attachedTo == destructable)
176
break
;
177
178
attachedTo = null;
179
}
180
181
if
(!attachedTo)
182
stage.
RegisterWaypoint
(destructable,
""
,
"CUSTOM"
);
183
}
184
}
185
else
186
{
187
tutorial.InsertStage(
"PLACE_CHARGES"
, tutorial.GetActiveStageIndex());
188
tutorial.SetStage(
"PLACE_CHARGES"
);
189
}
190
}
191
192
//------------------------------------------------------------------------------------------------
193
protected
void
OnCharacterInRange
(
IEntity
char
)
194
{
195
SCR_TutorialGamemodeComponent tutorialComponent = SCR_TutorialGamemodeComponent.Cast(
GetGame
().
GetGameMode
().FindComponent(SCR_TutorialGamemodeComponent));
196
if
(!tutorialComponent)
197
return
;
198
199
tutorialComponent.InsertStage(
"PlayerInRange"
, tutorialComponent.GetActiveStageIndex());
200
tutorialComponent.SetStage(tutorialComponent.GetStageIndexByName(
"PlayerInRange"
));
201
}
202
203
//------------------------------------------------------------------------------------------------
204
//TODO: Clean this up, as it is quite dirty
205
protected
void
OnPlayerWeaponFired
(
int
playerID,
BaseWeaponComponent
weapon,
IEntity
entity)
206
{
207
if
(!weapon || weapon.GetWeaponType() !=
EWeaponType
.WT_ROCKETLAUNCHER)
208
return
;
209
210
if
(weapon.GetCurrentMuzzle().GetAmmoCount() == 0)
211
m_OnAmmoDepletedChanged.Invoke();
212
}
213
214
//------------------------------------------------------------------------------------------------
215
protected
void
OnPlayerAmmoChangeCallback
(
BaseWeaponComponent
weapon,
BaseMuzzleComponent
muzzle,
BaseMagazineComponent
magazine,
int
ammoCount,
bool
isBarrelChambered)
216
{
217
//TODO> Check for M72 and RPG
218
if
(!weapon || !weapon.IsReloadPossible())
219
return
;
220
221
if
(m_OnAmmoAddedChanged && ammoCount != 0)
222
m_OnAmmoAddedChanged.Invoke();
223
}
224
225
//------------------------------------------------------------------------------------------------
226
bool
IsBarricadeDestroyed
()
227
{
228
if
(!m_aDestructables)
229
return
true
;
230
231
for
(
int
i = m_aDestructables.Count()-1; i >= 0; i--)
232
{
233
if
(!m_aDestructables[i])
234
m_aDestructables.Remove(i);
235
}
236
237
return
m_aDestructables.IsEmpty();
238
}
239
240
//------------------------------------------------------------------------------------------------
241
override
void
OnCourseEnd
()
242
{
243
GetGame
().GetCallqueue().Remove(
CheckPlacedCharges
);
244
m_aPlacedCharges = null;
245
m_aDestructables = null;
246
m_bRPGVoiceLinePlayed =
false
;
247
248
SCR_TutorialGamemodeComponent tutorialComponent = SCR_TutorialGamemodeComponent.Cast(
GetGame
().
GetGameMode
().FindComponent(SCR_TutorialGamemodeComponent));
249
if
(!tutorialComponent)
250
return
;
251
252
tutorialComponent.EnableArsenal(
"SW_ARSENAL_GRENADES"
,
false
);
253
tutorialComponent.EnableArsenal(
"SW_ARSENAL_USSR"
,
false
);
254
tutorialComponent.EnableArsenal(
"SW_ARSENAL_M72"
,
false
);
255
tutorialComponent.EnableArsenal(
"SW_ARSENAL_AMMO"
,
false
);
256
tutorialComponent.EnableArsenal(
"SW_ARSENAL_EXPLOSIVES"
,
false
);
257
258
IEntity
playerEnt = tutorialComponent.GetPlayer();
259
if
(playerEnt)
260
{
261
EventHandlerManagerComponent eventHandlerManager = EventHandlerManagerComponent.Cast(playerEnt.
FindComponent
(EventHandlerManagerComponent));
262
if
(eventHandlerManager)
263
eventHandlerManager.RemoveScriptHandler(
"OnAmmoCountChanged"
, playerEnt,
OnPlayerAmmoChangeCallback
);
264
}
265
266
m_OnAmmoDepletedChanged = null;
267
m_OnAmmoAddedChanged = null;
268
269
// SETUP Range trigger
270
SCR_BaseTriggerEntity rangeTrigger = SCR_BaseTriggerEntity.Cast(
GetGame
().GetWorld().FindEntityByName(
"SW_TRIGGER"
));
271
if
(!rangeTrigger)
272
return
;
273
274
rangeTrigger.EnablePeriodicQueries(
false
);
275
rangeTrigger.GetOnActivate().Clear();
276
}
277
}
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
BaseContainerProps
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
Definition
SCR_AIAnimationWaypoint.c:14
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition
SCR_BaseGameModeComponent.c:15
GetAttachedTo
override SCR_EditableEntityComponent GetAttachedTo()
Definition
SCR_EditableTaskComponent.c:80
BaseMagazineComponent
Definition
BaseMagazineComponent.c:13
BaseMuzzleComponent
Definition
BaseMuzzleComponent.c:13
BaseWeaponComponent
Definition
BaseWeaponComponent.c:13
ChimeraCharacter
Definition
ChimeraCharacter.c:13
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
IEntity::GetOrigin
proto external vector GetOrigin()
IEntity::GetChildren
proto external IEntity GetChildren()
IEntity::GetWorld
proto external BaseWorld GetWorld()
IEntity::GetParent
proto external IEntity GetParent()
IEntity::GetSibling
proto external IEntity GetSibling()
SCR_BaseTutorialCourseLogic
Definition
SCR_BaseTutorialCourseLogic.c:3
SCR_BaseTutorialStage
Definition
SCR_BaseTutorialStage.c:8
SCR_BaseTutorialStage::FinishStage
void FinishStage()
Definition
SCR_BaseTutorialStage.c:557
SCR_BaseTutorialStage::RegisterWaypoint
SCR_Waypoint RegisterWaypoint(string entityName, string title=string.Empty, string icon="MISC")
Definition
SCR_BaseTutorialStage.c:293
SCR_EntityHelper
Definition
SCR_EntityHelper.c:2
SCR_EntityHelper::GetMainParent
static IEntity GetMainParent(IEntity entity, bool self=false)
Definition
SCR_EntityHelper.c:325
SCR_PlaceableInventoryItemComponent
Definition
SCR_PlaceableInventoryItemComponent.c:11
SCR_Tutorial_SW_PLACE_CHARGES
Definition
SCR_Tutorial_SW_PLACE_CHARGES.c:8
SCR_TutorialLogic_SW
Definition
SCR_TutorialLogic_SW.c:3
SCR_TutorialLogic_SW::OnCourseEnd
override void OnCourseEnd()
Definition
SCR_TutorialLogic_SW.c:241
SCR_TutorialLogic_SW::GetAttachedTo
IEntity GetAttachedTo(SCR_PlaceableInventoryItemComponent charge)
Definition
SCR_TutorialLogic_SW.c:94
SCR_TutorialLogic_SW::OnCharacterInRange
void OnCharacterInRange(IEntity char)
Definition
SCR_TutorialLogic_SW.c:193
SCR_TutorialLogic_SW::OnCourseStart
override void OnCourseStart()
Definition
SCR_TutorialLogic_SW.c:13
SCR_TutorialLogic_SW::CheckPlacedCharges
void CheckPlacedCharges()
Definition
SCR_TutorialLogic_SW.c:118
SCR_TutorialLogic_SW::OnPlayerAmmoChangeCallback
void OnPlayerAmmoChangeCallback(BaseWeaponComponent weapon, BaseMuzzleComponent muzzle, BaseMagazineComponent magazine, int ammoCount, bool isBarrelChambered)
Definition
SCR_TutorialLogic_SW.c:215
SCR_TutorialLogic_SW::IsBarricadeDestroyed
bool IsBarricadeDestroyed()
Definition
SCR_TutorialLogic_SW.c:226
SCR_TutorialLogic_SW::m_vCheckOffset
vector m_vCheckOffset
Definition
SCR_TutorialLogic_SW.c:10
SCR_TutorialLogic_SW::OnPlayerWeaponFired
void OnPlayerWeaponFired(int playerID, BaseWeaponComponent weapon, IEntity entity)
Definition
SCR_TutorialLogic_SW.c:205
SCR_TutorialLogic_SW::RegisterDestructables
void RegisterDestructables()
Definition
SCR_TutorialLogic_SW.c:67
vector
Definition
vector.c:13
EWeaponType
EWeaponType
Definition
EWeaponType.c:13
ScriptInvoker
ScriptInvokerBase< func > ScriptInvoker
Definition
tools.c:134
scripts
Game
GameMode
Tutorial
Stages
SpecialWeapons
SCR_TutorialLogic_SW.c
Generated by
1.17.0