Changed how weapons count total damage dealt and kills
This commit is contained in:
parent
cf3cf65b06
commit
6a49fa1812
|
@ -17,6 +17,11 @@ namespace GameDev.CoreSystems
|
||||||
|
|
||||||
public UnityEvent DeathEvent;
|
public UnityEvent DeathEvent;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to ensure only one damage dealer gets the kill score
|
||||||
|
/// </summary>
|
||||||
|
private bool _isAlreadyDead;
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
_activeDamageableRuntimeSet.Add(this);
|
_activeDamageableRuntimeSet.Add(this);
|
||||||
|
@ -29,13 +34,30 @@ namespace GameDev.CoreSystems
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
public void ModifyHealth(int healthChange)
|
public void ModifyHealth(int healthChange, GameObject source)
|
||||||
{
|
{
|
||||||
if (IsInvulnerable) return;
|
var receivingDamage = healthChange < 0;
|
||||||
|
var receivingHealing = healthChange > 0;
|
||||||
|
|
||||||
|
if (IsInvulnerable && receivingDamage) return;
|
||||||
|
|
||||||
CurrentHealth += healthChange;
|
CurrentHealth += healthChange;
|
||||||
|
|
||||||
if (CurrentHealth >= 0) return;
|
source.TryGetComponent(out Weapon weapon);
|
||||||
|
|
||||||
|
if (weapon != null && !_isAlreadyDead)
|
||||||
|
{
|
||||||
|
weapon.IncrementDamageDealt(-healthChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CurrentHealth > 0 || _isAlreadyDead) return;
|
||||||
|
|
||||||
|
_isAlreadyDead = true;
|
||||||
|
|
||||||
|
if (weapon != null)
|
||||||
|
{
|
||||||
|
weapon.IncrementKillCount();
|
||||||
|
}
|
||||||
|
|
||||||
print($"{transform.parent.parent.name} died");
|
print($"{transform.parent.parent.name} died");
|
||||||
DeathEvent.Invoke();
|
DeathEvent.Invoke();
|
||||||
|
|
|
@ -26,7 +26,8 @@ namespace GameDev.CoreSystems
|
||||||
{
|
{
|
||||||
_timeUntilFire -= Time.deltaTime;
|
_timeUntilFire -= Time.deltaTime;
|
||||||
|
|
||||||
if (!(_timeUntilFire <= 0)) return;
|
var reloading = _timeUntilFire > 0;
|
||||||
|
if (reloading) return;
|
||||||
|
|
||||||
var position = BarrelEndPoint.position;
|
var position = BarrelEndPoint.position;
|
||||||
var forward = BarrelEndPoint.forward;
|
var forward = BarrelEndPoint.forward;
|
||||||
|
@ -36,12 +37,9 @@ namespace GameDev.CoreSystems
|
||||||
{
|
{
|
||||||
if (hitInfo.transform.TryGetComponent(out Targetable target))
|
if (hitInfo.transform.TryGetComponent(out Targetable target))
|
||||||
{
|
{
|
||||||
target.Damageable.DeathEvent.AddListener(IncrementKillCount);
|
|
||||||
Debug.DrawRay(position, forward * Vector3.Distance(position, target.GetCenterPosition()),
|
Debug.DrawRay(position, forward * Vector3.Distance(position, target.GetCenterPosition()),
|
||||||
Color.red, 0.1f);
|
Color.red, 0.1f);
|
||||||
target.Damageable.ModifyHealth(-Damage);
|
target.Damageable.ModifyHealth(-Damage, gameObject);
|
||||||
DamageDealt += Damage;
|
|
||||||
target.Damageable.DeathEvent.RemoveListener(IncrementKillCount);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +51,12 @@ namespace GameDev.CoreSystems
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void IncrementKillCount()
|
public void IncrementDamageDealt(int damage)
|
||||||
|
{
|
||||||
|
DamageDealt += damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void IncrementKillCount()
|
||||||
{
|
{
|
||||||
NumberOfKills += 1;
|
NumberOfKills += 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue