bleedingsource.c 4.6 KB

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