Initial Combat Implementation
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
using NUnit.Framework;
|
||||
using ProjectM.Server;
|
||||
using ProjectM.Simulation;
|
||||
using Unity.Entities;
|
||||
using Unity.Mathematics;
|
||||
using Unity.Transforms;
|
||||
|
||||
namespace ProjectM.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Plain-Entities test for <see cref="UpgradePickupSystem"/> (server grant). A player overlapping a
|
||||
/// pickup gets the pickup's modifier appended to its StatModifier buffer and the pickup is destroyed;
|
||||
/// a player out of range leaves the buffer empty and the pickup alive. The system's ECB plays back
|
||||
/// immediately (server pattern), so no separate ECB system is needed.
|
||||
/// </summary>
|
||||
public class UpgradePickupSystemTests
|
||||
{
|
||||
static (World world, Entity player, Entity pickup) MakeWorld(float3 playerPos, float3 pickupPos, float radius)
|
||||
{
|
||||
var world = new World("UpgradePickupTestWorld");
|
||||
var group = world.GetOrCreateSystemManaged<SimulationSystemGroup>();
|
||||
group.AddSystemToUpdateList(world.GetOrCreateSystem<UpgradePickupSystem>());
|
||||
group.SortSystems();
|
||||
|
||||
var em = world.EntityManager;
|
||||
|
||||
var player = em.CreateEntity(typeof(PlayerTag), typeof(StatModifier), typeof(LocalTransform));
|
||||
em.SetComponentData(player, LocalTransform.FromPosition(playerPos));
|
||||
|
||||
var pickup = em.CreateEntity(typeof(UpgradePickup), typeof(HitRadius), typeof(LocalTransform));
|
||||
em.SetComponentData(pickup, LocalTransform.FromPosition(pickupPos));
|
||||
em.SetComponentData(pickup, new HitRadius { Value = radius });
|
||||
em.SetComponentData(pickup, new UpgradePickup
|
||||
{
|
||||
Target = (byte)StatTarget.Damage, Op = (byte)ModOp.Flat, Value = 25f, SourceId = 7u
|
||||
});
|
||||
|
||||
return (world, player, pickup);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Overlap_Grants_Modifier_And_Destroys_Pickup()
|
||||
{
|
||||
var (world, player, pickup) = MakeWorld(float3.zero, new float3(0.5f, 0f, 0f), 1f);
|
||||
try
|
||||
{
|
||||
world.GetExistingSystemManaged<SimulationSystemGroup>().Update();
|
||||
var buf = world.EntityManager.GetBuffer<StatModifier>(player);
|
||||
Assert.AreEqual(1, buf.Length);
|
||||
Assert.AreEqual((byte)StatTarget.Damage, buf[0].Target);
|
||||
Assert.AreEqual((byte)ModOp.Flat, buf[0].Op);
|
||||
Assert.AreEqual(25f, buf[0].Value, 1e-4f);
|
||||
Assert.AreEqual(7u, buf[0].SourceId);
|
||||
Assert.IsFalse(world.EntityManager.Exists(pickup), "Pickup should be destroyed after grant.");
|
||||
}
|
||||
finally { world.Dispose(); }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Out_Of_Range_Leaves_Buffer_Empty_And_Pickup_Alive()
|
||||
{
|
||||
var (world, player, pickup) = MakeWorld(float3.zero, new float3(10f, 0f, 0f), 1f);
|
||||
try
|
||||
{
|
||||
world.GetExistingSystemManaged<SimulationSystemGroup>().Update();
|
||||
var buf = world.EntityManager.GetBuffer<StatModifier>(player);
|
||||
Assert.AreEqual(0, buf.Length);
|
||||
Assert.IsTrue(world.EntityManager.Exists(pickup), "Out-of-range pickup should remain.");
|
||||
}
|
||||
finally { world.Dispose(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user