f3eccec524
Four playtest do-now wins: - Enemy health bars: pooled world-space Canvas, on-damage-sticky + fade, always-on <25% HP (CombatFeedbackSystem; no new replication). - Telegraph fix: new baked client-safe EnemyTelegraph sizes the danger-cone ramp per enemy (0->1 ending at impact, fixes the Charger plateau); windup 18->22; a windup scale-pulse. - Build-mode toggle: BuildPaletteState.PaletteOpen hides the palette by default, Tab / gamepad-Y toggles, with a discovery chip (HudSystem/BuildSendSystem). - Charger committed-lunge tell: [GhostEnabledBit] IsLunging derived once/tick from LungeState (the Dead idiom); the danger cone persists through the lunge. 345/345 EditMode (+3 IsLunging derive tests); Play-validated: ghost-hash change did not break the handshake, bake correct (telegraph on all enemies, IsLunging baked-disabled on the Charger, replicated to client), no runtime errors. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
69 lines
3.4 KiB
C#
69 lines
3.4 KiB
C#
using ProjectM.Simulation;
|
|
using Unity.Entities;
|
|
using UnityEngine;
|
|
|
|
namespace ProjectM.Authoring
|
|
{
|
|
/// <summary>
|
|
/// Authoring for the Husk enemy prefab. Bakes the gameplay components onto a prefab whose ghost setup
|
|
/// (GhostAuthoringComponent: interpolated, ownerless) is inherited by DUPLICATING an existing interpolated
|
|
/// ghost (UpgradePickup.prefab) — so the Husk replicates to all clients with no hand-written <c>[GhostField]</c>
|
|
/// (the stock LocalTransform variant carries its server-driven position). Damageable exactly like the training
|
|
/// dummy (Health/HitRadius/DamageEvent) plus the Husk AI tunables. <c>GetEntity(Dynamic)</c> gives a
|
|
/// runtime-mutable LocalTransform for server-authoritative movement and hit tests.
|
|
/// </summary>
|
|
public class EnemyAuthoring : MonoBehaviour
|
|
{
|
|
[Min(0f), Tooltip("Starting and maximum health for the Husk.")]
|
|
public float MaxHealth = 30f;
|
|
|
|
[Min(0f), Tooltip("World-unit radius used by the projectile hit test.")]
|
|
public float HitRadius = 0.7f;
|
|
|
|
[Min(0f), Tooltip("Planar seek speed toward the nearest player, units/second.")]
|
|
public float MoveSpeed = 3.5f;
|
|
|
|
[Min(0f), Tooltip("Centre-to-centre distance at which the Husk can strike a player.")]
|
|
public float AttackRange = 1.6f;
|
|
|
|
[Min(0f), Tooltip("Damage dealt per strike.")]
|
|
public float AttackDamage = 8f;
|
|
|
|
[Min(1), Tooltip("Simulation ticks between strikes (~60 ticks/sec).")]
|
|
public int AttackCooldownTicks = 36;
|
|
|
|
private class EnemyBaker : Baker<EnemyAuthoring>
|
|
{
|
|
public override void Bake(EnemyAuthoring authoring)
|
|
{
|
|
var entity = GetEntity(authoring, TransformUsageFlags.Dynamic);
|
|
|
|
AddComponent<EnemyTag>(entity);
|
|
AddComponent(entity, new Health { Current = authoring.MaxHealth, Max = authoring.MaxHealth });
|
|
AddComponent(entity, new HitRadius { Value = authoring.HitRadius });
|
|
AddBuffer<DamageEvent>(entity);
|
|
AddComponent(entity, new EnemyStats
|
|
{
|
|
MoveSpeed = authoring.MoveSpeed,
|
|
AttackRange = authoring.AttackRange,
|
|
AttackDamage = authoring.AttackDamage,
|
|
AttackCooldownTicks = authoring.AttackCooldownTicks,
|
|
});
|
|
AddComponent(entity, new EnemyAttackCooldown { NextAttackTick = 0 });
|
|
AddComponent<KnockbackState>(entity); // server-only recoil state (zero = not knocked)
|
|
AddComponent<AttackWindup>(entity); // replicated telegraph signal (zero = not winding up)
|
|
// Slice 1 (Feature C): client-safe baked telegraph metadata. EnemyBaker is the SOLE writer of
|
|
// EnemyTelegraph even on a Charger (the prefab composes both authorings on one entity); reading the
|
|
// sibling ChargerAuthoring here avoids a double-AddComponent. WindupTicks = the client danger-ramp
|
|
// denominator per variant; IsCharger lets the client pick the Charger look (LungeState is server-only).
|
|
bool isCharger = GetComponent<ChargerAuthoring>() != null;
|
|
AddComponent(entity, new EnemyTelegraph
|
|
{
|
|
WindupTicks = (byte)(isCharger ? 30 : Tuning.AttackWindupTicks),
|
|
IsCharger = (byte)(isCharger ? 1 : 0),
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|