enemy spawner
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using MegaKoop.Game.Combat;
|
||||
using MegaKoop.Game.Networking;
|
||||
using MegaKoop.Game.Vfx;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MegaKoop.Game.WeaponSystem
|
||||
@@ -17,8 +19,9 @@ namespace MegaKoop.Game.WeaponSystem
|
||||
private Team sourceTeam;
|
||||
private GameObject owner;
|
||||
private Collider[] projectileColliders;
|
||||
private bool isAuthoritative = true;
|
||||
|
||||
public void Initialize(Vector3 shotDirection, float projectileSpeed, float damageAmount, float projectileLifetime, GameObject projectileOwner, Team ownerTeam, Collider[] ownerColliders, LayerMask mask)
|
||||
public void Initialize(Vector3 shotDirection, float projectileSpeed, float damageAmount, float projectileLifetime, GameObject projectileOwner, Team ownerTeam, Collider[] ownerColliders, LayerMask mask, bool authoritative = true)
|
||||
{
|
||||
direction = shotDirection.sqrMagnitude > 0f ? shotDirection.normalized : transform.forward;
|
||||
speed = Mathf.Max(0f, projectileSpeed);
|
||||
@@ -28,6 +31,7 @@ namespace MegaKoop.Game.WeaponSystem
|
||||
sourceTeam = ownerTeam;
|
||||
hitMask = mask;
|
||||
timeAlive = 0f;
|
||||
isAuthoritative = authoritative;
|
||||
|
||||
projectileColliders ??= GetComponentsInChildren<Collider>();
|
||||
if (ownerColliders != null && projectileColliders != null)
|
||||
@@ -102,6 +106,8 @@ namespace MegaKoop.Game.WeaponSystem
|
||||
}
|
||||
|
||||
IDamageable damageable = other.GetComponentInParent<IDamageable>();
|
||||
ProjectileImpactKind? impactKind = null;
|
||||
|
||||
if (damageable != null && damageable.IsAlive)
|
||||
{
|
||||
bool isFriendly = damageable.Team == sourceTeam && damageable.Team != Team.Neutral;
|
||||
@@ -110,13 +116,27 @@ namespace MegaKoop.Game.WeaponSystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (damage > 0f)
|
||||
if (damageable.Team == Team.Heroes)
|
||||
{
|
||||
impactKind = ProjectileImpactKind.Hero;
|
||||
}
|
||||
else if (damageable.Team == Team.Enemies)
|
||||
{
|
||||
impactKind = ProjectileImpactKind.Enemy;
|
||||
}
|
||||
|
||||
if (isAuthoritative && damage > 0f)
|
||||
{
|
||||
var payload = new DamagePayload(damage, hitPoint, hitNormal, owner, sourceTeam, other.gameObject);
|
||||
damageable.ApplyDamage(payload);
|
||||
}
|
||||
}
|
||||
|
||||
if (isAuthoritative && impactKind.HasValue)
|
||||
{
|
||||
ProjectileImpactVfxService.ReportImpact(impactKind.Value, hitPoint, hitNormal);
|
||||
}
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user