bleedingsourcesmanagerbase.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. class BleedingSourcesManagerBase
  2. {
  3. ref map<int, ref BleedingSource> m_BleedingSources = new map<int, ref BleedingSource>;
  4. ref map<string, ref BleedingSourceZone> m_BleedingSourceZone = new map<string, ref BleedingSourceZone>;
  5. ref map<int, int> m_BleedingSourcesByLocation = new map<int, int>;
  6. static ref map<int, int> m_BleedingSourcesZonesMaskByLocation = new map<int, int>;//for each inventory location, keep a bitmask where a bit is set to 1 for each bleeding source zone that belongs to that location
  7. static ref set<int> m_BleedingSourcesLocationsList = new set<int>;
  8. ItemBase m_Item;//item used to remove the bleeding source
  9. PlayerBase m_Player;
  10. //ref map<string, int> m_FireGeomToBit = new map<string, int>;
  11. ref map<int, string> m_BitToFireGeom = new map<int, string>;
  12. protected int m_Bit;
  13. int m_BitOffset = 0;
  14. void BleedingSourcesManagerBase( PlayerBase player )
  15. {
  16. m_Player = player;
  17. Init();
  18. }
  19. protected void Init()
  20. {
  21. //dmgZone_head
  22. RegisterBleedingZoneEx("Head",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "95 90 0" , "0.15 -0.08 0.00", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.MASK);
  23. //dmgZone_torso
  24. RegisterBleedingZoneEx("Neck", PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL,"", "-130 70 0" , "0.02 -0.05 0.05", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.HEADGEAR);
  25. RegisterBleedingZoneEx("Pelvis",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -135 0" , "0 0.12 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.BODY);
  26. RegisterBleedingZoneEx("Spine",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 55 0" , "0 -0.1 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.BODY);
  27. RegisterBleedingZoneEx("Spine1",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 155 0" , "0 -0.1 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.BODY);
  28. RegisterBleedingZoneEx("Spine2",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 55 0" , "0 -0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.BODY);
  29. RegisterBleedingZoneEx("Spine3",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.BODY);
  30. //dmgZone_leftArm
  31. RegisterBleedingZoneEx("LeftShoulder",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect", InventorySlots.BODY);
  32. RegisterBleedingZoneEx("LeftArm", PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "","0 90 90" , "0 -0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
  33. RegisterBleedingZoneEx("LeftArmRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
  34. RegisterBleedingZoneEx("LeftForeArm",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
  35. //dmgZone_rightArm
  36. RegisterBleedingZoneEx("RightShoulder",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
  37. RegisterBleedingZoneEx("RightArm", PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL,"", "0 -90 0" , "0 0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
  38. RegisterBleedingZoneEx("RightArmRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
  39. RegisterBleedingZoneEx("RightForeArm",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
  40. //dmgZone_leftHand
  41. RegisterBleedingZoneEx("LeftForeArmRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0.1 0 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.GLOVES);
  42. //dmgZone_rightHand
  43. RegisterBleedingZoneEx("RightForeArmRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "-0.1 0 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.GLOVES);
  44. //dmgZone_leftLeg
  45. RegisterBleedingZoneEx("LeftLeg",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
  46. RegisterBleedingZoneEx("LeftLegRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
  47. RegisterBleedingZoneEx("LeftUpLeg",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.12 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
  48. RegisterBleedingZoneEx("LeftUpLegRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.1 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM , "BleedingSourceEffect",InventorySlots.LEGS);
  49. //dmgZone_rightLeg
  50. RegisterBleedingZoneEx("RightLeg",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.06 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
  51. RegisterBleedingZoneEx("RightLegRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
  52. RegisterBleedingZoneEx("RightUpLeg",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.12 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
  53. RegisterBleedingZoneEx("RightUpLegRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.1 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
  54. //dmgZone_leftFoot
  55. RegisterBleedingZoneEx("LeftFoot",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 180 0" , "0 0 0.035", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.LEGS);
  56. RegisterBleedingZoneEx("LeftToeBase",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffect",InventorySlots.FEET);
  57. //dmgZone_rightFoot
  58. RegisterBleedingZoneEx("RightFoot",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 0 0" , "0 0 -0.035", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.LEGS);
  59. RegisterBleedingZoneEx("RightToeBase",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffect", InventorySlots.FEET);
  60. }
  61. protected void SetItem(ItemBase item)
  62. {
  63. m_Item = item;
  64. }
  65. set<int> GetBleedingSourcesLocations()
  66. {
  67. return m_BleedingSourcesLocationsList;
  68. }
  69. //for inventory location, get the active bits
  70. int GetBleedingSourceBitsByInvLocation(int inv_location)
  71. {
  72. if (m_BleedingSourcesByLocation.Contains(inv_location))
  73. {
  74. return m_BleedingSourcesByLocation.Get(inv_location);
  75. }
  76. return 0;
  77. }
  78. //for inventory location, get the active bits
  79. int GetFreeBleedingSourceBitsByInvLocation(int inv_location)
  80. {
  81. if (m_BleedingSourcesZonesMaskByLocation.Contains(inv_location))
  82. {
  83. return (~m_BleedingSourcesZonesMaskByLocation.Get(inv_location) & GetBleedingSourceBitsByInvLocation(inv_location)) | (m_BleedingSourcesZonesMaskByLocation.Get(inv_location) & ~GetBleedingSourceBitsByInvLocation(inv_location));//xor
  84. }
  85. return 0;
  86. }
  87. bool IsBleedingSourceActive(string name)
  88. {
  89. name.ToLower();
  90. int bit = GetBitFromSelectionName(name);
  91. return m_Player.GetBleedingBits() & bit;
  92. }
  93. protected int GetBitFromSelectionID(int id)
  94. {
  95. CachedObjectsArrays.ARRAY_STRING.Clear();
  96. m_Player.GetActionComponentNameList(id, CachedObjectsArrays.ARRAY_STRING, "fire");
  97. for (int i = 0; i < CachedObjectsArrays.ARRAY_STRING.Count(); i++)
  98. {
  99. /*
  100. string name = CachedObjectsArrays.ARRAY_STRING.Get(i);
  101. PrintString(name);
  102. */
  103. int bit = GetBitFromSelectionName(CachedObjectsArrays.ARRAY_STRING.Get(i));
  104. if ( bit !=0 )
  105. {
  106. return bit;
  107. }
  108. }
  109. return 0;
  110. }
  111. protected BleedingSourceZone GetBleedingSourceMeta(int bit)
  112. {
  113. return m_BleedingSourceZone.Get(GetSelectionNameFromBit(bit));
  114. }
  115. int GetRegisteredSourcesCount()
  116. {
  117. return m_BitOffset;
  118. }
  119. 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)
  120. {
  121. if ( m_BitOffset == BIT_INT_SIZE)
  122. {
  123. Error("Too many bleeding sources, max is "+BIT_INT_SIZE.ToString());
  124. }
  125. else
  126. {
  127. name.ToLower();
  128. //PrintString(name);
  129. //int bit = Math.Pow(2, m_BitOffset);
  130. m_Bit = 1 << m_BitOffset;
  131. //PrintString(bit.ToString());
  132. string bone_name = bone;
  133. if (bone_name == "")
  134. {
  135. bone_name = name;
  136. }
  137. m_BleedingSourceZone.Insert(name, new BleedingSourceZone(name, m_Bit, offset, orientation, bone_name, max_time, flow_modifier, particle_name));
  138. m_BleedingSourceZone.Get(name).SetInvLocation(inv_location);
  139. m_BitToFireGeom.Insert(m_Bit, name);
  140. m_BleedingSourcesZonesMaskByLocation.Set( inv_location, m_BleedingSourcesZonesMaskByLocation.Get(inv_location) | m_Bit);//set a bit to 1 to already existing bitmask for that location
  141. m_BleedingSourcesLocationsList.Insert(inv_location);
  142. m_BitOffset++;
  143. }
  144. }
  145. protected void RegisterBleedingZone(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")
  146. {
  147. RegisterBleedingZoneEx(name, max_time, bone, orientation, offset, flow_modifier, particle_name);
  148. }
  149. void RemoveAllSources()
  150. {
  151. //int count = m_BleedingSources.Count();
  152. while (m_BleedingSources.Count() > 0 )
  153. {
  154. int bit = m_BleedingSources.GetKey(0);
  155. RemoveBleedingSource(bit);
  156. }
  157. }
  158. protected int GetBitFromSelectionName(string name)
  159. {
  160. if (!m_BleedingSourceZone.Get(name))
  161. {
  162. return 0;
  163. }
  164. return m_BleedingSourceZone.Get(name).GetBit();
  165. }
  166. protected string GetSelectionNameFromBit(int bit)
  167. {
  168. return m_BitToFireGeom.Get(bit);
  169. }
  170. bool AttemptAddBleedingSource(int component)
  171. {
  172. int bit = GetBitFromSelectionID(component);
  173. if ( bit == 0 )
  174. {
  175. return false;
  176. }
  177. if ( CanAddBleedingSource(bit) )
  178. {
  179. AddBleedingSource(bit);
  180. return true;
  181. }
  182. return false;
  183. }
  184. bool AttemptAddBleedingSourceBySelection(string selection_name)
  185. {
  186. selection_name.ToLower();
  187. int bit = GetBitFromSelectionName(selection_name);
  188. if ( bit == 0 )
  189. {
  190. return false;
  191. }
  192. if ( CanAddBleedingSource(bit) )
  193. {
  194. AddBleedingSource(bit);
  195. return true;
  196. }
  197. return false;
  198. }
  199. bool AttemptAddBleedingSourceDirectly(int bit, eBleedingSourceType type = eBleedingSourceType.NORMAL, int context = 0)
  200. {
  201. if(CanAddBleedingSource(bit))
  202. {
  203. AddBleedingSourceEx(bit, type, context);
  204. return true;
  205. }
  206. return false;
  207. }
  208. protected bool CanAddBleedingSource(int bit)
  209. {
  210. if (!GetBleedingSourceMeta(bit))
  211. {
  212. return false;
  213. }
  214. if ((m_Player.GetBleedingBits() & bit) == 0)
  215. {
  216. return true;
  217. }
  218. return false;
  219. }
  220. protected void AddBleedingSourceEx(int bit, eBleedingSourceType type = eBleedingSourceType.NORMAL, int context = 0)
  221. {
  222. AddBleedingSource(bit);
  223. m_BleedingSources.Get(bit).SetType(type);
  224. }
  225. protected void AddBleedingSource(int bit)
  226. {
  227. BleedingSourceZone bsz = GetBleedingSourceMeta(bit);
  228. vector orientation = bsz.GetOrientation();
  229. vector offset = bsz.GetOffset();
  230. string bone_name = bsz.GetBoneName();
  231. float flow_modifier = bsz.GetFlowModifier();
  232. int max_time = bsz.GetMaxTime();
  233. string particle_name = bsz.GetParticleName();
  234. int inventory_loc = bsz.GetInvLocation();
  235. m_BleedingSourcesByLocation.Set(inventory_loc, (m_BleedingSourcesByLocation.Get(inventory_loc) | bit));
  236. m_BleedingSources.Insert(bit, new BleedingSource(m_Player, bit,bone_name, orientation, offset, max_time, flow_modifier, particle_name) );
  237. }
  238. int GetBleedingSourceActiveTime(int bit)
  239. {
  240. int time = -1;
  241. if (m_BleedingSources.Contains(bit))
  242. {
  243. time = m_BleedingSources.Get(bit).GetActiveTime();
  244. }
  245. return time;
  246. }
  247. void SetBleedingSourceActiveTime(int bit, int time)
  248. {
  249. if (m_BleedingSources.Contains(bit))
  250. {
  251. m_BleedingSources.Get(bit).SetActiveTime(time);
  252. }
  253. }
  254. void SetBleedingSourceType(int bit, eBleedingSourceType type)
  255. {
  256. if (m_BleedingSources.Contains(bit))
  257. {
  258. m_BleedingSources.Get(bit).SetType(type);
  259. }
  260. }
  261. eBleedingSourceType GetBleedingSourceType(int bit)
  262. {
  263. if (m_BleedingSources.Contains(bit))
  264. {
  265. return m_BleedingSources.Get(bit).GetType();
  266. }
  267. return -1;
  268. }
  269. protected bool RemoveBleedingSource(int bit)
  270. {
  271. if (m_BleedingSources.Contains(bit))
  272. {
  273. BleedingSourceZone bsz = GetBleedingSourceMeta(bit);
  274. int inventory_loc = bsz.GetInvLocation();
  275. m_BleedingSourcesByLocation.Set(inventory_loc, (m_BleedingSourcesByLocation.Get(inventory_loc) & ~bit));//deactivate the bit
  276. m_BleedingSources.Remove(bit);
  277. return true;
  278. }
  279. return false;
  280. }
  281. int GetBleedingSourcesCount()
  282. {
  283. return m_BleedingSources.Count();
  284. }
  285. /*void ChangeBleedingIndicatorVisibility(bool visible)
  286. {
  287. int count = m_BleedingSources.Count();
  288. for (int i = 0; i < count; i++)
  289. {
  290. m_BleedingSources.GetElement(i).ToggleSourceBleedingIndication(visible);
  291. }
  292. }*/
  293. }