23 lines
614 B
PHP
23 lines
614 B
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
namespace App\Game\Economy;
|
|||
|
|
|
|||
|
|
/** Lazy resources: stored + rate × elapsed, kept between 0 and the storage cap. */
|
|||
|
|
final class Settle
|
|||
|
|
{
|
|||
|
|
/**
|
|||
|
|
* @param array<string, float> $stored
|
|||
|
|
* @param array<string, float> $rates per hour
|
|||
|
|
* @return array<string, float>
|
|||
|
|
*/
|
|||
|
|
public static function advance(array $stored, array $rates, float $cap, float $hours): array
|
|||
|
|
{
|
|||
|
|
$result = [];
|
|||
|
|
foreach ($stored as $resource => $amount) {
|
|||
|
|
$result[$resource] = min($cap, max(0.0, $amount + ($rates[$resource] ?? 0.0) * $hours));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return $result;
|
|||
|
|
}
|
|||
|
|
}
|