Files
zeling_v2/Assets/Scripts/Support/AntiSoftlock/HardAbilityGate.cs
2026-05-13 09:19:54 +08:00

37 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using BaseGames.World;
using BaseGames.Player;
using BaseGames.Core.Save;
namespace BaseGames.Support.AntiSoftlock
{
/// <summary>
/// 硬性能力门禁(架构 16_SupportingModules §5.3)。
/// 在 AbilityGate 的基础上增加次级验证:检查玩家是否真正拾取了物理道具。
/// 当 _requirePhysicalValidation = true 时,还需要通过 _physicalPickupSwitchKey 确认。
/// </summary>
public class HardAbilityGate : AbilityGate
{
[Header("HardAbilityGate 设置")]
[Tooltip("是否还要求物理拾取验证(需要 World.Switches 中对应 Key = true")]
[SerializeField] private bool _requirePhysicalValidation = false;
[Tooltip("物理拾取验证 Switch Key需 SaveManager.Data.World.Switches[key] == true")]
[SerializeField] private string _physicalPickupSwitchKey;
[Header("引用")]
[SerializeField] private SaveManager _saveManager;
protected override bool EvaluateAccess()
{
if (!base.EvaluateAccess()) return false;
if (!_requirePhysicalValidation) return true;
// 次级检查:物理拾取确认
if (string.IsNullOrEmpty(_physicalPickupSwitchKey)) return true;
var save = _saveManager != null ? _saveManager.Data : null;
if (save?.World?.Switches == null) return false;
return save.World.Switches.TryGetValue(_physicalPickupSwitchKey, out bool val) && val;
}
}
}