54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
|
||
|
|
class Village extends Model
|
||
|
|
{
|
||
|
|
protected $guarded = [];
|
||
|
|
|
||
|
|
// resources_at keeps milliseconds, so ordering with events is exact.
|
||
|
|
protected $dateFormat = 'Y-m-d H:i:s.v';
|
||
|
|
|
||
|
|
protected function casts(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'wood' => 'float',
|
||
|
|
'clay' => 'float',
|
||
|
|
'iron' => 'float',
|
||
|
|
'food' => 'float',
|
||
|
|
'resources_at' => 'immutable_datetime',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function world(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(World::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function player(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Player::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function buildings(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(Building::class)->orderBy('id');
|
||
|
|
}
|
||
|
|
|
||
|
|
/** In queue order. */
|
||
|
|
public function orders(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(BuildOrder::class)->orderBy('id');
|
||
|
|
}
|
||
|
|
|
||
|
|
/** @return array{wood: float, clay: float, iron: float, food: float} */
|
||
|
|
public function resources(): array
|
||
|
|
{
|
||
|
|
return ['wood' => $this->wood, 'clay' => $this->clay, 'iron' => $this->iron, 'food' => $this->food];
|
||
|
|
}
|
||
|
|
}
|