bleedingsource.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. enum eBleedingSourceType
  2. {
  3. NORMAL,
  4. CONTAMINATED,
  5. }
  6. class BleedingSource
  7. {
  8. vector m_Position;
  9. Particle m_BloodParticle;
  10. PlayerBase m_Player;
  11. int m_Bit;
  12. string m_Bone;
  13. ref EffectParticle m_BleedingEffect;
  14. vector m_Orientation;
  15. Shape m_DebugShape;
  16. Shape m_DebugShape1;
  17. ref Timer m_DebugTick;
  18. vector m_Offset;
  19. float m_FlowModifier;
  20. float m_ActiveTime;
  21. float m_MaxTime;
  22. string m_ParticleName;
  23. bool m_DeleteRequested;
  24. eBleedingSourceType m_Type = eBleedingSourceType.NORMAL;
  25. #ifdef DIAG_DEVELOPER
  26. float m_DiagTimeStart; //for debug purposes only
  27. #endif
  28. void BleedingSource(PlayerBase player, int bit, string bone, vector orientation, vector offset,int max_time, float flow_modifier, string particle_name)
  29. {
  30. //m_Position = position;
  31. m_Player = player;
  32. m_Bit = bit;
  33. m_Bone = bone;
  34. m_Orientation = orientation;
  35. m_Offset = offset;
  36. m_FlowModifier = flow_modifier;
  37. m_MaxTime = max_time;
  38. m_ParticleName = particle_name;
  39. //CreateBleedSymptom();
  40. if (!GetGame().IsDedicatedServer())
  41. {
  42. CreateParticle();
  43. StartSourceBleedingIndication();
  44. }
  45. }
  46. void ~BleedingSource()
  47. {
  48. if (m_BloodParticle)
  49. RemoveParticle();
  50. RemoveDebugShape();
  51. StopSourceBleedingIndication(!m_Player || !m_Player.IsAlive());
  52. }
  53. void SetType(eBleedingSourceType type)
  54. {
  55. m_Type = type;
  56. }
  57. eBleedingSourceType GetType()
  58. {
  59. return m_Type;
  60. }
  61. int GetActiveTime()
  62. {
  63. return m_ActiveTime;
  64. }
  65. void SetActiveTime(int time)
  66. {
  67. m_ActiveTime = time;
  68. }
  69. int GetBit()
  70. {
  71. return m_Bit;
  72. }
  73. void CreateParticle()
  74. {
  75. int boneIdx = m_Player.GetBoneIndexByName(m_Bone);
  76. m_BleedingEffect = EffectParticle.Cast(m_ParticleName.ToType().Spawn());
  77. if (m_BleedingEffect)
  78. {
  79. SEffectManager.PlayInWorld(m_BleedingEffect, "0 0 0");
  80. m_BloodParticle = m_BleedingEffect.GetParticle();
  81. m_BloodParticle.SetOrientation(m_Orientation);
  82. vector pos;
  83. pos += m_Offset;
  84. m_BloodParticle.SetPosition(pos);
  85. float time = Math.RandomFloat01() * 2;
  86. //time = time;
  87. m_BloodParticle.SetParameter(-1, EmitorParam.CURRENT_TIME, time);
  88. //m_BloodParticle.SetParameter(1, EmitorParam.CURRENT_TIME, time);
  89. m_Player.AddChild(m_BloodParticle, boneIdx);
  90. return;
  91. }
  92. else
  93. {
  94. Error("bleeding source: failed to spawn the particle: "+m_ParticleName);
  95. }
  96. }
  97. void RemoveParticle()
  98. {
  99. SEffectManager.DestroyEffect(m_BleedingEffect);
  100. }
  101. void OnUpdateServer(float deltatime, float blood_scale, bool no_blood_loss)
  102. {
  103. m_ActiveTime += deltatime;
  104. if (m_ActiveTime >= m_MaxTime)
  105. {
  106. if (m_Player.GetBleedingManagerServer() && !m_DeleteRequested)
  107. {
  108. m_Player.GetBleedingManagerServer().RequestDeletion(GetBit());//add yourself to a list of sources to be deleted
  109. m_DeleteRequested = true;
  110. }
  111. }
  112. if (!no_blood_loss)
  113. {
  114. float flow = m_FlowModifier;
  115. switch (m_Type)
  116. {
  117. case eBleedingSourceType.NORMAL:
  118. {
  119. //do nothing
  120. break;
  121. }
  122. case eBleedingSourceType.CONTAMINATED:
  123. {
  124. flow *= PlayerConstants.BLEEDING_SOURCE_BURN_MODIFIER;
  125. }
  126. }
  127. m_Player.AddHealth("GlobalHealth","Blood", (PlayerConstants.BLEEDING_SOURCE_BLOODLOSS_PER_SEC * blood_scale * deltatime * flow));
  128. }
  129. }
  130. void StartSourceBleedingIndication()
  131. {
  132. if (m_Player.IsControlledPlayer())
  133. {
  134. #ifdef DIAG_DEVELOPER
  135. if (DbgBleedingIndicationStaticInfo.m_DbgEnableBleedingIndication)
  136. {
  137. #endif
  138. Param4<bool,int,vector,bool> par = new Param4<bool,int,vector,bool>(true,m_Bit,"0 0 0",false);
  139. GetGame().GetMission().GetEffectWidgets().AddActiveEffects({EffectWidgetsTypes.BLEEDING_LAYER});
  140. GetGame().GetMission().GetEffectWidgets().UpdateWidgets(EffectWidgetsTypes.BLEEDING_LAYER,0,par);
  141. #ifdef DIAG_DEVELOPER
  142. }
  143. #endif
  144. }
  145. }
  146. void StopSourceBleedingIndication(bool instant = false)
  147. {
  148. if (m_Player && m_Player.IsControlledPlayer() && GetGame() && (!GetGame().IsDedicatedServer()))
  149. {
  150. Param4<bool,int,vector,bool> par = new Param4<bool,int,vector,bool>(false,m_Bit,"0 0 0",instant);
  151. GetGame().GetMission().GetEffectWidgets().UpdateWidgets(EffectWidgetsTypes.BLEEDING_LAYER,0,par);
  152. }
  153. }
  154. void DrawDebugShape()
  155. {
  156. RemoveDebugShape();
  157. Particle p = m_BleedingEffect.GetParticle();
  158. vector pos = p.GetPosition();
  159. m_DebugShape = Debug.DrawSphere(pos, 0.009, COLOR_BLUE, ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE|ShapeFlags.NOZBUFFER);
  160. vector arrow_to = m_BloodParticle.GetOrientation();
  161. arrow_to = arrow_to.AnglesToVector();
  162. arrow_to = -arrow_to * 0.3;
  163. arrow_to = pos + arrow_to;
  164. m_DebugShape1 = Debug.DrawArrow(pos, arrow_to, 0.1, COLOR_GREEN);
  165. }
  166. void RemoveDebugShape()
  167. {
  168. if (m_DebugShape)
  169. {
  170. Debug.RemoveShape(m_DebugShape);
  171. }
  172. if (m_DebugShape1)
  173. {
  174. Debug.RemoveShape(m_DebugShape1);
  175. }
  176. }
  177. }