using System;
using Cielonos.MainGame.Inventory;
using Cielonos.MainGame.Interactions;
using Sirenix.OdinInspector;
using UnityEngine;
namespace Cielonos.MainGame.Rewards
{
///
/// Combat 节点奖励的基础类型。
/// RareMaterial 是即时奖励;SupplyPack/MechanicalTable 会生成交互物并阻塞节点完成。
///
public enum CombatRewardInstructionType
{
RareMaterial,
SupplyPack,
MechanicalTable,
}
///
/// 一条奖励指令。Profile 负责配置它,Resolver 会 Clone 后交给 Modifier 和 Dispatcher 使用。
///
[Serializable]
[InlineProperty]
[HideReferenceObjectPicker]
public class CombatRewardInstruction
{
[HorizontalGroup("Row", Width = 0.28f)]
[HideLabel]
public CombatRewardInstructionType type = CombatRewardInstructionType.RareMaterial;
[HorizontalGroup("Row", Width = 0.22f)]
[LabelText("Count")]
[MinValue(1)]
public int count = 1;
[ShowIf(nameof(IsRareMaterial))]
[LabelText("RareMaterial Range")]
public Vector2Int rareMaterialRange = new(10, 20);
public bool IsRareMaterial => type == CombatRewardInstructionType.RareMaterial;
public bool UsesInteractable => type == CombatRewardInstructionType.SupplyPack || type == CombatRewardInstructionType.MechanicalTable;
public string ResolveInteractablePrefabId()
{
return type switch
{
CombatRewardInstructionType.SupplyPack => nameof(SupplyPack),
CombatRewardInstructionType.MechanicalTable => nameof(MechanicalTable),
_ => string.Empty,
};
}
public int RollRareMaterial(System.Random rng)
{
if (rng == null)
{
return 0;
}
int min = Mathf.Min(rareMaterialRange.x, rareMaterialRange.y);
int max = Mathf.Max(rareMaterialRange.x, rareMaterialRange.y);
return Mathf.Max(0, rng.Next(min, max + 1));
}
public CombatRewardInstruction Clone()
{
return new CombatRewardInstruction
{
type = type,
count = count,
rareMaterialRange = rareMaterialRange,
};
}
}
}