bleedingsourcesmanagerremote.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. //this is instantiated on the client for both the controlled character, as well as the remote characters
  2. class BleedingSourcesManagerRemote extends BleedingSourcesManagerBase
  3. {
  4. int m_BleedingBits;
  5. bool m_ShowDiag;
  6. bool m_ShowingDiag;
  7. bool m_ShowingDiagDraw;
  8. Shape m_Point;
  9. bool m_EnableHitIndication = false;
  10. override protected void Init()
  11. {
  12. super.Init();
  13. if (GetGame().GetMission().GetEffectWidgets()/* && m_Player.IsControlledPlayer()*/)
  14. {
  15. Param3<bool,int,float> par = new Param3<bool,int,float>(true,0,0);
  16. GetGame().GetMission().GetEffectWidgets().RegisterGameplayEffectData(EffectWidgetsTypes.BLEEDING_LAYER,par);
  17. }
  18. }
  19. override protected void RegisterBleedingZoneEx(string name, int max_time, string bone = "", vector orientation = "0 0 0", vector offset = "0 0 0", float flow_modifier = 1, string particle_name = "BleedingSourceEffect", int inv_location = 0)
  20. {
  21. super.RegisterBleedingZoneEx(name,max_time,bone,orientation,offset,flow_modifier,particle_name,inv_location);
  22. if (GetGame().GetMission().GetEffectWidgets()/* && m_Player.IsControlledPlayer()*/)
  23. {
  24. Param3<bool,int,float> par = new Param3<bool,int,float>(false,m_Bit,flow_modifier);
  25. GetGame().GetMission().GetEffectWidgets().RegisterGameplayEffectData(EffectWidgetsTypes.BLEEDING_LAYER,par);
  26. }
  27. }
  28. void OnVariablesSynchronized(int current_bits)
  29. {
  30. if (current_bits != m_BleedingBits)
  31. {
  32. if (m_BleedingBits == 0)
  33. {
  34. m_Player.OnBleedingBegin();
  35. }
  36. OnBleedingBitsUpdate(m_BleedingBits, current_bits);
  37. m_BleedingBits = current_bits;
  38. if (m_BleedingBits == 0)
  39. {
  40. m_Player.OnBleedingEnd();
  41. }
  42. }
  43. }
  44. void Reload()
  45. {
  46. m_BleedingSourceZone.Clear();
  47. m_BitOffset = 0;
  48. Init();
  49. int bit_offset = 0;
  50. for (int i = 0; i < BIT_INT_SIZE; ++i)
  51. {
  52. int bit = 1 << bit_offset;
  53. bit_offset++;
  54. if ((bit & m_BleedingBits) != 0)
  55. {
  56. RemoveBleedingSource(bit);
  57. AddBleedingSource(bit);
  58. }
  59. }
  60. }
  61. override protected void AddBleedingSource(int bit)
  62. {
  63. super.AddBleedingSource(bit);
  64. #ifdef DIAG_DEVELOPER
  65. m_BleedingSources.Get(bit).m_DiagTimeStart = GetGame().GetTickTime();
  66. #endif
  67. if (GetGame().IsMultiplayer())
  68. m_Player.OnBleedingSourceAdded();
  69. }
  70. override protected bool RemoveBleedingSource(int bit)
  71. {
  72. if (super.RemoveBleedingSource(bit))
  73. {
  74. if (GetGame().IsMultiplayer())
  75. m_Player.OnBleedingSourceRemovedEx(m_Item);
  76. return true;
  77. }
  78. return false;
  79. }
  80. void OnBleedingBitsUpdate(int old_mask, int new_mask)
  81. {
  82. for (int i = 0; i < 32; ++i)
  83. {
  84. int compare_bit = 1 << i;
  85. int new_compare_result_bit = compare_bit & new_mask;
  86. int old_compare_result_bit = compare_bit & old_mask;
  87. if (new_compare_result_bit)
  88. {
  89. if (!(new_compare_result_bit & old_mask))
  90. {
  91. //a different active bit in the new mask
  92. AddBleedingSource(new_compare_result_bit);
  93. }
  94. }
  95. else
  96. {
  97. if (new_compare_result_bit != old_compare_result_bit)
  98. {
  99. RemoveBleedingSource(old_compare_result_bit);
  100. }
  101. }
  102. }
  103. }
  104. int GetBleedingSourceCountRemote()
  105. {
  106. int bleeding_source_count = 0;
  107. int pow = 0;
  108. for (int i = 0; i < BIT_INT_SIZE ; ++i)
  109. {
  110. int bit = Math.Pow(2, pow);
  111. pow++;
  112. if ((m_BleedingBits & bit) != 0)
  113. {
  114. bleeding_source_count++;
  115. }
  116. }
  117. return bleeding_source_count;
  118. }
  119. void SetDiag(bool value)
  120. {
  121. m_ShowDiag = value;
  122. }
  123. void OnUpdate()
  124. {
  125. #ifndef NO_GUI
  126. if (m_ShowDiag)
  127. {
  128. DisplayDebug();
  129. DisplayVisualDebug();
  130. }
  131. else if (m_ShowingDiag || m_ShowingDiagDraw)
  132. {
  133. if (m_ShowingDiag)
  134. CleanDebug();
  135. if (m_ShowingDiagDraw)
  136. CleanVisualDebug();
  137. }
  138. #endif
  139. }
  140. void DisplayDebug()
  141. {
  142. m_ShowingDiag = true;
  143. DbgUI.BeginCleanupScope();
  144. DbgUI.Begin("Bleeding Sources", 50, 50);
  145. int pow = 0;
  146. bool anyBleedingSourceActive = false;
  147. for (int i = 0; i < BIT_INT_SIZE ; ++i)
  148. {
  149. int bit = Math.Pow(2, pow);
  150. pow++;
  151. if ((m_BleedingBits & bit) != 0)
  152. {
  153. BleedingSourceZone bsz = GetBleedingSourceMeta(bit);
  154. string name = GetSelectionNameFromBit(bit);
  155. string slot_name = InventorySlots.GetSlotName(bsz.GetInvLocation());
  156. float timeRemaining = -1;
  157. #ifdef DIAG_DEVELOPER
  158. BleedingSource bsi = m_BleedingSources.Get(bit);
  159. timeRemaining = bsz.GetMaxTime() + bsi.m_DiagTimeStart - GetGame().GetTickTime();
  160. timeRemaining = Math.Round(timeRemaining);
  161. #endif
  162. DbgUI.Text(string.Format("zone: %1 | closest inv. slot: %2 | time remaining: %3", name, slot_name, timeRemaining.ToString()));
  163. anyBleedingSourceActive = true;
  164. }
  165. }
  166. if (!anyBleedingSourceActive)
  167. {
  168. DbgUI.Text("No bleeding sources are active.");
  169. }
  170. else
  171. {
  172. DbgUI.Text("");
  173. DbgUI.Text("Note: BleedingSourcesManagerServer only updates active sources every 3s, displayed times are client estimates.");
  174. }
  175. DbgUI.End();
  176. DbgUI.EndCleanupScope();
  177. }
  178. void CleanDebug()
  179. {
  180. m_ShowingDiag = false;
  181. DbgUI.BeginCleanupScope();
  182. DbgUI.Begin("Bleeding Sources", 50, 50);
  183. DbgUI.End();
  184. DbgUI.EndCleanupScope();
  185. }
  186. void DisplayVisualDebug()
  187. {
  188. /*
  189. if (m_Point)
  190. {
  191. Debug.RemoveShape(m_Point);
  192. }
  193. int boneIdx = m_Player.GetBoneIndexByName("LeftKneeExtra");
  194. int pointIdx = m_Player.GetMemoryPointIndex("lknee");
  195. vector posLS = DayZPlayerUtils.GetMemoryPointPositionBoneRelative(m_Player, boneIdx, pointIdx);
  196. vector pTm[4];
  197. m_Player.GetBoneTransformMS(boneIdx, pTm);
  198. vector posMS = posLS.Multiply4(pTm);
  199. vector pos = m_Player.ModelToWorld(posMS);
  200. m_Point = Debug.DrawSphere(pos, 0.1, COLOR_RED);
  201. */
  202. m_ShowingDiagDraw = true;
  203. int bsCount = m_BleedingSources.Count();
  204. for (int i = 0; i < bsCount; ++i)
  205. {
  206. m_BleedingSources.GetElement(i).DrawDebugShape();
  207. }
  208. }
  209. void CleanVisualDebug()
  210. {
  211. m_ShowingDiagDraw = false;
  212. int bsCount = m_BleedingSources.Count();
  213. for (int i = 0; i < bsCount; ++i)
  214. {
  215. m_BleedingSources.GetElement(i).RemoveDebugShape();
  216. }
  217. }
  218. }