Compare commits
No commits in common. "7e5c3a8279cee535986788daa9c386a6a10f7c3f" and "0b7bc936ef623fd293d642fa45a6bfc25cc3316b" have entirely different histories.
7e5c3a8279
...
0b7bc936ef
19 changed files with 4 additions and 484 deletions
|
|
@ -15,7 +15,7 @@ MonoBehaviour:
|
||||||
DisplayName: Fireball
|
DisplayName: Fireball
|
||||||
Description: Shoot a fireball
|
Description: Shoot a fireball
|
||||||
Icon: {fileID: 21300000, guid: eff45e5e3dab24f438c054a095d34578, type: 3}
|
Icon: {fileID: 21300000, guid: eff45e5e3dab24f438c054a095d34578, type: 3}
|
||||||
Cooldown: 15
|
Cooldown: 1
|
||||||
TargetType: 0
|
TargetType: 0
|
||||||
Radius: 5
|
Radius: 5
|
||||||
enemyLayerMask:
|
enemyLayerMask:
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 37cbc8b63ce7ae2e4b4abcfd7274bee7
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
%YAML 1.1
|
|
||||||
%TAG !u! tag:unity3d.com,2011:
|
|
||||||
--- !u!114 &11400000
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 0}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 21543cb1b54f0b16e9c80584f68988b3, type: 3}
|
|
||||||
m_Name: SplitOnDeathAbility
|
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::TD.Gameplay.EnemyAbilities.SplitOnDeathAbilityDefinition
|
|
||||||
DisplayName: Split on Death
|
|
||||||
Description: The enemy splits when it dies.
|
|
||||||
Weight: 100
|
|
||||||
SplitInto: {fileID: 11400000, guid: a05af37e2256f164d80a66cc2a582466, type: 2}
|
|
||||||
SplitCount: 2
|
|
||||||
ScatterRadius: 0.5
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 0305468bc8f912d429a8b20bf23f947c
|
|
||||||
NativeFormatImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
mainObjectFileID: 11400000
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
|
|
@ -17,7 +17,6 @@ GameObject:
|
||||||
- component: {fileID: 3756613737869398948}
|
- component: {fileID: 3756613737869398948}
|
||||||
- component: {fileID: 6036713598566100742}
|
- component: {fileID: 6036713598566100742}
|
||||||
- component: {fileID: -1575784752119152190}
|
- component: {fileID: -1575784752119152190}
|
||||||
- component: {fileID: 154042129325690845}
|
|
||||||
m_Layer: 10
|
m_Layer: 10
|
||||||
m_Name: Enemy_CrystalGolem_Blue
|
m_Name: Enemy_CrystalGolem_Blue
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
|
@ -126,7 +125,7 @@ MonoBehaviour:
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::TD.Gameplay.EnemyHealth
|
m_EditorClassIdentifier: Assembly-CSharp::TD.Gameplay.EnemyHealth
|
||||||
ShowTopMostFoldoutHeaderGroup: 1
|
ShowTopMostFoldoutHeaderGroup: 1
|
||||||
definition: {fileID: 11400000, guid: a05af37e2256f164d80a66cc2a582466, type: 2}
|
definition: {fileID: 0}
|
||||||
deathAnimator: {fileID: 1819643351848917197}
|
deathAnimator: {fileID: 1819643351848917197}
|
||||||
deathAnimationDuration: 1.5
|
deathAnimationDuration: 1.5
|
||||||
sinkDuration: 1.5
|
sinkDuration: 1.5
|
||||||
|
|
@ -225,19 +224,6 @@ MonoBehaviour:
|
||||||
volume: 0.75
|
volume: 0.75
|
||||||
minPitch: 0.95
|
minPitch: 0.95
|
||||||
maxPitch: 1.05
|
maxPitch: 1.05
|
||||||
--- !u!114 &154042129325690845
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1455822126534880203}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 9d1a26a32e8969cd29bce6010126a5f6, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::TD.Gameplay.EnemyAbility
|
|
||||||
ShowTopMostFoldoutHeaderGroup: 1
|
|
||||||
--- !u!1 &5361867751622119598
|
--- !u!1 &5361867751622119598
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
||||||
|
|
@ -2276,53 +2276,6 @@ Transform:
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1 &181002639
|
|
||||||
GameObject:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
serializedVersion: 6
|
|
||||||
m_Component:
|
|
||||||
- component: {fileID: 181002641}
|
|
||||||
- component: {fileID: 181002640}
|
|
||||||
m_Layer: 0
|
|
||||||
m_Name: EnemyAbilityPool
|
|
||||||
m_TagString: Untagged
|
|
||||||
m_Icon: {fileID: 0}
|
|
||||||
m_NavMeshLayer: 0
|
|
||||||
m_StaticEditorFlags: 0
|
|
||||||
m_IsActive: 1
|
|
||||||
--- !u!114 &181002640
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 181002639}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 4409eb25a8be555de8dc3a73d4ed95db, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::TD.Gameplay.EnemyAbilities.EnemyAbilityPool
|
|
||||||
abilities:
|
|
||||||
- {fileID: 11400000, guid: 0305468bc8f912d429a8b20bf23f947c, type: 2}
|
|
||||||
noAbilityWeight: 100
|
|
||||||
--- !u!4 &181002641
|
|
||||||
Transform:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 181002639}
|
|
||||||
serializedVersion: 2
|
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
||||||
m_LocalPosition: {x: 15.94346, y: 0, z: 194.22044}
|
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
|
||||||
m_ConstrainProportionsScale: 0
|
|
||||||
m_Children: []
|
|
||||||
m_Father: {fileID: 0}
|
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
||||||
--- !u!43 &203092944
|
--- !u!43 &203092944
|
||||||
Mesh:
|
Mesh:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
@ -29236,4 +29189,3 @@ SceneRoots:
|
||||||
- {fileID: 993870445}
|
- {fileID: 993870445}
|
||||||
- {fileID: 759470735}
|
- {fileID: 759470735}
|
||||||
- {fileID: 954434161}
|
- {fileID: 954434161}
|
||||||
- {fileID: 181002641}
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
namespace TD.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Identifies which enemy ability a
|
|
||||||
/// <see cref="TD.Gameplay.EnemyAbilities.EnemyAbilityDefinition"/> represents. Mirrors
|
|
||||||
/// <see cref="BuilderSpellKind"/> — a stable, enum-indexed identifier used by
|
|
||||||
/// <see cref="TD.Gameplay.EnemyAbilities.EnemyAbilityPool"/> instead of an asset reference.
|
|
||||||
/// </summary>
|
|
||||||
public enum EnemyAbilityKind : byte
|
|
||||||
{
|
|
||||||
/// <summary>No ability rolled. Never a real pool entry — only the sentinel value
|
|
||||||
/// <see cref="TD.Gameplay.EnemyAbility"/> reports before/absent a roll.</summary>
|
|
||||||
None = 0,
|
|
||||||
SplitOnDeath = 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: ec52a6b404fed65dfa48a63b5535373d
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 1c918164b61faf1d5af9f782c5237a60
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
// Assets/_Project/Scripts/Gameplay/EnemyAbilities/EnemyAbilityDefinition.cs
|
|
||||||
using UnityEngine;
|
|
||||||
using TD.Core;
|
|
||||||
|
|
||||||
namespace TD.Gameplay.EnemyAbilities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Base class for one enemy ability (e.g. "split into smaller enemies on death"). Rolled
|
|
||||||
/// at random for each spawned enemy by <see cref="EnemyAbilityPool.RollRandom"/> and applied
|
|
||||||
/// via <see cref="EnemyAbility.InitializeServer"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// <para><b>One asset per kind.</b> <see cref="Kind"/> is fixed per subclass, same as
|
|
||||||
/// <see cref="BuilderSpells.BuilderSpellDefinition"/>. <see cref="EnemyAbilityPool"/> uses
|
|
||||||
/// it to build a fixed-size, enum-indexed lookup table.</para>
|
|
||||||
///
|
|
||||||
/// <para><b>Server-only hooks.</b> All three hooks below only ever run on the server —
|
|
||||||
/// <see cref="EnemyAbility"/> only calls them when <c>IsServer</c> is true. <see
|
|
||||||
/// cref="ServerOnSpawn"/> and <see cref="ServerTick"/> are no-ops for abilities that don't
|
|
||||||
/// need spawn-time setup or a per-frame timer (e.g. Split on Death uses neither); they exist
|
|
||||||
/// so a future cooldown-driven ability (disable towers, teleport) doesn't need a base-class
|
|
||||||
/// change.</para>
|
|
||||||
/// </remarks>
|
|
||||||
public abstract class EnemyAbilityDefinition : ScriptableObject
|
|
||||||
{
|
|
||||||
/// <summary>Which enemy ability this asset's data belongs to.</summary>
|
|
||||||
public abstract EnemyAbilityKind Kind { get; }
|
|
||||||
|
|
||||||
[Header("Presentation")]
|
|
||||||
[Tooltip("Name shown in debug logs and future enemy-info UI.")]
|
|
||||||
public string DisplayName;
|
|
||||||
|
|
||||||
[Tooltip("Short description shown in future enemy-info UI.")]
|
|
||||||
[TextArea(2, 4)]
|
|
||||||
public string Description;
|
|
||||||
|
|
||||||
[Header("Selection")]
|
|
||||||
[Tooltip("Relative weight of this ability being rolled, vs. the pool's other abilities " +
|
|
||||||
"and its no-ability chance. Same semantics as DraftOption.Weight.")]
|
|
||||||
[Min(0f)]
|
|
||||||
public float Weight = 1f;
|
|
||||||
|
|
||||||
/// <summary>Server-only: called once, right after this ability is assigned (before the
|
|
||||||
/// enemy's NetworkObject is spawned to clients). Default no-op.</summary>
|
|
||||||
public virtual void ServerOnSpawn(EnemyAbility instance) { }
|
|
||||||
|
|
||||||
/// <summary>Server-only: called every frame this ability is active on a live enemy.
|
|
||||||
/// Default no-op.</summary>
|
|
||||||
public virtual void ServerTick(EnemyAbility instance, float dt) { }
|
|
||||||
|
|
||||||
/// <summary>Server-only: called the instant the enemy's HP reaches zero, before the
|
|
||||||
/// death animation/despawn sequence plays. Default no-op.</summary>
|
|
||||||
public virtual void ServerOnDeath(EnemyAbility instance, EnemyHealth health) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 855f7f0848d3086868816d25295fcdd6
|
|
||||||
|
|
@ -1,102 +0,0 @@
|
||||||
// Assets/_Project/Scripts/Gameplay/EnemyAbilities/EnemyAbilityPool.cs
|
|
||||||
using System;
|
|
||||||
using UnityEngine;
|
|
||||||
using TD.Core;
|
|
||||||
|
|
||||||
namespace TD.Gameplay.EnemyAbilities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Scene singleton holding every <see cref="EnemyAbilityDefinition"/> available this match,
|
|
||||||
/// authored as a flat array in the inspector for convenience. Internally it builds a
|
|
||||||
/// fixed-size table indexed by <see cref="EnemyAbilityKind"/> so lookups are a single array
|
|
||||||
/// access, not a scan. Mirrors <see cref="BuilderSpells.BuilderSpellPool"/> exactly.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// Plain MonoBehaviour: identical on every peer (same assets), so there is nothing to sync.
|
|
||||||
/// Only the server calls <see cref="RollRandom"/> (at enemy spawn time, in
|
|
||||||
/// <c>WaveManager.SpawnEnemy</c>).
|
|
||||||
/// </remarks>
|
|
||||||
public class EnemyAbilityPool : MonoBehaviour
|
|
||||||
{
|
|
||||||
public static EnemyAbilityPool Instance { get; private set; }
|
|
||||||
|
|
||||||
[Tooltip("Every EnemyAbilityDefinition asset available this match. One entry per " +
|
|
||||||
"EnemyAbilityKind — order doesn't matter, Kind on the asset itself decides " +
|
|
||||||
"its slot.")]
|
|
||||||
[SerializeField] private EnemyAbilityDefinition[] abilities;
|
|
||||||
|
|
||||||
[Tooltip("Relative weight of an enemy rolling no ability at all, vs. the combined " +
|
|
||||||
"weight of every entry in 'abilities'. Higher = abilities are rarer.")]
|
|
||||||
[Min(0f)]
|
|
||||||
[SerializeField] private float noAbilityWeight = 100f;
|
|
||||||
|
|
||||||
// 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 EnemyAbilityDefinition[] byKind;
|
|
||||||
|
|
||||||
private void Awake()
|
|
||||||
{
|
|
||||||
if (Instance != null && Instance != this)
|
|
||||||
{
|
|
||||||
Debug.LogError("[EnemyAbilityPool] Multiple instances detected. Only one per scene.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Instance = this;
|
|
||||||
|
|
||||||
int kindCount = Enum.GetValues(typeof(EnemyAbilityKind)).Length;
|
|
||||||
byKind = new EnemyAbilityDefinition[kindCount];
|
|
||||||
if (abilities == null) return;
|
|
||||||
|
|
||||||
for (int i = 0; i < abilities.Length; i++)
|
|
||||||
{
|
|
||||||
var def = abilities[i];
|
|
||||||
if (def == null) continue;
|
|
||||||
byKind[(int)def.Kind] = def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDestroy()
|
|
||||||
{
|
|
||||||
if (Instance == this) Instance = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Returns the ability asset for <paramref name="kind"/>, or null if none is
|
|
||||||
/// authored in this pool.</summary>
|
|
||||||
public EnemyAbilityDefinition Get(EnemyAbilityKind kind)
|
|
||||||
{
|
|
||||||
int i = (int)kind;
|
|
||||||
return (byKind != null && i >= 0 && i < byKind.Length) ? byKind[i] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Server-only: weighted random draw across every authored ability plus the
|
|
||||||
/// no-ability bucket. Returns null when "no ability" is drawn, or when the pool has
|
|
||||||
/// nothing authored.
|
|
||||||
/// </summary>
|
|
||||||
public EnemyAbilityDefinition RollRandom()
|
|
||||||
{
|
|
||||||
if (abilities == null || abilities.Length == 0) return null;
|
|
||||||
|
|
||||||
float total = noAbilityWeight;
|
|
||||||
for (int i = 0; i < abilities.Length; i++)
|
|
||||||
if (abilities[i] != null) total += abilities[i].Weight;
|
|
||||||
|
|
||||||
if (total <= 0f) return null;
|
|
||||||
|
|
||||||
float roll = UnityEngine.Random.Range(0f, total);
|
|
||||||
if (roll < noAbilityWeight) return null;
|
|
||||||
roll -= noAbilityWeight;
|
|
||||||
|
|
||||||
for (int i = 0; i < abilities.Length; i++)
|
|
||||||
{
|
|
||||||
var def = abilities[i];
|
|
||||||
if (def == null) continue;
|
|
||||||
if (roll < def.Weight) return def;
|
|
||||||
roll -= def.Weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 4409eb25a8be555de8dc3a73d4ed95db
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
// Assets/_Project/Scripts/Gameplay/EnemyAbilities/SplitOnDeathAbilityDefinition.cs
|
|
||||||
using UnityEngine;
|
|
||||||
using TD.Core;
|
|
||||||
|
|
||||||
namespace TD.Gameplay.EnemyAbilities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// On death, spawns <see cref="SplitCount"/> smaller copies of the dying enemy's own type at
|
|
||||||
/// the corpse's position, continuing on toward the goal instead of restarting from the wave's
|
|
||||||
/// spawner. There's no separate "minion" EnemyDefinition to author — the mini copies reuse
|
|
||||||
/// whichever EnemyDefinition/prefab the dying enemy itself was spawned from, scaled down by
|
|
||||||
/// <see cref="HpMultiplier"/>/<see cref="ScaleMultiplier"/>.
|
|
||||||
/// </summary>
|
|
||||||
[CreateAssetMenu(fileName = "SplitOnDeathAbility", menuName = "TD/Enemy Abilities/Split On Death")]
|
|
||||||
public class SplitOnDeathAbilityDefinition : EnemyAbilityDefinition
|
|
||||||
{
|
|
||||||
public override EnemyAbilityKind Kind => EnemyAbilityKind.SplitOnDeath;
|
|
||||||
|
|
||||||
[Header("Split")]
|
|
||||||
[Tooltip("How many mini copies spawn on death.")]
|
|
||||||
[Min(1)]
|
|
||||||
public int SplitCount = 2;
|
|
||||||
|
|
||||||
[Tooltip("Each mini copy's MaxHp = the dying enemy's own MaxHp * this multiplier.")]
|
|
||||||
[Range(0.01f, 1f)]
|
|
||||||
public float HpMultiplier = 0.5f;
|
|
||||||
|
|
||||||
[Tooltip("Uniform transform scale applied to each mini copy, relative to the normal " +
|
|
||||||
"prefab scale. Requires the enemy prefab's NetworkTransform to sync scale, " +
|
|
||||||
"or the mini will render full-size on remote peers.")]
|
|
||||||
[Range(0.1f, 1f)]
|
|
||||||
public float ScaleMultiplier = 0.6f;
|
|
||||||
|
|
||||||
[Tooltip("Random scatter radius (world units) applied to each split spawn so they don't " +
|
|
||||||
"spawn exactly on top of each other.")]
|
|
||||||
[Min(0f)]
|
|
||||||
public float ScatterRadius = 0.5f;
|
|
||||||
|
|
||||||
public override void ServerOnDeath(EnemyAbility instance, EnemyHealth health)
|
|
||||||
{
|
|
||||||
var def = health.Definition;
|
|
||||||
if (def == null) return;
|
|
||||||
|
|
||||||
var movement = instance.GetComponent<EnemyMovement>();
|
|
||||||
var atTile = GridCoordinates.WorldToGrid(instance.transform.position);
|
|
||||||
var ownerSlot = movement != null ? movement.OriginZone : PlayerSlot.None;
|
|
||||||
|
|
||||||
WaveManager.Instance?.ServerSpawnSplitEnemies(
|
|
||||||
def, SplitCount, atTile, ownerSlot, ScatterRadius, HpMultiplier, ScaleMultiplier);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 21543cb1b54f0b16e9c80584f68988b3
|
|
||||||
|
|
@ -1,87 +0,0 @@
|
||||||
// Assets/_Project/Scripts/Gameplay/EnemyAbility.cs
|
|
||||||
using Unity.Netcode;
|
|
||||||
using UnityEngine;
|
|
||||||
using TD.Core;
|
|
||||||
using TD.Gameplay.EnemyAbilities;
|
|
||||||
|
|
||||||
namespace TD.Gameplay
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Per-enemy ability slot. Holds the <see cref="EnemyAbilityDefinition"/> rolled for this
|
|
||||||
/// instance (if any) and drives its server-only hooks.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// <b>Initialization:</b> Call <see cref="InitializeServer"/> on the server immediately after
|
|
||||||
/// <c>Instantiate</c> and before <c>NetworkObject.Spawn()</c>, following the same pattern as
|
|
||||||
/// <c>EnemyHealth.InitializeServer</c> / <c>EnemyMovement.InitializeServer</c>.
|
|
||||||
///
|
|
||||||
/// <b>Optional component:</b> Not required by <c>EnemyHealth</c> or <c>EnemyMovement</c> —
|
|
||||||
/// <c>WaveManager.SpawnEnemy</c> only rolls and assigns an ability when this component is
|
|
||||||
/// present on the prefab, so existing enemy prefabs are unaffected until it's added to them.
|
|
||||||
///
|
|
||||||
/// <b>On-death hook is not event-driven:</b> <c>WaveManager.HandleEnemyKilled</c> calls
|
|
||||||
/// <see cref="EnemyAbilityDefinition.ServerOnDeath"/> directly (via <see cref="Definition"/>)
|
|
||||||
/// rather than this component subscribing to <c>EnemyHealth.OnDied</c> itself — that keeps a
|
|
||||||
/// split-spawn's <c>activeEnemyCount</c> increment ordered before the triggering kill's
|
|
||||||
/// decrement, regardless of NetworkBehaviour subscription order.
|
|
||||||
/// </remarks>
|
|
||||||
[RequireComponent(typeof(NetworkObject))]
|
|
||||||
public class EnemyAbility : NetworkBehaviour
|
|
||||||
{
|
|
||||||
private readonly NetworkVariable<byte> kind = new NetworkVariable<byte>(
|
|
||||||
(byte)EnemyAbilityKind.None,
|
|
||||||
NetworkVariableReadPermission.Everyone,
|
|
||||||
NetworkVariableWritePermission.Server);
|
|
||||||
|
|
||||||
// ----- Pre-spawn init (server-local) ----------------------------------
|
|
||||||
|
|
||||||
private EnemyAbilityDefinition pendingDefinition;
|
|
||||||
private bool hasPendingInit;
|
|
||||||
|
|
||||||
// ----- Public state -----------------------------------------------------
|
|
||||||
|
|
||||||
/// <summary>The ability rolled for this enemy, or null if none was rolled.</summary>
|
|
||||||
public EnemyAbilityDefinition Definition { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>Replicated kind of the rolled ability. <see cref="EnemyAbilityKind.None"/> if
|
|
||||||
/// none was rolled.</summary>
|
|
||||||
public EnemyAbilityKind Kind => (EnemyAbilityKind)kind.Value;
|
|
||||||
|
|
||||||
// ----- Server-only pre-spawn init -------------------------------------
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called by <c>WaveManager</c> on the server after <c>Instantiate</c> and before
|
|
||||||
/// <c>NetworkObject.Spawn()</c>. <paramref name="definition"/> may be null, meaning no
|
|
||||||
/// ability was rolled for this enemy.
|
|
||||||
/// </summary>
|
|
||||||
public void InitializeServer(EnemyAbilityDefinition definition)
|
|
||||||
{
|
|
||||||
pendingDefinition = definition;
|
|
||||||
hasPendingInit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----- NGO lifecycle --------------------------------------------------
|
|
||||||
|
|
||||||
public override void OnNetworkSpawn()
|
|
||||||
{
|
|
||||||
if (!IsServer || !hasPendingInit) return;
|
|
||||||
|
|
||||||
Definition = pendingDefinition;
|
|
||||||
kind.Value = (byte)(Definition != null ? Definition.Kind : EnemyAbilityKind.None);
|
|
||||||
hasPendingInit = false;
|
|
||||||
|
|
||||||
if (Definition != null)
|
|
||||||
Debug.Log($"[EnemyAbility] {name} rolled {Definition.Kind}.");
|
|
||||||
|
|
||||||
Definition?.ServerOnSpawn(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----- Server tick ------------------------------------------------
|
|
||||||
|
|
||||||
private void Update()
|
|
||||||
{
|
|
||||||
if (!IsServer || Definition == null) return;
|
|
||||||
Definition.ServerTick(this, Time.deltaTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 9d1a26a32e8969cd29bce6010126a5f6
|
|
||||||
|
|
@ -73,11 +73,6 @@ namespace TD.Gameplay
|
||||||
// the goal). Without this, every zone crossing was counted as a leak; only
|
// the goal). Without this, every zone crossing was counted as a leak; only
|
||||||
// the originating player should be credited a leak per the design.
|
// the originating player should be credited a leak per the design.
|
||||||
private PlayerSlot originZone = PlayerSlot.None;
|
private PlayerSlot originZone = PlayerSlot.None;
|
||||||
|
|
||||||
/// <summary>The zone (player) this enemy was originally spawned for — see
|
|
||||||
/// <see cref="InitializeServer"/>. Used by on-death abilities (e.g. Split on Death) so
|
|
||||||
/// spawned children preserve the same leak attribution as their parent.</summary>
|
|
||||||
public PlayerSlot OriginZone => originZone;
|
|
||||||
// Latches once the enemy has crossed its origin zone's leak volume, so we
|
// Latches once the enemy has crossed its origin zone's leak volume, so we
|
||||||
// never double-count a leak if the enemy re-enters its origin (rare but
|
// never double-count a leak if the enemy re-enters its origin (rare but
|
||||||
// possible if pathing is dynamic).
|
// possible if pathing is dynamic).
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ using UnityEngine;
|
||||||
using TD.Core;
|
using TD.Core;
|
||||||
using TD.Gameplay.BuilderEffects;
|
using TD.Gameplay.BuilderEffects;
|
||||||
using TD.Gameplay.Draft;
|
using TD.Gameplay.Draft;
|
||||||
using TD.Gameplay.EnemyAbilities;
|
|
||||||
using TD.Levels;
|
using TD.Levels;
|
||||||
using TD.UI;
|
using TD.UI;
|
||||||
|
|
||||||
|
|
@ -457,8 +456,7 @@ namespace TD.Gameplay
|
||||||
|
|
||||||
private void SpawnEnemy(EnemyDefinition def, Vector2Int spawnerTile, PlayerSlot ownerSlot,
|
private void SpawnEnemy(EnemyDefinition def, Vector2Int spawnerTile, PlayerSlot ownerSlot,
|
||||||
float xHalfExtent = 0f, float zHalfExtent = 0f, bool held = false,
|
float xHalfExtent = 0f, float zHalfExtent = 0f, bool held = false,
|
||||||
Direction facing = Direction.South, bool canRollAbility = true,
|
Direction facing = Direction.South)
|
||||||
float hpMultiplier = 1f, float visualScale = 1f)
|
|
||||||
{
|
{
|
||||||
if (def.EnemyPrefab == null)
|
if (def.EnemyPrefab == null)
|
||||||
{
|
{
|
||||||
|
|
@ -492,12 +490,6 @@ namespace TD.Gameplay
|
||||||
spawnPos,
|
spawnPos,
|
||||||
Quaternion.Euler(0f, yaw, 0f));
|
Quaternion.Euler(0f, yaw, 0f));
|
||||||
|
|
||||||
// Scales the whole prefab hierarchy uniformly (used for split-on-death minions).
|
|
||||||
// Relies on the enemy prefab's NetworkTransform syncing scale to clients — verify
|
|
||||||
// that's enabled if a scaled spawn doesn't look smaller on remote peers.
|
|
||||||
if (visualScale != 1f)
|
|
||||||
go.transform.localScale *= visualScale;
|
|
||||||
|
|
||||||
var health = go.GetComponent<EnemyHealth>();
|
var health = go.GetComponent<EnemyHealth>();
|
||||||
var movement = go.GetComponent<EnemyMovement>();
|
var movement = go.GetComponent<EnemyMovement>();
|
||||||
|
|
||||||
|
|
@ -509,17 +501,8 @@ namespace TD.Gameplay
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
health.InitializeServer(def.MaxHp * hpMultiplier, def.LivesCost, def.IsFlying, held);
|
health.InitializeServer(def.MaxHp, def.LivesCost, def.IsFlying, held);
|
||||||
movement.InitializeServer(def.MoveSpeed, spawnerTile, ownerSlot, def.IsFlying);
|
movement.InitializeServer(def.MoveSpeed, spawnerTile, ownerSlot, def.IsFlying);
|
||||||
|
|
||||||
// Optional — only prefabs with an EnemyAbility component roll an ability. See
|
|
||||||
// EnemyAbility's remarks for why on-death abilities aren't event-subscription driven.
|
|
||||||
// canRollAbility is false for split-spawned minions (see ServerSpawnSplitEnemies) so
|
|
||||||
// they can never chain into further splits or pick up any other ability.
|
|
||||||
var ability = go.GetComponent<EnemyAbility>();
|
|
||||||
if (ability != null)
|
|
||||||
ability.InitializeServer(canRollAbility ? EnemyAbilityPool.Instance?.RollRandom() : null);
|
|
||||||
|
|
||||||
if (held) heldEnemies.Add(health);
|
if (held) heldEnemies.Add(health);
|
||||||
|
|
||||||
health.OnDied += HandleEnemyKilled;
|
health.OnDied += HandleEnemyKilled;
|
||||||
|
|
@ -531,29 +514,6 @@ namespace TD.Gameplay
|
||||||
go.GetComponent<NetworkObject>().Spawn();
|
go.GetComponent<NetworkObject>().Spawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Server-only: spawns <paramref name="count"/> copies of <paramref name="def"/> at
|
|
||||||
/// <paramref name="atTile"/>, continuing that tile's A* path onward rather than
|
|
||||||
/// restarting from a wave spawner. Used by on-death abilities (e.g.
|
|
||||||
/// <c>SplitOnDeathAbilityDefinition</c>) to spawn smaller enemies from a corpse's
|
|
||||||
/// position. Reuses <see cref="SpawnEnemy"/> so split children get the same
|
|
||||||
/// <c>activeEnemyCount</c>/event-wiring bookkeeping as any other spawn.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// Split-spawned minions never roll an ability of their own — they're always plain,
|
|
||||||
/// so a split can't chain into further splits (or any other ability) regardless of
|
|
||||||
/// which EnemyDefinition/prefab is used for <paramref name="def"/>.
|
|
||||||
/// </remarks>
|
|
||||||
public void ServerSpawnSplitEnemies(EnemyDefinition def, int count, Vector2Int atTile,
|
|
||||||
PlayerSlot ownerSlot, float scatterRadius,
|
|
||||||
float hpMultiplier = 1f, float visualScale = 1f)
|
|
||||||
{
|
|
||||||
if (!IsServer) return;
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
SpawnEnemy(def, atTile, ownerSlot, scatterRadius, scatterRadius, canRollAbility: false,
|
|
||||||
hpMultiplier: hpMultiplier, visualScale: visualScale);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----- Enemy event handlers (server-only) -------------------------
|
// ----- Enemy event handlers (server-only) -------------------------
|
||||||
|
|
||||||
private void HandleEnemyKilled(EnemyHealth health)
|
private void HandleEnemyKilled(EnemyHealth health)
|
||||||
|
|
@ -591,13 +551,6 @@ namespace TD.Gameplay
|
||||||
if (totalReward > 0)
|
if (totalReward > 0)
|
||||||
ShowGoldRewardClientRpc(health.transform.position, totalReward);
|
ShowGoldRewardClientRpc(health.transform.position, totalReward);
|
||||||
|
|
||||||
// Resolve any on-death ability BEFORE unsubscribing/decrementing. A split-spawn's
|
|
||||||
// activeEnemyCount++ (inside ServerSpawnSplitEnemies -> SpawnEnemy) must land before
|
|
||||||
// this kill's activeEnemyCount-- below, or a split on a wave's last enemy could let
|
|
||||||
// CheckWaveComplete see activeEnemyCount hit 0 and advance the wave prematurely.
|
|
||||||
var ability = health.GetComponent<EnemyAbility>();
|
|
||||||
ability?.Definition?.ServerOnDeath(ability, health);
|
|
||||||
|
|
||||||
UnsubscribeEnemy(health);
|
UnsubscribeEnemy(health);
|
||||||
DecrementAndCheckComplete();
|
DecrementAndCheckComplete();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue