feat: raids follow real hours (every 20 to 40, three hours of warning) on every world, only the band marches at world speed; half a ram per wall level
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8fa72392c7
commit
1780ee510a
|
|
@ -95,18 +95,18 @@ final class Raids
|
|||
return array_fill_keys(self::RESOURCES, $each);
|
||||
}
|
||||
|
||||
/** Seconds until the next raid, at world speed, from a roll in [0, 1). */
|
||||
/** Real seconds until the next raid, from a roll in [0, 1); world speed doesn't shorten them. */
|
||||
public function interval(float $roll): int
|
||||
{
|
||||
[$min, $max] = $this->config->get('raids.every_hours');
|
||||
|
||||
return max(1, (int) round(($min + ($max - $min) * $roll) * 3600 / $this->config->speed()));
|
||||
return max(1, (int) round(($min + ($max - $min) * $roll) * 3600));
|
||||
}
|
||||
|
||||
/** How long a band gathers at its camp before it marches, at world speed. */
|
||||
/** How long a band gathers at its camp before it marches, in real seconds. */
|
||||
public function gatherSeconds(): int
|
||||
{
|
||||
return (int) round($this->config->get('raids.gather_hours', 0) * 3600 / $this->config->speed());
|
||||
return (int) round($this->config->get('raids.gather_hours', 0) * 3600);
|
||||
}
|
||||
|
||||
public function mode(): string
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ 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, shares as percent, switches as booleans. Labels and
|
||||
* formatting are the client's.
|
||||
* seconds at the world's speed (inactivity and raids in real seconds), shares as percent,
|
||||
* switches as booleans. Labels and formatting are the client's.
|
||||
*/
|
||||
final class WorldPresenter
|
||||
{
|
||||
|
|
@ -44,9 +44,10 @@ final class WorldPresenter
|
|||
'loyalty_drop' => $drop,
|
||||
'loyalty_regen' => round($config->get('combat.conquest.loyalty.regen_per_hour', 1) * $speed, 2),
|
||||
],
|
||||
// Real time, not world time.
|
||||
'raids' => (bool) $config->get('raids.enabled') ? [
|
||||
'every' => [$seconds($raidMin * 3600), $seconds($raidMax * 3600)],
|
||||
'warning' => $seconds($config->get('raids.gather_hours', 0) * 3600),
|
||||
'every' => [(int) round($raidMin * 3600), (int) round($raidMax * 3600)],
|
||||
'warning' => (int) round($config->get('raids.gather_hours', 0) * 3600),
|
||||
'range' => (int) $config->get('raids.range'),
|
||||
] : null,
|
||||
'tribes' => [
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
<?php
|
||||
|
||||
// Raiders (architecture.md, "Raids"): the nearest barbarian camp sends a band at every
|
||||
// player village now and then, announced while it gathers. Hours are at world speed 1.
|
||||
// player village now and then, announced while it gathers. every_hours and gather_hours
|
||||
// are real hours on every world: they follow the player's day, not world time. The band
|
||||
// marches at world speed.
|
||||
|
||||
return [
|
||||
'enabled' => true,
|
||||
|
||||
// Hours between two raids on one village, drawn evenly between the two. The first
|
||||
// comes when beginner protection ends.
|
||||
'every_hours' => [18, 30],
|
||||
'every_hours' => [20, 40],
|
||||
|
||||
// The band gathers this long at its camp before it marches; the village sees it
|
||||
// coming from the start, so this is the least warning it gets.
|
||||
|
|
@ -20,8 +22,9 @@ return [
|
|||
// Attack strength of a band: base + per_point × the village's points, in its camp's profile.
|
||||
'attack' => ['base' => 50, 'per_point' => 1.5],
|
||||
|
||||
// From this many village points on, rams come along: per_wall_level for each wall level.
|
||||
'rams' => ['from_points' => 300, 'per_wall_level' => 1.0],
|
||||
// From this many village points on, rams come along: per_wall_level for each wall
|
||||
// level, rounded.
|
||||
'rams' => ['from_points' => 300, 'per_wall_level' => 0.5],
|
||||
|
||||
// On arrival the band is as strong as its camp's garrison is (share of full strength);
|
||||
// below scatter_below it scatters, so hitting the camp first breaks the raid.
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
use App\Actions\ListWorlds;
|
||||
use App\Engine\Barbarians;
|
||||
use App\Engine\VillageFactory;
|
||||
use App\Models\GameEvent;
|
||||
use App\Models\Movement;
|
||||
use App\Models\Report;
|
||||
use App\Models\Village;
|
||||
use App\Models\World;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\WorldSeeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
|
@ -72,8 +74,39 @@ it('announces a band from the nearest camp hours before it arrives, and plans th
|
|||
->and($incoming['units'])->toBeNull();
|
||||
|
||||
$next = pendingRaid($village);
|
||||
expect($next->greaterThanOrEqualTo($movement->arrives_at->addHours(18)))->toBeTrue()
|
||||
->and($next->lessThanOrEqualTo($movement->arrives_at->addHours(30)))->toBeTrue();
|
||||
expect($next->greaterThanOrEqualTo($movement->arrives_at->addHours(20)))->toBeTrue()
|
||||
->and($next->lessThanOrEqualTo($movement->arrives_at->addHours(40)))->toBeTrue();
|
||||
});
|
||||
|
||||
it('times raids in real hours on a fast world; only the march runs at world speed', function () {
|
||||
$village = startVillage();
|
||||
raidCamp($village);
|
||||
World::whereKey($village->world_id)->update(['config' => ['world' => ['speed' => 100]]]);
|
||||
$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')
|
||||
->and($movement->sent_at->diffInSeconds($movement->arrives_at))->toBeLessThan(60);
|
||||
$next = pendingRaid($village);
|
||||
expect($next->greaterThanOrEqualTo($movement->arrives_at->addHours(20)))->toBeTrue()
|
||||
->and($next->lessThanOrEqualTo($movement->arrives_at->addHours(40)))->toBeTrue()
|
||||
->and(app(ListWorlds::class)->settings($village->world_id)['settings']['raids'])->toMatchArray(['every' => [20 * 3600, 40 * 3600], 'warning' => 3 * 3600]);
|
||||
});
|
||||
|
||||
it('brings a ram for every two wall levels; they fire half before the battle and the rest after winning it', function () {
|
||||
$village = startVillage();
|
||||
raidCamp($village);
|
||||
$village->buildings()->create(['type' => 'wall', 'level' => 10]);
|
||||
$village->update(['points' => 1000]);
|
||||
$movement = announced($village);
|
||||
expect($movement->units['ram'])->toBe(5);
|
||||
arrive($movement);
|
||||
|
||||
// 2.5 rams can't take wall 10 (4.35 needed); after the won battle the other 2.5 can.
|
||||
$report = Report::where('player_id', $village->player_id)->sole()->payload;
|
||||
expect($report['won'])->toBeTrue()
|
||||
->and($report['wall'])->toBe(['before' => 10, 'after' => 9])
|
||||
->and($village->buildings()->where('type', 'wall')->value('level'))->toBe(9);
|
||||
});
|
||||
|
||||
it('loots an undefended village and carries the loot back to its camp', function () {
|
||||
|
|
|
|||
|
|
@ -13,10 +13,12 @@ it('sizes a band by the village points in its camp profile', function () {
|
|||
->and($raids->band(null, 300, 0))->toBe([]);
|
||||
});
|
||||
|
||||
it('brings rams against the wall of a big enough village', function () {
|
||||
it('brings a ram for every two wall levels of a big enough village', function () {
|
||||
$raids = new Raids(gameConfig());
|
||||
|
||||
expect($raids->band('swordsmen', 300, 5))->toHaveKey('ram', 5)
|
||||
expect($raids->band('swordsmen', 300, 4))->toHaveKey('ram', 2)
|
||||
->and($raids->band('swordsmen', 300, 5))->toHaveKey('ram', 3)
|
||||
->and($raids->band('swordsmen', 300, 1))->toHaveKey('ram', 1)
|
||||
->and($raids->band('swordsmen', 299, 5))->not->toHaveKey('ram')
|
||||
->and($raids->band('swordsmen', 300, 0))->not->toHaveKey('ram');
|
||||
});
|
||||
|
|
@ -36,15 +38,15 @@ it('leaves half its attack strength as bounty when beaten', function () {
|
|||
expect((new Raids(gameConfig()))->bounty(['spear' => 25, 'sword' => 10]))->toBe(['wood' => 83, 'clay' => 83, 'iron' => 83]);
|
||||
});
|
||||
|
||||
it('comes every 18 to 30 hours at world speed, after a few hours of warning', function () {
|
||||
it('comes every 20 to 40 real hours on any world, after three real hours of warning', function () {
|
||||
$raids = new Raids(gameConfig());
|
||||
$fast = new Raids(gameConfig(['world' => ['speed' => 100]]));
|
||||
|
||||
expect($raids->interval(0.0))->toBe(18 * 3600)
|
||||
->and($raids->interval(0.5))->toBe(24 * 3600)
|
||||
->and($fast->interval(0.5))->toBe(864)
|
||||
expect($raids->interval(0.0))->toBe(20 * 3600)
|
||||
->and($raids->interval(0.5))->toBe(30 * 3600)
|
||||
->and($fast->interval(0.5))->toBe(30 * 3600)
|
||||
->and($raids->gatherSeconds())->toBe(3 * 3600)
|
||||
->and($fast->gatherSeconds())->toBe(108);
|
||||
->and($fast->gatherSeconds())->toBe(3 * 3600);
|
||||
});
|
||||
|
||||
it('picks the nearest camp in range', function () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue