From 4076d073d88f4c948f754162a027b53fc5b11054 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Tue, 3 Nov 2026 12:10:28 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20beginner=20protection=20lasts=205=20rea?= =?UTF-8?q?l=20days=20on=20every=20world=20speed,=20as=20in=20Die=20St?= =?UTF-8?q?=C3=A4mme;=20raids=20wait=20for=20it=20as=20before?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- app/Engine/Rally.php | 4 ++-- app/Presenters/WorldPresenter.php | 4 ++-- config/game/combat.php | 7 ++++--- tests/Feature/ConquestTest.php | 4 ++-- tests/Feature/LeavingTest.php | 2 +- tests/Feature/RaidTest.php | 16 +++++++++------- tests/Feature/RallyTest.php | 22 +++++++++++++++++++++- tests/Feature/SpecialisationTest.php | 2 +- 8 files changed, 42 insertions(+), 19 deletions(-) diff --git a/app/Engine/Rally.php b/app/Engine/Rally.php index 7051080..1e381b3 100644 --- a/app/Engine/Rally.php +++ b/app/Engine/Rally.php @@ -86,10 +86,10 @@ final class Rally return $defense; } - /** When beginner protection ends for this player. */ + /** When beginner protection ends for this player: real seconds, on every world speed. */ public function protectedUntil(Player $player): CarbonImmutable { - $seconds = $this->sim->config()->get('combat.beginner_protection', 0) / $this->sim->config()->speed(); + $seconds = $this->sim->config()->get('combat.beginner_protection', 0); // From joining, and again from a restart after losing every village. $since = $player->protected_since ?? $player->created_at->toImmutable(); diff --git a/app/Presenters/WorldPresenter.php b/app/Presenters/WorldPresenter.php index f7641cd..fd86706 100644 --- a/app/Presenters/WorldPresenter.php +++ b/app/Presenters/WorldPresenter.php @@ -8,7 +8,7 @@ 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 (inactivity and raids in real seconds), shares as percent, + * 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. */ final class WorldPresenter @@ -26,8 +26,8 @@ final class WorldPresenter 'pace' => [ 'speed' => $speed, 'unit_speed' => (float) $config->get('movement.unit_speed', 1), - 'protection' => $seconds($config->get('combat.beginner_protection', 0)), // Real time, not world time. + 'protection' => (int) $config->get('combat.beginner_protection', 0), 'inactive' => (int) ($config->get('world.inactive_days', 0) * 86400), ], 'village' => [ diff --git a/config/game/combat.php b/config/game/combat.php index 169ef3c..1752fd7 100644 --- a/config/game/combat.php +++ b/config/game/combat.php @@ -44,9 +44,10 @@ return [ // Levied villagers defend with these values per head. 'militia' => ['defense' => ['infantry' => 5, 'cavalry' => 5, 'archer' => 5]], - // New players can't be attacked by players for this long after joining (seconds at - // world speed 1), and can't attack players themselves meanwhile; barbarians are fine. - 'beginner_protection' => 3 * 86400, + // New players can't be attacked by players for this long after joining, and can't + // attack players themselves meanwhile; barbarians are fine. Real seconds, as in Die + // Stämme: world speed doesn't shorten it. + 'beginner_protection' => 5 * 86400, // Lazarett: of the own units that fall defending their village, `share` (rounded down) // come back wounded, as far as its hospitals have free beds. The wounded eat like diff --git a/tests/Feature/ConquestTest.php b/tests/Feature/ConquestTest.php index c191c28..89a0be7 100644 --- a/tests/Feature/ConquestTest.php +++ b/tests/Feature/ConquestTest.php @@ -111,7 +111,7 @@ it('leaves a village at loyalty 0 when the coins pay for no more villages, and t $victim = startVillage(); $village = nobleVillage(['spear' => 100, 'nobleman' => 2]); $village->player->update(['coins' => 0]); - $this->travel(4)->days(); + $this->travel(6)->days(); $victim->update(['loyalty' => 0, 'loyalty_at' => now()]); app(SendTroops::class)(owner($village), $village->id, 'attack', $victim->x, $victim->y, ['spear' => 100, 'nobleman' => 2], null, null); @@ -169,7 +169,7 @@ it('takes a player village with its queues, and the old owner starts over', func $victim->buildings()->create(['type' => 'rally_point', 'level' => 1]); $victim->troops()->create(['home_village_id' => $victim->id, 'unit' => 'spear', 'count' => 3]); $village = nobleVillage(['spear' => 100, 'nobleman' => 1]); - $this->travel(4)->days(); + $this->travel(6)->days(); $victim->update(['loyalty' => 5, 'loyalty_at' => now()]); // The victim has a build order and support standing in the attacker's village. diff --git a/tests/Feature/LeavingTest.php b/tests/Feature/LeavingTest.php index 1396e9f..e06aea4 100644 --- a/tests/Feature/LeavingTest.php +++ b/tests/Feature/LeavingTest.php @@ -88,7 +88,7 @@ it('tells a world settings in plain units', function () { $village = startVillage(); $settings = app(ListWorlds::class)->settings($village->world_id)['settings']; - expect($settings['pace'])->toBe(['speed' => 1.0, 'unit_speed' => 1.0, 'protection' => 3 * 86400, 'inactive' => 0]) + expect($settings['pace'])->toBe(['speed' => 1.0, 'unit_speed' => 1.0, 'protection' => 5 * 86400, 'inactive' => 0]) ->and($settings['village'])->toMatchArray(['space' => 40, 'space_per_hq_level' => 5]) ->and($settings['tribes'])->toBe(['max_members' => 25, 'notice' => 86400]) ->and($settings['season'])->toMatchArray(['crowns' => 5, 'needed' => 3, 'hold' => 7 * 86400]) diff --git a/tests/Feature/RaidTest.php b/tests/Feature/RaidTest.php index 92fa0e5..93f3f68 100644 --- a/tests/Feature/RaidTest.php +++ b/tests/Feature/RaidTest.php @@ -39,7 +39,7 @@ function pendingRaid(Village $village): ?CarbonImmutable /** Past beginner protection, with the band announced. */ function announced(Village $village): Movement { - test()->travel(3)->days(); + test()->travel(5)->days(); test()->artisan('game:events --once')->assertSuccessful(); return Movement::where('target_id', $village->id)->sole(); @@ -54,7 +54,7 @@ function arrive(Movement $movement): void it('plans the first raid for when beginner protection ends', function () { $village = startVillage(); - expect(pendingRaid($village)->toDateTimeString())->toBe('2026-11-01 12:00:00'); + expect(pendingRaid($village)->toDateTimeString())->toBe('2026-11-03 12:00:00'); }); it('announces a band from the nearest camp hours before it arrives, and plans the next raid', function () { @@ -67,10 +67,10 @@ it('announces a band from the nearest camp hours before it arrives, and plans th expect($movement->origin_id)->toBe($camp->id) ->and($movement->player_id)->toBeNull() ->and($movement->units)->toBe(['spear' => 4, 'sword' => 2]) - ->and($movement->arrives_at->toDateTimeString())->toBe('2026-11-01 16:06:00'); + ->and($movement->arrives_at->toDateTimeString())->toBe('2026-11-03 16:06:00'); $incoming = shown($village)['movements'][0]; - expect($incoming)->toMatchArray(['type' => 'attack', 'direction' => 'in', 'raid' => true, 'marches_at' => '2026-11-01T15:00:00.000Z', 'arrives_at' => '2026-11-01T16:06:00.000Z']) + expect($incoming)->toMatchArray(['type' => 'attack', 'direction' => 'in', 'raid' => true, 'marches_at' => '2026-11-03T15:00:00.000Z', 'arrives_at' => '2026-11-03T16:06:00.000Z']) ->and($incoming['units'])->toBeNull(); $next = pendingRaid($village); @@ -85,7 +85,7 @@ it('times raids in real hours on a fast world; only the march runs at world spee $movement = announced($village); // Three real hours of gathering, then 3 fields at 22 minutes / 100. - expect($movement->sent_at->toDateTimeString())->toBe('2026-11-01 15:00:00') + expect($movement->sent_at->toDateTimeString())->toBe('2026-11-03 15:00:00') ->and($movement->sent_at->diffInSeconds($movement->arrives_at))->toBeLessThan(60); $next = pendingRaid($village); expect($next->greaterThanOrEqualTo($movement->arrives_at->addHours(20)))->toBeTrue() @@ -98,7 +98,7 @@ it('stays home when the village is far too strong for the band, and tries again raidCamp($village); // 100 swordsmen hold 5000 against the band's 90: less than 30% of the defence. $village->troops()->create(['home_village_id' => $village->id, 'unit' => 'sword', 'count' => 100]); - $this->travel(3)->days(); + $this->travel(5)->days(); $this->artisan('game:events --once')->assertSuccessful(); $next = pendingRaid($village); @@ -157,6 +157,8 @@ it('pays a bounty when the village beats the band', function () { // 4 swordsmen hold 200 against the band's 90: strong enough to win, not to scare it off. $village->troops()->create(['home_village_id' => $village->id, 'unit' => 'sword', 'count' => 4]); $movement = announced($village); + // Five days of protection fill the storage: make room for the bounty. + Village::whereKey($village->id)->update(['wood' => 500, 'resources_at' => now()]); $wood = shown($village)['resources']['wood']; arrive($movement); @@ -199,7 +201,7 @@ it('plans raids for villages from before raids on deploy', function () { GameEvent::where('type', GameEvent::RAID_PLANNED)->delete(); (new WorldSeeder)->run(); - expect(pendingRaid($village)->toDateTimeString())->toBe('2026-11-01 12:00:00'); + expect(pendingRaid($village)->toDateTimeString())->toBe('2026-11-03 12:00:00'); (new WorldSeeder)->run(); expect(GameEvent::where('type', GameEvent::RAID_PLANNED)->count())->toBe(1); diff --git a/tests/Feature/RallyTest.php b/tests/Feature/RallyTest.php index 6e42e67..1e9fccc 100644 --- a/tests/Feature/RallyTest.php +++ b/tests/Feature/RallyTest.php @@ -1,6 +1,7 @@ and(rule(fn () => send($village, barbarianNear($village, 3, 4), ['spear' => 5], 'support')))->toBe('barbarian') ->and(Movement::count())->toBe(0); - // Beginner protection lasts three days at world speed 1. + // Beginner protection lasts five real days. + $this->travel(5 * 86400 - 1)->seconds(); + expect(rule(fn () => send($village, $other, ['spear' => 5])))->toBe('protected'); + $this->travel(1)->seconds(); + send($village, $other, ['spear' => 5]); + expect(Movement::count())->toBe(1); +}); + +it('counts beginner protection in real days on a fast world', function () { + $village = rallied(startVillage(), ['spear' => 10]); + $other = rallied(startVillage(), ['spear' => 10]); + worldRules($village, ['world' => ['speed' => 100]]); + + // Divided by world speed, five days would be 72 minutes here. $this->travel(4)->days(); + expect(rule(fn () => send($village, $other, ['spear' => 5])))->toBe('protected') + ->and(rule(fn () => send($other, $village, ['spear' => 5])))->toBe('protected') + ->and(shown($village)['rally']['protected_until'])->toBe('2026-11-03T12:00:00.000Z') + ->and(app(ListWorlds::class)->settings($village->world_id)['settings']['pace'])->toMatchArray(['speed' => 100.0, 'protection' => 5 * 86400]); + + $this->travel(1)->days(); send($village, $other, ['spear' => 5]); expect(Movement::count())->toBe(1); }); diff --git a/tests/Feature/SpecialisationTest.php b/tests/Feature/SpecialisationTest.php index 8d0f0f9..f2be849 100644 --- a/tests/Feature/SpecialisationTest.php +++ b/tests/Feature/SpecialisationTest.php @@ -61,7 +61,7 @@ it('lets a military village defend a tenth harder', function () { $camp = app(VillageFactory::class)->create($village->world, null, 'Barbarian village', $village->x + 3, $village->y, array_fill_keys($types, 8)); Barbarians::of($camp)->fill(); - $this->travel(3)->days(); + $this->travel(5)->days(); $this->artisan('game:events --once')->assertSuccessful(); $raid = Movement::where('target_id', $village->id)->sole(); // Spears that lose to the band on their own (15 defence each) but hold with +10%.