// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) VRMADA, All rights reserved.
//
// --------------------------------------------------------------------------------------------------------------------
using System;
using UnityEngine;
namespace UltimateXR.Mechanics.Weapons
{
///
/// Damage event parameters.
///
public class UxrDamageEventArgs : EventArgs
{
#region Public Types & Data
///
/// Gets the type of damage.
///
public UxrDamageType DamageType { get; }
///
/// Gets the actor that inflicted the damage, or null if the damage didn't come from any specific actor.
///
public UxrActor ActorSource { get; }
///
/// Gets the actor that received the damage.
///
public UxrActor ActorTarget { get; }
///
/// Gets the raycast information for projectile hits. Only valid if is
/// .
///
public RaycastHit RaycastHit { get; }
///
/// Gets the source position for explosive damage. Only valid if is
///
///
public Vector3 ExplosionPosition { get; }
///
/// Gets the amount of damage taken/inflicted.
///
public float Damage { get; }
///
/// Gets whether the damage will result in the death of the receiving actor.
///
public bool Dies { get; }
///
/// Gets if the damage was canceled for damage pre-events. Damage post-events cannot be canceled since the damage was
/// already inflicted.
///
public bool IsCanceled { get; private set; }
#endregion
#region Constructors & Finalizer
///
/// Constructor for projectile damage.
///
/// Source actor
/// Target actor
/// Raycast hit
/// Damage amount
/// Whether the damage results in death
public UxrDamageEventArgs(UxrActor source, UxrActor target, RaycastHit raycastHit, float damage, bool dies)
{
DamageType = UxrDamageType.ProjectileHit;
ActorSource = source;
ActorTarget = target;
RaycastHit = raycastHit;
Damage = damage;
Dies = dies;
}
///
/// Constructor for explosive damage.
///
/// Source actor or null if the damage didn't come from another actor
/// Target actor
/// Explosion world position
/// Damage amount
/// Whether the damage results in death
public UxrDamageEventArgs(UxrActor source, UxrActor target, Vector3 explosionPosition, float damage, bool dies)
{
DamageType = UxrDamageType.Explosive;
ActorSource = source;
ActorTarget = target;
ExplosionPosition = explosionPosition;
Damage = damage;
Dies = dies;
}
///
/// Constructor for generic damage.
///
/// Damage amount
/// Whether the damage results in death
public UxrDamageEventArgs(float damage, bool dies)
{
DamageType = UxrDamageType.Other;
Damage = damage;
Dies = dies;
}
#endregion
#region Public Methods
///
/// Allows pre-events to cancel the damage. post-events can not be cancelled since the damage was already taken.
///
public void Cancel()
{
IsCanceled = true;
}
#endregion
}
}