Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BleedingScreenEffect .c
Go to the documentation of this file.
2 {
3  // Play Animation of CreateEffectOverTime()
4  protected const int BLEEDING_REPEAT_DELAY = 2500;
5  protected const float BLEEDINGEFFECT_OPACITY_FADEOUT_1_DURATION = 0.2;
6  protected const float BLEEDINGEFFECT_PROGRESSION_FADEOUT_1_DURATION = 0.2;
7  protected const float BLEEDINGEFFECT_OPACITY_FADEOUT_2_DURATION = 0.3;
8  protected const float BLEEDINGEFFECT_PROGRESSION_FADEOUT_2_DURATION = 3;
9  protected const float BLEEDINGEFFECT_OPACITY_FADEIN_1_DURATION = 1;
10  protected const float BLEEDINGEFFECT_PROGRESSION_FADEIN_1_DURATION = 4.5;
11 
12  // Play Animation of BlackoutEffect()
13  protected const float BLACKOUT_OPACITY_MULTIPLIER = 0.20;
14 
15  //Saturation
16  private static float s_fSaturation;
17 
18  // Widgets
19  protected ImageWidget m_wBloodEffect1;
20  protected ImageWidget m_wBloodEffect2;
21  protected ImageWidget m_wBlackOut;
22  private int m_iEffectNo = 1;
23 
24  // Character
25  protected SCR_CharacterDamageManagerComponent m_pDamageManager;
26  protected SCR_CharacterBloodHitZone m_pBloodHZ;
27  protected ChimeraCharacter m_pCharacterEntity;
28 
29  protected bool m_bBleedingEffect;
30  protected bool m_bIsBleeding;
31  protected bool m_bPlayHeartBeat;
32 
33 
34  //------------------------------------------------------------------------------------------------
35  override void DisplayStartDraw(IEntity owner)
36  {
37  m_wBloodEffect1 = ImageWidget.Cast(m_wRoot.FindAnyWidget("BloodVignette1"));
38  m_wBloodEffect2 = ImageWidget.Cast(m_wRoot.FindAnyWidget("BloodVignette2"));
39  m_wBlackOut = ImageWidget.Cast(m_wRoot.FindAnyWidget("BlackOut"));
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  override void DisplayControlledEntityChanged(IEntity from, IEntity to)
44  {
45  ClearEffects();
46 
47  m_pCharacterEntity = ChimeraCharacter.Cast(to);
48  if (!m_pCharacterEntity)
49  return;
50 
51  m_pDamageManager = SCR_CharacterDamageManagerComponent.Cast(m_pCharacterEntity.GetDamageManager());
52  if (!m_pDamageManager)
53  return;
54 
55  // define hitzones for later getting
56  m_pBloodHZ = SCR_CharacterBloodHitZone.Cast(m_pDamageManager.GetBloodHitZone());
57 
58  // Invoker for momentary damage events and DOT damage events
59  m_pDamageManager.GetOnDamageOverTimeAdded().Insert(OnDamageOverTimeAdded);
60  m_pDamageManager.GetOnDamageOverTimeRemoved().Insert(OnDamageOverTimeRemoved);
61 
62  // In case player started bleeding before invokers were established, check if already bleeding
63  if (m_pDamageManager.IsDamagedOverTime(EDamageType.BLEEDING))
64  OnDamageOverTimeAdded(EDamageType.BLEEDING, m_pDamageManager.GetDamageOverTime(EDamageType.BLEEDING));
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  void OnDamageOverTimeAdded(EDamageType dType, float dps, HitZone hz = null)
69  {
70  m_bIsBleeding = m_pDamageManager.IsDamagedOverTime(EDamageType.BLEEDING);
71  if (!m_bBleedingEffect && m_bIsBleeding && m_pDamageManager.GetState() != EDamageState.DESTROYED)
72  CreateEffectOverTime(true);
73 
74  m_bBleedingEffect = m_bIsBleeding;
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  void OnDamageOverTimeRemoved(EDamageType dType, HitZone hz = null)
79  {
80  m_bIsBleeding = m_pDamageManager.IsDamagedOverTime(EDamageType.BLEEDING);
81  if (m_bIsBleeding)
82  return;
83 
84  ClearEffectOverTime(false);
85  GetGame().GetCallqueue().Remove(CreateEffectOverTime);
86  GetGame().GetCallqueue().Remove(ClearEffectOverTime);
87 
88  m_bBleedingEffect = false;
89  }
90 
91  //------------------------------------------------------------------------------------------------
92  protected override void DisplayOnSuspended()
93  {
94  m_bPlayHeartBeat = false;
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  protected override void DisplayOnResumed()
99  {
100  m_bPlayHeartBeat = true;
101  }
102 
103  //------------------------------------------------------------------------------------------------
104  void CreateEffectOverTime(bool repeat)
105  {
106  if (!m_wBloodEffect1 || !m_wBloodEffect2 || !m_pBloodHZ)
107  return;
108 
109  float effectStrength = 1;
110  const float REDUCEDSTRENGTH = 0.7;
111  bool playHeartBeat = m_bPlayHeartBeat;
112 
113  if (m_pBloodHZ.GetDamageOverTime(EDamageType.BLEEDING) < 5)
114  {
115  effectStrength *= REDUCEDSTRENGTH;
116  playHeartBeat = false;
117  }
118 
119  m_wBloodEffect1.SetSaturation(1);
120  m_wBloodEffect2.SetSaturation(1);
121 
122  if (m_iEffectNo == 1)
123  {
124  AnimateWidget.Opacity(m_wBloodEffect1, effectStrength, BLEEDINGEFFECT_OPACITY_FADEIN_1_DURATION);
125  AnimateWidget.AlphaMask(m_wBloodEffect1, effectStrength * 0.5, BLEEDINGEFFECT_PROGRESSION_FADEIN_1_DURATION);
126  AnimateWidget.Opacity(m_wBloodEffect2, 0, BLEEDINGEFFECT_OPACITY_FADEOUT_2_DURATION);
127  AnimateWidget.AlphaMask(m_wBloodEffect2, 0, BLEEDINGEFFECT_PROGRESSION_FADEOUT_2_DURATION);
128  }
129  else if (m_iEffectNo == 2)
130  {
131  AnimateWidget.Opacity(m_wBloodEffect1, 0, BLEEDINGEFFECT_OPACITY_FADEOUT_2_DURATION);
132  AnimateWidget.AlphaMask(m_wBloodEffect1, 0, BLEEDINGEFFECT_PROGRESSION_FADEOUT_2_DURATION);
133  AnimateWidget.Opacity(m_wBloodEffect2, effectStrength, BLEEDINGEFFECT_OPACITY_FADEIN_1_DURATION);
134  AnimateWidget.AlphaMask(m_wBloodEffect2, effectStrength * 0.5, BLEEDINGEFFECT_PROGRESSION_FADEIN_1_DURATION);
135  }
136 
137  BlackoutEffect(effectStrength);
138 
139  // Play heartbeat sound
140  if (playHeartBeat && m_pDamageManager.GetDefaultHitZone().GetDamageState() != EDamageState.DESTROYED)
141  {
142  SCR_UISoundEntity.SetSignalValueStr("BloodLoss", 1 - m_pBloodHZ.GetHealthScaled());
143  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_INJURED_PLAYERCHARACTER);
144  }
145 
146  GetGame().GetCallqueue().CallLater(ClearEffectOverTime, 1000, false, repeat, m_iEffectNo);
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  void ClearEffectOverTime(bool repeat)
151  {
152  if (m_iEffectNo == 1)
153  m_iEffectNo = 2;
154  else
155  m_iEffectNo = 1;
156 
157  AnimateWidget.Opacity(m_wBloodEffect1, 0, BLEEDINGEFFECT_PROGRESSION_FADEOUT_1_DURATION);
158  AnimateWidget.AlphaMask(m_wBloodEffect1, 0, BLEEDINGEFFECT_OPACITY_FADEOUT_1_DURATION);
159  AnimateWidget.Opacity(m_wBloodEffect2, 0, BLEEDINGEFFECT_PROGRESSION_FADEOUT_1_DURATION);
160  AnimateWidget.AlphaMask(m_wBloodEffect2, 0, BLEEDINGEFFECT_OPACITY_FADEOUT_1_DURATION);
161 
162  BlackoutEffect(0);
163 
164  if (repeat && m_bBleedingEffect)
165  GetGame().GetCallqueue().CallLater(CreateEffectOverTime, BLEEDING_REPEAT_DELAY, false, repeat);
166  }
167 
168  //------------------------------------------------------------------------------------------------
169  void BlackoutEffect(float effectStrength)
170  {
171  if (!m_wBlackOut)
172  return;
173 
174  if (effectStrength > 0)
175  {
176  m_wBlackOut.SetOpacity(1);
177  effectStrength *= BLACKOUT_OPACITY_MULTIPLIER;
178  AnimateWidget.AlphaMask(m_wBlackOut, effectStrength, BLEEDINGEFFECT_PROGRESSION_FADEIN_1_DURATION);
179  }
180  else
181  {
182  AnimateWidget.AlphaMask(m_wBlackOut, 0, BLEEDINGEFFECT_OPACITY_FADEOUT_1_DURATION);
183  }
184  }
185 
186  //------------------------------------------------------------------------------------------------
187  protected override void ClearEffects()
188  {
189  m_bBleedingEffect = 0;
190 
191  if (m_wBloodEffect1)
192  {
193  AnimateWidget.StopAllAnimations(m_wBloodEffect1);
194  m_wBloodEffect1.SetOpacity(0);
195  m_wBloodEffect1.SetMaskProgress(0);
196  }
197 
198  if (m_wBloodEffect2)
199  {
200  AnimateWidget.StopAllAnimations(m_wBloodEffect2);
201  m_wBloodEffect2.SetOpacity(0);
202  m_wBloodEffect2.SetMaskProgress(0);
203  }
204 
205  if (m_wBlackOut)
206  {
207  AnimateWidget.StopAllAnimations(m_wBlackOut);
208  m_wBlackOut.SetOpacity(0);
209  m_wBlackOut.SetMaskProgress(0);
210  }
211 
212  GetGame().GetCallqueue().Remove(CreateEffectOverTime);
213  GetGame().GetCallqueue().Remove(ClearEffectOverTime);
214 
215  if (!m_pDamageManager)
216  return;
217 
218  m_pDamageManager.GetOnDamageOverTimeAdded().Remove(OnDamageOverTimeAdded);
219  m_pDamageManager.GetOnDamageOverTimeRemoved().Remove(OnDamageOverTimeRemoved);
220  }
221 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_BaseScreenEffect
Definition: SCR_BaseScreenEffect.c:1
HitZone
Definition: HitZone.c:12
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
EDamageState
EDamageState
Definition: EDamageState.c:12
SCR_CharacterBloodHitZone
Blood - does not receive damage directly, only via scripted events.
Definition: SCR_CharacterHitZone.c:480
SCR_CharacterDamageManagerComponent
Definition: SCR_CharacterDamageManagerComponent.c:18
SCR_BleedingScreenEffect
Definition: SCR_BleedingScreenEffect .c:1
EDamageType
EDamageType
Definition: EDamageType.c:12