Route entity destruction through checkpoints

This commit is contained in:
Meta Vens 2026-06-16 04:47:42 +01:00
commit 729ab0e8d8
5 changed files with 111 additions and 25 deletions

View file

@ -1587,6 +1587,43 @@ public class ActionGameManager : MonoBehaviour
return false;
}
public bool CommitEntityDestroyed(Entity entity, ZoneRenderer zoneRenderer)
{
if (entity?.Zone == null)
return false;
if (zoneRenderer != null)
{
foreach (var gear in entity.Equipment)
{
if (gear == entity.EquippedHull || Random.value >= zoneRenderer.Settings.LootDropProbability)
continue;
zoneRenderer.DropItem(
entity.Position,
Random.onUnitSphere * zoneRenderer.Settings.LootDropVelocity,
gear.EquippableItem);
}
foreach (var cargo in entity.CargoBays)
{
foreach (var item in cargo.Cargo.Keys.ToArray())
{
zoneRenderer.DropItem(
entity.Position,
Random.onUnitSphere * zoneRenderer.Settings.LootDropVelocity,
item);
}
}
}
if (!entity.Zone.Entities.Remove(entity))
return false;
QueueRunCheckpoint("entity-destroyed");
return true;
}
public bool CommitCargoItemTransfer(
EquippedCargoBay origin,
EquippedCargoBay destination,

View file

@ -8,7 +8,6 @@ using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using float2 = Unity.Mathematics.float2;
using Random = UnityEngine.Random;
public class EntityInstance : MonoBehaviour
{
@ -421,37 +420,18 @@ public class EntityInstance : MonoBehaviour
_subscriptions.Add(Entity.HullDamage.Subscribe(_ =>
{
if (Entity.Hull.Durability < .01f)
if (!_destroyed && Entity.Hull.Durability < .01f)
{
if (!this) return;
_destroyed = true;
foreach (var gear in Entity.Equipment)
{
if (gear != Entity.EquippedHull && Random.value < ZoneRenderer.Settings.LootDropProbability)
{
ZoneRenderer.DropItem(
Entity.Position,
Random.onUnitSphere * ZoneRenderer.Settings.LootDropVelocity,
gear.EquippableItem);
}
}
if (ActionGameManager.Instance?.CommitEntityDestroyed(entity, ZoneRenderer) != true)
return;
foreach (var cargo in Entity.CargoBays)
{
foreach (var item in cargo.Cargo.Keys)
{
ZoneRenderer.DropItem(
Entity.Position,
Random.onUnitSphere * ZoneRenderer.Settings.LootDropVelocity,
item);
}
}
_destroyed = true;
if (DestroyEffect != null)
{
var t = Instantiate(DestroyEffect).transform;
t.position = transform.position;
}
entity.Zone.Entities.Remove(entity);
}
}));