50 lines
2.1 KiB
C#
50 lines
2.1 KiB
C#
// Assets/_Project/Scripts/Gameplay/Draft/BuilderSpellDraftOption.cs
|
|
using UnityEngine;
|
|
using TD.Core;
|
|
using TD.Gameplay.BuilderSpells;
|
|
|
|
namespace TD.Gameplay.Draft
|
|
{
|
|
/// <summary>
|
|
/// Draft choice — "gain a builder spell". Grants the player a key-triggered active ability,
|
|
/// adding it to their <see cref="PlayerSpellLoadout"/>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Mirrors <see cref="BuilderEffectDraftOption"/>: carries the <see cref="BuilderSpellKind"/>
|
|
/// directly rather than an asset reference, since the enum value is the stable identifier
|
|
/// <see cref="PlayerSpellLoadout"/> and <see cref="BuilderSpellPool"/> already key off of.
|
|
/// <see cref="IsValidFor"/> also checks slot capacity — once
|
|
/// <see cref="PlayerSpellLoadout.MaxSpellSlots"/> is reached, no further spell options are
|
|
/// offered.
|
|
/// </remarks>
|
|
[CreateAssetMenu(fileName = "BuilderSpellOption", menuName = "TD/Draft/Builder Spell Option")]
|
|
public class BuilderSpellDraftOption : DraftOption
|
|
{
|
|
[Header("Payload")]
|
|
[Tooltip("The builder spell this option grants.")]
|
|
public BuilderSpellKind Kind;
|
|
|
|
public override bool IsValidFor(ulong clientId)
|
|
{
|
|
var loadout = PlayerSpellLoadout.GetForClient(clientId);
|
|
if (loadout == null) return false;
|
|
if (loadout.SlotCount >= PlayerSpellLoadout.MaxSpellSlots) return false;
|
|
return !loadout.PlayerHasSpell(Kind);
|
|
}
|
|
|
|
public override bool ServerApply(ulong clientId)
|
|
{
|
|
var loadout = PlayerSpellLoadout.GetForClient(clientId);
|
|
return loadout != null && loadout.ServerGrantSpell(Kind);
|
|
}
|
|
|
|
/// <summary>Inherits the granted spell's icon (resolved from the pool by
|
|
/// <see cref="Kind"/>) unless this option assigns an override.</summary>
|
|
public override Sprite ResolveIcon()
|
|
{
|
|
if (Icon != null) return Icon;
|
|
var def = BuilderSpellPool.Instance != null ? BuilderSpellPool.Instance.Get(Kind) : null;
|
|
return def != null ? def.Icon : null;
|
|
}
|
|
}
|
|
}
|