9 [
Attribute(
"", UIWidgets.ResourceAssignArray,
"Generated projectiles will loop through the projectiles on this array",
"et")]
10 private ref array<ResourceName> m_ProjectilesToTrigger;
13 [
Attribute(
"0", UIWidgets.EditBox,
"Number of projectiles to create. 0 = until time ends")]
16 [
Attribute(
"0", UIWidgets.EditBox,
"Time until this entity creates a new projectile.")]
17 float m_TimeBetweenProjectiles;
19 [
Attribute(
"0", UIWidgets.EditBox,
"Size of zone around the point where the airstrike will take place")]
20 float m_AirstrikeRadius;
22 [
Attribute(
"0", UIWidgets.CheckBox,
"If true, even if there is a random radius it will have a bias towards the original airstrike target")]
23 bool m_BiasTowardsCenter;
25 [
Attribute(
"0", UIWidgets.Range,
"Random delay [0,X] applied to the time between projectiles to make it more believable. Ignore Z parameter, 2D vectors are not supported by script")]
26 vector m_RandomDelayBetweenRockets;
28 [
Attribute(
"0", UIWidgets.Range,
"Initial delay for the beginning of the airstrike")]
32 private ref array<ref Resource> m_LoadedPrefabs =
new array<ref Resource>();
35 int m_RemainingProjectiles = 0;
36 float m_TimeUntilNextProjectile = 0;
39 private int m_CurrentProjectilePrefab = 0;
40 private int m_PreviousProjectilePrefab = 0;
42 private ref RandomGenerator m_RandomGenerator =
new RandomGenerator;
45 private BaseSoundComponent m_SoundComponent;
46 private int m_SoundShotIndex = 0;
48 private vector m_direction;
49 private vector m_spawnPos;
50 private IEntity m_lastSpawnedProjectile =
null;
53 private IEntity m_owner =
null;
54 private RplComponent m_RplComponent =
null;
58 SetFlags(EntityFlags.ACTIVE,
false);
59 SetEventMask(EntityEvent.FRAME | EntityEvent.INIT);
61 for(
int i = 0; i < m_ProjectilesToTrigger.Count(); i++)
63 if(!m_ProjectilesToTrigger[i])
66 Resource projectile = Resource.Load(m_ProjectilesToTrigger[i]);
68 m_LoadedPrefabs.Insert(projectile);
71 m_RemainingProjectiles = m_NumProjectiles;
72 m_TimeUntilNextProjectile = m_TimeBetweenProjectiles;
74 AddRandomDelayToNextProjectile();
78 override protected void EOnInit(IEntity owner)
81 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
83 m_TimeUntilNextProjectile += m_InitialDelay;
86 override protected void EOnFrame(IEntity owner,
float timeSlice)
88 if(m_lastSpawnedProjectile)
90 Do_LaunchMissile(m_direction);
92 m_lastSpawnedProjectile =
null;
96 if (m_RemainingProjectiles <= 0)
98 ClearFlags(EntityFlags.ACTIVE,
false);
99 ClearEventMask(EntityEvent.FRAME);
103 m_TimeUntilNextProjectile -= timeSlice;
106 if (m_TimeUntilNextProjectile > 0)
110 m_TimeUntilNextProjectile += m_TimeBetweenProjectiles;
111 AddRandomDelayToNextProjectile();
117 protected void ReadyProjectile()
119 ref Resource prefab = m_LoadedPrefabs[m_CurrentProjectilePrefab];
121 AdvanceProjectilePrefab();
123 m_RemainingProjectiles--;
128 ref EntitySpawnParams spawnParams =
new EntitySpawnParams();
129 spawnParams.TransformMode = ETransformMode.WORLD;
132 vector missileTarget = ComputeMissileTarget();
134 ComputeProjectileTransform(spawnParams.Transform,
direction, missileTarget);
136 FireProjectile(prefab, spawnParams,
direction);
140 protected void AdvanceProjectilePrefab()
142 m_PreviousProjectilePrefab = m_CurrentProjectilePrefab;
143 ++m_CurrentProjectilePrefab;
145 if (m_CurrentProjectilePrefab >= m_LoadedPrefabs.Count())
146 m_CurrentProjectilePrefab = 0;
150 protected vector ComputeMissileTarget()
152 vector ownerTransform[4];
153 GetTransform(ownerTransform);
155 if(m_AirstrikeRadius == 0)
156 return ownerTransform[3];
158 vector missileTarget =
m_RandomGenerator.GenerateRandomPointInRadius(0, m_AirstrikeRadius, ownerTransform[3], !m_BiasTowardsCenter);
159 missileTarget[1] = ownerTransform[3][1];
161 return missileTarget;
164 protected void ComputeProjectileTransform(out vector transform[4], out vector
direction, vector missileTarget)
172 m_spawnPos[1] = m_spawnPos[1] + 100;
174 direction = vector.Direction(m_spawnPos, missileTarget);
177 Math3D.MatrixFromForwardVec(
direction, transform);
178 transform[3] = m_spawnPos;
182 void FireProjectile(Resource prefab, EntitySpawnParams spawnParams, vector
direction)
184 IEntity spawnedProjectile =
GetGame().SpawnEntityPrefab(prefab, GetWorld(), spawnParams);
186 m_lastSpawnedProjectile = spawnedProjectile;
193 RplComponent rplComp = RplComponent.Cast(m_lastSpawnedProjectile.FindComponent(RplComponent));
195 Rpc(RpcLaunchMissile_BC, rplComp.Id(),
direction);
197 LaunchMissile(m_lastSpawnedProjectile,
direction);
201 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
202 void RpcLaunchMissile_BC(RplId
id, vector
direction)
204 RplComponent rocketRplComp = RplComponent.Cast(Replication.FindItem(
id));
206 LaunchMissile(rocketRplComp.GetEntity(),
direction);
210 void LaunchMissile(IEntity rocket, vector
direction)
220 moveComp.Launch(
direction, vector.Zero, 1, rocket,
null,
null,
null,
null);
224 protected void AddRandomDelayToNextProjectile()
226 if(m_RandomDelayBetweenRockets[0] >= m_RandomDelayBetweenRockets[1])
229 float delay =
m_RandomGenerator.RandFloatXY(m_RandomDelayBetweenRockets[0], m_RandomDelayBetweenRockets[1]);
231 m_TimeUntilNextProjectile += delay;