RustToDust Phase 1: Core simulation, Ymir Box3D arena, and behavioral tests
This commit is contained in:
parent
ea63ae8f03
commit
1e6efd7b55
15 changed files with 3870 additions and 0 deletions
94
tests/RustToDust.Tests/SpectatorRingTests.cs
Normal file
94
tests/RustToDust.Tests/SpectatorRingTests.cs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using RustToDust.Core;
|
||||
using Xunit;
|
||||
|
||||
namespace RustToDust.Tests
|
||||
{
|
||||
public sealed class SpectatorRingTests
|
||||
{
|
||||
[Fact]
|
||||
public void Clearance_ZeroInsideSafeCircle_MonotonicOutside()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 101);
|
||||
float r = ring.SafeRadius; // 150f
|
||||
|
||||
// Inside safe circle -> 0 cleared
|
||||
ring.UpdateClearance(new[] { new RingContact(0, r - 20f, 0f, true) });
|
||||
Assert.Equal(0, ring.CountClearedFor(0));
|
||||
|
||||
// Just outside safe circle (+5m) -> 1 cleared
|
||||
ring.UpdateClearance(new[] { new RingContact(0, r + 5f, 0f, true) });
|
||||
int clearedNear = ring.CountClearedFor(0);
|
||||
Assert.Equal(1, clearedNear);
|
||||
|
||||
// Further outside (+30m) -> 1 + floor(30/12) = 3 cleared
|
||||
ring.UpdateClearance(new[] { new RingContact(0, r + 30f, 0f, true) });
|
||||
int clearedMid = ring.CountClearedFor(0);
|
||||
Assert.True(clearedMid > clearedNear);
|
||||
|
||||
// Far outside (+100m) -> capped at 8 cleared
|
||||
ring.UpdateClearance(new[] { new RingContact(0, r + 100f, 0f, true) });
|
||||
int clearedFar = ring.CountClearedFor(0);
|
||||
Assert.Equal(8, clearedFar);
|
||||
|
||||
// Stepping back inside safe circle revokes non-provoked clearance back to 0
|
||||
ring.UpdateClearance(new[] { new RingContact(0, 0f, 0f, true) });
|
||||
Assert.Equal(0, ring.CountClearedFor(0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Provocation_AttackingNeutralSpectatorLocksOntoAttackerEvenInsideSafeCircle()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 202);
|
||||
var targetSpec = ring.Spectators[0];
|
||||
Assert.Equal(SpectatorStance.Neutral, targetSpec.Stance);
|
||||
|
||||
// Contender 0 is dead center (well inside SafeRadius)
|
||||
var contenders = new[] { new RingContact(0, 0f, 0f, true) };
|
||||
ring.UpdateClearance(contenders);
|
||||
Assert.Equal(0, ring.CountClearedFor(0));
|
||||
|
||||
bool provoked = ring.OnSpectatorDamaged(targetSpec, attackerContenderId: 0);
|
||||
Assert.True(provoked);
|
||||
Assert.Equal(SpectatorStance.Provoked, targetSpec.Stance);
|
||||
Assert.Equal(0, targetSpec.TargetContenderId);
|
||||
|
||||
// Subsequent clearance updates inside the safe circle must NOT clear Provoked lock
|
||||
ring.UpdateClearance(contenders);
|
||||
Assert.Equal(SpectatorStance.Provoked, targetSpec.Stance);
|
||||
Assert.Equal(1, ring.CountProvokedFor(0));
|
||||
|
||||
// Once attacker dies, provocation reverts to Neutral
|
||||
ring.UpdateClearance(new[] { new RingContact(0, 0f, 0f, false) });
|
||||
Assert.Equal(SpectatorStance.Neutral, targetSpec.Stance);
|
||||
Assert.Null(targetSpec.TargetContenderId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SalvageDrops_TouristDropsImperialGearWhileExemplarDoesNot()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 303);
|
||||
var rng = new Random(99);
|
||||
|
||||
var tourists = ring.Spectators.Where(s => s.Tier == SpectatorTier.Tourist).ToList();
|
||||
var exemplars = ring.Spectators.Where(s => s.Tier == SpectatorTier.Exemplar).ToList();
|
||||
|
||||
Assert.NotEmpty(tourists);
|
||||
Assert.NotEmpty(exemplars);
|
||||
|
||||
foreach (var tourist in tourists)
|
||||
{
|
||||
var drops = SpectatorRing.RollSalvageDrops(tourist, rng);
|
||||
Assert.InRange(drops.Count, 1, 2);
|
||||
Assert.All(drops, d => Assert.True(d.IsImperial));
|
||||
}
|
||||
|
||||
foreach (var exemplar in exemplars)
|
||||
{
|
||||
var drops = SpectatorRing.RollSalvageDrops(exemplar, rng);
|
||||
Assert.DoesNotContain(drops, d => d.IsImperial);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue