game-village-politics-backend/app/Presenters/WorldPresenter.php

66 lines
3.0 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Presenters;
use App\Game\Map\Season;
use App\Game\Tribes\Diplomacy;
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, 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();
$night = $config->get('combat.night');
$season = new Season($config);
[$raidMin, $raidMax] = $config->get('raids.every_hours', [0, 0]);
$drop = $config->get('combat.conquest.loyalty.drop', [20, 35]);
return [
'pace' => [
'speed' => $speed,
'unit_speed' => (float) $config->get('movement.unit_speed', 1),
// Real time, not world time.
'protection' => (int) $config->get('combat.beginner_protection', 0),
'inactive' => (int) ($config->get('world.inactive_days', 0) * 86400),
],
'village' => [
'space' => (int) $config->get('world.village.space'),
'space_per_hq_level' => (int) $config->get('world.village.space_per_hq_level'),
'builders' => (int) $config->get('world.builders.base', 2),
'map_size' => (int) $config->get('world.map.size'),
],
'combat' => [
'morale' => (bool) ($config->get('combat.morale.enabled') ?? false),
'luck' => (int) round($config->get('combat.luck', 0) * 100),
'night' => ($night['enabled'] ?? false) ? ['start' => $night['start'], 'end' => $night['end'], 'factor' => $night['factor']] : null,
'noble_distance' => (int) $config->get('combat.conquest.max_distance', 0),
'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' => [(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' => [
'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' => (int) round($config->get('world.season.crowns_after_days', 30) * 86400),
'hold' => $season->holdSeconds(),
] : null,
];
}
}