Add tower Sell action with refund + coin VFX/SFX

Owner-validated sell RPC refunds SellRefundPercent of invested gold (Wall refunds 100% while un-upgraded), despawns the tower, and broadcasts a coin-burst VFX + rustle SFX. Refunds do not count as per-wave income. Investment/upgrade tracking added as the seam for the future upgrade system.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Matt F 2026-07-14 20:05:06 -07:00
parent 2429efbf6a
commit 9be31b1645
7 changed files with 361 additions and 12 deletions

View file

@ -5,6 +5,7 @@ using UnityEngine;
using TD.Core;
using TD.Levels;
using TD.Towers;
using TD.VFX;
namespace TD.Gameplay
{
@ -350,6 +351,26 @@ namespace TD.Gameplay
$"client {req.SenderClientId} ({placingSlot}) at anchor {req.Anchor}.");
}
// ----- Sell effects (persistent broadcaster) ----------------------
/// <summary>
/// Server-only: tells every peer to play the tower-sold VFX/SFX at
/// <paramref name="worldPos"/>. Called by <see cref="TowerInstance"/> as it sells,
/// because the tower's own NetworkObject despawns the same frame — a persistent
/// object must carry the broadcast so it isn't dropped.
/// </summary>
public void BroadcastSellEffect(Vector3 worldPos)
{
if (!IsServer) return;
PlaySellEffectRpc(worldPos);
}
[Rpc(SendTo.Everyone)]
private void PlaySellEffectRpc(Vector3 worldPos)
{
SellEffectSpawner.Instance?.Play(worldPos);
}
// ----- Server-side commit hooks called by Builder ------------------
/// <summary>