diff --git a/app/Game/Map/Season.php b/app/Game/Map/Season.php index 6c2bdef..6ad271c 100644 --- a/app/Game/Map/Season.php +++ b/app/Game/Map/Season.php @@ -13,16 +13,16 @@ final class Season { 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 { - 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 { - 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 diff --git a/app/Presenters/WorldPresenter.php b/app/Presenters/WorldPresenter.php index fd86706..16073d0 100644 --- a/app/Presenters/WorldPresenter.php +++ b/app/Presenters/WorldPresenter.php @@ -8,15 +8,14 @@ use App\Game\WorldConfig; /** * 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, - * switches as booleans. Labels and formatting are the client's. + * seconds at the world's speed (protection, inactivity, raids and the season in real + * seconds), shares as percent, switches as booleans. Labels and formatting are the client's. */ final class WorldPresenter { public static function settings(WorldConfig $config): array { $speed = $config->speed(); - $seconds = fn (float $atSpeedOne) => (int) round($atSpeedOne / $speed); $night = $config->get('combat.night'); $season = new Season($config); [$raidMin, $raidMax] = $config->get('raids.every_hours', [0, 0]); @@ -54,10 +53,11 @@ final class WorldPresenter 'max_members' => (new Diplomacy($config))->maxMembers(), 'notice' => (new Diplomacy($config))->noticeSeconds(), ], + // Real time, not world time. 'season' => $season->count() > 0 ? [ 'crowns' => $season->count(), '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(), ] : null, ]; diff --git a/config/game/world.php b/config/game/world.php index a723d2f..cd4e4c5 100644 --- a/config/game/world.php +++ b/config/game/world.php @@ -34,10 +34,11 @@ return [ 'start_buildings' => ['headquarters', 'storage', 'farm'], ], - // A world is a season. crowns_after_days (at world speed) after it starts, `crowns` - // crown forts appear on a ring of `radius` fields around 0|0: barbarian villages with - // these building levels and this garrison, which never raid. A player who holds more - // than half of them for hold_days wins; the world ends and the next one opens. + // A world is a season. crowns_after_days after it starts, `crowns` crown forts appear + // on a ring of `radius` fields around 0|0: barbarian villages with these building + // levels and this garrison, which never raid. A player who holds more than half of + // 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' => [ 'crowns_after_days' => 30, 'crowns' => 5, diff --git a/tests/Feature/SeasonTest.php b/tests/Feature/SeasonTest.php index 96b94b6..96aeed1 100644 --- a/tests/Feature/SeasonTest.php +++ b/tests/Feature/SeasonTest.php @@ -1,6 +1,7 @@ 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 () { config(['game.raids.enabled' => true]); $village = startVillage(); diff --git a/tests/Unit/Game/SeasonTest.php b/tests/Unit/Game/SeasonTest.php index 1799ce5..3051a11 100644 --- a/tests/Unit/Game/SeasonTest.php +++ b/tests/Unit/Game/SeasonTest.php @@ -3,12 +3,14 @@ use App\Game\Map\Season; 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'); + $fast = new Season(gameConfig(['world' => ['speed' => 100]])); 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((new Season(gameConfig()))->holdSeconds())->toBe(7 * 86400); + ->and($fast->crownsAt($start)->toDateTimeString())->toBe('2026-12-01 00:00:00') + ->and((new Season(gameConfig()))->holdSeconds())->toBe(7 * 86400) + ->and($fast->holdSeconds())->toBe(7 * 86400); }); it('places five crowns evenly round 0|0', function () {