Files
Arena/Assets/_Content/Scripts/Combat/DamageInfo.cs
2026-11-05 08:59:08 +01:00

49 lines
1.4 KiB
C#

using UnityEngine;
namespace Arena.Combat
{
/// <summary>
/// Everything a hit carries: amount, type, source and targeted team. Passed to IDamageable.TakeDamage.
/// </summary>
public readonly struct DamageInfo
{
public readonly int Amount;
public readonly DamageType Type;
/// <summary>
/// Object that dealt the damage: shooter, damage zone... Can be null.
/// </summary>
public readonly GameObject Source;
/// <summary>
/// Team hurt by this damage: Allied for enemy shots, Enemy for player shots, All for everyone.
/// </summary>
public readonly Team Target;
public DamageInfo(int amount, DamageType type, GameObject source = null, Team target = Team.All)
{
Amount = amount;
Type = type;
Source = source;
Target = target;
}
/// <summary>
/// True if this damage can hurt an IDamageable of the given team.
/// </summary>
public bool CanHit(Team team)
{
return CanHit(Target, team);
}
/// <summary>
/// True if a damage targeting a team can hurt an IDamageable of another team.
/// </summary>
public static bool CanHit(Team target, Team team)
{
return target == Team.All || team == Team.All || team == target;
}
}
}