Files
Project-M/Assets/_Project/Tests/EditMode/ClassTraitsTests.cs
T
kronic 9f61f7c6fe LANTERN kit into the shipping scene + frame rename (audit H2/M4)
H2 was the audit's sharpest finding: in Game.unity every player spawned
with four ability sockets pointing at SparkIds the baked AbilityDatabase
did not contain, so all four resolved to Damage=0 Range=0 Cooldown=0.
Melee and dash were the only working combat verbs in the built game.
Cause: the 5 LANTERN Sparks were added to GymSub.unity and never to
Gameplay.unity.

- Gameplay.unity's AbilityDatabaseAuthoring now carries all 9 defs (the
  4 legacy ids keep their numbers; Sparks are 5-9) with their effect
  prefabs. Live-verified in Play: sockets now read
  Vortex 8dmg/6range/420cd, Blink 20range/1cd, Hook & Pull
  15dmg/25range/120cd, Light Zone 6dmg/5range/480cd.
- Removed 6 orphaned authoring GameObjects the purge left behind in the
  subscene (StorageSpawner, StructureCatalog, ItemDatabase,
  SpitterProjectileConfig, BoonCatalog, MetaCatalog) and the RoomDressing
  object in Game.unity — the latter is what scattered 47 Synty desert
  props into the seabed murk.
- Deleted 4 now-unreferenced prefabs: EnemySpit, Pylon, Storage, Wall.
- Frame rename (M4): FrameKind.Warrior/Ranger -> Bathynaut/Harpooner,
  93 identifier sites. Byte values pinned (2/3), so no ghost-hash or save
  impact. The menu said "Warrior"/"Ranger" to players three weeks after
  the frames were renamed in design.
- Menu now reads LANTERN / "Light is territory — co-op descent" instead
  of "PROJECT M" / "Frontier colony — co-op" (the Awakening-Engine
  tagline, two directions stale).
- Removed the "Replay Tutorial" button and the Settings ONBOARDING
  section: both drove coach-marks DR-051 deleted. The settings fields
  still round-trip so existing settings files load unchanged.

All four project scenes + all prefabs verified free of missing scripts.
Server measured at 59.6 ticks/s against a 60 Hz target. 295/295 green.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 13:11:58 -07:00

146 lines
8.1 KiB
C#

