Compare commits

..

No commits in common. "ea2119913ae05cb512b9e5bc3b28b88e50ade9af" and "cf3cf65b068d861d5bd65db2fbbb53a55f5bbf4d" have entirely different histories.

4 changed files with 10 additions and 48 deletions

View File

@ -1,17 +1,10 @@
using UnityEngine;
namespace GameDev.CoreSystems
{
public interface IDamageable
{
#region Methods
/// <summary>
/// Modify the health of the damageable
/// </summary>
/// <param name="healthChange">Amount of health change</param>
/// <param name="source">Source GameObject, used to modify stats of the source. Total kills, etc.</param>
public void ModifyHealth(int healthChange, GameObject source);
public void ModifyHealth(int healthChange);
#endregion

View File

@ -2,13 +2,7 @@ namespace GameDev.CoreSystems
{
public interface IWeapon
{
/// <summary>
/// [s] Fire rate of the weapon
/// </summary>
public float FireRate { get; set; }
/// <summary>
/// Weapon damage
/// </summary>
public int Damage { get; set; }
}
}

View File

@ -17,11 +17,6 @@ namespace GameDev.CoreSystems
public UnityEvent DeathEvent;
/// <summary>
/// Used to ensure only one damage dealer gets the kill score
/// </summary>
private bool _isAlreadyDead;
private void OnEnable()
{
_activeDamageableRuntimeSet.Add(this);
@ -34,30 +29,13 @@ namespace GameDev.CoreSystems
#region Methods
public void ModifyHealth(int healthChange, GameObject source)
public void ModifyHealth(int healthChange)
{
var receivingDamage = healthChange < 0;
var receivingHealing = healthChange > 0;
if (IsInvulnerable && receivingDamage) return;
if (IsInvulnerable) return;
CurrentHealth += healthChange;
source.TryGetComponent(out Weapon weapon);
if (weapon != null && !_isAlreadyDead)
{
weapon.IncrementDamageDealt(-healthChange);
}
if (CurrentHealth > 0 || _isAlreadyDead) return;
_isAlreadyDead = true;
if (weapon != null)
{
weapon.IncrementKillCount();
}
if (CurrentHealth >= 0) return;
print($"{transform.parent.parent.name} died");
DeathEvent.Invoke();

View File

@ -26,8 +26,7 @@ namespace GameDev.CoreSystems
{
_timeUntilFire -= Time.deltaTime;
var reloading = _timeUntilFire > 0;
if (reloading) return;
if (!(_timeUntilFire <= 0)) return;
var position = BarrelEndPoint.position;
var forward = BarrelEndPoint.forward;
@ -37,9 +36,12 @@ namespace GameDev.CoreSystems
{
if (hitInfo.transform.TryGetComponent(out Targetable target))
{
target.Damageable.DeathEvent.AddListener(IncrementKillCount);
Debug.DrawRay(position, forward * Vector3.Distance(position, target.GetCenterPosition()),
Color.red, 0.1f);
target.Damageable.ModifyHealth(-Damage, gameObject);
target.Damageable.ModifyHealth(-Damage);
DamageDealt += Damage;
target.Damageable.DeathEvent.RemoveListener(IncrementKillCount);
}
}
@ -51,12 +53,7 @@ namespace GameDev.CoreSystems
}
}
public void IncrementDamageDealt(int damage)
{
DamageDealt += damage;
}
public void IncrementKillCount()
private void IncrementKillCount()
{
NumberOfKills += 1;
}