using UnityEngine;
using BaseGames.Player;
using BaseGames.Core.Events;
namespace BaseGames.Quest
{
///
/// 任务奖励 SO(架构 22_QuestChallengeModule §4)。
/// 由 QuestManager.CompleteQuest() 调用 Apply() 发放奖励。
/// 资产路径: Assets/ScriptableObjects/Quest/Reward_{questId}.asset
///
[CreateAssetMenu(menuName = "Quest/Reward")]
public class RewardSO : ScriptableObject
{
public int geo; // Geo 货币奖励
public int soulBonus; // 灵魂槽扩展(+MaxSoulPower)
public string[] itemIds; // 物品/护符 ID 列表(通过 InventoryManager 发放)
public int affinityBonus; // 对发布 NPC 的好感度增量(存入 SaveData.World.NpcRelations)
public string unlockDialogueKey; // 解锁 NPC 新台词集合 key(架构 §4)
[Tooltip("是否解锁能力(AbilityType 无 None 值,用 bool 标识)")]
public bool unlocksAbility; // ⚠️ AbilityType 无 None,用 bool 标识
public AbilityType unlockedAbility; // 仅当 unlocksAbility == true 有效
[Header("物品发放事件")]
[Tooltip("EVT_CollectiblePickup:向 QuestManager/EquipmentManager 广播 itemId")]
[SerializeField] private StringEventChannelSO _onCollectiblePickup;
/// 将奖励应用到游戏状态(由 QuestManager.CompleteQuest 调用)。
public void Apply(PlayerStats player)
{
if (player == null) return;
if (geo > 0) player.AddGeo(geo);
if (soulBonus > 0) player.AddSoulPower(soulBonus);
if (unlocksAbility) player.UnlockAbility(unlockedAbility);
// 通过 EVT_CollectiblePickup 事件频道广播每个物品 ID
if (itemIds != null && _onCollectiblePickup != null)
{
foreach (var id in itemIds)
_onCollectiblePickup.Raise(id);
}
}
}
}