增加收获属性逻辑,优化掉落物表现效果
This commit is contained in:
@@ -3,6 +3,7 @@ using SepCore.Event;
|
||||
using SepCore.Entity;
|
||||
using SepCore.Definition;
|
||||
using SepCore.EnemyManager;
|
||||
using SepCore.Battle;
|
||||
using SepCore.Simulation;
|
||||
using SepCore.Timer;
|
||||
using UnityEngine;
|
||||
@@ -12,16 +13,13 @@ namespace SepCore.Procedure
|
||||
{
|
||||
public class GameStateBattle : GameStateBase
|
||||
{
|
||||
private const float VacuumMaxDuration = 0.8f;
|
||||
private const float VacuumAbsorbSpeed = 30f;
|
||||
|
||||
public override GameStateType GameStateType => GameStateType.Battle;
|
||||
|
||||
private EnemyManagerComponent _enemyManager;
|
||||
private DropService _dropService;
|
||||
private int _currentLevel;
|
||||
private TimerHandle _levelTimerHandle;
|
||||
private bool _isWaveEnding;
|
||||
private float _vacuumTimer;
|
||||
|
||||
private Player Player => _procedureGame.Player;
|
||||
private ProcedureGame _procedureGame;
|
||||
@@ -41,14 +39,15 @@ namespace SepCore.Procedure
|
||||
public override void OnInit(ProcedureGame master)
|
||||
{
|
||||
_enemyManager = GameEntry.EnemyManager;
|
||||
_dropService = new DropService();
|
||||
_procedureGame = master;
|
||||
}
|
||||
|
||||
public override void OnEnter()
|
||||
{
|
||||
_dropService.Subscribe();
|
||||
_currentLevel = _procedureGame.CurrentLevel;
|
||||
_isWaveEnding = false;
|
||||
_vacuumTimer = 0f;
|
||||
|
||||
var levelConfig = GameEntry.Luban.Get<LevelConfig>(_currentLevel);
|
||||
_levelTimerHandle = GameEntry.Timer.ScheduleOnce(levelConfig.Duration, OnLevelTimeUp, this);
|
||||
@@ -69,10 +68,9 @@ namespace SepCore.Procedure
|
||||
Vector3 currentPos = Player.CachedTransform.position;
|
||||
GameEntry.SimulationWorld.Tick(new SimulationTickContext(elapseSeconds, currentPos));
|
||||
|
||||
_vacuumTimer -= elapseSeconds;
|
||||
if (GameEntry.SimulationWorld.PickupCount == 0 || _vacuumTimer <= 0f)
|
||||
if (_dropService.UpdateVacuum(elapseSeconds, Player))
|
||||
{
|
||||
CollectAllRemainingDrops(Player);
|
||||
HarvestSettlementUtility.Settle(Player);
|
||||
_isWaveEnding = false;
|
||||
_procedureGame.BattleToShopOrLevelUp();
|
||||
}
|
||||
@@ -93,7 +91,6 @@ namespace SepCore.Procedure
|
||||
if (_isWaveEnding) return;
|
||||
|
||||
_isWaveEnding = true;
|
||||
_vacuumTimer = VacuumMaxDuration;
|
||||
|
||||
// 1. 停止玩家移动与射击
|
||||
Player.Enable = false;
|
||||
@@ -104,9 +101,8 @@ namespace SepCore.Procedure
|
||||
// 3. 隐藏所有投射物
|
||||
HideEntityGroup(GameEntry.Luban.Global.ProjectileGroupName);
|
||||
|
||||
// 4. 触发全图磁铁,并提高吸附速度
|
||||
GameEntry.SimulationWorld.TriggerFullMapMagnet();
|
||||
GameEntry.SimulationWorld.SyncPlayerAbsorbSettings(999f, VacuumAbsorbSpeed, GameEntry.Luban.Global.CollectDistance);
|
||||
// 4. 触发掉落物全图吸附
|
||||
_dropService.StartVacuum();
|
||||
}
|
||||
|
||||
public override void OnLeave()
|
||||
@@ -127,35 +123,20 @@ namespace SepCore.Procedure
|
||||
// 停止玩家逻辑
|
||||
Player.Enable = false;
|
||||
|
||||
// 隐藏所有掉落物与投射物实体
|
||||
HideEntityGroup(GameEntry.Luban.Global.DropGroupName);
|
||||
// 清理掉落物并隐藏所有投射物实体
|
||||
_dropService.HideAllDrops();
|
||||
HideEntityGroup(GameEntry.Luban.Global.ProjectileGroupName);
|
||||
_dropService.Unsubscribe();
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
_dropService.Unsubscribe();
|
||||
_enemyManager = null;
|
||||
_dropService = null;
|
||||
_procedureGame = null;
|
||||
}
|
||||
|
||||
private static void CollectAllRemainingDrops(Player player)
|
||||
{
|
||||
if (player == null || !GameEntry.Entity.HasEntityGroup(GameEntry.Luban.Global.DropGroupName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var entityGroup = GameEntry.Entity.GetEntityGroup(GameEntry.Luban.Global.DropGroupName);
|
||||
var entities = entityGroup.GetAllEntities();
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (entity is UnityGameFramework.Runtime.Entity runtimeEntity && runtimeEntity.Logic is DropEntity drop)
|
||||
{
|
||||
drop.TryCollect(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void HideEntityGroup(string groupName)
|
||||
{
|
||||
if (!GameEntry.Entity.HasEntityGroup(groupName))
|
||||
|
||||
Reference in New Issue
Block a user