feat: model objectives, deployment zones, and victory conditions
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace BattleForge\Domain;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
final readonly class DeploymentZone
|
||||||
|
{
|
||||||
|
/** @param list<Position> $positions */
|
||||||
|
public function __construct(
|
||||||
|
public string $teamId,
|
||||||
|
public array $positions,
|
||||||
|
) {
|
||||||
|
if ($teamId === '') {
|
||||||
|
throw new InvalidArgumentException('Deployment zone team id cannot be empty.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($positions === []) {
|
||||||
|
throw new InvalidArgumentException('Deployment zone must contain at least one position.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!array_is_list($positions)) { // @phpstan-ignore function.alreadyNarrowedType (Runtime guard: PHPDoc is not a runtime contract for JSON-sourced arrays in Plan 4.)
|
||||||
|
throw new InvalidArgumentException('Deployment zone positions must be a list.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function contains(Position $position): bool
|
||||||
|
{
|
||||||
|
foreach ($this->positions as $candidate) {
|
||||||
|
if ($candidate->key() === $position->key()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace BattleForge\Domain;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
final readonly class ObjectiveControl
|
||||||
|
{
|
||||||
|
/** @param array<string, int> $roundsByTeam */
|
||||||
|
public function __construct(public array $roundsByTeam)
|
||||||
|
{
|
||||||
|
foreach ($roundsByTeam as $teamId => $count) {
|
||||||
|
if ($teamId === '') {
|
||||||
|
throw new InvalidArgumentException('Objective control team id cannot be empty.');
|
||||||
|
}
|
||||||
|
if ($count < 0) {
|
||||||
|
throw new InvalidArgumentException('Objective control count cannot be negative.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function empty(): self
|
||||||
|
{
|
||||||
|
return new self([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function recordRound(string $controllerTeamId): self
|
||||||
|
{
|
||||||
|
if ($controllerTeamId === '') {
|
||||||
|
throw new InvalidArgumentException('Controller team id cannot be empty.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$next = $this->roundsByTeam;
|
||||||
|
$next[$controllerTeamId] = ($next[$controllerTeamId] ?? 0) + 1;
|
||||||
|
|
||||||
|
return new self($next);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array{teamId: string, rounds: int} */
|
||||||
|
public function forTeam(string $teamId): array
|
||||||
|
{
|
||||||
|
return ['teamId' => $teamId, 'rounds' => $this->roundsByTeam[$teamId] ?? 0];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace BattleForge\Domain;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
final readonly class ObjectiveMarker
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public string $id,
|
||||||
|
public Position $position,
|
||||||
|
) {
|
||||||
|
if ($id === '') {
|
||||||
|
throw new InvalidArgumentException('Objective id cannot be empty.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function key(): string
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace BattleForge\Domain;
|
||||||
|
|
||||||
|
enum VictoryCondition: string
|
||||||
|
{
|
||||||
|
case EliminateAll = 'eliminate_all';
|
||||||
|
case HoldObjective = 'hold_objective';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user