add Ped.onDamaged event

This commit is contained in:
in0finite 2021-02-19 02:55:09 +01:00
parent ec436c6037
commit 7e97945021
4 changed files with 26 additions and 6 deletions

View file

@ -23,6 +23,22 @@ namespace SanAndreasUnity.Behaviours
private bool m_alreadyKilled = false;
public class DamageResult
{
public float DamageAmount { get; }
public DamageResult()
{
}
public DamageResult(float damageAmount)
{
DamageAmount = damageAmount;
}
}
public static event System.Action<Ped, DamageInfo, DamageResult> onDamaged = delegate {};
void AwakeForDamage ()
@ -103,8 +119,11 @@ namespace SanAndreasUnity.Behaviours
if (this.Health <= 0)
return;
this.CurrentState.OnDamaged(this.Damageable.LastDamageInfo);
var damageInfo = this.Damageable.LastDamageInfo;
var damageResult = this.CurrentState.OnDamaged(damageInfo);
F.InvokeEventExceptionSafe(onDamaged, this, damageInfo, damageResult);
}
public void SendDamagedEventToClients(DamageInfo damageInfo, float damageAmount)

View file

@ -308,7 +308,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States
weapon.PlayFireSound();
}
public virtual void OnDamaged(DamageInfo damageInfo)
public virtual Ped.DamageResult OnDamaged(DamageInfo damageInfo)
{
float amount = damageInfo.raycastHitTransform != null
? m_model.GetAmountOfDamageForBone(damageInfo.raycastHitTransform, damageInfo.amount)
@ -325,6 +325,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States
// notify clients
m_ped.SendDamagedEventToClients(damageInfo, amount);
return new Ped.DamageResult(amount);
}
public virtual void KillPed()

View file

@ -32,7 +32,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States
void OnWeaponFiredFromServer(Weapon weapon, Vector3 firePos);
void OnDamaged(DamageInfo damageInfo);
Ped.DamageResult OnDamaged(DamageInfo damageInfo);
}

View file

@ -195,15 +195,15 @@ namespace SanAndreasUnity.Behaviours.Peds.States
return base.GetCameraFocusPos();
}
public override void OnDamaged(DamageInfo damageInfo)
public override Ped.DamageResult OnDamaged(DamageInfo damageInfo)
{
if (damageInfo.damageType == DamageType.Explosion)
{
// ped should not be damaged by explosion while he is in vehicle
return;
return new Ped.DamageResult();
}
base.OnDamaged(damageInfo);
return base.OnDamaged(damageInfo);
}
}