1 [
EntityEditorProps(
category:
"GameScripted/FiringRange", description:
"Handeles behaviour of target. Evaluates a hit.", color:
"0 0 255 255")]
23 protected int m_iDesiredState;
26 [
Attribute(
"3", UIWidgets.Slider,
"Target in stays in folded position for... seconds",
"1 100 3")]
27 protected float m_fTimeInFoldedPosition;
30 [
Attribute(
"1", UIWidgets.Slider,
"How far is the target from shooting line.",
"1 9999 50")]
31 protected int m_iTargetDistance;
34 [
Attribute(
"3", UIWidgets.Slider,
"Target stays in erected position for... seconds",
"0.5 10 0.5")]
35 protected float m_fTimeInErectedPosition;
38 [
Attribute( defvalue:
"0", uiwidget: UIWidgets.CheckBox,
desc:
"Set if the target has to be used as hit indicator." )]
39 protected bool m_bIsIndicator;
42 [
Attribute( defvalue:
"1", uiwidget: UIWidgets.CheckBox,
desc:
"Set if the target should be reset to erected position." ),
RplProp()]
43 private bool m_bAutoResetTarget;
47 protected bool m_bWaitInPosition =
false;
50 private SignalsManagerComponent m_SignalManager;
51 private int m_iTargetHitSignal;
58 private ProcAnimComponent m_ProcAnimComponent;
61 private RplComponent m_RplComponent;
64 protected float m_fFallenTargetTimer;
67 protected bool m_bTargetHit =
false;
70 private IEntity m_OwnerEntity =
null;
73 private int m_iTargetOwner = -1;
76 private int m_iTargetMode = -1;
79 private int m_iHitValue;
82 private int m_iTargetState;
84 private IEntity m_FiringLineController;
86 ref ScriptInvoker Event_TargetChangeState =
new ScriptInvoker;
89 const float SCORE_CENTER = 10;
90 const float SCORE_CIRCLE_1 = 5;
91 const float SCORE_CIRCLE_2 = 3;
92 const float SCORE_CIRCLE_3 = 1;
96 const float AREA_10_W_LEFT = 0.03;
97 const float AREA_10_W_RIGHT = -0.03;
98 const float AREA_10_H_UP = 1.15;
99 const float AREA_10_H_DOWN = 1.03;
102 const float AREA_5_W_LEFT = 0.08;
103 const float AREA_5_W_RIGHT = -0.08;
104 const float AREA_5_H_UP = 1.2;
105 const float AREA_5_H_DOWN = 0.98;
108 const float AREA_3_W_LEFT = 0.13;
109 const float AREA_3_W_RIGHT = -0.13;
110 const float AREA_3_H_UP = 1.32;
111 const float AREA_3_H_DOWN = 0.84;
114 const float AREA_1_W_LEFT = 0.28;
115 const float AREA_1_W_RIGHT = -0.28;
116 const float AREA_1_H_UP = 1.77;
117 const float AREA_1_H_DOWN = 0.5;
119 const float AREA_BOTTOM_VALID = 0.40;
122 override void OnDamage(
float damage,
125 inout vector outMat[3],
126 IEntity damageSource,
136 if (!IsHitValid(CoordToLocal(outMat[0])))
139 super.OnDamage(damage,
type,pHitEntity,outMat,damageSource,instigator,colliderID,speed);
153 SetEventMask(EntityEvent.FRAME);
157 int playerID = instigator.GetInstigatorPlayerID();
160 if (m_iTargetOwner == playerID || m_iTargetMode ==
ETargetMode.TRAINING)
163 if (!m_FiringRangeManager)
166 if (GetValidityOfHit(CoordToLocal(outMat[0])))
167 m_FiringRangeManager.AddIndicator(CoordToLocal(outMat[0]),VectorToLocal(outMat[2] * -0.1), pHitEntity);
171 if (m_iTargetOwner == playerID && m_iTargetMode ==
ETargetMode.COMPETITION)
173 GetHitValue(CoordToLocal(outMat[0]),playerID);
179 void SetState(
int state)
181 Rpc(SetStateMP, state);
183 Replication.BumpMe();
186 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
187 void SetStateMP(
int state)
189 m_iDesiredState = state;
190 Event_TargetChangeState.Invoke(state,
this);
194 m_fFallenTargetTimer = 0;
196 m_bWaitInPosition =
true;
201 if (soundManagerEntity)
203 soundManagerEntity.CreateAndPlayAudioSource(
this,
SCR_SoundEvent.SOUND_TARGET_DOWN);
206 if (m_LineController)
207 m_LineController.CountPopUpTargets();
208 Replication.BumpMe();
212 m_fFallenTargetTimer = 0;
213 m_bTargetHit =
false;
214 m_bWaitInPosition =
false;
219 if (soundManagerEntity)
221 soundManagerEntity.CreateAndPlayAudioSource(
this,
SCR_SoundEvent.SOUND_TARGET_UP);
223 Replication.BumpMe();
245 return m_iTargetDistance;
252 return m_iTargetOwner;
257 void SetTargetOwner(
int playerID)
259 m_iTargetOwner = playerID;
264 void SetTargetMode(
int targetMode)
266 m_iTargetMode = targetMode;
271 int GetErectedDuration()
274 return m_fTimeInErectedPosition * 1000;
279 bool GetValidityOfHit(vector coordOfHit)
281 float HitY = coordOfHit[1];
282 if (HitY > AREA_1_H_DOWN)
290 void SetAutoResetTarget(
bool state)
292 m_bAutoResetTarget = state;
297 bool IsHitValid(vector coordOfHit)
299 float HitX = coordOfHit[0];
300 float HitY = coordOfHit[1];
302 if (HitX < AREA_1_W_LEFT && HitX > AREA_1_W_RIGHT && HitY < AREA_1_H_UP && HitY > AREA_BOTTOM_VALID)
312 return m_bIsIndicator;
317 void GetHitValue(vector coordOfHit,
int playerID)
319 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerID);
320 if (!playerController)
323 float HitX = coordOfHit[0];
324 float HitY = coordOfHit[1];
326 if (HitX < AREA_10_W_LEFT && HitX > AREA_10_W_RIGHT && HitY < AREA_10_H_UP && HitY > AREA_10_H_DOWN)
327 m_iHitValue = SCORE_CENTER;
329 else if (HitX < AREA_5_W_LEFT && HitX > AREA_5_W_RIGHT && HitY < AREA_5_H_UP && HitY > AREA_5_H_DOWN)
330 m_iHitValue = SCORE_CIRCLE_1;
332 else if (HitX < AREA_3_W_LEFT && HitX > AREA_3_W_RIGHT && HitY < AREA_3_H_UP && HitY > AREA_3_H_DOWN)
333 m_iHitValue = SCORE_CIRCLE_2;
335 else if (HitX < AREA_1_W_LEFT && HitX > AREA_1_W_RIGHT && HitY < AREA_1_H_UP && HitY > AREA_1_H_DOWN)
336 m_iHitValue = SCORE_CIRCLE_3;
338 m_FiringRangeManager.CountPlayerScore(m_iTargetOwner, m_iHitValue);
342 override void EOnFrame(IEntity owner,
float timeSlice)
345 if (m_bWaitInPosition && m_bAutoResetTarget)
347 if (m_fFallenTargetTimer < m_fTimeInFoldedPosition)
349 m_fFallenTargetTimer+= timeSlice;
356 ClearEventMask(EntityEvent.FRAME);
362 override bool RplSave(ScriptBitWriter writer)
365 m_iTargetState = GetState();
366 writer.Write(m_iTargetState, 1);
371 override bool RplLoad(ScriptBitReader reader)
374 if (!reader.Read(m_iTargetState, 1))
return false;
375 SetState(m_iTargetState);
380 override void EOnInit(IEntity owner)
382 m_SignalManager = SignalsManagerComponent.Cast(FindComponent(SignalsManagerComponent));
383 m_ProcAnimComponent = ProcAnimComponent.Cast(FindComponent(ProcAnimComponent));
397 if (!m_LineController)
401 m_LineController.SetIndicator(owner);
404 if (!m_FiringRangeManager)
407 m_RplComponent = RplComponent.Cast(m_FiringRangeManager.FindComponent(RplComponent));
413 SetEventMask(EntityEvent.INIT);
414 m_FiringLineController = parent;