重构清理敌人类

This commit is contained in:
2026-09-15 11:07:01 +08:00
parent 421f8bf619
commit 88ed35e757
34 changed files with 568 additions and 457 deletions
@@ -22,7 +22,6 @@ namespace SepCore.EnemyManager
public IReadOnlyCollection<EntityBase> Enemies => _enemyRegistry.Enemies;
private int _spawnEnemyMaxCount;
private int _spawnDistanceFromPlayer;
private int _currentSpawnEnemyId;
private int _currentLevel;
@@ -73,11 +72,18 @@ namespace SepCore.EnemyManager
return;
}
if (!_entity.HasEntityGroup(EnemyGroupName))
{
Log.Error("Entity group '{0}' does not exist.", EnemyGroupName);
return;
}
_isStopped = false;
_spawnEnemyMaxCount = GameEntry.Luban.Global.SpawnEnemyMaxCount;
_spawnDistanceFromPlayer = GameEntry.Luban.Global.SpawnDistanceFromPlayer / 1000;
float minDistance = GameEntry.Luban.Global.EnemySpawnDistanceMin / 1000f;
float maxDistance = GameEntry.Luban.Global.EnemySpawnDistanceMax / 1000f;
_player = player.CachedTransform;
_spawnPositionStrategy = new RandomCircleSpawnStrategy(_spawnDistanceFromPlayer);
_spawnPositionStrategy = new RandomCircleSpawnStrategy(minDistance, maxDistance);
_baseDuration = level.Duration;
_duration = _baseDuration;
@@ -8,7 +8,7 @@ namespace SepCore.EnemyManager
{
public class EnemySpawnScheduler
{
private const float MinSpawnRateScale = 0.1f;
private static float MinSpawnRateScale => GameEntry.Luban.Global.MinSpawnRateScale / 1000f;
private float _elapsedTime;
private float[] _baseIntervals;
@@ -5,19 +5,22 @@ namespace SepCore.EnemyManager
{
public class RandomCircleSpawnStrategy : ISpawnPositionStrategy
{
private readonly float _spawnDistance;
private readonly float _minDistance;
private readonly float _maxDistance;
public RandomCircleSpawnStrategy(float spawnDistance)
public RandomCircleSpawnStrategy(float minDistance, float maxDistance)
{
_spawnDistance = spawnDistance;
_minDistance = minDistance;
_maxDistance = maxDistance;
}
public Vector3 GetSpawnPosition(Transform player)
{
float x = Random.Range(-1f, 1f);
float z = Random.Range(-1f, 1f);
Vector3 dir = new Vector3(x, 0, z).normalized;
return player.position + dir * _spawnDistance;
Vector3 dir = new Vector3(x, 0f, z).normalized;
float distance = Random.Range(_minDistance, _maxDistance);
return player.position + dir * distance;
}
}
}
@@ -9,11 +9,9 @@ namespace SepCore.Simulation
// Bridges entity show/hide events into simulation state registration.
public sealed class EntitySync
{
private const string EnemyGroupName = "Enemy";
private const string DropGroupName = "Drop";
private const string BulletGroupName = "Bullet";
private const string ProjectileGroupName = "Projectile";
private const string EnemyProjectileGroupName = "EnemyProjectile";
private static string EnemyGroupName => GameEntry.Luban.Global.EnemyGroupName;
private static string DropGroupName => GameEntry.Luban.Global.DropGroupName;
private static string ProjectileGroupName => GameEntry.Luban.Global.ProjectileGroupName;
private readonly SimulationWorld _world;
private bool _isEventSubscribed;
@@ -74,8 +72,7 @@ namespace SepCore.Simulation
return;
}
if ((groupName == BulletGroupName || groupName == ProjectileGroupName ||
groupName == EnemyProjectileGroupName) &&
if (groupName == ProjectileGroupName &&
args.Entity.Logic is EntityBase projectileEntity)
{
_world.RegisterProjectileLifecycle(projectileEntity, args.UserData);
@@ -101,8 +98,7 @@ namespace SepCore.Simulation
return;
}
if (groupName == BulletGroupName || groupName == ProjectileGroupName ||
groupName == EnemyProjectileGroupName)
if (groupName == ProjectileGroupName)
{
_world.UnregisterProjectileLifecycle(args.EntityId);
}