playersoundeventbase.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. enum EPlayerSoundEventType
  2. {
  3. GENERAL = 0x00000001,
  4. MELEE = 0x00000002,
  5. STAMINA = 0x00000004,
  6. DAMAGE = 0x00000008,
  7. DUMMY = 0x00000010,
  8. INJURY = 0x00000020,
  9. DROWNING = 0x00000040,
  10. //HEAT_COMFORT = 0x00000080,
  11. }
  12. enum EPlayerSoundEventParam
  13. {
  14. SKIP_CONTROLLED_PLAYER = 0x00000001,
  15. HIGHEST_PRIORITY = 0x00000002,
  16. /*
  17. STAMINA = 0x00000004,
  18. DAMAGE = 0x00000008,
  19. DUMMY = 0x00000010,
  20. INJURY = 0x00000020,
  21. HEAT_COMFORT = 0x00000040,
  22. */
  23. // ONLY COUNT BELLOW
  24. ENUM_COUNT,
  25. }
  26. class PlayerSoundEventBase extends SoundEventBase
  27. {
  28. PlayerBase m_Player;
  29. float m_DummySoundLength;
  30. float m_DummyStartTime;
  31. bool m_IsDummyType;
  32. bool m_ProcessPlaybackEvent;
  33. float m_PlayTime;
  34. ref HumanMovementState m_Hms = new HumanMovementState();
  35. EPlayerSoundEventType m_HasPriorityOverTypes;
  36. bool IsDummy()
  37. {
  38. return m_IsDummyType;
  39. }
  40. EPlayerSoundEventType GetPriorityOverTypes()
  41. {
  42. return m_HasPriorityOverTypes;
  43. }
  44. // !can this event play during hold breath
  45. bool HasHoldBreathException()
  46. {
  47. return false;
  48. }
  49. void PlayerSoundEventBase()
  50. {
  51. m_Type = EPlayerSoundEventType.GENERAL;
  52. }
  53. void ~PlayerSoundEventBase()
  54. {
  55. if(!m_SoundSetCallback)
  56. OnEnd();
  57. }
  58. int GetSoundVoiceAnimEventClassID()
  59. {
  60. return m_SoundVoiceAnimEventClassID;
  61. }
  62. bool HasPriorityOverCurrent(PlayerBase player, EPlayerSoundEventID other_state_id, EPlayerSoundEventType type_other)
  63. {
  64. return true;
  65. }
  66. bool IsFinished()
  67. {
  68. if(IsDummy())
  69. {
  70. return IsDummyFinished();
  71. }
  72. else
  73. {
  74. return !IsSoundCallbackExist();
  75. }
  76. }
  77. bool IsDummyFinished()
  78. {
  79. return GetGame().GetTime() > (m_DummyStartTime + m_DummySoundLength);
  80. }
  81. void OnTick(float delta_time)
  82. {
  83. if ( m_SoundSetCallback )
  84. {
  85. m_SoundSetCallback.SetPosition(m_Player.GetPosition());
  86. //---------- Playback event -------------
  87. if( delta_time > 0 && m_ProcessPlaybackEvent )//delta_time 0 is for remotes
  88. {
  89. m_PlayTime += delta_time;
  90. //this is not 100% precise as the playback position is not obtained from the sound system
  91. float playback01 = Math.Clamp(m_PlayTime / m_SoundSetCallback.GetLength(),0,1);
  92. SendEvent(playback01);
  93. //---------- Playback event -------------
  94. }
  95. }
  96. }
  97. bool CanPlay(PlayerBase player)
  98. {
  99. player.GetMovementState(m_Hms);
  100. if (player.IsHoldingBreath() && !HasHoldBreathException())
  101. {
  102. return false;
  103. }
  104. if (player.m_IsDrowning || (player.IsSwimming() && m_Hms.m_iMovement != 0))
  105. {
  106. return false;
  107. }
  108. return true;
  109. }
  110. void Init(PlayerBase player)
  111. {
  112. InitEx(player,0);
  113. }
  114. void InitEx(PlayerBase player, int param)
  115. {
  116. m_Player = player;
  117. m_Param = param;
  118. if (param & EPlayerSoundEventParam.HIGHEST_PRIORITY)
  119. {
  120. m_HasPriorityOverTypes = -1;
  121. }
  122. }
  123. void OnEnd()
  124. {
  125. if(m_ProcessPlaybackEvent)
  126. SendEvent(1);
  127. }
  128. void SendEvent(float time)
  129. {
  130. if(m_PlayTime < 0 || !m_SoundSetCallback)//negative m_PlayTime value indicates the event has already been sent for playback01 = 1
  131. return;
  132. m_Player.OnVoiceEventPlayback(this, m_SoundSetCallback, time);
  133. if(time >= 1)
  134. m_PlayTime = -float.MAX;
  135. }
  136. void OnInterupt()
  137. {
  138. }
  139. override void OnPlay(PlayerBase player)
  140. {
  141. super.OnPlay(player);
  142. //Print("start playing -------------------->" + m_Type);
  143. player.OnVoiceEvent(this);
  144. //m_Player.OnVoiceEventDuration(m_SoundSetCallback, 0);
  145. }
  146. override bool Play()
  147. {
  148. if(!super.Play())
  149. return false;
  150. if( !IsDummy() )
  151. {
  152. m_SoundSetCallback = m_Player.ProcessVoiceEvent("","", m_SoundVoiceAnimEventClassID);
  153. if(m_SoundSetCallback)
  154. {
  155. AbstractWaveEvents events = AbstractWaveEvents.Cast(m_SoundSetCallback.GetUserData());
  156. events.Event_OnSoundWaveEnded.Insert( OnEnd );
  157. events.Event_OnSoundWaveStopped.Insert( OnInterupt );
  158. return true;
  159. }
  160. else
  161. return false;
  162. }
  163. else
  164. {
  165. m_DummyStartTime = GetGame().GetTime();
  166. return true;
  167. }
  168. return false;
  169. }
  170. }