mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-26 05:50:18 +00:00
make peds react to nearby gun shots
This commit is contained in:
parent
2277e0f35a
commit
92d5dc6bf9
5 changed files with 46 additions and 0 deletions
|
@ -77,6 +77,10 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
{
|
||||
}
|
||||
|
||||
protected internal virtual void OnWeaponConductedAttack(Weapon.AttackConductedEventData data)
|
||||
{
|
||||
}
|
||||
|
||||
protected internal virtual void OnRecruit(Ped recruiterPed)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -41,6 +41,35 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
|
||||
}
|
||||
|
||||
protected internal override void OnWeaponConductedAttack(Weapon.AttackConductedEventData data)
|
||||
{
|
||||
this.HandleOnWeaponConductedAttack(data);
|
||||
}
|
||||
|
||||
public void HandleOnWeaponConductedAttack(Weapon.AttackConductedEventData data)
|
||||
{
|
||||
if (data.Weapon.PedOwner == _ped)
|
||||
return;
|
||||
|
||||
if (data.Weapon.transform.Distance(_ped.transform.position) > PedManager.Instance.AIWeaponHearingDistance)
|
||||
return;
|
||||
|
||||
if (_pedAI.PedestrianType.IsCop())
|
||||
{
|
||||
Ped attackerPed = data.Weapon.PedOwner;
|
||||
if (attackerPed != null)
|
||||
_enemyPeds.AddIfNotPresent(attackerPed);
|
||||
}
|
||||
else if (_pedAI.PedestrianType.IsCriminal() || _pedAI.PedestrianType.IsGangMember())
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
else
|
||||
{
|
||||
_pedAI.StartEscaping();
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void OnRecruit(Ped recruiterPed)
|
||||
{
|
||||
this.HandleOnRecruit(recruiterPed);
|
||||
|
|
|
@ -54,6 +54,7 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
s_allPedAIs.Add(this);
|
||||
Ped.onDamaged += OnPedDamaged;
|
||||
Vehicle.onDamaged += OnVehicleDamaged;
|
||||
Weapon.onWeaponConductedAttack += OnWeaponConductedAttack;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
|
@ -61,6 +62,7 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
s_allPedAIs.Remove(this);
|
||||
Ped.onDamaged -= OnPedDamaged;
|
||||
Vehicle.onDamaged -= OnVehicleDamaged;
|
||||
Weapon.onWeaponConductedAttack -= OnWeaponConductedAttack;
|
||||
}
|
||||
|
||||
private void OnPedDamaged(Ped hitPed, DamageInfo dmgInfo, Ped.DamageResult dmgResult)
|
||||
|
@ -79,6 +81,11 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
this.CurrentState.OnVehicleDamaged(vehicle, damageInfo);
|
||||
}
|
||||
|
||||
void OnWeaponConductedAttack(Weapon.AttackConductedEventData data)
|
||||
{
|
||||
this.CurrentState.OnWeaponConductedAttack(data);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (NetStatus.IsServer)
|
||||
|
|
|
@ -71,6 +71,11 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
_pedAI.StateContainer.GetStateOrThrow<IdleState>().HandleOnMyPedDamaged(dmgInfo, dmgResult);
|
||||
}
|
||||
|
||||
protected internal override void OnWeaponConductedAttack(Weapon.AttackConductedEventData data)
|
||||
{
|
||||
_pedAI.StateContainer.GetStateOrThrow<IdleState>().HandleOnWeaponConductedAttack(data);
|
||||
}
|
||||
|
||||
protected internal override void OnRecruit(Ped recruiterPed)
|
||||
{
|
||||
_pedAI.StateContainer.GetStateOrThrow<IdleState>().HandleOnRecruit(recruiterPed);
|
||||
|
|
|
@ -61,6 +61,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
public float AIStoppingDistance = 3f;
|
||||
public float AIVehicleEnterDistance = 1.25f;
|
||||
public float AIWeaponHearingDistance = 40f;
|
||||
|
||||
[Header("Net")]
|
||||
|
||||
|
|
Loading…
Reference in a new issue