Slice 2 (WIP): class carrier (GoInGameRequest.ClassId) + Warrior cone archetype
The per-player class travels on GoInGameRequest.ClassId (client reads a ClassSelection singleton); GoInGameServerSystem seeds the class at spawn via ClassTraits (AbilityRef + permanent trait StatModifiers on a reserved ClassSourceId; CharacterStatsRef stays Default so the DRG-asymmetry deltas ride the replicated OwnerSendType.All buffer). AbilityFireSystem gains the aim-directed Cone archetype: cooldown predicted both worlds, server-only cone damage to living enemies (same-tick, SourceTick-stamped, like the melee cleave). 345/345. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -64,14 +64,18 @@ namespace ProjectM.Simulation
|
||||
|
||||
bool isServer = state.WorldUnmanaged.IsServer();
|
||||
|
||||
// Server-only auto-target candidate set: training-dummy world XZ positions, collected once.
|
||||
// Server-only target set (LIVING enemies/dummies), collected once: positions feed the gamepad
|
||||
// auto-target assist, and entities+positions feed the Warrior CONE archetype's server-only cleave.
|
||||
var candidatePositions = new NativeList<float3>(Allocator.Temp);
|
||||
var coneTargets = new NativeList<Entity>(Allocator.Temp);
|
||||
var coneTargetPos = new NativeList<float3>(Allocator.Temp);
|
||||
if (isServer)
|
||||
{
|
||||
foreach (var dummyTransform in
|
||||
SystemAPI.Query<RefRO<LocalTransform>>().WithAny<TrainingDummyTag, EnemyTag>())
|
||||
foreach (var (tx, th, te) in
|
||||
SystemAPI.Query<RefRO<LocalTransform>, RefRO<Health>>().WithAny<TrainingDummyTag, EnemyTag>().WithEntityAccess())
|
||||
{
|
||||
candidatePositions.Add(dummyTransform.ValueRO.Position);
|
||||
candidatePositions.Add(tx.ValueRO.Position);
|
||||
if (th.ValueRO.Current > 0f) { coneTargets.Add(te); coneTargetPos.Add(tx.ValueRO.Position); }
|
||||
}
|
||||
}
|
||||
var candidates = candidatePositions.AsArray();
|
||||
@@ -105,6 +109,35 @@ namespace ProjectM.Simulation
|
||||
// abilities are Projectile (0); hitscan/cone/aoe archetypes plug in at this point in MC-6.
|
||||
ref var adb = ref abilityDb.Value.Value;
|
||||
byte archetype = adb.TryGetAbility(abilityRef.ValueRO.Id, out var adef) ? adef.Archetype : (byte)AbilityArchetype.Projectile;
|
||||
|
||||
// Slice 2: the Warrior's aim-directed CONE secondary (no projectile ghost). Predict the cooldown on
|
||||
// both worlds; apply server-only cone damage to living enemies (mirrors the MeleeComboSystem cleave,
|
||||
// same-tick: this runs before HealthApplyDamageSystem in the predicted group). SourceTick-stamped.
|
||||
if (archetype == (byte)AbilityArchetype.Cone)
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
float2 cFace = facing.ValueRO.Direction;
|
||||
cFace = math.lengthsq(cFace) < 1e-6f ? new float2(0f, 1f) : math.normalize(cFace);
|
||||
float cRange = math.max(0.1f, eff.ValueRO.Range);
|
||||
float cCosHalf = math.cos(math.clamp(eff.ValueRO.AutoTargetConeRadians, 0.01f, 3.14159f));
|
||||
uint cStamp = TickUtil.NonZero(serverTick.TickIndexForValidTick);
|
||||
for (int ci = 0; ci < coneTargets.Length; ci++)
|
||||
{
|
||||
if (!MeleeConeMath.InCone(xform.ValueRO.Position, cFace, cRange, cCosHalf, coneTargetPos[ci]))
|
||||
continue;
|
||||
ecb.AppendToBuffer(coneTargets[ci], new DamageEvent
|
||||
{
|
||||
Amount = eff.ValueRO.Damage,
|
||||
SourceNetworkId = owner.ValueRO.NetworkId,
|
||||
SourceTick = cStamp,
|
||||
});
|
||||
}
|
||||
}
|
||||
uint coneCd = (uint)math.max(1, eff.ValueRO.CooldownTicks);
|
||||
cd.ValueRW.NextFireTick = TickUtil.NonZero(serverTick.TickIndexForValidTick + coneCd);
|
||||
continue;
|
||||
}
|
||||
if (archetype != (byte)AbilityArchetype.Projectile)
|
||||
continue;
|
||||
|
||||
@@ -179,6 +212,8 @@ namespace ProjectM.Simulation
|
||||
ecb.Playback(state.EntityManager);
|
||||
ecb.Dispose();
|
||||
candidatePositions.Dispose();
|
||||
coneTargets.Dispose();
|
||||
coneTargetPos.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using Unity.Entities;
|
||||
|
||||
namespace ProjectM.Simulation
|
||||
{
|
||||
/// <summary>
|
||||
/// Slice 2: the local player's chosen class (a <see cref="CharacterId"/> byte), staged in the CLIENT world as a
|
||||
/// singleton by the menu / WorldLauncher before going in-game. <see cref="GoInGameRequest"/> picks it up
|
||||
/// (GoInGameClientSystem) so the server seeds the right class at spawn. NOT replicated — it is client-local
|
||||
/// intent; the class travels to the server via the RPC, then back to all clients via the seeded StatModifiers +
|
||||
/// the replicated AbilityRef. 0 = unset (the server defaults to Warrior).
|
||||
/// </summary>
|
||||
public struct ClassSelection : IComponentData
|
||||
{
|
||||
public byte ClassId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22b13a41197f0fc42b3cce8c99bf02ba
|
||||
@@ -0,0 +1,52 @@
|
||||
using Unity.Entities;
|
||||
|
||||
namespace ProjectM.Simulation
|
||||
{
|
||||
/// <summary>
|
||||
/// Slice 2 — pure mapping from a chosen class (a <see cref="CharacterId"/> byte) to its spawn-time setup: the
|
||||
/// Fire-slot ability id + the permanent trait <see cref="StatModifier"/>s (tagged with the reserved
|
||||
/// <see cref="Tuning.ClassSourceId"/>, NEVER stripped). Applied by GoInGameServerSystem on the just-spawned
|
||||
/// player and unit-tested. Burst-safe (byte-only, no managed types).
|
||||
/// <para>
|
||||
/// Trait deltas seed onto the <see cref="CharacterId.Default"/> character (no per-class blob row needed — the
|
||||
/// deltas ride the replicated StatModifier buffer, OwnerSendType.All, so the owning client folds the correct
|
||||
/// EffectiveCharacterStats). The DRG-asymmetry (operator-locked): <b>Warrior</b> = melee bruiser (tankier,
|
||||
/// slower, harder + longer-reach melee via MeleeDamage/MeleeRange); <b>Ranger</b> = ranged anchor (faster,
|
||||
/// squishier, longer projectile range + a wider auto-target assist — the co-op synergy hook the Warrior's
|
||||
/// knockback feeds). The Warrior's Fire = the aim-directed cone (<see cref="AbilityId.WarriorCone"/>); the
|
||||
/// Ranger's Fire = the default projectile (<see cref="AbilityId.Primary"/>).
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static class ClassTraits
|
||||
{
|
||||
public const byte WarriorClass = (byte)CharacterId.Warrior;
|
||||
public const byte RangerClass = (byte)CharacterId.Ranger;
|
||||
|
||||
/// <summary>Normalize a wire ClassId to a known class (0 / unknown -> Warrior).</summary>
|
||||
public static byte Normalize(byte classId) => classId == RangerClass ? RangerClass : WarriorClass;
|
||||
|
||||
/// <summary>The Fire-slot ability id for a class (Warrior = cone, Ranger = the default projectile).</summary>
|
||||
public static byte AbilityFor(byte classId)
|
||||
=> classId == RangerClass ? (byte)AbilityId.Primary : (byte)AbilityId.WarriorCone;
|
||||
|
||||
/// <summary>Append a class's permanent trait modifiers onto a player's StatModifier buffer (via ECB at spawn).</summary>
|
||||
public static void AppendSeeds(byte classId, Entity player, EntityCommandBuffer ecb)
|
||||
{
|
||||
uint src = Tuning.ClassSourceId;
|
||||
if (classId == RangerClass)
|
||||
{
|
||||
ecb.AppendToBuffer(player, new StatModifier { Target = (byte)StatTarget.MoveSpeed, Op = (byte)ModOp.PercentMult, Value = 0.15f, SourceId = src });
|
||||
ecb.AppendToBuffer(player, new StatModifier { Target = (byte)StatTarget.MaxHealth, Op = (byte)ModOp.PercentMult, Value = -0.15f, SourceId = src + 1u });
|
||||
ecb.AppendToBuffer(player, new StatModifier { Target = (byte)StatTarget.Range, Op = (byte)ModOp.PercentAdd, Value = 0.30f, SourceId = src + 2u });
|
||||
ecb.AppendToBuffer(player, new StatModifier { Target = (byte)StatTarget.AutoTargetRange, Op = (byte)ModOp.Flat, Value = 3f, SourceId = src + 3u });
|
||||
}
|
||||
else
|
||||
{
|
||||
ecb.AppendToBuffer(player, new StatModifier { Target = (byte)StatTarget.MaxHealth, Op = (byte)ModOp.Flat, Value = 30f, SourceId = src });
|
||||
ecb.AppendToBuffer(player, new StatModifier { Target = (byte)StatTarget.MoveSpeed, Op = (byte)ModOp.PercentMult, Value = -0.15f, SourceId = src + 1u });
|
||||
ecb.AppendToBuffer(player, new StatModifier { Target = (byte)StatTarget.MeleeDamage, Op = (byte)ModOp.Flat, Value = 6f, SourceId = src + 2u });
|
||||
ecb.AppendToBuffer(player, new StatModifier { Target = (byte)StatTarget.MeleeRange, Op = (byte)ModOp.Flat, Value = 0.8f, SourceId = src + 3u });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f2897774c07bf14a87b2338114910ae
|
||||
Reference in New Issue
Block a user