An extended DamageInfo class that inherits Sandbox.DamageInfo and adds SWB-specific fields and factory methods. It stores Inflictor, Force, HitFlinch, MovementImpact, Extra dictionary, and provides FromBullet and FromDamageInfo static constructors to create populated instances.
using System.Collections.Generic;
namespace SWB.Shared;
/// <summary>
/// An extended version of Sandbox.DamageInfo with additional properties for SWB
/// </summary>
public class DamageInfo : Sandbox.DamageInfo
{
public string Inflictor { get; set; }
public Vector3 Force { get; set; }
public float HitFlinch { get; set; }
public MovementImpact MovementImpact { get; set; }
public Dictionary<string, string> Extra { get; set; }
public static DamageInfo FromBullet(
GameObject attacker,
GameObject? weapon,
Hitbox? hitbox,
Vector3 Position,
PhysicsShape? shape,
string inflictor,
float damage,
Vector3 origin,
Vector3 force,
float hitFlinch,
MovementImpact movementImpact,
string[] tags,
Dictionary<string, string> extra = null )
{
return new()
{
Attacker = attacker,
Weapon = weapon,
Hitbox = hitbox,
Position = Position,
Shape = shape,
Inflictor = inflictor,
Damage = damage,
Origin = origin,
Force = force,
HitFlinch = hitFlinch,
MovementImpact = movementImpact,
Tags = [.. tags, TagsHelper.Bullet],
Extra = extra
};
}
public static DamageInfo FromDamageInfo( Sandbox.DamageInfo info )
{
return new()
{
Attacker = info.Attacker,
Weapon = info.Weapon,
Damage = info.Damage,
Origin = info.Origin,
Position = info.Position,
Tags = info.Tags,
};
}
}