dayzinfected.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. enum DayZInfectedConstants
  2. {
  3. //! anim commands
  4. COMMANDID_MOVE,
  5. COMMANDID_VAULT,
  6. COMMANDID_DEATH,
  7. COMMANDID_HIT,
  8. COMMANDID_ATTACK,
  9. COMMANDID_CRAWL,
  10. COMMANDID_SCRIPT,
  11. //! mind states
  12. MINDSTATE_CALM,
  13. MINDSTATE_DISTURBED,
  14. MINDSTATE_ALERTED,
  15. MINDSTATE_CHASE,
  16. MINDSTATE_FIGHT,
  17. }
  18. enum DayZInfectedConstantsMovement
  19. {
  20. MOVEMENTSTATE_IDLE = 0,
  21. MOVEMENTSTATE_WALK,
  22. MOVEMENTSTATE_RUN,
  23. MOVEMENTSTATE_SPRINT
  24. }
  25. enum DayZInfectedDeathAnims
  26. {
  27. ANIM_DEATH_DEFAULT = 0,
  28. ANIM_DEATH_IMPULSE = 1,
  29. ANIM_DEATH_BACKSTAB = 2,
  30. ANIM_DEATH_NECKSTAB = 3
  31. }
  32. class DayZInfectedCommandMove extends AnimCommandBase
  33. {
  34. proto native void SetStanceVariation(int pStanceVariation);
  35. proto native void SetIdleState(int pIdleState);
  36. proto native void StartTurn(float pDirection, int pSpeedType);
  37. proto native bool IsTurning();
  38. }
  39. class DayZInfectedCommandDeath extends AnimCommandBase {}
  40. class DayZInfectedCommandHit extends AnimCommandBase {}
  41. class DayZInfectedCommandAttack extends AnimCommandBase
  42. {
  43. proto native bool WasHit();
  44. }
  45. class DayZInfectedCommandVault extends AnimCommandBase
  46. {
  47. proto native bool WasLand();
  48. }
  49. class DayZInfectedCommandCrawl extends AnimCommandBase {}
  50. /**
  51. *\brief DayZInfectedCommandScript fully scriptable command
  52. * \warning NON-MANAGED, will be managed by C++ once it is sent to the CommandHandler through DayZInfected.StartCommand_Script
  53. * \note So ideally, it is best to set up the DayZInfectedCommandScript, not create any instances and start it through DayZInfected.StartCommand_ScriptInst
  54. * In case an instance needs to be created, it needs manual deletion if not sent to the CommandHandler
  55. * But deleting it while it is in the CommandHandler will cause crashes
  56. */
  57. class DayZInfectedCommandScript extends AnimCommandBase
  58. {
  59. //! constructor must have 1st parameter to be DayZInfected
  60. void DayZInfectedCommandScript(DayZInfected pInfected) {}
  61. void ~DayZInfectedCommandScript() {}
  62. //---------------------------------------------------------------
  63. // usable everywhere
  64. //! this terminates command script and shows CommandHandler( ... pCurrentCommandFinished == true );
  65. proto native void SetFlagFinished(bool pFinished);
  66. //---------------------------------------------------------------
  67. // PrePhys Update
  68. //! script function usable in PrePhysUpdate
  69. proto native bool PrePhys_GetTranslation(out vector pOutTransl); // vec3 in local space !
  70. proto native bool PrePhys_GetRotation(out float pOutRot[4]); // quaternion in local space !
  71. proto native void PrePhys_SetTranslation(vector pInTransl); // vec3 in local space !
  72. proto native void PrePhys_SetRotation(float pInRot[4]); // quaternion in local space !
  73. //---------------------------------------------------------------
  74. // PostPhys Update
  75. //! override this !
  76. //! final adjustment of physics state (after physics was applied)
  77. //! returns true if command continues running / false if command should end (or you can use SetFlagFinished(true))
  78. bool PostPhysUpdate(float pDt);
  79. //! script function usable in PostPhysUpdate
  80. proto native void PostPhys_GetPosition(out vector pOutTransl); //! vec3 in world space
  81. proto native void PostPhys_GetRotation(out float pOutRot[4]); //! quaternion in world space
  82. proto native void PostPhys_SetPosition(vector pInTransl); //! vec3 in world space
  83. proto native void PostPhys_SetRotation(float pInRot[4]); //! quaternion in world space
  84. proto native void PostPhys_LockRotation(); //! do not process rotations !
  85. }
  86. class DayZInfected extends DayZCreatureAI
  87. {
  88. proto native DayZInfectedType GetDayZInfectedType();
  89. proto native DayZInfectedInputController GetInputController();
  90. proto native DayZInfectedCommandMove StartCommand_Move();
  91. proto native DayZInfectedCommandVault StartCommand_Vault(int pType);
  92. proto native void StartCommand_Death(int pType, float pDirection);
  93. proto native void StartCommand_Hit(bool pHeavy, int pType, float pDirection);
  94. proto native DayZInfectedCommandAttack StartCommand_Attack(EntityAI pTarget, int pType, float pSubtype);
  95. proto native void StartCommand_Crawl(int pType);
  96. proto native bool CanAttackToPosition(vector pTargetPosition);
  97. proto native DayZInfectedCommandMove GetCommand_Move();
  98. proto native DayZInfectedCommandVault GetCommand_Vault();
  99. proto native DayZInfectedCommandAttack GetCommand_Attack();
  100. //! scripted commands
  101. proto native DayZInfectedCommandScript StartCommand_Script(DayZInfectedCommandScript pInfectedCommand);
  102. proto native DayZInfectedCommandScript StartCommand_ScriptInst(typename pCallbackClass);
  103. proto native DayZInfectedCommandScript GetCommand_Script();
  104. //! gets transform in World Space
  105. proto native void GetTransformWS(out vector pTm[4]);
  106. const float LEG_CRIPPLE_THRESHOLD = 74.0;
  107. bool m_HeavyHitOverride;
  108. //-------------------------------------------------------------
  109. void DayZInfected();
  110. void ~DayZInfected();
  111. //-------------------------------------------------------------
  112. override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
  113. {
  114. super.EEHitBy(damageResult, damageType, source, component, dmgZone, ammo, modelPos, speedCoef);
  115. int transferShockToDamageCoef = g_Game.ConfigGetInt(string.Format("%1 %2 DamageApplied transferShockToDamage", CFG_AMMO, ammo));
  116. if (transferShockToDamageCoef == 1)
  117. {
  118. float damage = damageResult.GetDamage(dmgZone, "Shock");
  119. HandleSpecialZoneDamage(dmgZone, damage);
  120. AddHealth("", "Health", -ConvertNonlethalDamage(damage, damageType));
  121. }
  122. if (!IsAlive())
  123. {
  124. if (!m_DeathSyncSent) //to be sent only once on hit/death
  125. {
  126. Man killer = source.GetHierarchyRootPlayer();
  127. if (!m_KillerData) //only one player is considered killer in the event of crossfire
  128. {
  129. m_KillerData = new KillerData();
  130. m_KillerData.m_Killer = killer;
  131. m_KillerData.m_MurderWeapon = source;
  132. }
  133. if (killer && killer.IsPlayer())
  134. {
  135. // was infected killed by headshot?
  136. if (dmgZone == "Head") //no "Brain" damage zone defined (nor can it be caught like on player, due to missing command handler), "Head" is sufficient
  137. {
  138. m_KilledByHeadshot = true;
  139. if (m_KillerData.m_Killer == killer)
  140. m_KillerData.m_KillerHiTheBrain = true;
  141. }
  142. }
  143. SyncEvents.SendEntityKilled(this, m_KillerData.m_Killer, m_KillerData.m_MurderWeapon, m_KillerData.m_KillerHiTheBrain);
  144. m_DeathSyncSent = true;
  145. }
  146. }
  147. }
  148. override protected float ConvertNonlethalDamage(float damage, DamageType damageType)
  149. {
  150. switch (damageType)
  151. {
  152. case DamageType.CLOSE_COMBAT:
  153. return damage * GameConstants.NL_DAMAGE_CLOSECOMBAT_CONVERSION_INFECTED;
  154. case DamageType.FIRE_ARM:
  155. return damage * GameConstants.NL_DAMAGE_FIREARM_CONVERSION_INFECTED;
  156. }
  157. return super.ConvertNonlethalDamage(damage, damageType);
  158. }
  159. void HandleSpecialZoneDamage(string dmgZone, float damage)
  160. {
  161. if (damage < LEG_CRIPPLE_THRESHOLD)
  162. return;
  163. if (dmgZone == "LeftLeg" || dmgZone == "RightLeg")
  164. SetHealth(dmgZone,"Health",0.0);
  165. if (dmgZone == "Torso" || dmgZone == "Head")
  166. m_HeavyHitOverride = true;
  167. }
  168. override int GetHideIconMask()
  169. {
  170. return EInventoryIconVisibility.HIDE_VICINITY;
  171. }
  172. }