feat: a season counts real days: the crowns come 30 days after the start and a holder wins after 7, on every world speed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
230a1b0049
commit
ea593d932b
|
|
@ -13,16 +13,16 @@ final class Season
|
||||||
{
|
{
|
||||||
public function __construct(private readonly WorldConfig $config) {}
|
public function __construct(private readonly WorldConfig $config) {}
|
||||||
|
|
||||||
/** When the crowns appear: crowns_after_days after the start, at world speed. */
|
/** When the crowns appear: crowns_after_days real days after the start, on every world speed. */
|
||||||
public function crownsAt(CarbonImmutable $startedAt): CarbonImmutable
|
public function crownsAt(CarbonImmutable $startedAt): CarbonImmutable
|
||||||
{
|
{
|
||||||
return $startedAt->addSeconds((int) round($this->config->get('world.season.crowns_after_days', 30) * 86400 / $this->config->speed()));
|
return $startedAt->addSeconds((int) round($this->config->get('world.season.crowns_after_days', 30) * 86400));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** How long a holder must keep the crowns to win, at world speed. */
|
/** How long a holder must keep the crowns to win: hold_days real days, on every world speed. */
|
||||||
public function holdSeconds(): int
|
public function holdSeconds(): int
|
||||||
{
|
{
|
||||||
return max(1, (int) round($this->config->get('world.season.hold_days', 7) * 86400 / $this->config->speed()));
|
return max(1, (int) round($this->config->get('world.season.hold_days', 7) * 86400));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function count(): int
|
public function count(): int
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,14 @@ use App\Game\WorldConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A world's settings in the units players think in, for the world overview: durations in
|
* A world's settings in the units players think in, for the world overview: durations in
|
||||||
* seconds at the world's speed (protection, inactivity and raids in real seconds), shares as percent,
|
* seconds at the world's speed (protection, inactivity, raids and the season in real
|
||||||
* switches as booleans. Labels and formatting are the client's.
|
* seconds), shares as percent, switches as booleans. Labels and formatting are the client's.
|
||||||
*/
|
*/
|
||||||
final class WorldPresenter
|
final class WorldPresenter
|
||||||
{
|
{
|
||||||
public static function settings(WorldConfig $config): array
|
public static function settings(WorldConfig $config): array
|
||||||
{
|
{
|
||||||
$speed = $config->speed();
|
$speed = $config->speed();
|
||||||
$seconds = fn (float $atSpeedOne) => (int) round($atSpeedOne / $speed);
|
|
||||||
$night = $config->get('combat.night');
|
$night = $config->get('combat.night');
|
||||||
$season = new Season($config);
|
$season = new Season($config);
|
||||||
[$raidMin, $raidMax] = $config->get('raids.every_hours', [0, 0]);
|
[$raidMin, $raidMax] = $config->get('raids.every_hours', [0, 0]);
|
||||||
|
|
@ -54,10 +53,11 @@ final class WorldPresenter
|
||||||
'max_members' => (new Diplomacy($config))->maxMembers(),
|
'max_members' => (new Diplomacy($config))->maxMembers(),
|
||||||
'notice' => (new Diplomacy($config))->noticeSeconds(),
|
'notice' => (new Diplomacy($config))->noticeSeconds(),
|
||||||
],
|
],
|
||||||
|
// Real time, not world time.
|
||||||
'season' => $season->count() > 0 ? [
|
'season' => $season->count() > 0 ? [
|
||||||
'crowns' => $season->count(),
|
'crowns' => $season->count(),
|
||||||
'needed' => $season->needed(),
|
'needed' => $season->needed(),
|
||||||
'crowns_after' => $seconds($config->get('world.season.crowns_after_days', 30) * 86400),
|
'crowns_after' => (int) round($config->get('world.season.crowns_after_days', 30) * 86400),
|
||||||
'hold' => $season->holdSeconds(),
|
'hold' => $season->holdSeconds(),
|
||||||
] : null,
|
] : null,
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,11 @@ return [
|
||||||
'start_buildings' => ['headquarters', 'storage', 'farm'],
|
'start_buildings' => ['headquarters', 'storage', 'farm'],
|
||||||
],
|
],
|
||||||
|
|
||||||
// A world is a season. crowns_after_days (at world speed) after it starts, `crowns`
|
// A world is a season. crowns_after_days after it starts, `crowns` crown forts appear
|
||||||
// crown forts appear on a ring of `radius` fields around 0|0: barbarian villages with
|
// on a ring of `radius` fields around 0|0: barbarian villages with these building
|
||||||
// these building levels and this garrison, which never raid. A player who holds more
|
// levels and this garrison, which never raid. A player who holds more than half of
|
||||||
// than half of them for hold_days wins; the world ends and the next one opens.
|
// them for hold_days wins; the world ends and the next one opens. Both are real days,
|
||||||
|
// like beginner protection and raids: world speed doesn't shorten a season.
|
||||||
'season' => [
|
'season' => [
|
||||||
'crowns_after_days' => 30,
|
'crowns_after_days' => 30,
|
||||||
'crowns' => 5,
|
'crowns' => 5,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Actions\JoinWorld;
|
use App\Actions\JoinWorld;
|
||||||
|
use App\Actions\ListWorlds;
|
||||||
use App\Actions\QueueBuild;
|
use App\Actions\QueueBuild;
|
||||||
use App\Engine\Barbarians;
|
use App\Engine\Barbarians;
|
||||||
use App\Engine\Nobility;
|
use App\Engine\Nobility;
|
||||||
|
|
@ -85,6 +86,28 @@ it('lets a player who holds three crowns for a week win, and opens the next worl
|
||||||
->and(rule(fn () => app(JoinWorld::class)(User::factory()->create(), $world->id)))->toBe('world_ended');
|
->and(rule(fn () => app(JoinWorld::class)(User::factory()->create(), $world->id)))->toBe('world_ended');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('counts a season in real days on a fast world', function () {
|
||||||
|
$village = startVillage();
|
||||||
|
$world = $village->world;
|
||||||
|
$world->update(['config' => ['world' => ['speed' => 100]]]);
|
||||||
|
|
||||||
|
// Divided by world speed, 30 days would be 7 h 12 min here.
|
||||||
|
$this->travel(29)->days();
|
||||||
|
$this->artisan('game:events --once')->assertSuccessful();
|
||||||
|
expect(crowns($world))->toHaveCount(0)
|
||||||
|
->and(shown($village)['season']['crowns_at'])->toBe('2026-11-28T12:00:00.000Z')
|
||||||
|
->and(app(ListWorlds::class)->settings($world->id)['settings']['season'])->toMatchArray(['crowns_after' => 30 * 86400, 'hold' => 7 * 86400]);
|
||||||
|
|
||||||
|
$this->travel(1)->days();
|
||||||
|
$this->artisan('game:events --once')->assertSuccessful();
|
||||||
|
[$a, $b, $c] = crowns($world);
|
||||||
|
takeCrown($a, $village->player_id);
|
||||||
|
takeCrown($b, $village->player_id);
|
||||||
|
takeCrown($c, $village->player_id);
|
||||||
|
expect($world->fresh()->ends_at->toDateTimeString())->toBe('2026-12-05 12:00:00')
|
||||||
|
->and(shown($village)['season']['ends_at'])->toBe('2026-12-05T12:00:00.000Z');
|
||||||
|
});
|
||||||
|
|
||||||
it('keeps crowns out of raiding', function () {
|
it('keeps crowns out of raiding', function () {
|
||||||
config(['game.raids.enabled' => true]);
|
config(['game.raids.enabled' => true]);
|
||||||
$village = startVillage();
|
$village = startVillage();
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,14 @@
|
||||||
use App\Game\Map\Season;
|
use App\Game\Map\Season;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
|
|
||||||
it('brings the crowns after 30 days and lets a holder win after 7, at world speed', function () {
|
it('brings the crowns after 30 real days and lets a holder win after 7, on every world speed', function () {
|
||||||
$start = CarbonImmutable::parse('2026-11-01 00:00:00');
|
$start = CarbonImmutable::parse('2026-11-01 00:00:00');
|
||||||
|
$fast = new Season(gameConfig(['world' => ['speed' => 100]]));
|
||||||
|
|
||||||
expect((new Season(gameConfig()))->crownsAt($start)->toDateTimeString())->toBe('2026-12-01 00:00:00')
|
expect((new Season(gameConfig()))->crownsAt($start)->toDateTimeString())->toBe('2026-12-01 00:00:00')
|
||||||
->and((new Season(gameConfig(['world' => ['speed' => 100]])))->crownsAt($start)->toDateTimeString())->toBe('2026-11-01 07:12:00')
|
->and($fast->crownsAt($start)->toDateTimeString())->toBe('2026-12-01 00:00:00')
|
||||||
->and((new Season(gameConfig()))->holdSeconds())->toBe(7 * 86400);
|
->and((new Season(gameConfig()))->holdSeconds())->toBe(7 * 86400)
|
||||||
|
->and($fast->holdSeconds())->toBe(7 * 86400);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('places five crowns evenly round 0|0', function () {
|
it('places five crowns evenly round 0|0', function () {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue