Projext/Assets/Scripts/Enemy/BossAI/BossCounterPersistence.cs
2026-02-11 00:29:22 +09:00

140 lines
4.7 KiB
C#

using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 런 간 영구 저장되는 보스 카운터 잠금 해제 데이터.
/// "보스가 플레이어를 기억한다"는 서사를 담당합니다.
///
/// 핵심 규칙:
/// - 잠금 해제는 영구 (런이 끝나도 유지)
/// - 발동은 조건부 (해당 런에서 플레이어가 습관을 보여야만 활성화)
/// - 잠금 해제된 카운터는 임계치가 약간 낮아짐 (보스가 "이미 알고 있으니 더 빨리 눈치챔")
/// </summary>
[System.Serializable]
public class BossCounterSaveData
{
public bool dodgeCounterUnlocked = false;
public bool aimCounterUnlocked = false;
public bool pierceCounterUnlocked = false;
/// <summary>각 카운터가 발동된 총 횟수 (연출/난이도 스케일링에 활용 가능)</summary>
public int dodgeCounterActivations = 0;
public int aimCounterActivations = 0;
public int pierceCounterActivations = 0;
}
/// <summary>
/// 보스 카운터 영구 데이터를 관리합니다.
/// PlayerPrefs 기반으로 런 간 저장/로드합니다.
/// </summary>
public class BossCounterPersistence : MonoBehaviour
{
public static BossCounterPersistence Instance { get; private set; }
private const string SAVE_KEY = "BossCounterData";
public BossCounterSaveData Data { get; private set; }
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
Load();
}
// ═══════════════════════════════════════════
// 잠금 해제
// ═══════════════════════════════════════════
/// <summary>특정 카운터 타입을 영구 잠금 해제</summary>
public void UnlockCounter(CounterType type)
{
switch (type)
{
case CounterType.Dodge:
if (!Data.dodgeCounterUnlocked)
{
Data.dodgeCounterUnlocked = true;
Debug.Log("[BossCounter] 회피 카운터 영구 잠금 해제!");
}
break;
case CounterType.Aim:
if (!Data.aimCounterUnlocked)
{
Data.aimCounterUnlocked = true;
Debug.Log("[BossCounter] 조준 카운터 영구 잠금 해제!");
}
break;
case CounterType.Pierce:
if (!Data.pierceCounterUnlocked)
{
Data.pierceCounterUnlocked = true;
Debug.Log("[BossCounter] 관통 카운터 영구 잠금 해제!");
}
break;
}
Save();
}
/// <summary>카운터가 잠금 해제되어 있는지 확인</summary>
public bool IsUnlocked(CounterType type)
{
return type switch
{
CounterType.Dodge => Data.dodgeCounterUnlocked,
CounterType.Aim => Data.aimCounterUnlocked,
CounterType.Pierce => Data.pierceCounterUnlocked,
_ => false
};
}
/// <summary>카운터 발동 횟수 기록</summary>
public void RecordActivation(CounterType type)
{
switch (type)
{
case CounterType.Dodge: Data.dodgeCounterActivations++; break;
case CounterType.Aim: Data.aimCounterActivations++; break;
case CounterType.Pierce: Data.pierceCounterActivations++; break;
}
Save();
}
// ═══════════════════════════════════════════
// 저장 / 로드 / 리셋
// ═══════════════════════════════════════════
public void Save()
{
string json = JsonUtility.ToJson(Data);
PlayerPrefs.SetString(SAVE_KEY, json);
PlayerPrefs.Save();
}
public void Load()
{
if (PlayerPrefs.HasKey(SAVE_KEY))
{
string json = PlayerPrefs.GetString(SAVE_KEY);
Data = JsonUtility.FromJson<BossCounterSaveData>(json);
}
else
{
Data = new BossCounterSaveData();
}
}
/// <summary>모든 영구 데이터 초기화 (디버그/뉴게임+)</summary>
public void ResetAllData()
{
Data = new BossCounterSaveData();
PlayerPrefs.DeleteKey(SAVE_KEY);
Debug.Log("[BossCounter] 모든 보스 기억 데이터 초기화됨");
}
}