Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
dayzplayerimplementmeleecombat.c
Go to the documentation of this file.
2 {
3  NONE = -1,
4 
8  KICK,
12 
17 }
18 
20 {
22  protected const float TARGETING_ANGLE_NORMAL = 30.0;
23  protected const float TARGETING_ANGLE_SPRINT = 15.0;
24  protected const float TARGETING_MIN_HEIGHT = -2.0;
25  protected const float TARGETING_MAX_HEIGHT = 2.0;
26  protected const float TARGETING_RAY_RADIUS_EX = 0.5;
27  protected const float TARGETING_RAY_RADIUS = 0.25;
28  protected const float TARGETING_RAY_DIST = 5.0;
29  protected const float TARGETING_RAY_DIST_SHORT= 2.0;
30 
31  protected const float RANGE_EXTENDER_NORMAL = 0.65;
32  protected const float RANGE_EXTENDER_SPRINT = 1.35;
33 
34  protected const string DEFAULT_HIT_ZONE = "Torso";
35 
37  protected ref MeleeTargeting m_MeleeTargeting;
38 
40  protected Object m_TargetObject;
43 
44  #ifdef DIAG_DEVELOPER
45  protected Object m_PreviousTargetObject;
46  protected ref array<Object> m_AllPreviousTargetObjects;
47  #endif
48 
52 
55 
57  protected InventoryItem m_Weapon;
58  protected int m_WeaponMode;
59  protected float m_WeaponRange;
60 
62  protected bool m_ForceUntargetable;
63  protected bool m_SprintAttack;
64  protected bool m_WasHit;
65 
66  protected vector m_RayStart;
67  protected vector m_RayEnd;
68  protected vector m_RayEndShort;
69 
71 
73  protected int m_HitZoneIdx;
74  protected int m_FinisherType;
75  protected string m_HitZoneName;
76  protected vector m_HitPositionWS;
77 
78  #ifdef DIAG_DEVELOPER
79  protected int m_PreviousHitZoneIdx;
80  protected string m_PreviousHitZoneName;
81  protected vector m_PreviousHitPositionWS;
82  #endif
83 
85 
86  // ------------------------------------------------------------
87  // CONSTRUCTOR
88  // ------------------------------------------------------------
89 
91  {
92  Init(player);
93  }
94 
96  {
97  m_DZPlayer = player;
98 
99  m_MeleeTargeting = new MeleeTargeting;
100 
101  m_HitZoneName = "";
102  m_HitZoneIdx = -1;
103  m_FinisherType = -1;
104  m_HitPositionWS = vector.Zero;
105 
106  m_SprintAttack = false;
107  m_WasHit = false;
108 
109  m_TargetObject = null;
110  m_TargetType = EMeleeTargetType.ALIGNABLE;
112  #ifdef DIAG_DEVELOPER
113  m_AllPreviousTargetObjects = new array<Object>;
114  #endif
115 
117 
118  m_TargetableObjects = new array<typename>; //checks against CONFIG hierarchy
122 
124  m_NonAlignableObjects.Insert(Building);
125  m_NonAlignableObjects.Insert(Car);
130 
132  m_BlacklistedDamageZones.Insert("Brain");
133  }
134 
136 
137  // ------------------------------------------------------------
138  // PUBLIC
139  // ------------------------------------------------------------
140 
142  {
143  return m_HitType;
144  }
145 
146  void SetHitZoneIdx(int pHitZone)
147  {
148  m_HitZoneIdx = pHitZone;
149  }
150 
152  {
153  return EntityAI.Cast(m_TargetObject);
154  }
155 
156  void SetTargetObject(Object pTarget)
157  {
158  m_TargetObject = pTarget;
159  }
160 
163  {
164  return m_HitZoneIdx;
165  }
166 
168  {
169  return m_HitPositionWS;
170  }
171 
172  void SetHitPos(vector pHitPos)
173  {
174  m_HitPositionWS = pHitPos;
175  }
176 
178  {
179  return m_FinisherType;
180  }
181 
182  void SetFinisherType(int pFinisherType)
183  {
184  m_FinisherType = pFinisherType;
185  }
186 
188  {
189  return m_WeaponMode;
190  }
191 
192  void Reset(InventoryItem weapon, EMeleeHitType hitMask, bool wasHitEvent = false)
193  {
194  m_Weapon = weapon;
195  m_HitType = hitMask;
196  m_TargetType = EMeleeTargetType.ALIGNABLE;
197  m_SprintAttack = hitMask == EMeleeHitType.SPRINT;
198  m_WeaponMode = SelectWeaponMode(weapon);
200  m_WasHit = wasHitEvent;
201 
202  #ifdef DIAG_DEVELOPER
203  m_AllPreviousTargetObjects = m_AllTargetObjects;
204  #endif
205  m_AllTargetObjects.Clear();
206  }
207 
208  void ResetTarget()
209  {
210  #ifdef DIAG_DEVELOPER
211  m_PreviousTargetObject = m_TargetObject;
212  m_PreviousHitPositionWS = m_HitPositionWS;
213  m_PreviousHitZoneIdx = m_HitZoneIdx;
214  m_PreviousHitZoneName = m_HitZoneName;
215  #endif
216 
218  }
219 
220  void Update(InventoryItem weapon, EMeleeHitType hitMask, bool wasHitEvent = false)
221  {
222  Reset(weapon, hitMask, wasHitEvent);
223 
224  #ifndef SERVER
225  if (!ScriptInputUserData.CanStoreInputUserData())
226  {
227  //Error("DayZPlayerImplementMeleeCombat - ScriptInputUserData already posted");
228  return;
229  }
230 
231  TargetSelection();
233 
235  if (GetGame().IsMultiplayer())
236  {
238  ctx.Write(INPUT_UDT_MELEE_TARGET);
239  ctx.Write(m_TargetObject);
240  ctx.Write(m_HitPositionWS);
241  ctx.Write(m_HitZoneIdx);
242  ctx.Write(m_FinisherType);
243  ctx.Send();
244  }
245  #endif
246  }
247 
249  {
250  if (m_Weapon)
251  {
252  ItemBase item = ItemBase.Cast(m_Weapon.ProcessMeleeItemDamage(GetWeaponMode()));
253 
254  if (item && item.GetHierarchyRootPlayer())
255  {
256  PlayerBase.Cast(item.GetHierarchyRootPlayer()).SetCheckMeleeItem(item);
257  }
258  else if (m_Weapon && m_Weapon.GetHierarchyRootPlayer())
259  {
260  PlayerBase.Cast(m_Weapon.GetHierarchyRootPlayer()).SetCheckMeleeItem(ItemBase.Cast(m_Weapon));
261  }
262  }
263  }
264 
265  // ------------------------------------------------------------
266  // protected
267  // ------------------------------------------------------------
268 
269  protected int SelectWeaponMode(InventoryItem weapon)
270  {
271  if (weapon)
272  {
274  if (weapon.IsInherited(Weapon))
275  {
276  switch (m_HitType)
277  {
278  case EMeleeHitType.WPN_HIT:
279  return 0;
280  case EMeleeHitType.WPN_HIT_BUTTSTOCK:
281  return 1;
282  case EMeleeHitType.WPN_STAB:
283  return 2;
284  }
285  }
286  else
287  {
289  switch (m_HitType)
290  {
291  case EMeleeHitType.LIGHT:
292  return weapon.GetMeleeMode();
293  case EMeleeHitType.HEAVY:
294  return weapon.GetMeleeHeavyMode();
295  case EMeleeHitType.SPRINT:
296  return weapon.GetMeleeSprintMode();
297  }
298  }
299  }
300 
302  switch (m_HitType)
303  {
304  case EMeleeHitType.HEAVY:
305  return 1;
306  case EMeleeHitType.SPRINT:
307  return 2;
308  }
309 
310  return 0;
311  }
312 
313  protected float GetWeaponRange(InventoryItem weapon, int weaponMode)
314  {
315  if ( weapon )
316  return weapon.GetMeleeCombatData().GetModeRange(weaponMode);
317  else
318  return m_DZPlayer.GetMeleeCombatData().GetModeRange(weaponMode);
319  }
320 
321  protected float GetRange()
322  {
324  }
325 
326  protected float GetAngle()
327  {
328  if (m_SprintAttack)
329  return TARGETING_ANGLE_SPRINT;
330  else
331  return TARGETING_ANGLE_NORMAL;
332  }
333 
334  protected void TargetSelection()
335  {
336  // Prepare common variables
337  PlayerBase player = PlayerBase.Cast(m_DZPlayer);
338  vector pos = m_DZPlayer.GetPosition();
339  vector rayStart = m_DZPlayer.GetBonePositionWS(m_DZPlayer.GetBoneIndexByName("Head"));
340 
341  vector cameraPos, cameraRot, cameraDir;
342  m_DZPlayer.GetCurrentCameraTransform(cameraPos, cameraDir, cameraRot);
343  vector dir = MiscGameplayFunctions.GetHeadingVector(player);
344  dir[1] = cameraDir[1];
345 
346  // Calculate max distances
347  float dist = GetRange();
348  float angle = GetAngle();
349  float dist2 = Math.SqrFloat(dist);
350 
351  // There's generally 2 TargetSelection calls per animation
352  // First to obtain target to move towards during animation
353  // Second one is to see if that target is still in range before applying damage to it
354  // m_WasHit means the hit event occured, so this is the second call
355 
356  if (m_WasHit && GetFinisherType() == -1)
357  {
358  // See if the component is still in range
359  if (CanObjectBeTargeted(m_TargetObject) && ( vector.DistanceSq(rayStart, m_TargetObject.GetDamageZonePos(m_HitZoneName)) <= dist2 ))
360  {
362  // This result should still be cached, so no need to fill it in again
363  return;
364  }
365  }
366 
367  // Find a new target
369 
370  Object target;
371  vector hitPos;
372  int hitZone;
373 
374  // First pass - Prefer what the player is looking at (only aligneable ones, we will try for nonaligneable later)
375  if (HitZoneSelectionRaycastHelper(hitPos, hitZone, target))
376  {
378  {
379  SetTarget(target, hitPos, hitZone);
380  return;
381  }
382 
383  if (CanObjectBeTargeted(target) && vector.DistanceSq(rayStart, hitPos) <= dist2)
384  {
385  m_AllTargetObjects.Insert(target);
386 
387  SetTarget(target, hitPos, hitZone);
388  return;
389  }
390  }
391 
392  // Second pass - Try to obtain something aligneable closeby the player watching direction
394 
395  if (targetData)
396  {
397  SetTarget(targetData.Obj, targetData.HitPos, targetData.HitComponent);
398  return;
399  }
400 
401  // Third pass - We found no aligneable target, check if the target that we are directly looking at is nonalignable (big)
402  if (CanObjectBeTargeted(target, true) && vector.DistanceSq(rayStart, hitPos) <= dist2)
403  {
404  m_AllTargetObjects.Insert(target);
405 
406  SetTarget(target, hitPos, hitZone);
407  return;
408  }
409  }
410 
417  protected int TrySelectFinisherType(InventoryItem weapon, EntityAI target)
418  {
419  if (m_WasHit)
420  return -1;
421 
422  if (target)
423  {
424  vector dir = target.GetPosition() - m_DZPlayer.GetPosition();
425 
426  IEntity hitEntity;
427  vector hitPos, hitNormal;
428 
429  float moveFraction = m_DZPlayer.CollisionMoveTest(dir, vector.Zero, 1.0, target, hitEntity, hitPos, hitNormal);
430  if (moveFraction < 1.0)
431  return -1;
432  }
433 
435  if (target && target.CanBeBackstabbed() && weapon && (weapon.IsMeleeFinisher() || m_HitType == EMeleeHitType.WPN_STAB) && !weapon.IsRuined() )
436  {
437  bool playGenericFinisherAnimation = false;
438  ZombieBase targetZombie = ZombieBase.Cast(target);
439  if (targetZombie && m_DebugForcedFinisherType == -1)
440  {
442  if (!IsEntityBehindEntityInAngle(m_DZPlayer, target, 60))
443  {
444  return -1;
445  }
446 
447  int mindState = targetZombie.GetMindStateSynced();
449  if (mindState >= DayZInfectedConstants.MINDSTATE_DISTURBED)
450  {
451  return -1;
452  }
453  }
454 
455  PlayerBase targetPlayer = PlayerBase.Cast(target);
457  if (targetZombie)
458  {
459  playGenericFinisherAnimation = targetZombie.IsCrawling();
460  }
461  else if (targetPlayer)
462  {
463  playGenericFinisherAnimation = targetPlayer.IsInProne();
464  }
465  else
466  {
467  playGenericFinisherAnimation = true;
468  }
469 
471  if (weapon.IsWeapon())
472  {
473  return EMeleeHitType.WPN_STAB_FINISHER;
474  }
475  else if (playGenericFinisherAnimation)
476  {
477  return EMeleeHitType.FINISHER_GENERIC;
478  }
479  else //specific hit depending on the component hit (gotten from the target)
480  {
481  return DetermineSpecificFinisherType(ItemBase.Cast(weapon));
482  }
483  }
484 
485  return -1;
486  }
487 
489  {
490  if (m_DebugForcedFinisherType > -1)
491  {
492  array<int> finishers = {
493  EMeleeHitType.FINISHER_LIVERSTAB,
494  EMeleeHitType.FINISHER_NECKSTAB
495  };
496 
497  return finishers[m_DebugForcedFinisherType];
498  }
499 
500  if (!weapon || !weapon.GetValidFinishers() || weapon.GetValidFinishers().Count() == 0)
501  {
502  return EMeleeHitType.FINISHER_LIVERSTAB;
503  }
504 
505  PlayerBase player = PlayerBase.Cast(m_DZPlayer);
506  int idx = Math.Round(Math.Lerp(0, weapon.GetValidFinishers().Count() - 1, player.GetRandomGeneratorSyncManager().GetRandom01(RandomGeneratorSyncUsage.RGSGeneric)));
507  return weapon.GetValidFinishers()[idx];
508  }
509 
510  protected void InternalResetTarget()
511  {
512  m_TargetObject = null;
513  m_HitPositionWS = vector.Zero;
514  m_HitZoneIdx = -1;
515  m_HitZoneName = "";
516  SetFinisherType(-1);
517  }
518 
519  protected void SetTarget(Object obj, vector hitPos, int hitZone)
520  {
521  if (obj)
522  {
523  m_TargetObject = obj;
524  m_HitPositionWS = hitPos;
525  m_HitZoneIdx = hitZone;
526  m_HitZoneName = m_TargetObject.GetDamageZoneNameByComponentIndex(m_HitZoneIdx);
527  }
528  }
529 
530  protected bool CanObjectBeTargeted(Object obj, bool checkNonAligneAble = false)
531  {
532  return obj && obj.IsAlive() && ( obj.IsAnyInherited(m_TargetableObjects) || (checkNonAligneAble && obj.IsAnyInherited(m_NonAlignableObjects)) );
533  }
534 
535  protected bool HitZoneSelectionRaycastHelper(out vector hitPos, out int hitZone, out Object target)
536  {
537  return HitZoneSelectionRaycast(hitPos, hitZone, target, false);
538  // Not sure if desired, as it can give some results that feel a little odd
539  // But it will depend entirely on the player and situation..
540  // I guess the crosshair is hidden while melee anyways though
541  // || ( m_DZPlayer.IsInThirdPerson() && HitZoneSelectionRaycast(hitPos, hitZone, target, true);
542  }
543 
544  protected bool HitZoneSelectionRaycast(out vector hitPos, out int hitZone, out Object target, bool useCamera)
545  {
546  PlayerBase player = PlayerBase.Cast(m_DZPlayer);
547 
548  vector pos;
549  vector dir;
550  vector playerDir;
551  if (useCamera)
552  { // What the player camera is looking at (crosshair)
553  vector cameraRotation;
554  player.GetCurrentCameraTransform(pos, dir, cameraRotation);
555  playerDir = dir;
556  }
557  else
558  { // What the player himself is looking at
559  playerDir = MiscGameplayFunctions.GetHeadingVector(player);
560  dir = GetGame().GetCurrentCameraDirection();
561  MiscGameplayFunctions.GetHeadBonePos(player, pos);
562  }
563 
565  if (vector.Dot(dir, playerDir) < 0.5)
566  {
567  return false;
568  }
569 
570  m_RayStart = pos;
571  m_RayEnd = m_RayStart + GetRange() * dir;
572 
573  // raycast
574  set<Object> hitObjects = new set<Object>;
575  vector hitNormal;
576 
577  if ( DayZPhysics.RaycastRV(m_RayStart, m_RayEnd, hitPos, hitNormal, hitZone, hitObjects, null, player, false, false, ObjIntersectIFire) && hitObjects.Count() > 0 )
578  {
579  target = hitObjects[0];
580  m_ForceUntargetable = false;
581 
583  PlayerBase playerTarget = PlayerBase.Cast(target);
584  if (playerTarget && playerTarget.IsInVehicle())
585  {
586  if (vector.DistanceSq(pos, hitPos) > Math.SqrFloat(GetRange() * 0.5))
587  {
588  m_ForceUntargetable = true;
589  target = null;
590  hitPos = vector.Zero;
591  hitZone = -1;
592  }
593  }
594 
595  return true;
596  }
597 
598  return false;
599  }
600 
602  protected void HitZoneSelection()
603  {
604  Object cursorTarget = null;
605  PlayerBase player = PlayerBase.Cast(m_DZPlayer);
606 
607  // ray properties
608  vector pos;
609  vector cameraDirection = GetGame().GetCurrentCameraDirection();
610 
611  MiscGameplayFunctions.GetHeadBonePos(player, pos);
612  m_RayStart = pos;
613  m_RayEnd = pos + cameraDirection * TARGETING_RAY_DIST;
614  m_RayEndShort = pos + cameraDirection * TARGETING_RAY_DIST_SHORT;
615 
616  // raycast
617  set<Object> hitObjects = new set<Object>;
618  int hitComponentIndex;
619  float hitFraction;
620  vector start, end, hitNormal, hitPosObstructed;
621  PhxInteractionLayers collisionLayerMask = PhxInteractionLayers.DEFAULT;
622 
623  if ( !DayZPhysics.RaycastRV(m_RayStart, m_RayEndShort, m_HitPositionWS, hitNormal, m_HitZoneIdx, hitObjects, null, player, false, false, ObjIntersectIFire) && !DayZPhysics.RaycastRV(m_RayStart, m_RayEnd, m_HitPositionWS, hitNormal, m_HitZoneIdx, hitObjects, null, player, false, false, ObjIntersectIFire, TARGETING_RAY_RADIUS) )
624  {
625  m_HitZoneIdx = -1;
626  //Print("HitZoneSelection failed");
627  }
628  else if ( hitObjects.Count() > 0 )
629  {
630  cursorTarget = hitObjects.Get(0);
631 
633  vector playerPos = m_DZPlayer.GetPosition();
634  vector hitPos = m_HitPositionWS;
636  playerPos[1] = 0;
637  hitPos[1] = 0;
638 
640  if ( cursorTarget.IsAnyInherited(m_NonAlignableObjects) && vector.Distance(playerPos, hitPos) <= GetWeaponRange(m_Weapon, GetWeaponMode()))
641  {
643  if (m_TargetObject == null)
644  {
645  m_TargetObject = cursorTarget;
646  }
647  }
648 
649  if (cursorTarget == m_TargetObject)
650  {
651  m_HitZoneName = cursorTarget.GetDamageZoneNameByComponentIndex(m_HitZoneIdx);
652  //Print("hit object: " + m_TargetObject + " | component idx: " + m_HitZoneIdx + " | hitzone name: " + m_HitZoneName);
653  }
654  else
655  {
657  m_HitZoneName = DEFAULT_HIT_ZONE; //Default to torso if no zone is targeted
658  }
659  }
660  else
661  {
662  m_HitZoneIdx = -1;
663  //Print("HitZoneSelection failed");
664  }
665  }
666 
668  protected bool IsObstructed(Object object)
669  {
670  // check direct visibility of object (obstruction check)
672  int hitComponentIndex;
673  float hitFraction;
674  vector start, end, hitNormal, hitPosObstructed;
675  Object hitObject = null;
676  PlayerBase player = PlayerBase.Cast(m_DZPlayer);
677 
678  if (object)
679  {
680  MiscGameplayFunctions.GetHeadBonePos(player, start);
681  end = start + MiscGameplayFunctions.GetHeadingVector(player) * vector.Distance(player.GetPosition(), object.GetPosition());
682 
683  if ( end == start )
684  return true;
685 
686  return DayZPhysics.RayCastBullet( start, end, collisionLayerMask, null, hitObject, hitPosObstructed, hitNormal, hitFraction);
687  }
688 
689  return false;
690  }
691 
692  private bool IsEntityBehindEntityInAngle(EntityAI source, EntityAI target, float angle)
693  {
694  vector targetDirection = target.GetDirection();
695  ZombieBase targetZombie;
696  if (Class.CastTo(targetZombie, target))
697  {
698  targetDirection = Vector(targetZombie.GetOrientationSynced(),0,0);
699  targetDirection = targetDirection.AnglesToVector();
700  }
701  vector toSourceDirection = (source.GetPosition() - target.GetPosition());
702 
703  targetDirection[1] = 0;
704  toSourceDirection[1] = 0;
705 
706  targetDirection.Normalize();
707  toSourceDirection.Normalize();
708 
709  float cosFi = vector.Dot(targetDirection, toSourceDirection);
710  vector cross = targetDirection * toSourceDirection;
711 
712  int hitDir = Math.Acos(cosFi) * Math.RAD2DEG;
713 
714  if (cross[1] < 0)
715  hitDir = -hitDir;
716 
717  return hitDir <= (-180 + angle) || hitDir >= (180 - angle);
718  }
719 
720 #ifdef DIAG_DEVELOPER
721  // ------------------------------------------------------------
722  // DEBUG
723  // ------------------------------------------------------------
724  protected ref array<Shape> dbgConeShapes = new array<Shape>();
725  protected ref array<Shape> dbgTargets = new array<Shape>();
726  protected ref array<Shape> hitPosShapes = new array<Shape>();
727 
728  void Debug(InventoryItem weapon, EMeleeHitType hitType)
729  {
730  CleanAllDebugShapes();
731 
732  if (!DiagMenu.GetBool(DiagMenuIDs.MELEE_DEBUG))
733  return;
734 
735  if (DiagMenu.GetBool(DiagMenuIDs.MELEE_CONTINUOUS) && (!GetGame().IsMultiplayer() || !GetGame().IsServer()))
736  Update(weapon, hitType);
737 
738  if (DiagMenu.GetBool(DiagMenuIDs.MELEE_SHOW_TARGETS))
739  ShowDebugMeleeTarget();
740 
741  if (DiagMenu.GetBool(DiagMenuIDs.MELEE_DRAW_TARGETS))
742  DrawDebugTargets();
743 
744  if (DiagMenu.GetBool(DiagMenuIDs.MELEE_DRAW_RANGE))
745  {
746  DrawDebugMeleeHitPosition();
747  DrawDebugMeleeCone();
748  }
749 
750  if (DiagMenu.GetBool(DiagMenuIDs.MELEE_DRAW_BLOCK_RANGE_AI))
751  DrawDebugBlockCone(GameConstants.AI_MAX_BLOCKABLE_ANGLE, COLOR_GREEN);
752 
753  if (DiagMenu.GetBool(DiagMenuIDs.MELEE_DRAW_BLOCK_RANGE_PVP))
754  DrawDebugBlockCone(GameConstants.PVP_MAX_BLOCKABLE_ANGLE, COLOR_YELLOW);
755  }
756 
757  int DebugGetForcedFinisherType()
758  {
760  }
761 
762  void DebugSetForcedFinisherType(int pFinisherType)
763  {
764  m_DebugForcedFinisherType = pFinisherType;
765  }
766 
768  protected void ShowDebugMeleeTarget()
769  {
770  int windowPosX = 0;
771  int windowPosY = 500;
772 
773  DbgUI.Begin("Melee Target", windowPosX, windowPosY);
774  HumanCommandMelee2 hmc2 = m_DZPlayer.GetCommand_Melee2();
775  if (hmc2)
776  {
777  DbgUI.Text("Current combo: " + hmc2.GetComboCount());
778  }
779 
780  if (m_PreviousTargetObject)
781  {
782  DbgUI.Text("Previous Character: " + m_PreviousTargetObject.GetDisplayName());
783  DbgUI.Text("Previous HitZone: " + m_PreviousHitZoneName + "(" + m_PreviousHitZoneIdx + ")");
784  DbgUI.Text("Previous HitPosWS:" + m_PreviousHitPositionWS);
785  DbgUI.Text("Previous Distance:" + vector.Distance(m_PreviousHitPositionWS, m_DZPlayer.GetPosition()));
786  }
787 
788  if (m_TargetObject)
789  {
790  DbgUI.Text("Character: " + m_TargetObject.GetDisplayName());
791  DbgUI.Text("HitZone: " + m_HitZoneName + "(" + m_HitZoneIdx + ")");
792  DbgUI.Text("HitPosWS:" + m_HitPositionWS);
793  DbgUI.Text("Distance:" + vector.Distance(m_HitPositionWS, m_DZPlayer.GetPosition()));
794  }
795  DbgUI.End();
796  }
797 
799  protected void DrawDebugTargets()
800  {
801  DrawDebugTargetsHelper(m_AllPreviousTargetObjects, m_PreviousTargetObject, COLOR_RED_A, COLOR_YELLOW_A);
802  DrawDebugTargetsHelper(m_AllTargetObjects, m_TargetObject, COLOR_RED, COLOR_YELLOW);
803  }
804 
805  protected void DrawDebugTargetsHelper(array<Object> allTargets, Object target, int colorMainTarget, int colorTarget)
806  {
807  for (int i = 0; i < allTargets.Count(); ++i )
808  {
809  if ( m_TargetObject && allTargets.Count() )
810  {
811  Object obj = allTargets[i];
812  vector w_pos = obj.GetPosition();
813  // sphere pos tweaks
814  vector w_pos_sphr = w_pos;
815  w_pos_sphr[1] = w_pos_sphr[1] + 1.8;
816  // line pos tweaks
817  vector w_pos_lend = w_pos;
818  w_pos_lend[1] = w_pos_lend[1] + 1.8;
819 
820  if ( obj == m_TargetObject )
821  {
822  dbgTargets.Insert( Debug.DrawSphere(w_pos_sphr, 0.05, colorMainTarget, ShapeFlags.NOOUTLINE) );
823  dbgTargets.Insert( Debug.DrawLine(w_pos, w_pos_lend, colorMainTarget) );
824  }
825  else
826  {
827  dbgTargets.Insert( Debug.DrawSphere(w_pos_sphr, 0.05, colorTarget, ShapeFlags.NOOUTLINE) );
828  dbgTargets.Insert( Debug.DrawLine(w_pos, w_pos_lend, colorTarget) );
829  }
830  }
831  }
832  }
833 
834  protected void DrawDebugMeleeHitPosition()
835  {
836  if (m_PreviousTargetObject)
837  hitPosShapes.Insert( Debug.DrawSphere(m_PreviousHitPositionWS, 0.15, COLOR_YELLOW_A, ShapeFlags.NOOUTLINE|ShapeFlags.TRANSP) );
838 
839  if (m_TargetObject)
840  hitPosShapes.Insert( Debug.DrawSphere(m_HitPositionWS, 0.15, COLOR_YELLOW, ShapeFlags.NOOUTLINE|ShapeFlags.TRANSP) );
841  }
842 
843  protected void DrawDebugMeleeCone()
844  {
845  // cone settings
846  float dist = GetRange();
847  vector start = m_DZPlayer.GetPosition();
848 
849  vector normDir = MiscGameplayFunctions.GetHeadingVector(PlayerBase.Cast(m_DZPlayer));
850  normDir[1] = 0;
851  normDir.Normalize();
852  float playerAngle = -Math.Atan2(normDir[0], normDir[2]);
853 
854  dbgConeShapes.InsertArray(Debug.DrawCone(start, dist, GetAngle() * Math.DEG2RAD, playerAngle + Math.PI_HALF, COLOR_BLUE));
855  }
856 
857  protected void DrawDebugBlockCone(float angle, int color)
858  {
859  // cone settings
860  float dist = 3;
861  vector start = m_DZPlayer.GetPosition();
862 
863  vector dir = GetGame().GetCurrentCameraDirection();
864  dir[1] = 0;
865  dir.Normalize();
866  float playerAngle = -Math.Atan2(dir[0], dir[2]);
867 
868  dbgConeShapes.InsertArray(Debug.DrawCone(start, dist, angle * Math.DEG2RAD, playerAngle + Math.PI_HALF, color));
869  }
870 
871  protected void CleanAllDebugShapes()
872  {
873  CleanupDebugShapes(dbgTargets);
874  CleanupDebugShapes(dbgConeShapes);
875  CleanupDebugShapes(hitPosShapes);
876  }
877 
878  protected void CleanupDebugShapes(array<Shape> shapes)
879  {
880  for ( int it = 0; it < shapes.Count(); ++it )
881  Debug.RemoveShape( shapes[it] );
882 
883  shapes.Clear();
884  }
885 #endif
886 }
ItemBase
Definition: inventoryitem.c:730
GetHitPos
vector GetHitPos()
Definition: dayzplayerimplementmeleecombat.c:167
GetGame
proto native CGame GetGame()
TARGETING_ANGLE_SPRINT
const protected float TARGETING_ANGLE_SPRINT
Second Pass: Half angle of cone during sprint.
Definition: dayzplayerimplementmeleecombat.c:23
CarDoor
Definition: inventoryitem.c:496
TARGETING_MAX_HEIGHT
const protected float TARGETING_MAX_HEIGHT
Second Pass: How high the cone goes in meters from player position.
Definition: dayzplayerimplementmeleecombat.c:25
WPN_STAB
@ WPN_STAB
Definition: dayzplayerimplementmeleecombat.c:15
CheckMeleeItem
void CheckMeleeItem()
Definition: dayzplayerimplementmeleecombat.c:248
CanObjectBeTargeted
protected bool CanObjectBeTargeted(Object obj, bool checkNonAligneAble=false)
Definition: dayzplayerimplementmeleecombat.c:530
MeleeTargetSettings
ref array< typename > TargetableObjects void MeleeTargetSettings(vector coneOrigin, float coneLength, float coneHalfAngle, float coneMinHeight, float coneMaxHeight, vector rayStart, vector dir, float maxDist, EntityAI pToIgnore, array< typename > targetableObjects)
Definition: meleetargeting.c:36
HitZoneSelectionRaycastHelper
protected bool HitZoneSelectionRaycastHelper(out vector hitPos, out int hitZone, out Object target)
Definition: dayzplayerimplementmeleecombat.c:535
SPRINT
@ SPRINT
Definition: dayzplayerimplementmeleecombat.c:7
DbgUI
Definition: dbgui.c:59
FINISHER_GENERIC
@ FINISHER_GENERIC
Definition: dayzplayerimplementmeleecombat.c:11
WPN_HIT
@ WPN_HIT
Definition: dayzplayerimplementmeleecombat.c:13
DiagMenu
Definition: endebug.c:232
TARGETING_RAY_RADIUS
const protected float TARGETING_RAY_RADIUS
DEPRECATED: "HitZoneSelection".
Definition: dayzplayerimplementmeleecombat.c:27
Update
void Update(InventoryItem weapon, EMeleeHitType hitMask, bool wasHitEvent=false)
Definition: dayzplayerimplementmeleecombat.c:220
Reset
void Reset(InventoryItem weapon, EMeleeHitType hitMask, bool wasHitEvent=false)
Definition: dayzplayerimplementmeleecombat.c:192
HumanCommandMelee2
Definition: human.c:536
TARGETING_RAY_DIST_SHORT
const protected float TARGETING_RAY_DIST_SHORT
DEPRECATED: "HitZoneSelection".
Definition: dayzplayerimplementmeleecombat.c:29
ScriptInputUserData
Definition: gameplay.c:120
TARGETING_MIN_HEIGHT
const protected float TARGETING_MIN_HEIGHT
Second Pass: How deep the cone goes in meters from player position.
Definition: dayzplayerimplementmeleecombat.c:24
RANGE_EXTENDER_SPRINT
const protected float RANGE_EXTENDER_SPRINT
General range extension while in sprint.
Definition: dayzplayerimplementmeleecombat.c:32
m_RayEnd
protected vector m_RayEnd
End position of most recent HitZoneSelectionRaycast.
Definition: dayzplayerimplementmeleecombat.c:67
TARGETING_RAY_RADIUS_EX
const protected float TARGETING_RAY_RADIUS_EX
Second Pass: Max distance from ray projected from player looking direction.
Definition: dayzplayerimplementmeleecombat.c:26
Weapon
script counterpart to engine's class Weapon
Definition: inventoryitem.c:48
SetTargetObject
void SetTargetObject(Object pTarget)
Definition: dayzplayerimplementmeleecombat.c:156
InternalResetTarget
protected void InternalResetTarget()
Definition: dayzplayerimplementmeleecombat.c:510
m_HitZoneIdx
protected int m_HitZoneIdx
Hit result - cache.
Definition: dayzplayerimplementmeleecombat.c:73
FINISHER_LIVERSTAB
@ FINISHER_LIVERSTAB
Definition: dayzplayerimplementmeleecombat.c:9
GetWeaponMode
int GetWeaponMode()
Definition: dayzplayerimplementmeleecombat.c:187
KICK
@ KICK
Definition: dayzplayerimplementmeleecombat.c:8
m_HitZoneName
protected string m_HitZoneName
Most recent target HitZone name.
Definition: dayzplayerimplementmeleecombat.c:75
TARGETING_ANGLE_NORMAL
enum EMeleeHitType TARGETING_ANGLE_NORMAL
Target selection settings.
DayZPlayerImplementMeleeCombat
void DayZPlayerImplementMeleeCombat(DayZPlayerImplement player)
Definition: dayzplayerimplementmeleecombat.c:90
COLOR_YELLOW_A
const int COLOR_YELLOW_A
Definition: constants.c:72
DayZInfected
Definition: zombiebase.c:1
~DayZPlayerImplementMeleeCombat
void ~DayZPlayerImplementMeleeCombat()
Definition: dayzplayerimplementmeleecombat.c:135
m_DZPlayer
protected DayZPlayerImplement m_DZPlayer
Parent.
Definition: dayzplayerimplementmeleecombat.c:54
COLOR_RED_A
const int COLOR_RED_A
Definition: constants.c:69
COLOR_YELLOW
const int COLOR_YELLOW
Definition: constants.c:67
SetTarget
protected void SetTarget(Object obj, vector hitPos, int hitZone)
Definition: dayzplayerimplementmeleecombat.c:519
WPN_STAB_FINISHER
@ WPN_STAB_FINISHER
Definition: dayzplayerimplementmeleecombat.c:16
TargetSelection
protected void TargetSelection()
Definition: dayzplayerimplementmeleecombat.c:334
InventoryItem
Definition: itembase.c:13
TARGETING_RAY_DIST
const protected float TARGETING_RAY_DIST
DEPRECATED: "HitZoneSelection".
Definition: dayzplayerimplementmeleecombat.c:28
DayZPlayer
Definition: dayzplayerimplement.c:72
IEntity
Definition: enentity.c:164
m_Weapon
protected InventoryItem m_Weapon
Weapons - cache.
Definition: dayzplayerimplementmeleecombat.c:57
m_MeleeTargeting
protected ref MeleeTargeting m_MeleeTargeting
Target selecting "component".
Definition: dayzplayerimplementmeleecombat.c:37
DEFAULT_HIT_ZONE
const protected string DEFAULT_HIT_ZONE
DEPRECATED: "HitZoneSelection".
Definition: dayzplayerimplementmeleecombat.c:34
DiagMenuIDs
DiagMenuIDs
Definition: ediagmenuids.c:1
RandomGeneratorSyncUsage
RandomGeneratorSyncUsage
Definition: randomgeneratorsyncmanager.c:1
TrySelectFinisherType
protected int TrySelectFinisherType(InventoryItem weapon, EntityAI target)
General condition for finisher attacks.
Definition: dayzplayerimplementmeleecombat.c:417
WPN_HIT_BUTTSTOCK
@ WPN_HIT_BUTTSTOCK
Definition: dayzplayerimplementmeleecombat.c:14
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
HitZoneSelectionRaycast
protected bool HitZoneSelectionRaycast(out vector hitPos, out int hitZone, out Object target, bool useCamera)
Definition: dayzplayerimplementmeleecombat.c:544
FINISHER_NECKSTAB
@ FINISHER_NECKSTAB
Definition: dayzplayerimplementmeleecombat.c:10
BaseBuildingBase
Definition: fence.c:1
windowPosX
class PresenceNotifierNoiseEvents windowPosX
dbgUI settings
windowPosY
const int windowPosY
Definition: pluginpresencenotifier.c:80
m_WasHit
protected bool m_WasHit
If most recent attack was.
Definition: dayzplayerimplementmeleecombat.c:64
m_WeaponMode
protected int m_WeaponMode
WeaponMode used during most recent Update.
Definition: dayzplayerimplementmeleecombat.c:58
ShapeFlags
ShapeFlags
Definition: endebug.c:125
m_DebugForcedFinisherType
private int m_DebugForcedFinisherType
Definition: dayzplayerimplementmeleecombat.c:84
m_TargetObject
protected Object m_TargetObject
Targets - types.
Definition: dayzplayerimplementmeleecombat.c:40
Object
Definition: objecttyped.c:1
GetAngle
protected float GetAngle()
Definition: dayzplayerimplementmeleecombat.c:326
CarWheel
Definition: inventoryitem.c:413
DayZInfectedConstants
DayZInfectedConstants
Definition: dayzinfected.c:1
m_FinisherType
protected int m_FinisherType
Definition: dayzplayerimplementmeleecombat.c:74
COLOR_GREEN
const int COLOR_GREEN
Definition: constants.c:65
m_RayStart
protected vector m_RayStart
Start position of most recent HitZoneSelectionRaycast.
Definition: dayzplayerimplementmeleecombat.c:66
TentBase
Definition: cartent.c:1
DayZPlayerImplement
Definition: manbase.c:1
GetHitZoneIdx
int GetHitZoneIdx()
component idx
Definition: dayzplayerimplementmeleecombat.c:162
MeleeTargetData
Definition: meleetargeting.c:1
COLOR_RED
const int COLOR_RED
Definition: constants.c:64
DetermineSpecificFinisherType
protected int DetermineSpecificFinisherType(ItemBase weapon)
Definition: dayzplayerimplementmeleecombat.c:488
HEAVY
@ HEAVY
Definition: dayzplayerimplementmeleecombat.c:6
m_BlacklistedDamageZones
protected ref array< string > m_BlacklistedDamageZones
List of blacklisted damage zone names (cannot use indices due to the possible changes when p3d compon...
Definition: dayzplayerimplementmeleecombat.c:51
INPUT_UDT_MELEE_TARGET
const int INPUT_UDT_MELEE_TARGET
Definition: _constants.c:6
EMeleeHitType
EMeleeHitType
Definition: dayzplayerimplementmeleecombat.c:1
m_TargetType
protected EMeleeTargetType m_TargetType
DEPRECATED: Was added but never used..?
Definition: dayzplayerimplementmeleecombat.c:41
SetFinisherType
void SetFinisherType(int pFinisherType)
Definition: dayzplayerimplementmeleecombat.c:182
array< Object >
m_HitType
protected EMeleeHitType m_HitType
Hit type of the most recent attack.
Definition: dayzplayerimplementmeleecombat.c:70
GetFinisherType
int GetFinisherType()
Definition: dayzplayerimplementmeleecombat.c:177
IsEntityBehindEntityInAngle
private bool IsEntityBehindEntityInAngle(EntityAI source, EntityAI target, float angle)
Definition: dayzplayerimplementmeleecombat.c:692
m_NonAlignableObjects
protected ref array< typename > m_NonAlignableObjects
Typenames of objects that can be targeted, but are not a priority (3rd Pass)
Definition: dayzplayerimplementmeleecombat.c:50
GetRange
protected float GetRange()
Definition: dayzplayerimplementmeleecombat.c:321
m_TargetableObjects
protected ref array< typename > m_TargetableObjects
Typenames of all directly/preferred targetable objects (1st Pass + 2nd Pass)
Definition: dayzplayerimplementmeleecombat.c:49
GetWeaponRange
protected float GetWeaponRange(InventoryItem weapon, int weaponMode)
Definition: dayzplayerimplementmeleecombat.c:313
m_SprintAttack
protected bool m_SprintAttack
If most recent attack was a sprint attack.
Definition: dayzplayerimplementmeleecombat.c:63
Init
void Init(DayZPlayerImplement player)
Definition: dayzplayerimplementmeleecombat.c:95
NONE
@ NONE
Definition: dayzplayerimplementmeleecombat.c:3
GameConstants
Definition: constants.c:612
Debug
Definition: debug.c:13
DayZPhysics
Definition: dayzphysics.c:123
m_RayEndShort
protected vector m_RayEndShort
DEPRECATED: "HitZoneSelection".
Definition: dayzplayerimplementmeleecombat.c:68
GetHitType
EMeleeHitType GetHitType()
Definition: dayzplayerimplementmeleecombat.c:141
m_WeaponRange
protected float m_WeaponRange
WeaponRange used during most recent Update.
Definition: dayzplayerimplementmeleecombat.c:59
m_ForceUntargetable
protected bool m_ForceUntargetable
Misc - cache.
Definition: dayzplayerimplementmeleecombat.c:62
HitZoneSelection
protected void HitZoneSelection()
DEPRECATED.
Definition: dayzplayerimplementmeleecombat.c:602
Debug
void Debug()
Definition: universaltemperaturesource.c:297
SetHitZoneIdx
void SetHitZoneIdx(int pHitZone)
Definition: dayzplayerimplementmeleecombat.c:146
m_AllTargetObjects
protected ref array< Object > m_AllTargetObjects
All potential targets found during most recent TargetSelection.
Definition: dayzplayerimplementmeleecombat.c:42
RANGE_EXTENDER_NORMAL
const protected float RANGE_EXTENDER_NORMAL
General range extension.
Definition: dayzplayerimplementmeleecombat.c:31
IsObstructed
protected bool IsObstructed(Object object)
DEPRECATED - New function in MeleeTargeting.
Definition: dayzplayerimplementmeleecombat.c:668
Math
Definition: enmath.c:6
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
COLOR_BLUE
const int COLOR_BLUE
Definition: constants.c:66
SelectWeaponMode
protected int SelectWeaponMode(InventoryItem weapon)
Definition: dayzplayerimplementmeleecombat.c:269
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
ResetTarget
void ResetTarget()
Definition: dayzplayerimplementmeleecombat.c:208
LIGHT
@ LIGHT
Definition: dayzplayerimplementmeleecombat.c:5
ZombieBase
Definition: zombiefemalebase.c:1
EntityAI
Definition: building.c:5
m_HitPositionWS
protected vector m_HitPositionWS
Most recent target position.
Definition: dayzplayerimplementmeleecombat.c:76
PhxInteractionLayers
PhxInteractionLayers
Definition: dayzphysics.c:1
GetTargetEntity
EntityAI GetTargetEntity()
Definition: dayzplayerimplementmeleecombat.c:151
EMeleeTargetType
EMeleeTargetType
Definition: emeleetargettype.c:1
DayZAnimal
Definition: animalbase.c:1
SetHitPos
void SetHitPos(vector pHitPos)
Definition: dayzplayerimplementmeleecombat.c:172