Initial Combat Implementation
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using NUnit.Framework;
|
||||
using ProjectM.Simulation;
|
||||
using Unity.Collections;
|
||||
using Unity.Entities;
|
||||
|
||||
namespace ProjectM.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds an AbilityDatabaseBlob with BlobBuilder (the same shape the AbilityDatabaseAuthoring baker
|
||||
/// produces) and verifies the id lookups round-trip values including FixedString names, and that a
|
||||
/// missing id returns false. Version-independent, no ECS world.
|
||||
/// </summary>
|
||||
public class AbilityDatabaseBlobTests
|
||||
{
|
||||
static BlobAssetReference<AbilityDatabaseBlob> Build()
|
||||
{
|
||||
using var builder = new BlobBuilder(Allocator.Temp);
|
||||
ref var root = ref builder.ConstructRoot<AbilityDatabaseBlob>();
|
||||
|
||||
var abilities = builder.Allocate(ref root.Abilities, 2);
|
||||
abilities[0] = new AbilityDefBlob
|
||||
{
|
||||
Id = (byte)AbilityId.Primary, Damage = 20f, ProjectileSpeed = 25f, Range = 20f,
|
||||
AutoTargetRange = 12f, AutoTargetConeRadians = 0.6f, CooldownTicks = 12, Name = "Primary"
|
||||
};
|
||||
abilities[1] = new AbilityDefBlob
|
||||
{
|
||||
Id = (byte)AbilityId.FastLight, Damage = 8f, ProjectileSpeed = 40f, Range = 16f,
|
||||
AutoTargetRange = 12f, AutoTargetConeRadians = 0.6f, CooldownTicks = 5, Name = "FastLight"
|
||||
};
|
||||
|
||||
var chars = builder.Allocate(ref root.Characters, 1);
|
||||
chars[0] = new CharacterStatsBlob
|
||||
{
|
||||
Id = (byte)CharacterId.Default, MoveSpeed = 6f, TurnRateRadiansPerSec = 12.5f,
|
||||
MaxHealth = 100f, Name = "Default"
|
||||
};
|
||||
|
||||
return builder.CreateBlobAssetReference<AbilityDatabaseBlob>(Allocator.Persistent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryGetAbility_Hit_Returns_Fields()
|
||||
{
|
||||
var blob = Build();
|
||||
try
|
||||
{
|
||||
Assert.IsTrue(blob.Value.TryGetAbility((byte)AbilityId.FastLight, out var def));
|
||||
Assert.AreEqual(8f, def.Damage, 1e-4f);
|
||||
Assert.AreEqual(40f, def.ProjectileSpeed, 1e-4f);
|
||||
Assert.AreEqual(5, def.CooldownTicks);
|
||||
Assert.AreEqual("FastLight", def.Name.ToString());
|
||||
}
|
||||
finally { blob.Dispose(); }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryGetAbility_Miss_Returns_False()
|
||||
{
|
||||
var blob = Build();
|
||||
try
|
||||
{
|
||||
Assert.IsFalse(blob.Value.TryGetAbility((byte)AbilityId.SlowHeavy, out _));
|
||||
}
|
||||
finally { blob.Dispose(); }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryGetCharacter_Hit_Returns_Fields()
|
||||
{
|
||||
var blob = Build();
|
||||
try
|
||||
{
|
||||
Assert.IsTrue(blob.Value.TryGetCharacter((byte)CharacterId.Default, out var def));
|
||||
Assert.AreEqual(6f, def.MoveSpeed, 1e-4f);
|
||||
Assert.AreEqual(100f, def.MaxHealth, 1e-4f);
|
||||
Assert.AreEqual("Default", def.Name.ToString());
|
||||
}
|
||||
finally { blob.Dispose(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user