feat: beginner protection lasts 5 real days on every world speed, as in Die Stämme; raids wait for it as before
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
70f07d87fc
commit
4076d073d8
|
|
@ -86,10 +86,10 @@ final class Rally
|
||||||
return $defense;
|
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
|
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.
|
// From joining, and again from a restart after losing every village.
|
||||||
$since = $player->protected_since ?? $player->created_at->toImmutable();
|
$since = $player->protected_since ?? $player->created_at->toImmutable();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ 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 (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.
|
* switches as booleans. Labels and formatting are the client's.
|
||||||
*/
|
*/
|
||||||
final class WorldPresenter
|
final class WorldPresenter
|
||||||
|
|
@ -26,8 +26,8 @@ final class WorldPresenter
|
||||||
'pace' => [
|
'pace' => [
|
||||||
'speed' => $speed,
|
'speed' => $speed,
|
||||||
'unit_speed' => (float) $config->get('movement.unit_speed', 1),
|
'unit_speed' => (float) $config->get('movement.unit_speed', 1),
|
||||||
'protection' => $seconds($config->get('combat.beginner_protection', 0)),
|
|
||||||
// Real time, not world time.
|
// Real time, not world time.
|
||||||
|
'protection' => (int) $config->get('combat.beginner_protection', 0),
|
||||||
'inactive' => (int) ($config->get('world.inactive_days', 0) * 86400),
|
'inactive' => (int) ($config->get('world.inactive_days', 0) * 86400),
|
||||||
],
|
],
|
||||||
'village' => [
|
'village' => [
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,10 @@ return [
|
||||||
// Levied villagers defend with these values per head.
|
// Levied villagers defend with these values per head.
|
||||||
'militia' => ['defense' => ['infantry' => 5, 'cavalry' => 5, 'archer' => 5]],
|
'militia' => ['defense' => ['infantry' => 5, 'cavalry' => 5, 'archer' => 5]],
|
||||||
|
|
||||||
// New players can't be attacked by players for this long after joining (seconds at
|
// New players can't be attacked by players for this long after joining, and can't
|
||||||
// world speed 1), and can't attack players themselves meanwhile; barbarians are fine.
|
// attack players themselves meanwhile; barbarians are fine. Real seconds, as in Die
|
||||||
'beginner_protection' => 3 * 86400,
|
// 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)
|
// 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
|
// come back wounded, as far as its hospitals have free beds. The wounded eat like
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ it('leaves a village at loyalty 0 when the coins pay for no more villages, and t
|
||||||
$victim = startVillage();
|
$victim = startVillage();
|
||||||
$village = nobleVillage(['spear' => 100, 'nobleman' => 2]);
|
$village = nobleVillage(['spear' => 100, 'nobleman' => 2]);
|
||||||
$village->player->update(['coins' => 0]);
|
$village->player->update(['coins' => 0]);
|
||||||
$this->travel(4)->days();
|
$this->travel(6)->days();
|
||||||
$victim->update(['loyalty' => 0, 'loyalty_at' => now()]);
|
$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);
|
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->buildings()->create(['type' => 'rally_point', 'level' => 1]);
|
||||||
$victim->troops()->create(['home_village_id' => $victim->id, 'unit' => 'spear', 'count' => 3]);
|
$victim->troops()->create(['home_village_id' => $victim->id, 'unit' => 'spear', 'count' => 3]);
|
||||||
$village = nobleVillage(['spear' => 100, 'nobleman' => 1]);
|
$village = nobleVillage(['spear' => 100, 'nobleman' => 1]);
|
||||||
$this->travel(4)->days();
|
$this->travel(6)->days();
|
||||||
$victim->update(['loyalty' => 5, 'loyalty_at' => now()]);
|
$victim->update(['loyalty' => 5, 'loyalty_at' => now()]);
|
||||||
|
|
||||||
// The victim has a build order and support standing in the attacker's village.
|
// The victim has a build order and support standing in the attacker's village.
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ it('tells a world settings in plain units', function () {
|
||||||
$village = startVillage();
|
$village = startVillage();
|
||||||
$settings = app(ListWorlds::class)->settings($village->world_id)['settings'];
|
$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['village'])->toMatchArray(['space' => 40, 'space_per_hq_level' => 5])
|
||||||
->and($settings['tribes'])->toBe(['max_members' => 25, 'notice' => 86400])
|
->and($settings['tribes'])->toBe(['max_members' => 25, 'notice' => 86400])
|
||||||
->and($settings['season'])->toMatchArray(['crowns' => 5, 'needed' => 3, 'hold' => 7 * 86400])
|
->and($settings['season'])->toMatchArray(['crowns' => 5, 'needed' => 3, 'hold' => 7 * 86400])
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ function pendingRaid(Village $village): ?CarbonImmutable
|
||||||
/** Past beginner protection, with the band announced. */
|
/** Past beginner protection, with the band announced. */
|
||||||
function announced(Village $village): Movement
|
function announced(Village $village): Movement
|
||||||
{
|
{
|
||||||
test()->travel(3)->days();
|
test()->travel(5)->days();
|
||||||
test()->artisan('game:events --once')->assertSuccessful();
|
test()->artisan('game:events --once')->assertSuccessful();
|
||||||
|
|
||||||
return Movement::where('target_id', $village->id)->sole();
|
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 () {
|
it('plans the first raid for when beginner protection ends', function () {
|
||||||
$village = startVillage();
|
$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 () {
|
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)
|
expect($movement->origin_id)->toBe($camp->id)
|
||||||
->and($movement->player_id)->toBeNull()
|
->and($movement->player_id)->toBeNull()
|
||||||
->and($movement->units)->toBe(['spear' => 4, 'sword' => 2])
|
->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];
|
$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();
|
->and($incoming['units'])->toBeNull();
|
||||||
|
|
||||||
$next = pendingRaid($village);
|
$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);
|
$movement = announced($village);
|
||||||
|
|
||||||
// Three real hours of gathering, then 3 fields at 22 minutes / 100.
|
// 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);
|
->and($movement->sent_at->diffInSeconds($movement->arrives_at))->toBeLessThan(60);
|
||||||
$next = pendingRaid($village);
|
$next = pendingRaid($village);
|
||||||
expect($next->greaterThanOrEqualTo($movement->arrives_at->addHours(20)))->toBeTrue()
|
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);
|
raidCamp($village);
|
||||||
// 100 swordsmen hold 5000 against the band's 90: less than 30% of the defence.
|
// 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]);
|
$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();
|
$this->artisan('game:events --once')->assertSuccessful();
|
||||||
|
|
||||||
$next = pendingRaid($village);
|
$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.
|
// 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]);
|
$village->troops()->create(['home_village_id' => $village->id, 'unit' => 'sword', 'count' => 4]);
|
||||||
$movement = announced($village);
|
$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'];
|
$wood = shown($village)['resources']['wood'];
|
||||||
arrive($movement);
|
arrive($movement);
|
||||||
|
|
||||||
|
|
@ -199,7 +201,7 @@ it('plans raids for villages from before raids on deploy', function () {
|
||||||
GameEvent::where('type', GameEvent::RAID_PLANNED)->delete();
|
GameEvent::where('type', GameEvent::RAID_PLANNED)->delete();
|
||||||
|
|
||||||
(new WorldSeeder)->run();
|
(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();
|
(new WorldSeeder)->run();
|
||||||
expect(GameEvent::where('type', GameEvent::RAID_PLANNED)->count())->toBe(1);
|
expect(GameEvent::where('type', GameEvent::RAID_PLANNED)->count())->toBe(1);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Actions\CancelMovement;
|
use App\Actions\CancelMovement;
|
||||||
|
use App\Actions\ListWorlds;
|
||||||
use App\Actions\QueueUpgrade;
|
use App\Actions\QueueUpgrade;
|
||||||
use App\Actions\SendSupportHome;
|
use App\Actions\SendSupportHome;
|
||||||
use App\Actions\SendTroops;
|
use App\Actions\SendTroops;
|
||||||
|
|
@ -188,8 +189,27 @@ it('refuses what the rally point cannot do', function () {
|
||||||
->and(rule(fn () => send($village, barbarianNear($village, 3, 4), ['spear' => 5], 'support')))->toBe('barbarian')
|
->and(rule(fn () => send($village, barbarianNear($village, 3, 4), ['spear' => 5], 'support')))->toBe('barbarian')
|
||||||
->and(Movement::count())->toBe(0);
|
->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();
|
$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]);
|
send($village, $other, ['spear' => 5]);
|
||||||
expect(Movement::count())->toBe(1);
|
expect(Movement::count())->toBe(1);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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));
|
$camp = app(VillageFactory::class)->create($village->world, null, 'Barbarian village', $village->x + 3, $village->y, array_fill_keys($types, 8));
|
||||||
Barbarians::of($camp)->fill();
|
Barbarians::of($camp)->fill();
|
||||||
|
|
||||||
$this->travel(3)->days();
|
$this->travel(5)->days();
|
||||||
$this->artisan('game:events --once')->assertSuccessful();
|
$this->artisan('game:events --once')->assertSuccessful();
|
||||||
$raid = Movement::where('target_id', $village->id)->sole();
|
$raid = Movement::where('target_id', $village->id)->sole();
|
||||||
// Spears that lose to the band on their own (15 defence each) but hold with +10%.
|
// Spears that lose to the band on their own (15 defence each) but hold with +10%.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue