mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-14 16:27:19 +00:00
add OnWeaponConductedAttack event
This commit is contained in:
parent
695592f6d6
commit
2277e0f35a
1 changed files with 34 additions and 0 deletions
|
@ -190,6 +190,28 @@ namespace SanAndreasUnity.Behaviours
|
|||
}
|
||||
}
|
||||
|
||||
public class AttackConductedEventData
|
||||
{
|
||||
public Weapon Weapon { get; }
|
||||
public DamageInfo DamageInfo { get; }
|
||||
public Damageable Damageable { get; }
|
||||
|
||||
public AttackConductedEventData(Weapon weapon)
|
||||
{
|
||||
Weapon = weapon;
|
||||
}
|
||||
|
||||
public AttackConductedEventData(Weapon weapon, DamageInfo damageInfo, Damageable damageable)
|
||||
{
|
||||
Weapon = weapon;
|
||||
DamageInfo = damageInfo;
|
||||
Damageable = damageable;
|
||||
}
|
||||
}
|
||||
|
||||
public static event System.Action<AttackConductedEventData> onWeaponConductedAttack = delegate {};
|
||||
|
||||
|
||||
|
||||
static Weapon ()
|
||||
{
|
||||
|
@ -695,11 +717,13 @@ namespace SanAndreasUnity.Behaviours
|
|||
if (this.FiresProjectile)
|
||||
{
|
||||
Projectile.Create(this.ProjectilePrefab, firePos, Quaternion.LookRotation(fireDir), m_ped);
|
||||
F.InvokeEventExceptionSafe(onWeaponConductedAttack, new AttackConductedEventData(this));
|
||||
return;
|
||||
}
|
||||
|
||||
// raycast against all (non-breakable ?) objects
|
||||
|
||||
bool shouldIvokeEvent = true;
|
||||
RaycastHit hit;
|
||||
if (this.ProjectileRaycast (firePos, fireDir, out hit, parameters))
|
||||
{
|
||||
|
@ -716,6 +740,8 @@ namespace SanAndreasUnity.Behaviours
|
|||
{
|
||||
// ray hit owner ped
|
||||
// don't do anything
|
||||
|
||||
shouldIvokeEvent = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -730,12 +756,20 @@ namespace SanAndreasUnity.Behaviours
|
|||
attackingPlayer = m_ped != null ? m_ped.PlayerOwner : null,
|
||||
damageType = DamageType.Bullet,
|
||||
};
|
||||
|
||||
damageable.Damage(damageInfo);
|
||||
|
||||
F.InvokeEventExceptionSafe(onWeaponConductedAttack, new AttackConductedEventData(this, damageInfo, damageable));
|
||||
|
||||
shouldIvokeEvent = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldIvokeEvent)
|
||||
F.InvokeEventExceptionSafe(onWeaponConductedAttack, new AttackConductedEventData(this));
|
||||
|
||||
}
|
||||
|
||||
public bool ProjectileRaycast (Vector3 source, Vector3 dir, out RaycastHit hit, WeaponAttackParams parameters)
|
||||
|
|
Loading…
Reference in a new issue