new builder option per draft - first one is gold per kill

This commit is contained in:
Ian Woods 2026-07-07 22:55:35 -07:00
parent 4a37d3747c
commit 157b77ebfa
21 changed files with 456 additions and 7 deletions

View file

@ -0,0 +1,34 @@
// Assets/_Project/Scripts/Gameplay/BuilderEffects/BuilderEffectDefinition.cs
using UnityEngine;
using TD.Core;
namespace TD.Gameplay.BuilderEffects
{
/// <summary>
/// Base class for one builder effect — a passive perk that applies to every tower a
/// player's Builder constructs (e.g. "kills yield bonus gold"). Granted via the draft
/// (<see cref="TD.Gameplay.Draft.BuilderEffectDraftOption"/>) and tracked per-player by
/// <see cref="BuilderUpgradeManager"/>.
/// </summary>
/// <remarks>
/// <para><b>One asset per kind.</b> <see cref="Kind"/> is fixed per subclass (each concrete
/// type overrides it to its own <see cref="BuilderEffectKind"/>), so there's no way to
/// mis-tag an asset in the inspector. <see cref="BuilderEffectPool"/> uses it to build a
/// fixed-size, enum-indexed lookup table — no scanning to resolve a kind to its data.</para>
///
/// <para><b>No shared "Apply" contract.</b> Concrete subclasses (e.g.
/// <see cref="GoldPerKillEffectDefinition"/>) carry whatever payload they need. Effects with
/// different application shapes — a simple value read at an existing game-event hook vs.
/// behavior that needs its own component on the tower — are still just subclasses; consumers
/// query the concrete type they care about directly (see
/// <see cref="BuilderUpgradeManager.GetTotalGoldPerKillBonus"/>).</para>
/// </remarks>
public abstract class BuilderEffectDefinition : ScriptableObject
{
/// <summary>Which builder effect this asset's data belongs to.</summary>
public abstract BuilderEffectKind Kind { get; }
[Tooltip("Name shown wherever a player's active builder effects are listed.")]
public string DisplayName;
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3a939cb6af19202e1a9bddf01d9f1857

View file

@ -0,0 +1,66 @@
// Assets/_Project/Scripts/Gameplay/BuilderEffects/BuilderEffectPool.cs
using System;
using UnityEngine;
using TD.Core;
namespace TD.Gameplay.BuilderEffects
{
/// <summary>
/// Scene singleton holding every <see cref="BuilderEffectDefinition"/> available this match,
/// authored as a flat array in the inspector for convenience. Internally it builds a
/// fixed-size table indexed by <see cref="BuilderEffectKind"/> so lookups are a single array
/// access, not a scan.
/// </summary>
/// <remarks>
/// Plain MonoBehaviour: identical on every peer (same assets), so there is nothing to sync.
/// The server reads it to resolve grants; clients read it to render an "active effects" list.
/// </remarks>
public class BuilderEffectPool : MonoBehaviour
{
public static BuilderEffectPool Instance { get; private set; }
[Tooltip("Every BuilderEffectDefinition asset available this match. One entry per " +
"BuilderEffectKind — order doesn't matter, Kind on the asset itself decides " +
"its slot.")]
[SerializeField] private BuilderEffectDefinition[] effects;
// Fixed-size, enum-indexed lookup built once in Awake. Sized to the enum's entry count,
// not authored count, so an out-of-range Kind is a compile-time impossibility rather
// than a bounds check we'd otherwise need on every Get().
private BuilderEffectDefinition[] byKind;
private void Awake()
{
if (Instance != null && Instance != this)
{
Debug.LogError("[BuilderEffectPool] Multiple instances detected. Only one per scene.");
return;
}
Instance = this;
int kindCount = Enum.GetValues(typeof(BuilderEffectKind)).Length;
byKind = new BuilderEffectDefinition[kindCount];
if (effects == null) return;
for (int i = 0; i < effects.Length; i++)
{
var def = effects[i];
if (def == null) continue;
byKind[(int)def.Kind] = def;
}
}
private void OnDestroy()
{
if (Instance == this) Instance = null;
}
/// <summary>Returns the effect asset for <paramref name="kind"/>, or null if none is
/// authored in this pool.</summary>
public BuilderEffectDefinition Get(BuilderEffectKind kind)
{
int i = (int)kind;
return (byKind != null && i >= 0 && i < byKind.Length) ? byKind[i] : null;
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6226c6e672c5b358a9cdc2a1bee47daf

View file

@ -0,0 +1,22 @@
// Assets/_Project/Scripts/Gameplay/BuilderEffects/GoldPerKillEffectDefinition.cs
using UnityEngine;
using TD.Core;
namespace TD.Gameplay.BuilderEffects
{
/// <summary>
/// Builder effect #1 — every tower the player owns yields extra gold per kill.
/// Read by <see cref="BuilderUpgradeManager.GetTotalGoldPerKillBonus"/>, which
/// <see cref="TD.Gameplay.WaveManager"/> queries when awarding kill gold.
/// </summary>
[CreateAssetMenu(fileName = "GoldPerKillEffect", menuName = "TD/Builder Effects/Gold Per Kill")]
public class GoldPerKillEffectDefinition : BuilderEffectDefinition
{
public override BuilderEffectKind Kind => BuilderEffectKind.GoldPerKill;
[Tooltip("Flat bonus gold awarded on top of the normal kill reward, for every kill by " +
"any of this player's towers.")]
[Min(0)]
public int BonusGoldPerKill = 1;
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5ce77a7f27ed228a0ad0494dfc1a4749