47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/** A shipment from a village repeated every `every` real seconds; a trade.route event at next_at sends it. */
|
|
class TradeRoute extends Model
|
|
{
|
|
public const OWNER_CHANGED = 'owner_changed';
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $dateFormat = 'Y-m-d H:i:s.v';
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'wood' => 'integer',
|
|
'clay' => 'integer',
|
|
'iron' => 'integer',
|
|
'every' => 'integer',
|
|
'paused' => 'boolean',
|
|
'next_at' => 'immutable_datetime',
|
|
'last_sent_at' => 'immutable_datetime',
|
|
'last_cargo' => 'array',
|
|
];
|
|
}
|
|
|
|
public function village(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Village::class);
|
|
}
|
|
|
|
public function target(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Village::class, 'target_id');
|
|
}
|
|
|
|
/** @return array{wood: int, clay: int, iron: int} */
|
|
public function amounts(): array
|
|
{
|
|
return ['wood' => $this->wood, 'clay' => $this->clay, 'iron' => $this->iron];
|
|
}
|
|
}
|