81 lines
2.7 KiB
C#
81 lines
2.7 KiB
C#
using Cielonos.MainGame.Characters;
|
|
using SLSUtilities.General;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame
|
|
{
|
|
public partial class RunManager
|
|
{
|
|
/// <summary>
|
|
/// 记录一局 Run 的统计数据。
|
|
/// 这里只维护计数和计时,不决定节点完成、奖励发放或结算 UI。
|
|
/// </summary>
|
|
public class RunProgressSubmodule : SubmoduleBase<RunManager>
|
|
{
|
|
private const string RunManagerHurtKey = "RunManager_HurtTracking";
|
|
private const string RunManagerDeathKey = "RunManager_Death";
|
|
|
|
public RunProgressSubmodule(RunManager owner) : base(owner)
|
|
{
|
|
}
|
|
|
|
public void SubscribePlayerEvents()
|
|
{
|
|
if (MainGameManager.Player == null) return;
|
|
|
|
CharacterBase.EventSubmodule playerEvents = MainGameManager.Player.eventSm;
|
|
playerEvents.onHurt.InsertByPriority(RunManagerHurtKey, new PrioritizedAction<AttackAreaBase>(_ => OnPlayerHurt(), priority: 0));
|
|
|
|
playerEvents.onDeath.InsertByPriority(RunManagerDeathKey, new PrioritizedAction(OnPlayerDeath, priority: 0));
|
|
}
|
|
|
|
public void UnsubscribePlayerEvents()
|
|
{
|
|
if (MainGameManager.Player == null) return;
|
|
|
|
CharacterBase.EventSubmodule playerEvents = MainGameManager.Player.eventSm;
|
|
playerEvents.onHurt.Remove(RunManagerHurtKey);
|
|
playerEvents.onDeath.Remove(RunManagerDeathKey);
|
|
}
|
|
|
|
public void RecordEnemyDefeated(CharacterBase enemy)
|
|
{
|
|
if (owner.currentRun == null || enemy == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
owner.currentRun.enemiesDefeated++;
|
|
}
|
|
|
|
public void TickElapsedTime()
|
|
{
|
|
if (owner.currentRun != null &&
|
|
owner.currentPhase != RunPhase.Idle &&
|
|
owner.currentPhase != RunPhase.Settlement)
|
|
{
|
|
owner.currentRun.elapsedTime += Time.deltaTime;
|
|
}
|
|
}
|
|
|
|
private void OnPlayerHurt()
|
|
{
|
|
if (owner.currentRun != null)
|
|
{
|
|
owner.currentRun.hurtCount++;
|
|
}
|
|
}
|
|
|
|
private void OnPlayerDeath()
|
|
{
|
|
if (owner.currentRun == null) return;
|
|
|
|
owner.currentRun.isCompleted = false;
|
|
Debug.Log("[RunManager] 玩家死亡,进入结算。");
|
|
owner.phaseSm.TransitionToPhase(RunPhase.Settlement);
|
|
owner.RaiseRunEnded(owner.currentRun);
|
|
}
|
|
}
|
|
}
|
|
}
|