using NUnit.Framework;
using ProjectM.Simulation;
using Unity.Collections;
using Unity.Entities;
namespace ProjectM.Tests
{
/// <summary>
/// Slice 2 — the pure class mapping: which Fire ability each class gets, and that the DRG-asymmetric trait
/// seeds fold the right direction (Bathynaut = melee bruiser / tankier / slower; Harpooner = ranged / faster /
/// squishier + a wider auto-assist co-op hook), all on the reserved <see cref="Tuning.ClassSourceId"/> range.
/// </summary>
public class ClassTraitsTests
{
static DynamicBuffer<StatModifier> SeededBuffer(World world, byte classId)
{
var em = world.EntityManager;
var e = em.CreateEntity();
em.AddBuffer<StatModifier>(e);
var ecb = new EntityCommandBuffer(Allocator.Temp);
ClassTraits.AppendSeeds(classId, e, ecb);
ecb.Playback(em);
ecb.Dispose();
return em.GetBuffer<StatModifier>(e);
}
[Test]
public void Normalize_DefaultsToWarrior()
{
Assert.AreEqual(ClassTraits.BathynautFrame, ClassTraits.Normalize(0));
Assert.AreEqual(ClassTraits.BathynautFrame, ClassTraits.Normalize(99));
Assert.AreEqual(ClassTraits.HarpoonerFrame, ClassTraits.Normalize(ClassTraits.HarpoonerFrame));
}
[Test]
public void Warrior_Seeds_Buff_Melee_And_Tankiness_And_Slow()
{
using var world = new World("ClassTraitsWarrior");
var mods = SeededBuffer(world, ClassTraits.BathynautFrame);
Assert.AreEqual(4, mods.Length, "Bathynaut seeds 4 trait modifiers.");
Assert.Greater(StatMath.Apply(10f, StatTarget.MeleeDamage, mods), 10f, "Bathynaut hits harder in melee.");
Assert.Greater(StatMath.Apply(2.6f, StatTarget.MeleeRange, mods), 2.6f, "Bathynaut reaches further in melee.");
Assert.Less(StatMath.Apply(5f, StatTarget.MoveSpeed, mods), 5f, "Bathynaut moves slower.");
Assert.Greater(StatMath.Apply(100f, StatTarget.MaxHealth, mods), 100f, "Bathynaut is tankier.");
for (int i = 0; i < mods.Length; i++)
Assert.GreaterOrEqual(mods[i].SourceId, Tuning.ClassSourceId, "class seeds use the reserved SourceId range.");
}
[Test]
public void Ranger_Seeds_Buff_Range_Speed_Assist_And_Leave_Melee_Weak()
{
using var world = new World("ClassTraitsRanger");
var mods = SeededBuffer(world, ClassTraits.HarpoonerFrame);
Assert.AreEqual(4, mods.Length, "Harpooner seeds 4 trait modifiers.");
Assert.Greater(StatMath.Apply(5f, StatTarget.MoveSpeed, mods), 5f, "Harpooner moves faster.");
Assert.Less(StatMath.Apply(100f, StatTarget.MaxHealth, mods), 100f, "Harpooner is squishier.");
Assert.Greater(StatMath.Apply(20f, StatTarget.Range, mods), 20f, "Harpooner has longer projectile range.");
Assert.Greater(StatMath.Apply(0f, StatTarget.AutoTargetRange, mods), 0f, "Harpooner has a wider auto-assist (the co-op hook).");
Assert.AreEqual(10f, StatMath.Apply(10f, StatTarget.MeleeDamage, mods), 0.001f, "Harpooner melee is unbuffed (weaker than the Bathynaut).");
}
static int CountClassSeeds(DynamicBuffer<StatModifier> mods)
{
int n = 0;
for (int i = 0; i < mods.Length; i++)
if (ClassTraits.IsClassSeed(mods[i].SourceId)) n++;
return n;
}
static bool ContainsSource(DynamicBuffer<StatModifier> mods, uint sourceId)
{
for (int i = 0; i < mods.Length; i++)
if (mods[i].SourceId == sourceId) return true;
return false;
}
[Test]
public void AppendSeeds_EmitsExactlyClassSeedCount_AllInClassRange()
{
foreach (var classId in new[] { ClassTraits.BathynautFrame, ClassTraits.HarpoonerFrame })
{
using var world = new World("ClassTraitsCount");
var em = world.EntityManager;
var e = em.CreateEntity();
em.AddBuffer<StatModifier>(e);
ClassTraits.AppendSeeds(classId, em.GetBuffer<StatModifier>(e));
var seeded = em.GetBuffer<StatModifier>(e);
Assert.AreEqual(ClassTraits.ClassSeedCount, seeded.Length, "AppendSeeds emits exactly ClassSeedCount seeds.");
for (int i = 0; i < seeded.Length; i++)
Assert.IsTrue(ClassTraits.IsClassSeed(seeded[i].SourceId), "every emitted seed SourceId is inside the class range.");
}
}
[Test]
public void Reapply_RoundTrip_StaysAtClassSeedCount_AndFoldsLikeFreshSpawn()
{
using var world = new World("ClassTraitsReapply");
var em = world.EntityManager;
var e = em.CreateEntity();
em.AddBuffer<StatModifier>(e);
// Seed Bathynaut, swap to Harpooner, then back to Bathynaut.
ClassTraits.Reapply(ClassTraits.BathynautFrame, em.GetBuffer<StatModifier>(e));
Assert.AreEqual(ClassTraits.ClassSeedCount, CountClassSeeds(em.GetBuffer<StatModifier>(e)), "Bathynaut seeds the class-seed count.");
ClassTraits.Reapply(ClassTraits.HarpoonerFrame, em.GetBuffer<StatModifier>(e));
Assert.AreEqual(ClassTraits.ClassSeedCount, CountClassSeeds(em.GetBuffer<StatModifier>(e)), "Harpooner leaves exactly the class-seed count (old seeds stripped).");
Assert.Greater(StatMath.Apply(5f, StatTarget.MoveSpeed, em.GetBuffer<StatModifier>(e)), 5f, "Harpooner moves faster after the swap.");
ClassTraits.Reapply(ClassTraits.BathynautFrame, em.GetBuffer<StatModifier>(e));
var back = em.GetBuffer<StatModifier>(e);
Assert.AreEqual(ClassTraits.ClassSeedCount, CountClassSeeds(back), "Bathynaut again: no accumulation across swaps.");
// Value-equality vs a fresh-spawned Bathynaut buffer (the ECB overload) — catches same-target PercentMult
// doubling or a strip-order regression that a count-only assert would miss.
using var refWorld = new World("ClassTraitsWarriorRef");
var fresh = SeededBuffer(refWorld, ClassTraits.BathynautFrame);
Assert.AreEqual(StatMath.Apply(100f, StatTarget.MaxHealth, fresh), StatMath.Apply(100f, StatTarget.MaxHealth, back), 1e-4f, "MaxHealth folds identically to a fresh Bathynaut.");
Assert.AreEqual(StatMath.Apply(5f, StatTarget.MoveSpeed, fresh), StatMath.Apply(5f, StatTarget.MoveSpeed, back), 1e-4f, "MoveSpeed folds identically to a fresh Bathynaut.");
}
[Test]
public void Reapply_StripsOnlyClassSeeds_PreservesForeignAndBoundaryMods()
{
using var world = new World("ClassTraitsForeign");
var em = world.EntityManager;
var e = em.CreateEntity();
var seed = em.AddBuffer<StatModifier>(e);
// A debug-upgrade mod + a boundary mod at ClassSourceId + ClassSeedCount (first id OUTSIDE the class range).
uint boundary = Tuning.ClassSourceId + (uint)ClassTraits.ClassSeedCount;
Assert.IsFalse(ClassTraits.IsClassSeed(boundary), "ClassSourceId + ClassSeedCount is just outside the class-seed range.");
seed.Add(new StatModifier { Target = (byte)StatTarget.Damage, Op = (byte)ModOp.PercentAdd, Value = 0.25f, SourceId = 0x00DEB061u });
seed.Add(new StatModifier { Target = (byte)StatTarget.MaxHealth, Op = (byte)ModOp.Flat, Value = 10f, SourceId = boundary });
ClassTraits.Reapply(ClassTraits.HarpoonerFrame, em.GetBuffer<StatModifier>(e));
var after = em.GetBuffer<StatModifier>(e);
Assert.AreEqual(ClassTraits.ClassSeedCount, CountClassSeeds(after), "exactly the class-seed count of class seeds present.");
Assert.AreEqual(ClassTraits.ClassSeedCount + 2, after.Length, "both foreign mods survive Reapply.");
Assert.IsTrue(ContainsSource(after, 0x00DEB061u), "the debug damage upgrade survives.");
Assert.IsTrue(ContainsSource(after, boundary), "the boundary mod at ClassSourceId+ClassSeedCount survives.");
}
}
}