11 const static int NO_TARGET_OWNER = -1;
12 const static int RESET_COUNTER_TIME = 1500;
13 const static int POWER_LIGHT_DELAY = 1000;
14 const static int INDICATOR_MAX_VALUE = 9999;
17 const static int DIGIT_ZERO = 0;
18 const static int DIGIT_ONE = 315;
19 const static int DIGIT_TWO = 280;
20 const static int DIGIT_THREE = 245;
21 const static int DIGIT_FOUR = 210;
22 const static int DIGIT_FIVE = 175;
23 const static int DIGIT_SIX = 140;
24 const static int DIGIT_SEVEN = 105;
25 const static int DIGIT_EIGHT = 70;
26 const static int DIGIT_NINE = 35;
28 const static string LIGHT_POWER =
"light_001_power";
29 const static string LIGHT_SEQUENCE =
"light_002_sequence";
30 const static string LIGHT_MALFUNCTION =
"light_003_malfunction";
32 const static int LIGHT_EMISSIVITY_ON = 1;
33 const static int LIGHT_EMISSIVITY_OFF = 0;
35 const static bool LIGHT_ON =
true;
36 const static bool LIGHT_OFF =
false;
44 private bool m_bRoundLightState =
false;
45 private int m_iDistanceIndicatorValue;
46 private int m_iNumberOfTargetsIndicatorValue;
49 const static int ERROR_LIGHT_DURATION = 1000;
52 [
Attribute(
"4",
UIWidgets.Slider,
"For how long target stays in erected position in seconds.",
"1 100 1")]
56 [
Attribute(
"{F2E83D562703F861}Assets/Decals/Impact/DecalHitIndicator.emat",
UIWidgets.ResourceNamePicker,
"Material used for target hit indicator",
"emat")]
69 private int m_iTargetsInRound;
72 private int m_iCountShots = 0;
75 private int m_iTargetSetDistance;
79 private int m_iFiringLineOwner = NO_TARGET_OWNER;
84 private int m_iElementInArray = 0;
85 private int m_iValuePos;
86 private int m_iHighestPossibleDistance;
88 private static ref array<SCR_FiringRangeController> s_aInstances = {};
89 private ref array<SCR_FiringRangeTarget> m_aAllTargetsArray = {};
90 private ref array<int> m_aDistances = {};
91 private ref array<Decal> m_aIndicators = {};
94 private ref array<vector> m_aIndicatorsCoords = {};
95 private ref array<vector> m_aIndicatorsVector = {};
98 private float m_fTargetErectedDuration;
104 private RplComponent m_RplComponent;
105 private SignalsManagerComponent m_SignalManager;
107 private SCR_FiringRangeManager m_FiringRangeManager;
110 override void EOnInit(
IEntity owner)
112 m_SignalManager = SignalsManagerComponent.Cast(owner.
FindComponent(SignalsManagerComponent));
114 array<EntitySlotInfo> slots = {}; EntitySlotInfo.GetSlotInfos(owner, slots);
118 foreach (EntitySlotInfo slot: slots)
123 IEntity ent = slot.GetAttachedEntity();
127 slotBone = slot.GetBoneName();
128 if (!slotBone.IsEmpty())
132 case LIGHT_POWER: {m_LightPower = ParametricMaterialInstanceComponent.Cast(ent.
FindComponent(ParametricMaterialInstanceComponent));
break;};
133 case LIGHT_SEQUENCE: {m_LightSequence = ParametricMaterialInstanceComponent.Cast(ent.
FindComponent(ParametricMaterialInstanceComponent));
break;};
134 case LIGHT_MALFUNCTION: {m_LightMalfunction = ParametricMaterialInstanceComponent.Cast(ent.
FindComponent(ParametricMaterialInstanceComponent));
break;};
140 CollectAllDistances(owner);
147 void AnimateTargets(
IEntity pOwnerEntity,
int playerID)
158 SCR_SoundManagerModule.CreateAndPlayAudioSource(pOwnerEntity, SCR_SoundEvent.SOUND_RANGECP_STARTBUTTON);
162 array<SCR_FiringRangeTarget> targetArray =
new array<SCR_FiringRangeTarget>();
165 m_iFiringLineOwner = playerID;
166 Replication.BumpMe();
170 SCR_FiringRangeTarget target = SCR_FiringRangeTarget.Cast(child);
173 if (!target.IsIndicator())
176 m_aAllTargetsArray.Insert(target);
178 if ((target.GetSetDistance() == m_iTargetSetDistance) || m_iTargetSetDistance == -1)
180 targetArray.Insert(target);
185 target.SetAutoResetTarget(
false);
188 target.SetTargetOwner(playerID);
197 SCR_SoundManagerModule.CreateAndPlayAudioSource(pOwnerEntity, SCR_SoundEvent.SOUND_RANGECP_ROUNDSTART);
199 GetGame().GetCallqueue().CallLater(ResetCountPopUpTargets, RESET_COUNTER_TIME,
false);
202 if (m_FiringRangeManager)
208 void ErectRandomTarget(array<SCR_FiringRangeTarget> targetArray)
211 if (m_iCountShots >= m_iTargetsInRound)
213 BackToDefaultTarget();
217 m_LastSelectedTarget = m_CurrentSelectedTarget;
218 while (m_LastSelectedTarget == m_CurrentSelectedTarget && targetArray.Count() > 1)
220 m_CurrentSelectedTarget = targetArray.GetRandomElement();
223 if (m_CurrentSelectedTarget)
225 m_fTargetErectedDuration = m_CurrentSelectedTarget.GetErectedDuration();
226 m_CurrentSelectedTarget.SetState(
ETargetState.TARGET_UP);
227 GetGame().GetCallqueue().CallLater(FoldTarget, m_fTargetErectedDuration,
false, m_CurrentSelectedTarget);
233 void FoldTarget(SCR_FiringRangeTarget selectedTarget)
235 if (m_fTargetErectedDuration == 0)
240 float TargetState = selectedTarget.GetState();
241 if (TargetState == 0)
248 void BackToDefaultTarget()
257 m_iFiringLineOwner = NO_TARGET_OWNER;
258 Replication.BumpMe();
260 GetGame().GetCallqueue().Remove(ErectRandomTarget);
262 foreach (SCR_FiringRangeTarget target : m_aAllTargetsArray)
268 target.SetAutoResetTarget(
true);
270 target.SetTargetOwner(NO_TARGET_OWNER);
273 m_aAllTargetsArray.Clear();
274 if (m_FiringRangeManager)
279 void SetIndicator(
IEntity indicator)
281 m_Indicator = indicator;
286 void BackToDefaultTargetsFromLineArea()
289 m_fTargetErectedDuration = 0;
292 PlayerController playerController =
GetGame().GetPlayerController();
293 if (!playerController)
297 SCR_FiringRangeNetworkEntity firingRangeNetworkEntity = SCR_FiringRangeNetworkEntity.GetInstance();
298 if (!firingRangeNetworkEntity)
302 if (m_FiringRangeManager)
304 m_FiringRangeManager.ControllerLight(
this,
ControllerLightType.LIGHT_MALFUNCTION, LIGHT_ON);
306 GetGame().GetCallqueue().CallLater(m_FiringRangeManager.ControllerLight, ERROR_LIGHT_DURATION,
false,
this,
ControllerLightType.LIGHT_MALFUNCTION, LIGHT_OFF);
310 SCR_SoundManagerModule.CreateAndPlayAudioSource(
this, SCR_SoundEvent.SOUND_RANGECP_ROUNDABORT);
315 void CollectAllDistances(
IEntity owner)
320 SCR_FiringRangeTarget target = SCR_FiringRangeTarget.Cast(child);
321 if (target && !target.IsIndicator())
323 int distance = target.GetSetDistance();
324 if (m_aDistances.Find(
distance) == -1)
331 if (m_aDistances.IsEmpty())
335 m_iTargetSetDistance = m_aDistances[0];
342 Replication.BumpMe();
347 array<int> GetAllDistances()
354 int GetFiringLineOwnerId()
356 return m_iFiringLineOwner;
360 bool IsLowestDistanceSet()
366 bool IsHighestDistanceSet()
373 int CalculateTargetDistance(
bool increase)
382 int currentDistance = m_iTargetSetDistance;
385 if (m_iTargetSetDistance == -1)
387 m_iTargetSetDistance = 0;
388 Replication.BumpMe();
392 m_iHighestPossibleDistance = m_aDistances.Count()-1;
394 m_iValuePos = m_aDistances.Find(m_iTargetSetDistance);
403 m_iTargetSetDistance = m_aDistances[m_iValuePos];
404 Replication.BumpMe();
408 if (m_SignalManager && m_FiringRangeManager)
409 m_FiringRangeManager.SetControllerCounter(
this,
EControlerSection.DISTANCE, m_iTargetSetDistance);
412 SCR_SoundManagerModule.CreateAndPlayAudioSource(
this, SCR_SoundEvent.SOUND_RANGECP_CHANGEDISTANCE);
414 return m_iTargetSetDistance;
419 void UpdateNumberOfTargets(
bool increase)
432 m_FiringRangeManager.SetControllerCounter(
this,
EControlerSection.NUMBER_OF_TARGETS, m_iTargetsInRound);
435 SCR_SoundManagerModule.CreateAndPlayAudioSource(
this, SCR_SoundEvent.SOUND_RANGECP_CHANGETARGET);
445 int digitHundredIndex;
446 int digitThousandIndex;
453 digitOneIndex = m_SignalManager.FindSignal(
"DistanceOne");
454 digitTenIndex = m_SignalManager.FindSignal(
"DistanceTen");
455 digitHundredIndex = m_SignalManager.FindSignal(
"DistanceHundred");
456 digitThousandIndex = m_SignalManager.FindSignal(
"DistanceThousand");
457 m_iDistanceIndicatorValue = value;
462 digitOneIndex = m_SignalManager.FindSignal(
"RoundOne");
463 digitTenIndex = m_SignalManager.FindSignal(
"RoundTen");
464 digitHundredIndex = m_SignalManager.FindSignal(
"RoundHundred");
465 digitThousandIndex = m_SignalManager.FindSignal(
"RoundThousand");
466 m_iNumberOfTargetsIndicatorValue = value;
472 array<int> digits = {0,0,0,0};
483 for (
int y = digits.Count() - 1; y >= 0; y--)
485 float signalVal = GetSignalValue(digits[y]);
488 case EDigit.DIGIT_ONE: {m_SignalManager.SetSignalValue(digitOneIndex,signalVal);
break;};
489 case EDigit.DIGIT_TEN: {m_SignalManager.SetSignalValue(digitTenIndex,signalVal);
break;};
490 case EDigit.DIGIT_HUNDRED: {m_SignalManager.SetSignalValue(digitHundredIndex,signalVal);
break;};
491 case EDigit.DIGIT_THOUSAND: {m_SignalManager.SetSignalValue(digitThousandIndex,signalVal);
break;};
498 float GetSignalValue(
int num)
502 case 0: {
return DIGIT_ZERO;
break;};
503 case 1: {
return DIGIT_ONE;
break;};
504 case 2: {
return DIGIT_TWO;
break;};
505 case 3: {
return DIGIT_THREE;
break;};
506 case 4: {
return DIGIT_FOUR;
break;};
507 case 5: {
return DIGIT_FIVE;
break;};
508 case 6: {
return DIGIT_SIX;
break;};
509 case 7: {
return DIGIT_SEVEN;
break;};
510 case 8: {
return DIGIT_EIGHT;
break;};
511 case 9: {
return DIGIT_NINE;
break;};
518 void CountPopUpTargets()
521 Replication.BumpMe();
526 void ResetCountPopUpTargets()
529 Replication.BumpMe();
534 void AddIndicator(vector localCoordOfHit, vector localVectorOfHit)
541 Decal decal = world.CreateDecal(
543 m_Indicator.CoordToParent(localCoordOfHit),
544 m_Indicator.VectorToParent(localVectorOfHit),
558 m_aIndicators.Insert(decal);
559 Replication.BumpMe();
561 m_aIndicatorsCoords.Insert(localCoordOfHit);
562 m_aIndicatorsVector.Insert(localVectorOfHit);
574 void RemoveIndicators()
577 while (m_aIndicators.Count() > 0)
579 Decal decal = m_aIndicators.Get(0);
582 world.RemoveDecal(decal);
583 m_aIndicators.Remove(0);
587 m_aIndicatorsVector.Clear();
588 m_aIndicatorsCoords.Clear();
594 return m_iTargetSetDistance;
598 int GetTargetsInRound()
600 return m_iTargetsInRound;
604 float GetMaxScoreInRound()
606 return m_iTargetsInRound * SCR_FiringRangeTarget.SCORE_CENTER;
614 Print(
"Master-only method (SCR_FiringRangeController." + methodName +
") called on proxy. Some functionality might be broekn!",
LogLevel.WARNING);
639 light.SetEmissiveMultiplier(LIGHT_EMISSIVITY_ON);
643 light.SetEmissiveMultiplier(LIGHT_EMISSIVITY_OFF);
652 m_RplComponent = RplComponent.Cast(
FindComponent(RplComponent));
654 return (m_RplComponent && m_RplComponent.IsProxy());
661 writer.WriteIntRange(m_iDistanceIndicatorValue, 0, INDICATOR_MAX_VALUE);
662 writer.WriteIntRange(m_iNumberOfTargetsIndicatorValue, 0, INDICATOR_MAX_VALUE);
665 writer.WriteBool(m_bRoundLightState);
668 int count = m_aIndicatorsCoords.Count();
669 writer.WriteInt(count);
671 for (
int i = 0; i < count; i++)
673 writer.WriteVector(m_aIndicatorsCoords[i]);
674 writer.WriteVector(m_aIndicatorsVector[i]);
684 reader.ReadIntRange(m_iDistanceIndicatorValue, 0, INDICATOR_MAX_VALUE);
685 reader.ReadIntRange(m_iNumberOfTargetsIndicatorValue, 0, INDICATOR_MAX_VALUE);
688 reader.ReadBool(m_bRoundLightState);
692 reader.ReadInt(count);
694 for (
int i = 0; i < count; i++)
706 SetControllerCounter(
EControlerSection.NUMBER_OF_TARGETS ,m_iNumberOfTargetsIndicatorValue);
717 s_aInstances.Insert(
this);
721 if (m_FiringRangeManager)
722 m_FiringRangeManager.RegisterFiringRangeController(
this);
729 s_aInstances.RemoveItem(
this);