dayzplayersyncjunctures.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. // *************************************************************************************
  2. // ! DayZPlayerSyncJunctures - sync junctures for dayz player - static functions
  3. // *************************************************************************************
  4. class DayZPlayerSyncJunctures
  5. {
  6. static const int SJ_DAMAGE_HIT = 0;
  7. static const int SJ_INJURY = 1;
  8. static const int SJ_ACTION_INTERRUPT = 2;
  9. static const int SJ_PLAYER_STATES = 3;
  10. static const int SJ_QUICKBAR_SET_SHORTCUT = 4;
  11. static const int SJ_INVENTORY = 5;
  12. static const int SJ_ACTION_ACK_ACCEPT = 6;
  13. static const int SJ_ACTION_ACK_REJECT = 7;
  14. static const int SJ_WEAPON_ACTION_ACK_ACCEPT = 8;
  15. static const int SJ_WEAPON_ACTION_ACK_REJECT = 9;
  16. static const int SJ_WEAPON_SET_JAMMING_CHANCE = 10;
  17. static const int SJ_UNCONSCIOUSNESS = 11;
  18. static const int SJ_DEATH = 12;
  19. static const int SJ_PLAYER_FB_MODIFIER = 13;
  20. static const int SJ_PLAYER_ADD_MODIFIER = 14;
  21. static const int SJ_KURU_REQUEST = 15;
  22. static const int SJ_GESTURE_REQUEST = 16;
  23. static const int SJ_INVENTORY_REPAIR = 17;
  24. static const int SJ_WEAPON_LIFT = 18;
  25. static const int SJ_WEAPON_RAISE_COMPLETED = 19;
  26. static const int SJ_DELETE_ITEM = 20;
  27. static const int SJ_BROKEN_LEGS = 21;
  28. static const int SJ_SHOCK = 22;
  29. static const int SJ_STAMINA = 23;
  30. static const int SJ_STAMINA_MISC = 24;
  31. static const int SJ_ADS_RESET = 25;
  32. static const int SJ_INVENTORY_FAILURE = 26;
  33. #ifdef DEVELOPER
  34. static const int SJ_DEBUG_GET_IN_VEHICLE = 200;
  35. #endif
  36. #ifdef DEVELOPER
  37. //-------------------------------------------------------------
  38. //!
  39. //!Get in Car
  40. //!
  41. static void SendGetInVehicle(DayZPlayer pPlayer, EntityAI vehicle)
  42. {
  43. ScriptJunctureData ctx = new ScriptJunctureData();
  44. ctx.Write(vehicle);
  45. pPlayer.SendSyncJuncture(SJ_DEBUG_GET_IN_VEHICLE, ctx);
  46. }
  47. static bool ReadGetInVehicleParams(ParamsReadContext pCtx, out EntityAI vehicle)
  48. {
  49. if (!pCtx.Read(vehicle))
  50. return false;
  51. return true;
  52. }
  53. #endif
  54. //-------------------------------------------------------------
  55. //!
  56. //! Death
  57. //!
  58. static void SendDeath(DayZPlayer pPlayer, int pType, float pHitDir)
  59. {
  60. ScriptJunctureData ctx = new ScriptJunctureData;
  61. ctx.Write(pType);
  62. ctx.Write(pHitDir);
  63. pPlayer.SendSyncJuncture(SJ_DEATH, ctx);
  64. }
  65. static bool ReadDeathParams(ParamsReadContext pCtx, out int pType, out float pHitDir)
  66. {
  67. if (!pCtx.Read(pType))
  68. return false;
  69. if (!pCtx.Read(pHitDir))
  70. return false;
  71. return true;
  72. }
  73. //-------------------------------------------------------------
  74. //!
  75. //! DamageHit
  76. //!
  77. static void SendDamageHit(DayZPlayer pPlayer, int pType, float pHitDir, bool pFullbody)
  78. {
  79. ScriptJunctureData ctx = new ScriptJunctureData;
  80. ctx.Write(pType);
  81. ctx.Write(pHitDir);
  82. ctx.Write(pFullbody);
  83. pPlayer.SendSyncJuncture(SJ_DAMAGE_HIT, ctx);
  84. }
  85. static void SendDamageHitEx(DayZPlayer pPlayer, int pType, float pHitDir, bool pFullbody, TotalDamageResult pDamageResult, int pDamageType, EntityAI pSource, string pComponent, string pAmmoType, vector pModelPos)
  86. {
  87. ScriptJunctureData ctx = new ScriptJunctureData;
  88. SyncHitInfo data = new SyncHitInfo;
  89. data.m_AnimType = pType;
  90. data.m_HitDir = pHitDir;
  91. data.m_Fullbody = pFullbody;
  92. data.m_HasSource = pSource != null;
  93. if ( !pDamageResult )
  94. {
  95. data.m_HealthDamage = -1.0;
  96. }
  97. else
  98. {
  99. data.m_HealthDamage = pDamageResult.GetHighestDamage("Health");
  100. }
  101. ctx.Write(data);
  102. pPlayer.SendSyncJuncture(SJ_DAMAGE_HIT, ctx);
  103. }
  104. static bool ReadDamageHitParams(ParamsReadContext pCtx, out int pType, out float pHitDir, out bool pFullbody)
  105. {
  106. if (!pCtx.Read(pType))
  107. return false;
  108. if (!pCtx.Read(pHitDir))
  109. return false;
  110. if (!pCtx.Read(pFullbody))
  111. return false;
  112. return true;
  113. }
  114. static bool ReadDamageHitParamsEx(ParamsReadContext pCtx, out SyncHitInfo pData)
  115. {
  116. if (!pCtx.Read(pData))
  117. return false;
  118. return true;
  119. }
  120. //-------------------------------------------------------------
  121. //!
  122. //! Injury
  123. //!
  124. static void SendInjury(DayZPlayer pPlayer, bool pEnable, eInjuryHandlerLevels level)
  125. {
  126. ScriptJunctureData ctx = new ScriptJunctureData;
  127. ctx.Write(pEnable);
  128. ctx.Write(level);
  129. pPlayer.SendSyncJuncture(SJ_INJURY, ctx);
  130. }
  131. static bool ReadInjuryParams(ParamsReadContext pCtx, out bool pEnable, out eInjuryHandlerLevels level)
  132. {
  133. if ( !pCtx.Read(pEnable) )
  134. return false; // error
  135. if ( !pCtx.Read(level) )
  136. return false; // error
  137. return true;
  138. }
  139. //-------------------------------------------------------------
  140. //!
  141. //! Conscious / Unconscious
  142. //!
  143. static void SendPlayerUnconsciousness(DayZPlayer pPlayer, bool enable)
  144. {
  145. ScriptJunctureData ctx = new ScriptJunctureData;
  146. ctx.Write(enable);
  147. pPlayer.SendSyncJuncture(SJ_UNCONSCIOUSNESS, ctx);
  148. }
  149. static bool ReadPlayerUnconsciousnessParams(ParamsReadContext pCtx, out bool enable)
  150. {
  151. if ( !pCtx.Read(enable) )
  152. {
  153. return false;
  154. }
  155. return true;
  156. }
  157. //-------------------------------------------------------------
  158. //!
  159. //! Full body
  160. //!
  161. static void SendPlayerFBModifier(PlayerBase pPlayer, int type)
  162. {
  163. ScriptJunctureData ctx = new ScriptJunctureData;
  164. ctx.Write(type);
  165. pPlayer.SendSyncJuncture(SJ_PLAYER_FB_MODIFIER, ctx);
  166. }
  167. static bool ReadPlayerFBModifier(ParamsReadContext pCtx, out int type)
  168. {
  169. if ( !pCtx.Read(type) )
  170. return false; // error
  171. return true;
  172. }
  173. //-------------------------------------------------------------
  174. //!
  175. //! Additive Symptoms
  176. //!
  177. static void SendPlayerSymptomADD(DayZPlayer pPlayer, int type, int state_type)
  178. {
  179. ScriptJunctureData ctx = new ScriptJunctureData;
  180. ctx.Write(state_type);
  181. ctx.Write(type);
  182. pPlayer.SendSyncJuncture(SJ_PLAYER_ADD_MODIFIER, ctx);
  183. }
  184. static bool ReadPlayerSymptomADDParams(ParamsReadContext pCtx, out int type)
  185. {
  186. if ( !pCtx.Read(type) )
  187. return false; // error
  188. return true;
  189. }
  190. //-------------------------------------------------------------
  191. //!
  192. //! Full body Symptoms
  193. //!
  194. static void SendPlayerSymptomFB(DayZPlayer pPlayer, DayZPlayerConstants anim_id, int state_type, int stance_mask, float duration)
  195. {
  196. ScriptJunctureData ctx = new ScriptJunctureData;
  197. ctx.Write(state_type);
  198. ctx.Write(anim_id);
  199. ctx.Write(stance_mask);
  200. ctx.Write(duration);
  201. //ctx.Write(pPlayer);
  202. pPlayer.SendSyncJuncture(SJ_PLAYER_STATES, ctx);
  203. }
  204. static bool ReadPlayerSymptomFBParams(ParamsReadContext pCtx, out DayZPlayerConstants anim_id, out int stance_mask, out float duration)
  205. {
  206. if ( !pCtx.Read(anim_id) )
  207. return false; // error
  208. if ( !pCtx.Read(stance_mask) )
  209. return false; // error
  210. if ( !pCtx.Read(duration) )
  211. return false; // error
  212. //if ( !pCtx.Read(pPlayer) )
  213. //return false; // error
  214. return true;
  215. }
  216. //-------------------------------------------------------------
  217. //!
  218. //! Action interrupt
  219. //!
  220. static void SendActionInterrupt(DayZPlayer pPlayer)
  221. {
  222. ScriptJunctureData ctx = new ScriptJunctureData;
  223. pPlayer.SendSyncJuncture(SJ_ACTION_INTERRUPT, ctx);
  224. }
  225. static bool ReadActionInterruptParams(ParamsReadContext pCtx)
  226. {
  227. return true;
  228. }
  229. //-------------------------------------------------------------
  230. //!
  231. //! Action Acknowledgment
  232. //!
  233. static void SendActionAcknowledgment(DayZPlayer pPlayer, int AckID, bool accept)
  234. {
  235. ScriptJunctureData ctx = new ScriptJunctureData;
  236. ctx.Write(AckID);
  237. if (accept)
  238. pPlayer.SendSyncJuncture(SJ_ACTION_ACK_ACCEPT, ctx);
  239. else
  240. pPlayer.SendSyncJuncture(SJ_ACTION_ACK_REJECT, ctx);
  241. }
  242. static void SendWeaponActionAcknowledgment(DayZPlayer pPlayer, int AckID, bool accept)
  243. {
  244. ScriptJunctureData ctx = new ScriptJunctureData;
  245. ctx.Write(AckID);
  246. if (accept)
  247. pPlayer.SendSyncJuncture(SJ_WEAPON_ACTION_ACK_ACCEPT, ctx);
  248. else
  249. pPlayer.SendSyncJuncture(SJ_WEAPON_ACTION_ACK_REJECT, ctx);
  250. }
  251. //-------------------------------------------------------------
  252. //!
  253. //! Kuru Disease Shake
  254. //!
  255. static bool ReadKuruRequest(ParamsReadContext pCtx, out float amount)
  256. {
  257. if ( !pCtx.Read(amount) )
  258. return false; // error
  259. return true;
  260. }
  261. static void SendKuruRequest(DayZPlayer pPlayer, float amount)
  262. {
  263. ScriptJunctureData ctx = new ScriptJunctureData;
  264. ctx.Write(amount);
  265. pPlayer.SendSyncJuncture(SJ_KURU_REQUEST, ctx);
  266. }
  267. //-------------------------------------------------------------
  268. //!
  269. //! Quickbar
  270. //!
  271. static void SendQuickbarSetShortcut(DayZPlayer pPlayer, EntityAI item, int index, bool force = false )
  272. {
  273. ScriptJunctureData ctx = new ScriptJunctureData;
  274. ctx.Write(item);
  275. ctx.Write(index);
  276. ctx.Write(force);
  277. pPlayer.SendSyncJuncture(SJ_QUICKBAR_SET_SHORTCUT, ctx);
  278. }
  279. static void SendWeaponJamChance(DayZPlayer pPlayer, float jamChance )
  280. {
  281. ScriptJunctureData ctx = new ScriptJunctureData;
  282. ctx.Write(jamChance);
  283. pPlayer.SendSyncJuncture(SJ_WEAPON_SET_JAMMING_CHANCE, ctx);
  284. }
  285. /*static bool ReadQuickbarSetShortcut(ParamsReadContext pCtx, out EntityAI item, out int index)
  286. {
  287. Param2<EntityAI,int> shortcutParam = new Param2<EntityAI,int>(NULL,-1);
  288. if( pCtx.Read(shortcutParam))
  289. {
  290. item = shortcutParam.param1;
  291. index = shortcutParam.param2;
  292. return true;
  293. }
  294. return false;
  295. }*/
  296. static void SendDeleteItem( DayZPlayer pPlayer, EntityAI item )
  297. {
  298. ScriptJunctureData ctx = new ScriptJunctureData;
  299. ctx.Write(item);
  300. pPlayer.SendSyncJuncture(SJ_DELETE_ITEM, ctx);
  301. }
  302. //-------------------------------------------------------------
  303. //!
  304. //! BrokenLegs
  305. //!
  306. static void SendBrokenLegs(DayZPlayer pPlayer, bool canPlaySound, eBrokenLegs currentState, eBrokenLegs localState)
  307. {
  308. ScriptJunctureData ctx = new ScriptJunctureData;
  309. ctx.Write(canPlaySound);
  310. ctx.Write(currentState);
  311. ctx.Write(localState);
  312. pPlayer.SendSyncJuncture(SJ_BROKEN_LEGS, ctx);
  313. }
  314. static bool ReadBrokenLegsParams(ParamsReadContext pCtx, out bool canPlaySound, out eBrokenLegs currentState, out eBrokenLegs localState)
  315. {
  316. if ( !pCtx.Read(canPlaySound) )
  317. return false; // error
  318. if ( !pCtx.Read(currentState) )
  319. return false; // error
  320. if ( !pCtx.Read(localState) )
  321. return false;
  322. return true;
  323. }
  324. static void SendBrokenLegsEx(DayZPlayer pPlayer, int currentState)
  325. {
  326. ScriptJunctureData ctx = new ScriptJunctureData;
  327. ctx.Write(currentState);
  328. pPlayer.SendSyncJuncture(SJ_BROKEN_LEGS, ctx);
  329. }
  330. static bool ReadBrokenLegsParamsEx(ParamsReadContext pCtx, out int currentState)
  331. {
  332. if ( !pCtx.Read(currentState) )
  333. return false;
  334. return true;
  335. }
  336. //-------------------------------------------------------------
  337. //!
  338. //! Shock
  339. //!
  340. static void SendShock(DayZPlayer pPlayer, float shockValue)
  341. {
  342. ScriptJunctureData ctx = new ScriptJunctureData;
  343. ctx.Write(shockValue);
  344. pPlayer.SendSyncJuncture(SJ_SHOCK, ctx);
  345. }
  346. static bool ReadShockParams(ParamsReadContext pCtx, out float shockValue)
  347. {
  348. if ( !pCtx.Read(shockValue) )
  349. return false; // error
  350. return true;
  351. }
  352. }