bleedingsourcesmanagerremote.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. if (GetGame().IsMultiplayer())
  65. m_Player.OnBleedingSourceAdded();
  66. }
  67. override protected bool RemoveBleedingSource(int bit)
  68. {
  69. if (super.RemoveBleedingSource(bit))
  70. {
  71. if (GetGame().IsMultiplayer())
  72. m_Player.OnBleedingSourceRemovedEx(m_Item);
  73. return true;
  74. }
  75. return false;
  76. }
  77. void OnBleedingBitsUpdate(int old_mask, int new_mask)
  78. {
  79. for (int i = 0; i < 32; i++)
  80. {
  81. int compare_bit = 1 << i;
  82. int new_compare_result_bit = compare_bit & new_mask;
  83. int old_compare_result_bit = compare_bit & old_mask;
  84. if ( new_compare_result_bit )
  85. {
  86. if ( !(new_compare_result_bit & old_mask))
  87. {
  88. //a different active bit in the new mask
  89. AddBleedingSource(new_compare_result_bit);
  90. }
  91. }
  92. else
  93. {
  94. if ( new_compare_result_bit != old_compare_result_bit )
  95. {
  96. RemoveBleedingSource(old_compare_result_bit);
  97. }
  98. }
  99. }
  100. }
  101. int GetBleedingSourceCountRemote()
  102. {
  103. int bleeding_source_count = 0;
  104. int pow = 0;
  105. for (int i = 0; i < BIT_INT_SIZE ; i++)
  106. {
  107. int bit = Math.Pow(2, pow);
  108. pow++;
  109. if ( (m_BleedingBits & bit) != 0)
  110. {
  111. bleeding_source_count++;
  112. }
  113. }
  114. return bleeding_source_count;
  115. }
  116. void SetDiag(bool value)
  117. {
  118. m_ShowDiag = value;
  119. return;
  120. int boneIdx = m_Player.GetBoneIndexByName("RightArmExtra");
  121. if ( boneIdx != -1 )
  122. {
  123. Object linkedObject = GetGame().CreateObject("Ammo_ArrowBolt", "0 0 0");
  124. //linkedObject.SetPosition("0 1 0");
  125. //linkedObject.SetOrientation("0 90 0");
  126. /*
  127. Set local space transform for linked object
  128. */
  129. BleedingSourceEffect eff = new BleedingSourceEffect();
  130. eff.SetAutodestroy(true);
  131. SEffectManager.PlayInWorld( eff, "0 0 0" );
  132. Particle p = eff.GetParticle();
  133. //p.SetOrientation("0 90 0");
  134. m_Player.AddChild(p, boneIdx);
  135. m_Player.AddChild(linkedObject, boneIdx);
  136. }
  137. }
  138. void OnUpdate()
  139. {
  140. #ifndef NO_GUI
  141. if (m_ShowDiag)
  142. {
  143. DisplayDebug();
  144. DisplayVisualDebug();
  145. }
  146. else if ( m_ShowingDiag || m_ShowingDiagDraw )
  147. {
  148. if (m_ShowingDiag)
  149. CleanDebug();
  150. if (m_ShowingDiagDraw)
  151. CleanVisualDebug();
  152. }
  153. #endif
  154. }
  155. void DisplayDebug()
  156. {
  157. m_ShowingDiag = true;
  158. DbgUI.BeginCleanupScope();
  159. DbgUI.Begin("Bleeding Sources", 50, 50);
  160. int pow = 0;
  161. bool anyBleedingSourceActive = false;
  162. for (int i = 0; i < BIT_INT_SIZE ; i++)
  163. {
  164. int bit = Math.Pow(2, pow);
  165. pow++;
  166. if ( (m_BleedingBits & bit) != 0)
  167. {
  168. BleedingSourceZone bsz = GetBleedingSourceMeta(bit);
  169. string name = GetSelectionNameFromBit(bit);
  170. string slot_name = InventorySlots.GetSlotName(bsz.GetInvLocation());
  171. DbgUI.Text(name + "| slot name: "+ slot_name);
  172. anyBleedingSourceActive = true;
  173. }
  174. }
  175. if (!anyBleedingSourceActive)
  176. {
  177. DbgUI.Text("Currently no bleeding sources are active.");
  178. }
  179. DbgUI.End();
  180. DbgUI.EndCleanupScope();
  181. }
  182. void CleanDebug()
  183. {
  184. m_ShowingDiag = false;
  185. DbgUI.BeginCleanupScope();
  186. DbgUI.Begin("Bleeding Sources", 50, 50);
  187. DbgUI.End();
  188. DbgUI.EndCleanupScope();
  189. }
  190. void DisplayVisualDebug()
  191. {
  192. /*
  193. if(m_Point)
  194. {
  195. Debug.RemoveShape(m_Point);
  196. }
  197. int boneIdx = m_Player.GetBoneIndexByName("LeftKneeExtra");
  198. int pointIdx = m_Player.GetMemoryPointIndex("lknee");
  199. vector posLS = DayZPlayerUtils.GetMemoryPointPositionBoneRelative(m_Player, boneIdx, pointIdx);
  200. vector pTm[4];
  201. m_Player.GetBoneTransformMS(boneIdx, pTm);
  202. vector posMS = posLS.Multiply4(pTm);
  203. vector pos = m_Player.ModelToWorld(posMS);
  204. m_Point = Debug.DrawSphere(pos, 0.1, COLOR_RED);
  205. */
  206. m_ShowingDiagDraw = true;
  207. int bsCount = m_BleedingSources.Count();
  208. for (int i = 0; i < bsCount; ++i)
  209. {
  210. m_BleedingSources.GetElement(i).DrawDebugShape();
  211. }
  212. }
  213. void CleanVisualDebug()
  214. {
  215. m_ShowingDiagDraw = false;
  216. int bsCount = m_BleedingSources.Count();
  217. for (int i = 0; i < bsCount; ++i)
  218. {
  219. m_BleedingSources.GetElement(i).RemoveDebugShape();
  220. }
  221. }
  222. }