ped damage handling is done by State classes

This commit is contained in:
in0finite 2020-06-29 17:12:48 +02:00
parent 9734b6f515
commit e5c6144706
3 changed files with 23 additions and 16 deletions

View file

@ -96,21 +96,7 @@ namespace SanAndreasUnity.Behaviours
if (this.Health <= 0)
return;
DamageInfo damageInfo = this.Damageable.LastDamageInfo;
float amount = damageInfo.raycastHitTransform != null
? this.PlayerModel.GetAmountOfDamageForBone(damageInfo.raycastHitTransform, damageInfo.amount)
: damageInfo.amount;
this.Health -= amount;
if (this.Health <= 0)
{
Object.Destroy(this.gameObject);
}
// notify clients
this.SendDamagedEventToClients(damageInfo, amount);
this.CurrentState.OnDamaged(this.Damageable.LastDamageInfo);
}

View file

@ -308,6 +308,24 @@ namespace SanAndreasUnity.Behaviours.Peds.States
weapon.PlayFireSound();
}
}
public virtual void OnDamaged(DamageInfo damageInfo)
{
float amount = damageInfo.raycastHitTransform != null
? m_model.GetAmountOfDamageForBone(damageInfo.raycastHitTransform, damageInfo.amount)
: damageInfo.amount;
m_ped.Health -= amount;
if (m_ped.Health <= 0)
{
Object.Destroy(m_ped.gameObject);
}
// notify clients
m_ped.SendDamagedEventToClients(damageInfo, amount);
}
}
}

View file

@ -1,3 +1,4 @@
using SanAndreasUnity.Utilities;
using UnityEngine;
namespace SanAndreasUnity.Behaviours.Peds.States
@ -31,6 +32,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States
void OnWeaponFiredFromServer(Weapon weapon, Vector3 firePos);
void OnDamaged(DamageInfo damageInfo);
}
}