playersoundeventhandler.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // defined in animEventsSoundVoice.hpp
  2. enum EPlayerSoundEventID
  3. {
  4. HOLD_BREATH = 1,
  5. EXHAUSTED_BREATH,
  6. RELEASE_BREATH,
  7. STAMINA_DOWN_LIGHT,
  8. STAMINA_DOWN_HEAVY,
  9. STAMINA_UP_LIGHT,
  10. STAMINA_UP_HEAVY,
  11. STAMINA_UP_END,
  12. STAMINA_NORMAL_DUMMY,
  13. TAKING_DMG_LIGHT,
  14. TAKING_DMG_HEAVY,
  15. SYMPTOM_COUGH,
  16. SYMPTOM_LAUGHTER,
  17. SYMPTOM_SNEEZE,
  18. SYMPTOM_GASP,
  19. JUMP,
  20. MELEE_ATTACK_LIGHT,
  21. MELEE_ATTACK_HEAVY
  22. INJURED_LIGHT,
  23. INJURED_MEDIUM,
  24. INJURED_HIGH,
  25. FREEZING,
  26. RATTLING_TEETH,
  27. HOT,
  28. SYMPTOM_FATIGUE,
  29. STAMINA_LOW_FILTER_UPPER,
  30. STAMINA_LOW_FILTER_MID,
  31. STAMINA_LOW_FILTER_LOWER,
  32. DROWNING_BREATH,
  33. DROWNING_PAIN,
  34. PICKUP_HEAVY,
  35. THIRST,
  36. FORCE_FEED,
  37. FORCE_DRINK,
  38. //--------------
  39. // Count bellow, put enums above
  40. //--------------
  41. ENUM_COUNT,
  42. }
  43. class PlayerSoundEventHandler extends SoundEventHandler
  44. {
  45. PlayerBase m_Player;
  46. const int SOUND_EVENTS_MAX = EPlayerSoundEventID.ENUM_COUNT;
  47. static ref PlayerSoundEventBase m_AvailableStates[SOUND_EVENTS_MAX];
  48. static ref map<int,int> m_ConfigIDToScriptIDmapping = new ref map<int,int> ;
  49. ref PlayerSoundEventBase m_CurrentState;
  50. ref Timer m_UpdateTimer;
  51. void PlayerSoundEventHandler(PlayerBase player)
  52. {
  53. m_Player = player;
  54. if(!m_UpdateTimer && !m_Player.IsControlledPlayer())
  55. {
  56. m_UpdateTimer = new Timer();
  57. m_UpdateTimer.Run(1, this, "OnTick", null, true);//ticking for remotes, the controlled player is ticking on command handler at higher intervals
  58. }
  59. RegisterState(new HoldBreathSoundEvent());
  60. RegisterState(new ExhaustedBreathSoundEvent());
  61. RegisterState(new FatigueSoundEvent());
  62. RegisterState(new ReleaseBreathSoundEvent());
  63. RegisterState(new StaminaDownLight());
  64. RegisterState(new StaminaDownHeavy());
  65. RegisterState(new StaminaUpLight());
  66. RegisterState(new StaminaUpHeavy());
  67. RegisterState(new StaminaUpEnd());
  68. RegisterState(new DamageLightSoundEvent());
  69. RegisterState(new DamageHeavySoundEvent());
  70. RegisterState(new SneezeSoundEvent());
  71. RegisterState(new LaugherSoundEvent());
  72. RegisterState(new CoughSoundEvent());
  73. RegisterState(new GaspSoundEvent());
  74. RegisterState(new JumpSoundEvent());
  75. RegisterState(new MeleeAttackLightEvent());
  76. RegisterState(new MeleeAttackHeavyEvent());
  77. RegisterState(new StaminaNormalDummy());
  78. RegisterState(new InjuryLightSoundEvent());
  79. RegisterState(new InjuryMediumSoundEvent());
  80. RegisterState(new InjuryHeavySoundEvent());
  81. RegisterState(new FreezingSoundEvent());
  82. RegisterState(new RattlingTeethSoundEvent());
  83. RegisterState(new HotSoundEvent());
  84. RegisterState(new StaminaLowFilterUpper());
  85. RegisterState(new StaminaLowFilterMid());
  86. RegisterState(new StaminaLowFilterLower());
  87. RegisterState(new DrowningEvent1());
  88. RegisterState(new DrowningEvent2());
  89. RegisterState(new PickupHeavySoundEvent());
  90. RegisterState(new ThirstSoundEvent());
  91. RegisterState(new ForceFeedSoundEvent());
  92. RegisterState(new ForceDrinkSoundEvent());
  93. }
  94. void RegisterState(PlayerSoundEventBase state)
  95. {
  96. int index = state.GetSoundEventID();
  97. m_AvailableStates[index] = state;
  98. m_ConfigIDToScriptIDmapping.Insert(state.GetSoundVoiceAnimEventClassID(),index);
  99. }
  100. void OnTick(float delta_time)
  101. {
  102. if (m_CurrentState)
  103. {
  104. if( m_CurrentState.IsFinished())
  105. m_CurrentState = null;
  106. else
  107. m_CurrentState.OnTick(delta_time);
  108. }
  109. }
  110. int ConvertAnimIDtoEventID(int anim_id)
  111. {
  112. return m_ConfigIDToScriptIDmapping.Get(anim_id);
  113. }
  114. override static EPlayerSoundEventType GetSoundEventType(int id)
  115. {
  116. return m_AvailableStates[id].GetSoundEventType();
  117. }
  118. override int GetCurrentStateEventID()
  119. {
  120. if(m_CurrentState)
  121. {
  122. return m_CurrentState.GetSoundEventID();
  123. }
  124. return -1;
  125. }
  126. override int GetCurrentStateEventType()
  127. {
  128. if(m_CurrentState)
  129. {
  130. return m_CurrentState.GetSoundEventType();
  131. }
  132. return -1;
  133. }
  134. override bool PlayRequestEx(EPlayerSoundEventID id, bool sent_from_server = false, int param = 0)
  135. {
  136. if (id < 0 || id > (SOUND_EVENTS_MAX - 1))
  137. {
  138. Error("EPlayerSoundEventID out of bounds");
  139. }
  140. PlayerSoundEventBase requested_state = m_AvailableStates[id];
  141. if ( sent_from_server && (param & EPlayerSoundEventParam.SKIP_CONTROLLED_PLAYER) && m_Player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT )
  142. {
  143. return false;
  144. }
  145. if ( !requested_state.CanPlay(m_Player) )
  146. {
  147. return false;
  148. }
  149. if (m_CurrentState)
  150. {
  151. if (param & EPlayerSoundEventParam.HIGHEST_PRIORITY)
  152. {
  153. m_CurrentState.Stop();
  154. }
  155. else
  156. {
  157. int current_type = m_CurrentState.GetSoundEventType();
  158. //int requested_type = requested_state.GetSoundEventType();
  159. if ( (requested_state.GetPriorityOverTypes() & current_type) == 0 )
  160. {
  161. return false;
  162. }
  163. if (!requested_state.HasPriorityOverCurrent(m_Player, id, current_type) )
  164. {
  165. return false;
  166. }
  167. m_CurrentState.Stop();
  168. }
  169. }
  170. m_CurrentState = PlayerSoundEventBase.Cast(requested_state.ClassName().ToType().Spawn());
  171. m_CurrentState.InitEx(m_Player, param);
  172. if (m_CurrentState.Play())
  173. {
  174. m_CurrentState.OnPlay(m_Player);
  175. }
  176. return true;
  177. }
  178. override bool PlayRequest(EPlayerSoundEventID id, bool sent_from_server = false)
  179. {
  180. return PlayRequestEx(id, sent_from_server);
  181. }
  182. }