Separate defense build branches from enemy lanes
This commit is contained in:
@@ -151,6 +151,50 @@ namespace BumpCombat.PlayModeTests
|
||||
}
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator DefensePrototype_PadBranchesStaySeparateFromEnemyRoutes()
|
||||
{
|
||||
yield return StartDefenseRun();
|
||||
DefensePrototypeController controller = DefensePrototypeController.Instance;
|
||||
DefenseConstants tuning = controller.Tuning;
|
||||
Vector2 home = tuning.GetBasePosition(0);
|
||||
Assert.That(tuning.GetBasePosition(1), Is.EqualTo(home));
|
||||
for (int pad = 0; pad < 6; pad++)
|
||||
{
|
||||
Vector2 position = tuning.GetBuildPadPosition(pad);
|
||||
float distance = float.MaxValue;
|
||||
for (int lane = 0; lane < 2; lane++)
|
||||
{
|
||||
Vector2 previous = tuning.GetPortalPosition(lane);
|
||||
for (int waypoint = 0; waypoint < 3; waypoint++)
|
||||
{
|
||||
Vector2 next = waypoint < 2
|
||||
? tuning.GetWaypointPosition(lane, waypoint)
|
||||
: tuning.GetBasePosition(lane);
|
||||
distance = Mathf.Min(distance,
|
||||
DistanceToSegment(position, previous, next));
|
||||
previous = next;
|
||||
}
|
||||
}
|
||||
Assert.That(distance, Is.GreaterThan(tuning.BuildInteractionRadius),
|
||||
$"Pad {pad + 1} must not sit on an enemy route.");
|
||||
}
|
||||
|
||||
for (int lane = 0; lane < 2; lane++)
|
||||
{
|
||||
GameObject branch = GameObject.Find(
|
||||
$"Pad Branch {lane + 1} Segment 1");
|
||||
Assert.That(branch, Is.Not.Null,
|
||||
"Each build branch must be visible separately from enemy routes.");
|
||||
LineRenderer line = branch.GetComponent<LineRenderer>();
|
||||
Assert.That(line, Is.Not.Null);
|
||||
Assert.That((Vector2)line.GetPosition(0), Is.EqualTo(home));
|
||||
float padY = tuning.GetBuildPadPosition(lane).y;
|
||||
Assert.That((Vector2)line.GetPosition(1),
|
||||
Is.EqualTo(new Vector2(home.x, padY)));
|
||||
}
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator DefensePrototype_DefaultBuildsCanDamageTheirPortalLanes()
|
||||
{
|
||||
@@ -637,7 +681,7 @@ namespace BumpCombat.PlayModeTests
|
||||
Assert.That(controller.CanOperateTowers, Is.True);
|
||||
Assert.That(playerHealth.CurrentHealth,
|
||||
Is.EqualTo(playerHealth.MaxHealth));
|
||||
MovePlayerNear(player, Vector2.zero);
|
||||
MovePlayerNear(player, new Vector2(10f, -5f));
|
||||
|
||||
SaveDefenseConstants(controller.Tuning);
|
||||
touchedDefenseConstants.PortalSpawnInterval = 0.01f;
|
||||
@@ -653,6 +697,7 @@ namespace BumpCombat.PlayModeTests
|
||||
yield return DriveArrivalsUntilBaseDestroyed(controller);
|
||||
Assert.That(controller.GetBaseHealth(0), Is.EqualTo(0));
|
||||
Assert.That(RunManager.Instance.IsGameOver, Is.True);
|
||||
SetTestField(playerHealth, "invulnerableUntil", Time.time);
|
||||
|
||||
Assert.That(playerHealth.TryTakeDamage(
|
||||
playerHealth.MaxHealth + 1f, Vector2.left, 0f), Is.True);
|
||||
@@ -1986,6 +2031,17 @@ namespace BumpCombat.PlayModeTests
|
||||
Assert.That(runManager.IsSelectionOpen, Is.False);
|
||||
|
||||
}
|
||||
private static float DistanceToSegment(
|
||||
Vector2 point, Vector2 from, Vector2 to)
|
||||
{
|
||||
Vector2 segment = to - from;
|
||||
float fraction = segment.sqrMagnitude > 0f
|
||||
? Mathf.Clamp01(Vector2.Dot(point - from, segment)
|
||||
/ segment.sqrMagnitude)
|
||||
: 0f;
|
||||
return Vector2.Distance(point, from + segment * fraction);
|
||||
}
|
||||
|
||||
private static DefenseTower BuildTower(
|
||||
DefensePrototypeController controller,
|
||||
PlayerController player,
|
||||
@@ -2159,7 +2215,10 @@ namespace BumpCombat.PlayModeTests
|
||||
}
|
||||
|
||||
Assert.That(agent.HasArrived, Is.True,
|
||||
"A public route agent must reach the shared base when driven through its route.");
|
||||
$"A public route agent must reach the shared base when driven through its route. "
|
||||
+ $"Lane={agent.Lane}, position={agent.transform.position}, "
|
||||
+ $"state={agent.Enemy?.State}, dead={agent.Enemy?.IsDead}, "
|
||||
+ $"stunned={agent.Enemy?.IsStunned}, speed={agent.Enemy?.MovementSpeedMultiplier}.");
|
||||
}
|
||||
|
||||
private static IEnumerator DriveArrivalsUntilBaseDestroyed(
|
||||
@@ -2175,6 +2234,7 @@ namespace BumpCombat.PlayModeTests
|
||||
{
|
||||
if (agents[i] != null && !agents[i].HasArrived)
|
||||
{
|
||||
yield return WaitForAgentReady(agents[i]);
|
||||
DriveAgentToArrival(agents[i]);
|
||||
if (controller.GetBaseHealth(0) <= 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user